id
stringlengths
36
36
text
stringlengths
1
1.25M
feeffde4-0214-4fb1-b572-ee648ad0b4a8
public FHeapNode getParent(){ return parent; }
3afcd1b3-28af-4d0c-90a9-1106c556a887
public void setParent(FHeapNode parent){ this.parent = parent; }
400d07dc-3021-47b3-9993-a83255483e4a
public FHeapNode getChild(){ return child; }
f19d6b5a-a24c-4adb-848e-5998c185b95c
public void setChild(FHeapNode child){ this.child = child; }
63f59eb2-31ef-4930-9c63-197fe4640942
public boolean isMarked(){ return marked; }
97354464-4a28-4ebe-9142-b96eaa0393f7
public void setMarked(boolean marked){ this.marked = marked; }
8d5ca331-bcae-4106-b0bc-8854f02f27ae
public int getDegree(){ return degree; }
91b43fbf-4623-4991-97e8-ee69aafee94c
public void setDegree(int degree){ this.degree = degree; }
9b5fd416-5877-454b-854f-3560943c0297
public int getIndex(){ return index; }
6360c6f5-d234-4075-bd49-1364e8f987dd
public void setIndex(int index){ this.index = index; }
3a17de66-8625-43e6-8072-7e8196346a1f
public int getPredecessor(){ return predecessor; }
cdb0218a-4294-4446-a277-19baf86b3042
public void setPredecessor(int predecessor){ this.predecessor = predecessor; }
0446e7db-de12-46a1-b4a9-301d26569dcc
public boolean isAlreadyInMST(){ return alreadyInMST; }
dd974b93-e148-49fe-8826-828dc221c81f
public void setAlreadyInMST(boolean alreadyInMST){ this.alreadyInMST = alreadyInMST; }
0266fc90-323f-454e-a99c-24b5ad9a2e90
@PreUpdate void preUpdate(final BaseEntity entity) { entity.setModified(Calendar.getInstance()); }
0656c744-c909-487f-b602-fe3fabdd487a
@PrePersist void prePersist(final BaseEntity entity) { entity.setCreated(Calendar.getInstance()); // set modified as well entity.setModified(Calendar.getInstance()); }
6ac8343d-4b97-4a25-b4ce-780a858ab0b6
public static String convertCalendar(final Calendar calendar) { String formattedCalendar = null; if (calendar != null) { final DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); formattedCalendar = formatter.format(calendar.getTime()); } return formattedCalendar; }
84b83b6e-72a2-41a2-a6fa-86d3e2986d2f
public String getName() { return name; }
f1ef7382-e9f4-4c1e-8582-aff9565b7b00
public void setName(final String name) { this.name = name; }
5d37b3b9-338e-4f0c-b53a-a758b265b336
public String getValue() { return value; }
9249dda3-8d55-4aa6-956a-a7aefa0267f2
public void setValue(final String value) { this.value = value; }
4b09e0ec-6150-4ea0-9208-a6664977980b
public Calendar getCreated() { return created; }
8b7af0f3-3ecf-46ce-a592-cb8dc24720c9
public void setCreated(final Calendar created) { this.created = created; }
1ed28a94-39c9-43b2-a250-56b35629fe8b
public Calendar getModified() { return modified; }
be7bc8de-dcc1-4492-a51c-e94a14e75c6a
public void setModified(final Calendar modified) { this.modified = modified; }
558e2fb8-5354-4a16-a145-b6493e7ee8bf
public int getVersion() { return version; }
52fdfea2-3f47-46b2-a6cf-275c4ce00d4c
public void setVersion(final int version) { this.version = version; }
5cc83b5d-9991-4f8c-ba1d-78e0e0e02eb3
public Long getId() { return id; }
4b0c4f42-e185-41c3-9fa7-a3aa113a5837
public void setId(final Long id) { this.id = id; }
8ec5fb21-3f39-4201-9453-f0360c4701a5
public Parent getParent() { return parent; }
d0b31cbd-b783-4f16-879f-67980b9fb64b
public void setParent(final Parent parent) { this.parent = parent; }
fd642971-bcc2-482f-ba30-7a3a56312689
@Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("Child ["); builder.append("ID="); builder.append(id); builder.append("; NAME="); builder.append(name); builder.append("; VALUE="); builder.append(value); builder.append("; CREATED="); builder.append(DateHelper.convertCalendar(created)); builder.append("; MODIFIED="); builder.append(DateHelper.convertCalendar(modified)); builder.append("; VERSION="); builder.append(version); builder.append("]"); return builder.toString(); }
88fb1a8f-c15f-4c1a-b503-6f6b8fa0e81c
public Long getId() { return id; }
c6926c02-541e-4720-893b-ab6d6cc950b6
public void setId(final Long id) { this.id = id; }
4f4d112f-52da-4cc8-92bf-4b8776e411ea
public List<Child> getChildList() { return childList; }
8fa6e81e-3f9f-4866-852a-0be2ae91341c
public List<Child> getChildListSortedByName() { // need to use a new ArrayList for sorting otherwise collection is marked dirty by OpenJPA final List<Child> list = new ArrayList<Child>(getChildList()); Collections.sort(list, new ChildComparator()); return list; }
085e0795-3c3f-4ebf-ad75-c0f2567d389b
public void setChildList(final List<Child> childList) { this.childList = childList; }
54e243f2-39a4-40f0-b3af-0470fb07e1d3
public void addChild(final Child child) { child.setParent(this); if (childList == null) { childList = new ArrayList<Child>(); } childList.add(child); }
7e3ac15b-ebe5-4685-9857-7607ab4b326d
public void removeChild(final Child child) { if (childList != null) { childList.remove(child); child.setParent(null); } }
d7948b57-0d3d-4e9b-8933-07fcb8627b15
@Override public int compare(final Child element1, final Child element2) { return element1.getName().compareTo(element2.getName()); }
3053753c-46b9-44a5-8f15-695f59f0ace9
@Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("Parent ["); builder.append("ID="); builder.append(id); builder.append("; NAME="); builder.append(name); builder.append("; VALUE="); builder.append(value); builder.append("; CREATED="); builder.append(DateHelper.convertCalendar(created)); builder.append("; MODIFIED="); builder.append(DateHelper.convertCalendar(modified)); builder.append("; VERSION="); builder.append(version); builder.append("]"); return builder.toString(); }
5b4a010f-6735-4b66-9fac-3033c0c9ce45
@Before public void setUp() { emf = Persistence.createEntityManagerFactory("pu"); em = emf.createEntityManager(); try { createTestData(); } catch (final Exception e) { e.printStackTrace(); System.err.println("Error creating tables and data."); } }
225cb704-ae37-4537-a258-9e6d7d9639d2
@After public void tearDown() { try { removeTestData(); } catch (final Exception e) { e.printStackTrace(); System.err.println("Error removing data."); } if (em != null) { em.close(); } if (emf != null) { emf.close(); } }
9f8a7be4-1769-436e-8f15-734435f689d8
private void createTestData() throws Exception { final Parent parent = new Parent(); parent.setName("Parent"); final Child child1 = new Child(); child1.setName("Child1"); parent.addChild(child1); final Child child2 = new Child(); child2.setName("Child2"); parent.addChild(child2); final Child child3 = new Child(); child3.setName("Child3"); parent.addChild(child3); final Child child4 = new Child(); child4.setName("Child4"); parent.addChild(child4); em.getTransaction().begin(); em.persist(parent); em.getTransaction().commit(); }
1501a921-8dc7-4d0e-997f-67c750d803ec
private void removeTestData() throws Exception { em.getTransaction().begin(); em.createNativeQuery(DROP_ALL_OBJECTS).executeUpdate(); em.getTransaction().commit(); }
f3fcbd01-c58d-45e6-9c77-cab66f4e141c
protected BaseEntity detachEntity(final BaseEntity entity) { serialize(entity); return deserialize(); }
c011a883-5faa-4053-a697-4f1d9e0b8e6b
private void serialize(final BaseEntity entity) { FileOutputStream fout; try { fout = new FileOutputStream(FILE_NAME); final ObjectOutputStream objout = new ObjectOutputStream(fout); // write object objout.writeObject(entity); } catch (final FileNotFoundException e) { e.printStackTrace(); } catch (final IOException ioe) { ioe.printStackTrace(); } }
c6ccb240-94ae-4a0f-956d-8f8a24218166
private BaseEntity deserialize() { FileInputStream fin; try { fin = new FileInputStream(FILE_NAME); final ObjectInputStream objin = new ObjectInputStream(fin); // read object return (BaseEntity) objin.readObject(); } catch (final FileNotFoundException e) { e.printStackTrace(); return null; } catch (final IOException ioe) { ioe.printStackTrace(); return null; } catch (final ClassNotFoundException e) { e.printStackTrace(); return null; } }
a6a6cf2b-b1e9-42e1-8df4-cb7c880fbb82
protected Parent fetchData() { final Parent parent = (Parent) em.createQuery("SELECT p FROM Parent p WHERE p.id = 1").getSingleResult(); System.out.println(parent.toString()); for (final Child child : parent.getChildListSortedByName()) { System.out.println(child.toString()); } return parent; }
ec27db4b-029d-4853-ae49-fa1d07c791db
@Test public void updateParent() { Parent parent = fetchData(); System.out.println("Now updating Parent..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // change name of parent parent.setValue(TEST); // save parent with children em.getTransaction().begin(); em.merge(parent); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertEquals(parent.getChildList().get(0).getCreated(), parent.getChildList().get(0).getModified()); Assert.assertEquals(parent.getChildList().get(1).getCreated(), parent.getChildList().get(1).getModified()); Assert.assertEquals(parent.getChildList().get(2).getCreated(), parent.getChildList().get(2).getModified()); Assert.assertEquals(parent.getChildList().get(3).getCreated(), parent.getChildList().get(3).getModified()); Assert.assertEquals(2, parent.getVersion()); Assert.assertEquals(1, parent.getChildList().get(0).getVersion()); Assert.assertEquals(1, parent.getChildList().get(1).getVersion()); Assert.assertEquals(1, parent.getChildList().get(2).getVersion()); Assert.assertEquals(1, parent.getChildList().get(3).getVersion()); }
83fa3447-a443-49a3-91d4-b7a19cea0c7f
@Test public void updateChild() { Parent parent = fetchData(); System.out.println("Now updating Child..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // change name of first child parent.getChildList().get(0).setValue(TEST); // save parent with children em.getTransaction().begin(); em.merge(parent); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertEquals(parent.getCreated(), parent.getModified()); Assert.assertFalse(parent.getChildList().get(0).getCreated().equals(parent.getChildList().get(0).getModified())); Assert.assertEquals(parent.getChildList().get(1).getCreated(), parent.getChildList().get(1).getModified()); Assert.assertEquals(parent.getChildList().get(2).getCreated(), parent.getChildList().get(2).getModified()); Assert.assertEquals(parent.getChildList().get(3).getCreated(), parent.getChildList().get(3).getModified()); Assert.assertEquals(1, parent.getVersion()); Assert.assertEquals(2, parent.getChildList().get(0).getVersion()); Assert.assertEquals(1, parent.getChildList().get(1).getVersion()); Assert.assertEquals(1, parent.getChildList().get(2).getVersion()); Assert.assertEquals(1, parent.getChildList().get(3).getVersion()); }
81fdb73e-29d9-4810-80cd-e74bbdf276b1
@Test public void addChildToParent() { Parent parent = fetchData(); System.out.println("Now adding Child to Parent..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // add a new child to parent final Child child5 = new Child(); child5.setName("Child5"); child5.setValue(TEST); parent.addChild(child5); // save parent with children em.getTransaction().begin(); em.merge(parent); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertFalse(parent.getCreated().equals(parent.getModified())); Assert.assertTrue(parent.getChildList().get(0).getCreated().equals(parent.getChildList().get(0).getModified())); Assert.assertTrue(parent.getChildList().get(1).getCreated().equals(parent.getChildList().get(1).getModified())); Assert.assertTrue(parent.getChildList().get(2).getCreated().equals(parent.getChildList().get(2).getModified())); Assert.assertTrue(parent.getChildList().get(3).getCreated().equals(parent.getChildList().get(3).getModified())); Assert.assertEquals(2, parent.getVersion()); Assert.assertEquals(1, parent.getChildList().get(0).getVersion()); Assert.assertEquals(1, parent.getChildList().get(1).getVersion()); Assert.assertEquals(1, parent.getChildList().get(2).getVersion()); Assert.assertEquals(1, parent.getChildList().get(3).getVersion()); Assert.assertEquals(1, parent.getChildList().get(4).getVersion()); }
d5b6a050-890c-4617-871a-f4040e1d53ec
@Test public void removeChildFromParent() { Parent parent = fetchData(); System.out.println("Now removing Child from Parent..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // remove child from parent parent.getChildList().remove(parent.getChildList().get(0)); // save parent with children em.getTransaction().begin(); em.merge(parent); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertFalse(parent.getCreated().equals(parent.getModified())); Assert.assertTrue(parent.getChildList().get(0).getCreated().equals(parent.getChildList().get(0).getModified())); Assert.assertTrue(parent.getChildList().get(1).getCreated().equals(parent.getChildList().get(1).getModified())); Assert.assertTrue(parent.getChildList().get(2).getCreated().equals(parent.getChildList().get(2).getModified())); Assert.assertEquals(2, parent.getVersion()); Assert.assertEquals(1, parent.getChildList().get(0).getVersion()); Assert.assertEquals(1, parent.getChildList().get(1).getVersion()); Assert.assertEquals(1, parent.getChildList().get(2).getVersion()); }
5e190668-09ea-46cb-adf5-c329bc527aaf
@Test public void updateChild() { Parent parent = fetchData(); System.out.println("Now updating Child..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // change name of first child parent.getChildList().get(0).setValue(TEST); // save parent with children em.getTransaction().begin(); em.merge(parent.getChildList().get(0)); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertEquals(parent.getCreated(), parent.getModified()); Assert.assertFalse(parent.getChildListSortedByName().get(0).getCreated().equals(parent.getChildListSortedByName().get(0).getModified())); Assert.assertEquals(parent.getChildListSortedByName().get(1).getCreated(), parent.getChildListSortedByName().get(1).getModified()); Assert.assertEquals(parent.getChildListSortedByName().get(2).getCreated(), parent.getChildListSortedByName().get(2).getModified()); Assert.assertEquals(parent.getChildListSortedByName().get(3).getCreated(), parent.getChildListSortedByName().get(3).getModified()); Assert.assertEquals(1, parent.getVersion()); Assert.assertEquals(2, parent.getChildListSortedByName().get(0).getVersion()); Assert.assertEquals(1, parent.getChildListSortedByName().get(1).getVersion()); Assert.assertEquals(1, parent.getChildListSortedByName().get(2).getVersion()); Assert.assertEquals(1, parent.getChildListSortedByName().get(3).getVersion()); }
26324a92-8c6b-4d3c-b983-a44601594678
@Test public void addChildToParent() { Parent parent = fetchData(); System.out.println("Now adding Child to Parent..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // add child to parent final Child child5 = new Child(); child5.setName("Child5"); child5.setValue(TEST); parent.addChild(child5); // save new child em.getTransaction().begin(); em.persist(child5); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertEquals(parent.getCreated(), parent.getModified()); Assert.assertEquals(parent.getChildList().get(0).getCreated(), parent.getChildList().get(0).getModified()); Assert.assertEquals(parent.getChildList().get(1).getCreated(), parent.getChildList().get(1).getModified()); Assert.assertEquals(parent.getChildList().get(2).getCreated(), parent.getChildList().get(2).getModified()); Assert.assertEquals(parent.getChildList().get(3).getCreated(), parent.getChildList().get(3).getModified()); Assert.assertEquals(1, parent.getVersion()); Assert.assertEquals(1, parent.getChildList().get(0).getVersion()); Assert.assertEquals(1, parent.getChildList().get(1).getVersion()); Assert.assertEquals(1, parent.getChildList().get(2).getVersion()); Assert.assertEquals(1, parent.getChildList().get(3).getVersion()); Assert.assertEquals(1, parent.getChildList().get(4).getVersion()); }
b2ac4572-35c8-487b-b065-c32d55b2f6e2
@Test public void removeChildFromParent() { Parent parent = fetchData(); System.out.println("Now removing Child from Parent..."); // serialize entity in order to detach parent = (Parent) detachEntity(parent); em.clear(); // remove a child em.getTransaction().begin(); final Query query = em.createQuery("DELETE FROM Child c WHERE c.id = " + parent.getChildList().get(0).getId()); query.executeUpdate(); em.getTransaction().commit(); // reread parent parent = fetchData(); Assert.assertEquals(parent.getCreated(), parent.getModified()); Assert.assertEquals(parent.getChildList().get(0).getCreated(), parent.getChildList().get(0).getModified()); Assert.assertEquals(parent.getChildList().get(1).getCreated(), parent.getChildList().get(1).getModified()); Assert.assertEquals(parent.getChildList().get(2).getCreated(), parent.getChildList().get(2).getModified()); Assert.assertEquals(1, parent.getVersion()); Assert.assertEquals(1, parent.getChildList().get(0).getVersion()); Assert.assertEquals(1, parent.getChildList().get(1).getVersion()); Assert.assertEquals(1, parent.getChildList().get(2).getVersion()); }
0d079986-85f6-4c98-9493-d69295fe6cb5
public static void main(String username, String password, String ram) throws IOException { List<String> args = new ArrayList<String>(); args.add(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java" + (System.getProperty("os.name").toLowerCase().contains("win") ? "w" : "")); args.add("-Xms256M"); args.add("-Xmx" + ram + "M"); args.add("-XX:PermSize=256M"); args.add("-Dfml.ignorePatchDiscrepancies=true"); args.add("-Dfml.ignoreInvalidMinecraftCertificates=true"); args.add("-Dfml.log.level=INFO"); args.add("-Djava.library.path=" + getWorkingDirectory() + File.separator + "bin" + File.separator + "natives-" + getOS()); args.add("-cp"); String classpath = ""; File libs = new File(getWorkingDirectory() + File.separator + "bin"); for (int i = 0; i < libs.list().length; i++) { if (! libs.list()[i].contains("natives")) { classpath += libs.getAbsolutePath() + File.separator + libs.list()[i]; if (i != libs.list().length - 1) classpath +=File.pathSeparator; } } args.add(classpath); args.add("net.minecraft.launchwrapper.Launch"); args.add("--username"); args.add(username); args.add("--session"); args.add("****:****"); args.add("--accessToken"); args.add(username); args.add("--userProperties"); args.add("{}"); args.add("--version"); args.add(Unity.mc_version); args.add("--gameDir"); args.add(getWorkingDirectory()); args.add("--assetIndex"); args.add(Unity.mc_version); args.add("--assetsDir"); args.add(getWorkingDirectory() + File.separator + "assets"); args.add("--tweakClass=cpw.mods.fml.common.launcher.FMLTweaker"); System.out.print("Executing: "); for (int i = 0; i < args.size(); i++) { System.out.print(args.get(i) + " "); } ProcessBuilder processBuilder = new ProcessBuilder(args); processBuilder.directory(new File(getWorkingDirectory())); processBuilder.redirectErrorStream(true); processBuilder.start(); }
4839db7c-72f8-4c21-b388-da2f0b9ccf6f
public static String getOS() { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { os = "win"; }; if (os.contains("linux")) {os = "linux";} if (os.contains("unix") || os.contains("sunos") || os.contains("solaris")) { os = "solaris"; } if (os.contains("macos")) { os = "macosx"; } return os; }
5559c127-21eb-4a4f-bad2-f53fb3dfe4f7
public static String getWorkingDirectory() { String home = System.getProperty("user.home", "."); File dir; String os = System.getProperty("os.name").toLowerCase(); if (os.contains("linux") || os.contains("unix") || os.contains("sunos") || os.contains("solaris")) { dir = new File(home, (new StringBuilder()).append('.').append(Unity.folder).append('/').toString()); } else if (os.contains("win")) { String s2 = System.getenv("APPDATA"); if(s2 != null) { dir = new File(s2, (new StringBuilder()).append(".").append(Unity.folder).append('/').toString()); } else { dir = new File(home, (new StringBuilder()).append('.').append(Unity.folder).append('/').toString()); } } else if(os.contains("macos")) { dir = new File(home, (new StringBuilder()).append("Library/Application Support/").append(Unity.folder).toString()); } else { dir = new File(home, (new StringBuilder()).append(Unity.folder).append('/').toString()); } if(!dir.exists() && !dir.mkdirs()) { throw new RuntimeException((new StringBuilder()).append("The working directory could not be created: ").append(dir).toString()); } else { return dir.getAbsolutePath(); } }
d12f2702-e379-4375-a43c-d55c7b38c6ae
public static void setup() throws IOException, InterruptedException, FontFormatException { //fonts roboto_thin = Font.createFont(Font.TRUETYPE_FONT, Unity.class.getResourceAsStream("/res/Roboto-Thin.ttf")); roboto_regular = Font.createFont(Font.TRUETYPE_FONT, Unity.class.getResourceAsStream("/res/Roboto-Regular.ttf")); // main window = new Window(Unity.title, Unity.favicon, Unity.background, 791, 527); release = new Label(Unity.release, Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 12)); server_lbl = new Label("Server:", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 12)); server_stat_lbl = new Label("Offline",Color.RED,roboto_regular.deriveFont(Font.PLAIN, 12)); settingsButton = new Button(); settingsButton.setImage("/res/gear.png"); settingsButton.removeDecorations(); settingsButton.addActionListener(new settingsButton_action()); // splash screen update_lbl = new Label("Updating", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 32)); progress = new ProgressBar(new Color(255, 255, 255, 100), new Color(255, 255, 255, 255)); progress.removeDecorations(); progressText = new Label("Ready.", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); // login screen username = new TextField(prefs.get("username", ""), Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); password = new PasswordField(Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); username_lbl = new Label("Username:", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); password_lbl = new Label("Password:", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); loginButton = new Button("Login", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 28)); loginButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1)); loginButton.center(); loginButton.addActionListener(new loginButton_action()); invalid_login_lbl = new Label("Invalid Login", Color.RED, roboto_regular.deriveFont(Font.PLAIN, 14)); invalid_login_lbl.setVisible(false); // settings screen settings_lbl = new Label("Settings", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 32)); deleteButton = new Button(); deleteButton.setImage("/res/recycle.png"); deleteButton.removeDecorations(); deleteButton.addActionListener(new deleteButton_action()); ram_size = new TextField(prefs.get("ram_size", default_ram), Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); ram_lbl = new Label("RAM Usage (MB):", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14)); invalid_ram_lbl = new Label(Color.RED, roboto_regular.deriveFont(Font.PLAIN, 14)); invalid_ram_lbl.setVisible(false); saveButton = new Button("Save", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 28)); saveButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1)); saveButton.center(); saveButton.addActionListener(new saveButton_action()); // sizing and layout release.setBounds(5, window.getHeight() - 50, 140, 20); server_lbl.setBounds(5, window.getHeight() - 50, 140, 20); server_stat_lbl.setBounds(45 ,window.getHeight() - 50,200,20); update_lbl.setBounds(115, 20, 320, 50); progress.setBounds(20, 75, 320, 10); progressText.setBounds(20, 90, 320, 20); username.setBounds(155, 30, 115, 20); password.setBounds(155, 60, 115, 20); username_lbl.setBounds(80, 30, 115, 20); password_lbl.setBounds(79, 60, 115, 20); loginButton.setBounds(110, 110, 140, 40); invalid_login_lbl.setBounds(135, 165, 140, 20); settingsButton.setBounds(window.getWidth() - 45, window.getHeight() - 65, 32, 32); settings_lbl.setBounds(115, 5, 320, 50); deleteButton.setBounds(155, 50, 32, 32); ram_size.setBounds(175, 90, 115, 20); ram_lbl.setBounds(60, 90, 115, 20); saveButton.setBounds(110, 125, 140, 40); // setup screens login_window = new Label(); login_window.setBounds(216, 180, 360, 200); login_window.add(update_lbl); login_window.add(progress); login_window.add(progressText); login_window.add(username); login_window.add(password); login_window.add(username_lbl); login_window.add(password_lbl); login_window.add(loginButton); login_window.add(invalid_login_lbl); login_window.add(settings_lbl); login_window.add(deleteButton); login_window.add(ram_size); login_window.add(invalid_ram_lbl); login_window.add(ram_lbl); login_window.add(saveButton); // setup and show window window.addComponent(release); window.addComponent(server_lbl); window.addComponent(server_stat_lbl); window.addComponent(login_window); window.addComponent(settingsButton); window.getRootPane().setDefaultButton(loginButton); window.setLocationRelativeTo(null); release.setVisible(false); window.setVisible(true); start(); }
28ecbaba-5d68-4297-b3e7-93e27a8a444c
public static void start() throws IOException,InterruptedException { updated = false; settingsWindow(false); mainWindow(false); updateWindow(true); networkStatus("start"); Downloader.update(); updated = true; updateWindow(false); mainWindow(true); }
20924e10-7caf-4136-895d-d8efb80bcbaa
public static void removeWindowContent() { login_window.removeAll(); window.pack(); }
db108a74-2ece-4938-9320-fda6ad2ec8e1
public static void updateWindow(boolean visible) { update_lbl.setVisible(visible); progress.setVisible(visible); progressText.setVisible(visible); }
25d12085-1406-45eb-a3e5-ed0cd4dfffa4
public static void mainWindow(boolean visible) { username.setVisible(visible); password.setVisible(visible); username_lbl.setVisible(visible); password_lbl.setVisible(visible); loginButton.setVisible(visible); invalid_login_lbl.setVisible(false); }
d976293c-6baf-4d84-a267-3a4a1999d26e
public static void settingsWindow(boolean visible) { server_lbl.setVisible(visible==false); server_stat_lbl.setVisible(visible==false); release.setVisible(visible); settings_lbl.setVisible(visible); deleteButton.setVisible(visible); ram_size.setVisible(visible); ram_lbl.setVisible(visible); saveButton.setVisible(visible); }
a891a292-8afb-447c-8ccf-0168500e7c7a
@SuppressWarnings("deprecation") public void actionPerformed(ActionEvent e) { if (!(username.getText().equals("")) && (!(password.getPassword().toString()).equals(""))) { try { Document doc = Jsoup.connect("http://uniteddev.com/mc_auth.php?username=" + username.getText() + "&password=" + new String(password.getPassword())).get(); String response = doc.text(); System.out.println("Authentication: " + response); if (response.equals("success")) { invalid_login_lbl.setVisible(false); prefs.put("username", username.getText()); window.setVisible(false); window.dispose(); networkStatus("stop"); try { Minecraft.main(username.getText(), new String(password.getPassword()), prefs.get("ram_size", default_ram)); } catch (IOException e1) { e1.printStackTrace(); } networkProbe.stop(); } else { invalid_login_lbl.setVisible(true); } } catch (IOException e1) { } } else { invalid_login_lbl.setVisible(true); } }
e92880d8-8611-49a6-bc82-db1815f96032
public void actionPerformed(ActionEvent e) { try { FileUtils.deleteDirectory(new File(Minecraft.getWorkingDirectory())); window.setVisible(false); window.dispose(); } catch (IOException e1) { } }
12c90699-9c58-4044-8409-4f28fcbb659e
public void actionPerformed(ActionEvent e) { if (updated) { mainWindow(false); settingsWindow(true); } }
2ff1e683-f748-4e47-b568-2cabf4647a82
public void actionPerformed(ActionEvent e) { String temp = ram_size.getText(); try { invalid_ram_lbl.setBounds(112, 175, 140, 20); invalid_ram_lbl.setText("RAM must be numeric"); int tempint = Integer.parseInt(temp); if (768 >= tempint) { invalid_ram_lbl.setText("RAM must be greater than 768MB"); invalid_ram_lbl.setBounds(75, 175, 230, 20); throw new Exception(); } } catch (Exception e1) { invalid_ram_lbl.setVisible(true); return; } prefs.put("ram_size", temp); invalid_ram_lbl.setVisible(false); settingsWindow(false); mainWindow(true); }
1efa54bc-7934-4a2b-b911-4ff17374b6f3
public static void networkStatus(String state) { class networkService implements Runnable { public void run () { while (true) { Socket s = null; boolean connected = false; try { s = new Socket(Unity.ip, Integer.parseInt(Unity.port)); connected = true; } catch (Exception e) { } finally { if (s != null) { try { s.close(); } catch(IOException e1) { } } } if (connected) { System.out.println("Connection to server established."); server_stat_lbl.setText("Online"); server_stat_lbl.setForeground(Color.GREEN); } else { System.out.println("Unable to establish connection."); server_stat_lbl.setText("Offline"); server_stat_lbl.setForeground(Color.RED); } try { Thread.sleep(5000); } catch (Exception e) {}; } } } if (state=="start") { networkProbe = new Thread(new networkService()); networkProbe.start(); } else if (state=="stop") { // kill thread only if it is sleeping, otherwise // we may have open socket connections try { while (networkProbe.getState() != Thread.State.TIMED_WAITING) { networkProbe.join(1000); } networkProbe.interrupt(); } catch (InterruptedException e) { } } }
858f96cb-3e19-47a9-9c2c-9ed2fba49faa
public void run () { while (true) { Socket s = null; boolean connected = false; try { s = new Socket(Unity.ip, Integer.parseInt(Unity.port)); connected = true; } catch (Exception e) { } finally { if (s != null) { try { s.close(); } catch(IOException e1) { } } } if (connected) { System.out.println("Connection to server established."); server_stat_lbl.setText("Online"); server_stat_lbl.setForeground(Color.GREEN); } else { System.out.println("Unable to establish connection."); server_stat_lbl.setText("Offline"); server_stat_lbl.setForeground(Color.RED); } try { Thread.sleep(5000); } catch (Exception e) {}; } }
b54337d6-cb76-4042-a2d7-0e40e1c727e3
public static void update() throws IOException, InterruptedException { files = new ArrayList<String>(); rename_files = new ArrayList<String>(); folders = new ArrayList<String>(); Login.progress.setValue(0); ArrayList<String> listing = getDirectoryListing(""); recursiveFileListing(listing, ""); // TODO: merge similar thread pooling code & cleanup removeOutdated(); removeRedundancies(); downloadFiles(); renameFiles(); System.out.println("File Check Complete."); Login.progress.setValue(100); Login.progressText.setText("Update complete."); }
315e30bb-adf6-4287-bcd7-564d9b5c3213
public static void recursiveFileListing(ArrayList<String> extracted_links, String folder) throws IOException { for (int i = 0; i < extracted_links.size(); i++) { String target = extracted_links.get(i).toString(); String new_folder = folder + target; while (target.endsWith("/")) { folders.add(new_folder); String foldername[] = new_folder.split("/"); folder((Minecraft.getWorkingDirectory() + File.separator + new_folder), foldername[foldername.length - 1]); recursiveFileListing(getDirectoryListing(new_folder), new_folder); break; } if (! new_folder.endsWith("/")) { files.add(new_folder); rename_files.add(new_folder); } } }
6baa7306-701b-4898-8f78-d3a6df8a6f8a
public static ArrayList<String> getDirectoryListing(String url) throws IOException { Document doc = Jsoup.connect(Unity.url + Unity.folder + "/" + url).get(); Elements extracted_links = doc.select("a[href]"); ArrayList<String> links = new ArrayList<String>(); for (int i = 0; i < extracted_links.size(); i++) { String check = extracted_links.get(i).attr("href"); if (!(check.contains("?C=N;O=D"))&&!(check.contains("?C=M;O=A"))&&!(check.contains("?C=D;O=A"))&&!(check.contains("?C=S;O=A"))&&!(check.contains("content/minecraft/files"))) { links.add(extracted_links.get(i).attr("href")); } } return links; }
3b408e43-7e39-4f14-84a2-21d771124f26
public static void removeOutdated() throws IOException,InterruptedException { Login.progressText.setText("Removing outdated files..."); System.out.println("Removing outdated files..."); class removefile implements Runnable { private int i; removefile (int i) { this.i=i; } public void run() { if (! ((folders.get(this.i).contains("bin/"))||(folders.get(this.i).contains("resources/")))) { try { //System.out.println("Currently attempting Pool Index: "+this.i); ArrayList<String> online_list = getDirectoryListing(folders.get(this.i)); ArrayList<String> offline_list = new ArrayList<String>(); if (new File(Minecraft.getWorkingDirectory(), folders.get(this.i)).isDirectory()) { File[] offline_files = new File(Minecraft.getWorkingDirectory(), folders.get(this.i)).listFiles(); for (int j = 0; j < offline_files.length; j++) { if (! offline_files[j].isDirectory()) { offline_list.add(offline_files[j].getName()); } } } for (int j = 0; j < online_list.size(); j++) { online_list.set(j, namefix(online_list.get(j))); } for (int j = 0; j < offline_list.size(); j++) { if (! online_list.contains(offline_list.get(j))) { clean(Minecraft.getWorkingDirectory() + File.separator + folders.get(this.i), offline_list.get(j)); } } } catch (IOException e) { e.printStackTrace(); } } } } ExecutorService pool = Executors.newFixedThreadPool(cores+2); for (int i = 0; i < folders.size(); i++) { pool.submit(new removefile(i)); } pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE , TimeUnit.MILLISECONDS); }
3160c02b-65a9-4d1b-971f-fe2c80559b54
removefile (int i) { this.i=i; }
30bd21dc-b83e-462a-ae0b-4d373a4e8b9c
public void run() { if (! ((folders.get(this.i).contains("bin/"))||(folders.get(this.i).contains("resources/")))) { try { //System.out.println("Currently attempting Pool Index: "+this.i); ArrayList<String> online_list = getDirectoryListing(folders.get(this.i)); ArrayList<String> offline_list = new ArrayList<String>(); if (new File(Minecraft.getWorkingDirectory(), folders.get(this.i)).isDirectory()) { File[] offline_files = new File(Minecraft.getWorkingDirectory(), folders.get(this.i)).listFiles(); for (int j = 0; j < offline_files.length; j++) { if (! offline_files[j].isDirectory()) { offline_list.add(offline_files[j].getName()); } } } for (int j = 0; j < online_list.size(); j++) { online_list.set(j, namefix(online_list.get(j))); } for (int j = 0; j < offline_list.size(); j++) { if (! online_list.contains(offline_list.get(j))) { clean(Minecraft.getWorkingDirectory() + File.separator + folders.get(this.i), offline_list.get(j)); } } } catch (IOException e) { e.printStackTrace(); } } }
53e71a1a-d5ee-4074-8230-acda3bcfd466
public static void removeRedundancies() throws InterruptedException { class removeRedundancy implements Runnable { private int i; removeRedundancy(int i) { this.i=i; } public void run() { files.remove(this.i); } } int i =0; ExecutorService pool = Executors.newFixedThreadPool(cores); while (i < files.size()) { String file = files.get(i); file = namefix(file); if (new File(Minecraft.getWorkingDirectory(), file).exists()) pool.submit(new removeRedundancy(i)); // this was originally a while loop else i++; } pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE , TimeUnit.MILLISECONDS); }
324dc1b5-801e-4cfa-9d6a-00c61c89253e
removeRedundancy(int i) { this.i=i; }
aa38f50a-f32f-4795-ab1d-304fe2be3501
public void run() { files.remove(this.i); }
6397ec84-c588-427f-ab6b-bee411dd56e1
public static void downloadFiles() throws MalformedURLException, IOException, InterruptedException { class downloadFile implements Runnable { private int i; downloadFile(int i) { this.i=i; } public void run() { String filename = files.get(this.i).substring(files.get(this.i).lastIndexOf('/') + 1, files.get(this.i).length()); File f = new File(Minecraft.getWorkingDirectory(), files.get(this.i)); try { Login.progressText.setText("Downloading: " + filename); System.out.println("Downloading: " + filename); //System.out.println("Currently attempting Pool Index: "+this.i); HttpURLConnection connect_url = setupHTTP(Unity.url + Unity.folder + "/" + files.get(this.i)); FileUtils.copyInputStreamToFile(connect_url.getInputStream(), f); } catch(FileNotFoundException e) { Login.progressText.setText("File not found!"); } catch (MalformedURLException e) { System.out.println("DEV: FIX URL"); e.printStackTrace(); } catch (IOException e) { System.out.println("FileSystem Error"); e.printStackTrace(); } } } Login.progressText.setText("Downloading new files..."); System.out.println("Downloading new files..."); System.out.println("Number of files to download: " + files.size()); ExecutorService pool = Executors.newFixedThreadPool(10); for (int i = 0; i < files.size(); i++) { pool.submit(new downloadFile(i)); Login.progress.setValue((int)(((double) i / files.size()) * 100)); } pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE , TimeUnit.MILLISECONDS); }
efda93b9-c7ae-4eee-b602-411b29824d64
downloadFile(int i) { this.i=i; }
c1870601-d391-498a-b684-359526c9a972
public void run() { String filename = files.get(this.i).substring(files.get(this.i).lastIndexOf('/') + 1, files.get(this.i).length()); File f = new File(Minecraft.getWorkingDirectory(), files.get(this.i)); try { Login.progressText.setText("Downloading: " + filename); System.out.println("Downloading: " + filename); //System.out.println("Currently attempting Pool Index: "+this.i); HttpURLConnection connect_url = setupHTTP(Unity.url + Unity.folder + "/" + files.get(this.i)); FileUtils.copyInputStreamToFile(connect_url.getInputStream(), f); } catch(FileNotFoundException e) { Login.progressText.setText("File not found!"); } catch (MalformedURLException e) { System.out.println("DEV: FIX URL"); e.printStackTrace(); } catch (IOException e) { System.out.println("FileSystem Error"); e.printStackTrace(); } }
371d1a33-46c4-49dd-8514-a964608f61a2
public static void renameFiles() throws IOException,InterruptedException { Login.progressText.setText("Renaming files..."); System.out.println("Renaming files..."); class renameFile implements Runnable { private int i; renameFile(int i) { this.i=i; } public void run() { //System.out.println("Currently attempting Pool Index: "+this.i); String file = rename_files.get(this.i); if (file.contains("%20")||file.contains("%5b")||file.contains("%5d")) { file = namefix(file); File oldfile = new File(Minecraft.getWorkingDirectory(), rename_files.get(this.i)); if (oldfile.exists()) { File newfile = new File(Minecraft.getWorkingDirectory(), file); oldfile.renameTo(newfile); System.out.println("Renamed " + oldfile.getName() + " to " + newfile.getName()); } } } } ExecutorService pool = Executors.newFixedThreadPool(cores+4); for (int i = 0; i < rename_files.size(); i++) { pool.submit(new renameFile(i)); } pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE , TimeUnit.MILLISECONDS); }
ee51b069-d424-487e-8204-f416be3f80bd
renameFile(int i) { this.i=i; }
fdfa44ab-1ebc-4006-b4df-f90f7fe85bbe
public void run() { //System.out.println("Currently attempting Pool Index: "+this.i); String file = rename_files.get(this.i); if (file.contains("%20")||file.contains("%5b")||file.contains("%5d")) { file = namefix(file); File oldfile = new File(Minecraft.getWorkingDirectory(), rename_files.get(this.i)); if (oldfile.exists()) { File newfile = new File(Minecraft.getWorkingDirectory(), file); oldfile.renameTo(newfile); System.out.println("Renamed " + oldfile.getName() + " to " + newfile.getName()); } } }
999036df-5026-46aa-95c2-89bea39afb54
public static void clean(String folder, String file) { if (!(file.equals("rei_minimap"))) { // rei_minimap quick fix File local_file = new File(folder, file); Login.progressText.setText("File no longer needed: " + local_file.getAbsolutePath()); System.out.println("File no longer needed: " + local_file.getAbsolutePath()); local_file.delete(); } }
96d38003-3459-422a-9f56-9533d77b57ba
public static void folder(String dir, String dirname) { File folder = new File(dir); if (! folder.exists()) { folder.mkdir(); Login.progressText.setText("Created directory: " + dirname); System.out.println("Created directory: " + dirname); } }
f2597691-d800-482b-b25e-3077c7637c2e
public static String namefix(String file) { String[][] fixes = { {"%20", " "}, {"%5b", "["}, {"%5d", "]"} }; for (int i = 0; i < fixes.length; i++) { file = file.replaceAll(fixes[i][0], fixes[i][1]); } return file; }
fe69053e-687a-4b96-9921-5fad44844b01
public static HttpURLConnection setupHTTP(String fileurl) throws MalformedURLException, IOException { HttpURLConnection httpConnection = (HttpURLConnection) new URL(fileurl).openConnection(); httpConnection.setRequestMethod("GET"); httpConnection.setRequestProperty ("Content-Type","application/java-archive"); httpConnection.setRequestProperty ("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31"); return httpConnection; }
76b0ce98-9065-4eba-a768-d882fdb7c37b
public static void main(String[] args) throws Exception { try { Login.setup(); } catch (Exception e) { e.printStackTrace(); } }
9b3208b0-ed4a-4378-8d39-c0f1ff55fb69
public Window(String title, int width, int height) { this.defaultSettings(); this.setTitle(title); }
e59655db-bcb4-4f67-bc41-e575664996da
public Window(String title, String favicon, int width, int height) throws IOException { this.defaultSettings(); this.setTitle(title); this.setFavicon(favicon); this.setupContent(width, height); }
dc15a018-751c-4635-8f47-9b31a186ae14
public Window(String title, String favicon, String background, int width, int height) throws IOException { this.defaultSettings(); this.setTitle(title); this.setFavicon(favicon); this.setupContent(background, width, height); }
64d3f376-d4b2-4896-b1d8-c7aa9b871ff4
public void setupContent(int width, int height) { content = new JLabel(); content.setSize(width, height); content.setLayout(null); this.add(content); this.pack(); }
df5fbfc9-cc89-4dae-a26e-1e72d326b695
public void setupContent(String background, int width, int height) { content = new JLabel(); content.setIcon(new ImageIcon(this.getClass().getResource(background))); content.setSize(width, height); content.setLayout(null); this.add(content); this.pack(); }
880f74c3-7362-4b34-8d3a-b804d442daa5
public void setSize(int width, int height) { content.setSize(width, height); }
2eea3cd5-0a70-4649-9d47-d54897555b2a
public void setFavicon(String favicon) throws IOException { this.setIconImage(ImageIO.read(this.getClass().getResource(favicon))); }
93612ad5-6a6d-44d8-9ae9-0443e13b1c7e
public void defaultSettings() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); }
7628bf2d-1bde-4d2f-8af4-ca7f3926c708
public void addComponent(Component component) { content.add(component); }