/* * to broadcast a private message to all Clients */ private synchronized void broadcastOnlyOne(String message, ChatMessage cm) { // add HH:mm:ss and \n to the message String time = sdf.format(new Date()); String messageLf = time + " " + message + "\r\n"; System.out.print(messageLf); serverGUI.serverTextArea.append(messageLf); // we loop in reverse order in case we would have to remove a Client // because it has disconnected for (int i = al.size(); --i >= 0; ) { ClientThread ct = al.get(i); // try to write to the Client if it fails remove it from the list if (cm.getType() == ChatMessage.ESTABLISHCONNECTION || cm.getType() == ChatMessage.ESTABLISHCONNECTIONANDPLAY) { if (cm.getTO().equalsIgnoreCase(ct.username) && !ct.writeMsg(cm)) { al.remove(i); display("Disconnected Client " + ct.username + " removed from list."); break; } } else { if (cm.getTO().equalsIgnoreCase(ct.username) && !ct.writeMsg(message)) { al.remove(i); display("Disconnected Client " + ct.username + " removed from list."); break; } } } }
public static void doIt() throws Exception { Scanner scanner = new Scanner(System.in); Integer currentBalance = scanner.nextInt(); int removeLast, removePenultimate; StringBuffer buf = new StringBuffer(); ArrayList<Character> chars = new ArrayList<Character>(); for (Character c : currentBalance.toString().toCharArray()) chars.add(c); ArrayList<Character> c1 = (ArrayList<Character>) chars.clone(); c1.remove(c1.size() - 1); for (Character cc : c1) buf.append(cc); removeLast = new Integer(buf.toString()); buf = new StringBuffer(); ArrayList<Character> c2 = (ArrayList<Character>) chars.clone(); c2.remove(c2.size() - 2); for (Character cc : c2) buf.append(cc); removePenultimate = new Integer(buf.toString()); System.out.println(Math.max(currentBalance, Math.max(removeLast, removePenultimate))); }
public void pairClusters(ArrayList<Record> pair1, ArrayList<Record> pair2, boolean left) { for (int i = 0; i < pair1.size(); i++) { for (int j = 0; j < pair2.size(); j++) { if (pair1.get(i).isInsertionPair(pair2.get(j), left)) { System.out.println(pair1.get(i) + "\n" + pair2.get(j) + "\n"); pair1.remove(i); pair2.remove(j); i--; j--; break; } } } if ((pair1.size() + pair2.size()) > 0) { System.out.println("***** UNPAIRED *****"); for (int i = 0; i < pair1.size(); i++) { System.out.println(pair1.get(i)); } for (int j = 0; j < pair2.size(); j++) { System.out.println(pair2.get(j)); } System.out.println("**** END OF UNPAIRED ****\n"); } // System.out.println("\n"); }
public static void main(String[] args) throws IOException { String line = ""; ArrayList<String> list = new ArrayList<>(); try (Scanner scanner = new Scanner(System.in); BufferedReader reader = new BufferedReader(new FileReader(scanner.nextLine()))) { while ((line = reader.readLine()) != null) { list.addAll(Arrays.asList(line.split(" "))); } for (int i = 0; i < list.size(); i++) { String s = list.get(i); String reverse = new StringBuffer(s).reverse().toString(); if (list.indexOf(reverse) != -1 & !s.equals("") & !s.equals(reverse)) { result.add(new Pair(s, reverse)); list.remove(s); list.remove(reverse); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private static void getTopDocuments(int num, HashMap<String, Float> scoremap, String filename) throws FileNotFoundException { PrintWriter out = new PrintWriter(filename); Iterator<String> itr = scoremap.keySet().iterator(); ArrayList<String> urls = new ArrayList<String>(); ArrayList<Float> scores = new ArrayList<Float>(); while (itr.hasNext()) { String key = itr.next(); if (scores.size() < num) { scores.add(scoremap.get(key)); urls.add(key); } else { int index = scores.indexOf(Collections.min(scores)); if (scores.get(index) < scoremap.get(key)) { scores.set(index, scoremap.get(key)); urls.set(index, key); } } } while (scores.size() > 0) { int index = scores.indexOf(Collections.max(scores)); out.println(urls.get(index) + "\t" + scores.get(index)); urls.remove(index); scores.remove(index); } out.close(); }
public String pairClusters2string( ArrayList<Record> pair1, ArrayList<Record> pair2, boolean left) { StringBuffer bf = new StringBuffer(); for (int i = 0; i < pair1.size(); i++) { for (int j = 0; j < pair2.size(); j++) { if (pair1.get(i).isInsertionPair(pair2.get(j), left)) { bf.append(pair1.get(i) + "\n" + pair2.get(j) + "\n\n"); pair1.remove(i); pair2.remove(j); i--; j--; break; } } } if ((pair1.size() + pair2.size()) > 0) { bf.append("***** UNPAIRED *****\n"); for (int i = 0; i < pair1.size(); i++) { bf.append(pair1.get(i) + "\n"); } for (int j = 0; j < pair2.size(); j++) { bf.append(pair2.get(j) + "\n"); } bf.append("**** END OF UNPAIRED ****\n"); } // bf.append("\n"); return bf.toString(); }
// DELETION FIXED public void getISDra2FixedDel() { for (int i = 0; i < records.size(); i++) { Record cur = records.get(i); if (cur.regular) { if (cur.doesFirstMatch(674400, 674850, true, "EDGE:145:213") && cur.doesSecondMatch(676750, 677000, false, "EDGE:216:277")) { System.out.println(cur); records.remove(i); i--; } else if (cur.doesFirstMatch(1387250, 1387550, true, "EDGE:149:325") && cur.doesSecondMatch(1389450, 1389700, false, "EDGE:168:281")) { System.out.println(cur); records.remove(i); i--; } else if (cur.doesFirstMatch(1611150, 1611550, true, "EDGE:192:280") && cur.doesSecondMatch(1613400, 1613750, false, "EDGE:147:324")) { System.out.println(cur); records.remove(i); i--; } else if (cur.doesFirstMatch(1952800, 1953125, true, "EDGE:271:283") && cur.doesSecondMatch(1955000, 1955300, false, "EDGE:146:313")) { System.out.println(cur); records.remove(i); i--; } else if (cur.doesFirstMatch(2321000, 2321350, true, "EDGE:190:282") && cur.doesSecondMatch(2323250, 2323600, false, "EDGE:150:242")) { System.out.println(cur); records.remove(i); i--; } } } System.out.println(); }
public static void golf(String file_name) { Random rand = new Random(); ArrayList<Person> players = new ArrayList(); try { Scanner in = new Scanner(new FileReader(file_name)); while (in.hasNextLine()) { String name = in.nextLine(); Person person = new Person(name); players.add(person); } } catch (Exception e) { System.out.println("Could not find file"); } while (!players.isEmpty()) { int first, second; do { first = rand.nextInt(players.size()); second = rand.nextInt(players.size()); } while (first == second); System.out.println("Team:"); System.out.println(players.get(first).name); System.out.println(players.get(second).name); System.out.print("\n"); players.remove(second); if (second < first) { players.remove(first - 1); } else { players.remove(first); } } }
public static void remove(ArrayList<Integer> list, ArrayList<Integer> list2) { for (int i = 0; i < list.size() - 1; i++) { for (int k = i + 1; k < list.size(); k++) { if (list.get(i).equals(list.get(k)) && list2.get(i).equals(list2.get(k))) { list.remove(k); list2.remove(k); k--; } } } }
public String getIS2621FixedDel() { StringBuffer bf = new StringBuffer(); Record pair1 = null; int pair1Index = -1; Record pair2 = null; int pair2Index = -1; for (int i = 0; i < records.size(); i++) { Record cur = records.get(i); if (cur.regular) { if (cur.doesFirstMatch(1637700, 1638000, true, "EDGE:147:324") && cur.doesSecondMatch(1639600, 1639900, false, "EDGE:107:349")) { bf.append(cur + "\n\n"); records.remove(i); i--; } else if (cur.doesFirstMatch(1337450, 1337750, true, "EDGE:28:109") && cur.doesSecondMatch(1339350, 1339600, false, "EDGE:149:325")) { bf.append(cur + "\n\n"); records.remove(i); i--; } else if (cur.doesFirstMatch(231925, 231975, false, "EDGE:194:330") && cur.doesSecondMatch(881050, 881300, true, "EDGE:111:239")) { pair1 = cur; records.remove(i); i--; pair1Index = i; } else if (cur.doesFirstMatch(881200, 881350, true, "EDGE:111:239") && cur.doesSecondMatch(883000, 883200, false, "EDGE:185:335")) { pair2 = cur; records.remove(i); i--; pair2Index = i; } } } if (pair1Index > -1 && pair2Index > -1) { bf.append(pair1 + "\n" + pair2 + "\n\n"); // records.remove(pair1Index); // records.remove(pair2Index); } else if (pair1Index == -1 && pair2Index > -1) { bf.append("**MISSING**\n" + pair2 + "\n\n"); // records.remove(pair2Index); } else if (pair1Index > -1 && pair2Index == -1) { bf.append(pair1 + "\n**MISSING**\n\n"); // records.remove(pair1Index); } else { bf.append("**MISSING**\n**MISSING**\n\n"); } return bf.toString(); }
Point[] getConvex(Point[] points) { ArrayList<Point> hull = new ArrayList<Point>(); for (Point p : points) { while (hull.size() >= 2 && !isConvex(hull.get(hull.size() - 2), hull.get(hull.size() - 1), p)) { hull.remove(hull.size() - 1); } hull.add(p); } while (hull.size() >= 2 && hull.get(hull.size() - 1).x == hull.get(hull.size() - 2).x) { hull.remove(hull.size() - 1); } return hull.toArray(new Point[0]); }
public void draw(node leaf, Graphics2D g, int px, int py) { int lvl = leaf.getLevel(); double l = lvl; counts[lvl]++; double xfraq = counts[lvl] / (spacing[lvl] + 1); double yfraq = l / depth; int x = new Double(1600 * xfraq).intValue(); int y = new Double(1200 * yfraq).intValue() + 10; if (leaf.getAttr() != null) { g.drawString(leaf.getAttr(), x - 20, y); } if (leaf.getCrit() != null) { g.drawString(leaf.getCrit(), x - 20, y + 10); } if (leaf.getResult() != null) { g.drawString(leaf.getResult(), x - 20, y + 10); } g.drawLine(x, y, px, py); // g.fillRect(x,y,20,20); ArrayList children = leaf.getChildren(); while (!children.isEmpty()) { draw((node) children.remove(0), g, x, y); } }
protected void writeAuditTrail(String strPath, String strUser, StringBuffer sbValues) { BufferedReader reader = WFileUtil.openReadFile(strPath); String strLine; ArrayList aListData = WUtil.strToAList(sbValues.toString(), false, "\n"); StringBuffer sbData = sbValues; String strPnl = (this instanceof DisplayTemplate) ? "Data Template " : "Data Dir "; if (reader == null) { Messages.postDebug("Error opening file " + strPath); return; } try { while ((strLine = reader.readLine()) != null) { // if the line in the file is not in the arraylist, // then that line has been deleted if (!aListData.contains(strLine)) WUserUtil.writeAuditTrail(new Date(), strUser, "Deleted " + strPnl + strLine); // remove the lines that are also in the file or those which // have been deleted. aListData.remove(strLine); } // Traverse through the remaining new lines in the arraylist, // and write it to the audit trail for (int i = 0; i < aListData.size(); i++) { strLine = (String) aListData.get(i); WUserUtil.writeAuditTrail(new Date(), strUser, "Added " + strPnl + strLine); } reader.close(); } catch (Exception e) { e.printStackTrace(); } }
public void checkEnemyCollision() { for (Enemy e : enemyList) { if (e.getOnScreen()) { // can be removed later on // goes through all the enemies and checks if they collide if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) { if (player1.getInvi() == false) { // If the player is not invisble then you get spiked. if (player1.getVelocity() > 0) { // if the player hits it from the bottom player1.setSpikeVelo(); loseCoins(); } else { player1.setVelo( 50); // if the player is on top instead the player bounces off the enemy if (musicOn) { bounce.play(); } } } eRemove.add(e); // once we hit, we remove the enemy } } else { eRemove.add(e); // if the enemy goes of the screen, we remove } } for (Enemy e : eRemove) { poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies enemyList.remove(e); } eRemove = new ArrayList<Enemy>(); }
private static void analyzeNext() { ArrayList previous = new ArrayList(); String token = nextToken(); analysis.add("", token, 0); // Insert 1st token directly. previous.add(token); while (true) { int nWords = Math.min(previous.size(), MAX); token = nextToken(); if (token == PERIOD) break; for (int j = 1; j <= nWords; j++) { String s1 = concat(previous, j); // ({"a", "b", "c"}, 2) -> "b c" analysis.add(s1, token, j); } previous.add(token); if (previous.size() == MAX) previous.remove(0); } int nWords = Math.min(previous.size(), MAX); for (int j = 1; j < nWords; j++) { String s1 = concat(previous, j); // ({"a", "b", "c"}, 2) -> "b c" analysis.add(s1, PERIOD, j); } }
private synchronized void init() throws SQLException { if (isClosed) return; // do tables exists? Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(TABLE_NAMES_SELECT_STMT); ArrayList<String> missingTables = new ArrayList(TABLES.keySet()); while (rs.next()) { String tableName = rs.getString("name"); missingTables.remove(tableName); } for (String missingTable : missingTables) { try { Statement createStmt = conn.createStatement(); // System.out.println("Adding table "+ missingTable); createStmt.executeUpdate(TABLES.get(missingTable)); createStmt.close(); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } } }
@Override public void ignoreProblem(RefEntity refEntity, CommonProblemDescriptor problem, int idx) { if (refEntity == null) return; final Set<QuickFix> localQuickFixes = getQuickFixActions().get(refEntity); final QuickFix[] fixes = problem.getFixes(); if (isIgnoreProblem(fixes, localQuickFixes, idx)) { getProblemToElements().remove(problem); Map<RefEntity, CommonProblemDescriptor[]> problemElements = getProblemElements(); synchronized (lock) { CommonProblemDescriptor[] descriptors = problemElements.get(refEntity); if (descriptors != null) { ArrayList<CommonProblemDescriptor> newDescriptors = new ArrayList<CommonProblemDescriptor>(Arrays.asList(descriptors)); newDescriptors.remove(problem); getQuickFixActions().put(refEntity, null); if (!newDescriptors.isEmpty()) { problemElements.put( refEntity, newDescriptors.toArray(new CommonProblemDescriptor[newDescriptors.size()])); for (CommonProblemDescriptor descriptor : newDescriptors) { collectQuickFixes(descriptor.getFixes(), refEntity); } } else { ignoreProblemElement(refEntity); } } } } }
// Option 10 public void removeCity(String c) { City city = null; for (int i = 0; i < numCities; i++) { if (cities[i].name().equals(c)) { city = cities[i]; } } if (city == null) { System.out.println("Invalid city choice"); return; } // Remove all routes connected to the city for (Route r : adj[city.id() - 1]) { City other = r.other(city); adj[other.id() - 1].remove(r); routes.remove(r); numRoutes--; } cities[city.id() - 1] = null; adj[city.id() - 1] = null; numCities--; // Shift and resize arrays as necessary shiftCities(city.id() - 1); shiftAdj(city.id() - 1); if (numCities < cities.length / 2) { // halve the lengths of the arrays resizeCities(cities.length / 2); resizeAdj(cities.length / 2); } }
public void checkStarCollision() { for (Star s : starList) { if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides if (s.checkCollision( s.getPics().get(s.getCounter()), player1)) { // if the player collides with the star we remove it then change the // velosity to the distance that the star provides sRemove.add(s); // remove star once you collide with it player1.setVelo(s.getDist()); // changes the velocity player1.setInvi(true); // sets the player invisble for a few seconds score += s.getPoints(); // points increase by the star type if (musicOn) { starSound.play(); // playthe star sound } } } else { sRemove.add(s); // remove the star if its not on the screen } } for (Star s : sRemove) { poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect starList.remove(s); } sRemove = new ArrayList<Star>(); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------- // Decorations public void newDecos() { int prob = (int) (Math.random() * 100); // randomly spawnst he decoration if (prob == 1) { if (decoList.size() < 1) { int prob2 = (int) (Math.random() * 2); if (prob2 == 1) { // right side or left side decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, false)); } else { decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, true)); } } } Boolean check = true; for (Decorations i : decoList) { if (i.getYTop() >= 2000) { check = false; break; } } if (check == false && decoList.size() > 0) { // theres only on in the lsit but for consitency we kept it as a list decoList.remove(0); } }
/** Removes the specified class listener so no that it no longer receives class events. */ public void removeClassListener(ClassListener listener) { if (listener != null) { synchronized (classListeners) { classListeners.remove(listener); } } }
/** Removes the specified listener so no that it no longer receives events. */ public void removeInvocationListener(InvocationListener listener) { if (listener != null) { synchronized (invocationListeners) { invocationListeners.remove(listener); } } }
public static void main(String... orange) throws IOException { Scanner scan = new Scanner(new File("barn1.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("barn1.out"))); int bars = scan.nextInt(); int total = scan.nextInt(); int have = scan.nextInt(); ArrayList<Integer> values = new ArrayList<Integer>(); ArrayList<Integer> locations = new ArrayList<Integer>(); for (int i = 0; i < have; i++) { values.add(scan.nextInt()); } Collections.sort(values); int first = values.get(0); for (int i = 1; i < have; i++) { int current = values.get(i); locations.add(current - first); first = current; } if (bars >= have) { out.println(have); } else { for (int i = 0; i < bars - 1; i++) { locations.remove(Collections.max(locations)); } int sum = 0; for (int i = 0; i < locations.size(); i++) sum += locations.get(i); sum += bars; out.println(sum); } out.close(); System.exit(0); }
/** Removes the specified listener so that it no longer receives events. */ public void removePackageListener(PackageListener listener) { if (listener != null) { synchronized (packageListeners) { packageListeners.remove(listener); } } }
/** Removes the specified listener so that it no longer receives events. */ public void removeCompileListener(CompileListener listener) { if (listener != null) { synchronized (compileListeners) { compileListeners.remove(listener); } } }
/** Removes the specified listener so that it no longer receives events. */ public void removeApplicationListener(ApplicationListener listener) { if (listener != null) { synchronized (applicationListeners) { applicationListeners.remove(listener); } } }
/** Removes the specified listener so that it no longer receives events. */ public void removeExtensionEventListener(ExtensionEventListener listener) { if (listener != null) { synchronized (eventListeners) { eventListeners.remove(listener); } } }
/** * BFS algorith * * @param: print boolean if to print node during traversal * @return List of nodes in order visited */ public ArrayList<String> bfs(boolean print) { ArrayList<String> ops = new ArrayList<>(); GraphNode v = source; ArrayList<GraphNode> Q = new ArrayList<>(); Q.add(v); v.setVisited(true); while (Q.size() != 0) { v = Q.remove(0); if (print) System.out.println(v); ops.add(v.toString()); // if(checkStoppingCondition(v, getN())) { // return; // } List<Integer> edgeTarget = matrix.get(v.getID()); for (int i = 0; i < edgeTarget.size(); ++i) { if (edgeTarget.get(i) == 1) { GraphNode w = info.get(i + 1); if (!w.getVisited()) { Q.add(w); w.setVisited(true); } } } } return ops; }
private void oddPoint(ArrayList<Integer> oddPoints, int from) { if (oddPoints.contains(from)) { oddPoints.remove(new Integer(from)); } else { oddPoints.add(from); } }
public void getISUnknownFixedIns() { Record pair1 = null; int pair1Index = -1; Record pair2 = null; int pair2Index = -1; for (int i = 0; i < records.size(); i++) { Record cur = records.get(i); if (cur.regular) { if (cur.edgeName1.equals("EDGE:111:239") && cur.edgeName2.equals("EDGE:72:203") && !cur.fwd1 && cur.fwd2 && cur.doesFirstOverlapWith(847025, 847475) && cur.doesSecondOverlapWith(1820800, 1821075)) { // pair1 pair1 = cur; pair1Index = i; records.remove(i); i--; } else if (cur.edgeName1.equals("EDGE:111:239") && cur.edgeName2.equals("EDGE:72:203") && cur.fwd1 && !cur.fwd2 && cur.doesFirstOverlapWith(847700, 848050) && cur.doesSecondOverlapWith(1821225, 1821625)) { // pair1 pair2 = cur; pair2Index = i; records.remove(i); i--; } } } if (pair1Index > -1 && pair2Index > -1) { System.out.println("*FIXED\n" + pair1 + "\n" + pair2 + "\n"); // records.remove(pair1Index); // records.remove(pair2Index); } else if (pair1Index == -1 && pair2Index > -1) { System.out.println("*FIXED\n**MISSING**\n" + pair2 + "\n"); // records.remove(pair2Index); } else if (pair1Index > -1 && pair2Index == -1) { System.out.println("*FIXED\n" + pair1 + "\n**MISSING**\n"); // records.remove(pair1Index); } else { System.out.println("*FIXED\n**MISSING**\n**MISSING**\n"); } }