/** * This method should setup the flags/switches for the java command which will determine the * actual command to be executed. * * <p>Sets up flags like : * * <ul> * <li>-Dem.home * <li>-Dprocess.name * </ul> * * <br> * add computes the classpath. */ protected void updateFlags(ServerCommand serverCmd) { String bootDir = System.getProperty("em.home"); String appType = System.getProperty("appType"); String appInst = System.getProperty("appInst"); String javaClasspath = serverCmd.getClasspath(); String processName = getProcessNameForLog(); List jvmFlags = serverCmd.getJVMFlags(); int cpToken = -1; for (int i = 0; i < jvmFlags.size(); i++) { String token = (String) jvmFlags.get(i); if (token.startsWith("-classpath")) { cpToken = i; javaClasspath = null; } else if (token.startsWith("-Dem.home")) { bootDir = null; } else if (token.startsWith("-Dprocess.name")) { processName = null; } } List addonJVMFlags = new LinkedList(); if (bootDir != null) { addonJVMFlags.add("-Dem.home=" + bootDir); } if (processName != null) { addonJVMFlags.add("-Dprocess.name=" + processName); } if (!(appType == null || appType.trim().equals(""))) { addonJVMFlags.add("-DappType=" + appType); } if (!(appInst == null || appInst.trim().equals(""))) { addonJVMFlags.add("-DappInst=" + appInst); } if (cpToken != -1) { jvmFlags.remove(cpToken); String str = (String) jvmFlags.remove(cpToken); serverCmd.setClasspath(str); } jvmFlags.addAll(addonJVMFlags); }
/** * @param table_list lista de tabelas * @param visited_tables lista de tabelas visitadas * @param final_table tabela final/pretendida */ public static Node iterativeDepthFirstSearch( int[][] initial_table, int[][] final_table, int max_depth) { List table_list = new List(); table_list.addFirst(initial_table, 0, ""); List visited_tables = new List(); int[][] current_table = new int[3][3]; int depth = 0; String path = new String(); while (!table_list.isEmpty()) { List child_nodes = new List(); path = table_list.getPath(); depth = table_list.getDepth(); current_table = table_list.remove(); if (isSolution(current_table, final_table)) return new Node(current_table, depth, path, null); visited_tables.addFirst(current_table, depth, path); if (depth < max_depth) { child_nodes = playDFS(child_nodes, current_table, depth, path); // verifica se algum dos filhos já foi visitado while (!child_nodes.isEmpty()) { int d = child_nodes.getDepth(); String s = child_nodes.getPath(); int[][] child_table = child_nodes.remove(); if (!visited_tables.contains(child_table)) table_list.addFirst(child_table, d, s); } } } return iterativeDepthFirstSearch(initial_table, final_table, max_depth + 1); }
public void compareArrays() { int decrement_index = -1; int increment_index = -1; for (int i = 0; i < listX.size(); i++) { Integer elemX = listX.get(i); Integer elemY = listY.get(i); if ((elemX < elemY) && increment_index == -1) { increment_index = i; } else if ((elemY < elemX) && decrement_index == -1) { decrement_index = i; } if (increment_index != -1 && decrement_index != -1) { int elemI = listX.remove(increment_index); listX.add(increment_index, ++elemI); increment_index = 1; int elemD = listX.remove(decrement_index); listX.add(decrement_index, --elemD); decrement_index = -1; if (nop == -1) nop = 0; nop++; } } }
public static void main(String[] args) { List<Card> cards = new LinkedList<Card>(); for (Value v : Value.values()) { for (Suit s : Suit.values()) { cards.add(new Card(v, s)); } } Random rand = new Random(); Card[] cards1 = new Card[7]; Card[] cards2 = new Card[7]; for (int i = 0; i < 7; i++) { // Card c = cards.remove(rand.nextInt(cards.size())) ; Card c1 = cards.remove(2 + i * 3); cards1[i] = c1; Card c2 = cards.remove(rand.nextInt(cards.size())); cards2[i] = c2; } System.out.println("------ Card 1 ---------"); for (Card c : cards1) { System.out.println(c.getSuit() + " " + c.getValue()); } System.out.println(Round.getRank(cards1)); System.out.println("------ Card 2 ---------"); for (Card c : cards2) { System.out.println(c.getSuit() + " " + c.getValue()); } System.out.println(Round.getRank(cards2)); }
public RubyValue replace(int start, int length, RubyValue value) { int index = getRealIndex(start); if (value == RubyConstant.QNIL) { for (int i = 0; i < length; i++) { array_.remove(index); } return value; } if (length < 0) { throw new RubyException(RubyRuntime.IndexErrorClass, "negative length (" + length + ")"); } else if (0 == length) { if (value instanceof RubyArray) { array_.addAll(index, ((RubyArray) value).array_); } else { array_.add(index, value); } } else { for (int i = 0; i < length - 1; ++i) { array_.remove(index); } if (value instanceof RubyArray) { array_.remove(index); array_.addAll(index, ((RubyArray) value).array_); } else { array_.set(index, value); } } return value; }
public static void main(String[] args) { // ArrayList list = new ArrayList(); // List list1 = new ArrayList(); List list1 = new Vector(); list1.add(1); list1.add(2); list1.add("Hello"); list1.add(5.5); // Add an element at index 4 list1.add(4, "Yeah"); // list1.add(new Book("Book 1")); list1.set(2, 100); list1.remove("Hello"); list1.remove(1); if (list1.contains("Yeah")) { System.out.println("----EXISTS-------"); } // for (int i = 0; i < list1.size(); i++) { // Object element = list1.get(i); // System.out.println(element); // } // Enhanced For Loop for (Object element : list1) { System.out.println(element); } }
public static Phylogeny generateRandomTree(int size, boolean randomNames) { Random random = new Random(); List<PhylogenyNode> nodes = new ArrayList<>(); for (int i = 0; i < size; i++) { PhylogenyNode newNode = new PhylogenyNode(); newNode.setName(i + ""); nodes.add(newNode); } while (nodes.size() > 1) { int i = random.nextInt(nodes.size()); PhylogenyNode node1 = nodes.get(i); nodes.remove(i); int j = random.nextInt(nodes.size()); PhylogenyNode node2 = nodes.get(j); nodes.remove(j); PhylogenyNode newNode = new PhylogenyNode(); newNode.setChild1(node1); newNode.setChild2(node2); nodes.add(newNode); newNode.setName(newNode.getId() + ""); } Phylogeny tree = new Phylogeny(); tree.setRoot(nodes.get(0)); if (!randomNames) { renameTreeLeavesLeftToRight(tree); } return tree; }
private void setResultIds(Item item, int index) { if (item != null && item instanceof CatalogItem) { CatalogItem catalogItem = (CatalogItem) item; if (catalogItem.IsChecked) { int insertIndex = index <= 0 ? -1 : (index - 1); if (mySelectedItems.contains(catalogItem)) { mySelectedItems.remove(catalogItem); } if (insertIndex >= 0) { mySelectedItems.add(insertIndex, catalogItem); } else { mySelectedItems.add(catalogItem); } } else { mySelectedItems.remove(catalogItem); } final ArrayList<String> ids = new ArrayList<String>(); for (Item selectedItem : mySelectedItems) { if (selectedItem instanceof CatalogItem) { final CatalogItem ci = (CatalogItem) selectedItem; if (ci.IsChecked) { ids.add(ci.Id); } } } setResult( RESULT_OK, new Intent() .putStringArrayListExtra(NetworkLibraryActivity.ENABLED_CATALOG_IDS_KEY, ids)); } }
static void recursive(List<List<String>> nqueens, List<Integer> list, int n) { if (list.size() == n) { List<String> board = new ArrayList<String>(); for (int i = 0; i < n; i++) { StringBuilder row = new StringBuilder(); for (int j = 0; j < n; j++) row.append(list.get(i) == j ? "Q" : "."); board.add(row.toString()); } nqueens.add(board); list.remove(list.size() - 1); return; } for (int i = 0; i < n; i++) { boolean isValid = true; int x1 = list.size(); int y1 = i; for (int j = 0; j < list.size(); j++) { int x2 = j; int y2 = list.get(j); if (y1 == y2 || Math.abs(x1 - x2) == Math.abs(y1 - y2)) { isValid = false; break; } } if (isValid) { list.add(i); recursive(nqueens, list, n); } } if (!list.isEmpty()) list.remove(list.size() - 1); }
/** * If the user has selected random colors, pick them randomly for the user. * * @param selectedColors a string of the colors selected. * @return a String representation of the new colors chosen. */ private static String getRandomColors(String selectedColors) { Random random = new Random(); List<Character> availableColors = new ArrayList<>(); for (ColoredManaSymbol cms : ColoredManaSymbol.values()) { availableColors.add(cms.toString().charAt(0)); } StringBuilder generatedColors = new StringBuilder(); int randomColors = 0; for (int i = 0; i < selectedColors.length(); i++) { char currentColor = selectedColors.charAt(i); if (currentColor != 'X') { generatedColors.append(currentColor); availableColors.remove(new Character(currentColor)); } else { randomColors++; } } for (int i = 0; i < randomColors && !availableColors.isEmpty(); i++) { int index = random.nextInt(availableColors.size()); generatedColors.append(availableColors.remove(index)); } return generatedColors.toString(); }
protected static String[] reorder(String[] enabled, String[] known, String[] blacklisted) { List<String> unknown = new ArrayList<String>(); Collections.addAll(unknown, enabled); // Remove blacklisted items if (blacklisted != null) { for (String item : blacklisted) { unknown.remove(item); } } // Order known items List<String> result = new ArrayList<String>(); for (String item : known) { if (unknown.remove(item)) { result.add(item); } } // Add unknown items at the end. This way security won't get worse when unknown ciphers // start showing up in the future. result.addAll(unknown); return result.toArray(new String[result.size()]); }
public static void main(String[] args) { Scanner cin = new Scanner(System.in); List<String> s1 = new ArrayList<String>(); List<String> s2 = new ArrayList<String>(); int indexS1 = 0; int indexS2 = 0; s1.add(cin.nextLine()); while (s1.get(indexS1).charAt(0) != 'X') { indexS1++; s1.add(cin.nextLine()); } s1.remove(indexS1); Collections.sort(s1); s2.add(cin.nextLine()); while (s2.get(indexS2).charAt(0) != 'X') { indexS2++; s2.add(cin.nextLine()); } s2.remove(indexS2); for (int i = 0; i < s2.size(); i++) { boolean out = false; for (int j = 0; j < s1.size(); j++) { if (isSame(s2.get(i), s1.get(j))) { System.out.println(s1.get(j)); out = true; } } if (!out) { System.out.println("NOT A VALID WORD"); } System.out.println("******"); } }
private void clearOutTheINEventAndIrpListForISO(List listOfPipeEvents, List listOfIrps) { // all of the IRPs and events in which we are interested SHOULD have a non zero length // amount of data returned. // Once the zero length data IRPs and events are removed, only the IRPs and events that received // the // expected OUT data should be left in the lists printDebug("Total pipe events for IN ISO is " + listOfPipeEvents.size()); for (int i = (listOfPipeEvents.size() - 1); i >= 0; i--) { // all of the IRPs in which we are interested SHOULD have a non zero length // amount of data returned. // Once the zero length data IRP events are removed, only the IRP events that received the // expected OUT data should be left in the list Assert.assertTrue( "There should be no error events in the list.", ((UsbPipeEvent) listOfPipeEvents.get(i)).getClass() == UsbPipeDataEvent.class); if (((UsbPipeDataEvent) listOfPipeEvents.get(i)).getUsbIrp().getActualLength() == 0) { listOfPipeEvents.remove(i); Assert.assertEquals( "Original Irps and pipe event Irps should be zero actual length in the same position in the list.", 0, ((UsbIrp) listOfIrps.get(i)).getActualLength()); listOfIrps.remove(i); } else { Assert.assertEquals( "Original Irps and pipe event Irps actual length should be the same at the same position in the list.", ((UsbPipeDataEvent) listOfPipeEvents.get(i)).getUsbIrp().getActualLength(), ((UsbIrp) listOfIrps.get(i)).getActualLength()); printDebug("Non-zero actual length pipe event found at index " + i); } } Assert.assertFalse( "None of the Isochronous IN IRPs received any data", 0 == listOfPipeEvents.size()); };
/** * fileReader builds a scene from a file * * @return sceneOfInput * @throws IOException */ public static Scene fileReader() throws IOException { long startTime = System.currentTimeMillis(); // FileReader fr = new FileReader("file/LogManager-short.dat"); FileReader fr = new FileReader("file/LogManager-live-tool-2.dat"); // FileReader fr = new FileReader("file/LogManager-example.dat"); // FileReader fr = new FileReader("file/LogManager-long.dat"); BufferedReader br = new BufferedReader(fr); String line = ""; List<Tick> tmpTickList = new ArrayList<Tick>(); /* * Read file, split lines into Type and Timestamp, generate Ticks */ while ((line = br.readLine()) != null) { String[] parts = line.split(";", -1); int tmpTimestamp = Integer.parseInt(parts[0]); Tick tmpTick = new Tick(tmpTimestamp, parts[1], parts[2]); tmpTickList.add(tmpTick); } br.close(); /* * filtering out special hashmarks and adding their content to mark before */ int lastHashMark = 0; for (int i = 0; i < tmpTickList.size(); i++) { Tick currentTick = tmpTickList.get(i); if (currentTick.getType().compareTo("########") == 0) { lastHashMark = i; } else if (currentTick.getType().compareTo("#+#+#+#+") == 0) { if (lastHashMark == 0) { // if first mark is special hash tmpTickList.remove(i); // remove it } else { tmpTickList.remove(lastHashMark); // otherwise remove last normal hash currentTick.setType("########"); // and convert special to normal hash // thus adding special object to normal lastHashMark = i - 1; // set new hashmark } } } List<Sequence> sequenceList = structureCreator(tmpTickList); Sequence[] sequenceArray = new Sequence[sequenceList.size()]; sequenceArray = sequenceList.toArray(sequenceArray); Scene sceneFromInput = new Scene(sequenceArray); System.out.println((System.currentTimeMillis() - startTime) + " milliseconds to read log"); return sceneFromInput; }
private void removePlayer(Player player) { int index = players.indexOf(player); if (index < 0) return; players.remove(index); Game game = games.remove(index); removeController(player, index); game.destroy(); }
public void deleteChangeList(final ShelvedChangeList changeList) { deleteListImpl(changeList); if (!changeList.isRecycled()) { myShelvedChangeLists.remove(changeList); } else { myRecycledShelvedChangeLists.remove(changeList); } notifyStateChanged(); }
public void addBookToRecentList(Book book) { final List<Long> ids = myDatabase.loadRecentBookIds(); final Long bookId = book.getId(); ids.remove(bookId); ids.add(0, bookId); if (ids.size() > 12) { ids.remove(12); } myDatabase.saveRecentBookIds(ids); }
/** * Removes an object from the collection of choices. * * @param object The object to be removed */ public void remove(T object) { int index = choices.indexOf(object); total -= currentFreqs.get(index); choices.remove(index); baseFreqs.remove(index); currentFreqs.remove(index); while (pregenerated.remove(object)) /* nothing inside loop */ ; }
private static void filter(List<Class> tests) { // Requires separate datasets project tests.remove(ParseFolderTestBig.class); // Too slow tests.remove(ConcurrentKeyTest.class); tests.remove(ValueArrayToFrameTestAll.class); // Pure JUnit test // tests.remove(CBSChunkTest.class); //tests.remove(GBMDomainTest.class); }
public static void main(String[] args) { Random rand = new Random(47); List<Pet> pets = Pets.arrayList(7); print("1: " + pets); Hamster h = new Hamster(); pets.add(h); // Automatically resizes print("2: " + pets); print("3: " + pets.contains(h)); pets.remove(h); // Remove by object Pet p = pets.get(2); print("4: " + p + " " + pets.indexOf(p)); Pet cymric = new Cymric(); print("5: " + pets.indexOf(cymric)); print("6: " + pets.remove(cymric)); // Must be the exact object: print("7: " + pets.remove(p)); print("8: " + pets); pets.add(3, new Mouse()); // Insert at an index print("9: " + pets); List<Pet> sub = pets.subList(1, 4); print("subList: " + sub); print("10: " + pets.containsAll(sub)); Collections.sort(sub); // In-place sort print("sorted subList: " + sub); // Order is not important in containsAll(): print("11: " + pets.containsAll(sub)); Collections.shuffle(sub, rand); // Mix it up print("shuffled subList: " + sub); print("12: " + pets.containsAll(sub)); List<Pet> copy = new ArrayList<Pet>(pets); sub = Arrays.asList(pets.get(1), pets.get(4)); print("sub: " + sub); copy.retainAll(sub); print("13: " + copy); copy = new ArrayList<Pet>(pets); // Get a fresh copy copy.remove(2); // Remove by index print("14: " + copy); copy.removeAll(sub); // Only removes exact objects print("15: " + copy); copy.set(1, new Mouse()); // Replace an element print("16: " + copy); copy.addAll(2, sub); // Insert a list in the middle print("17: " + copy); print("18: " + pets.isEmpty()); pets.clear(); // Remove all elements print("19: " + pets); print("20: " + pets.isEmpty()); pets.addAll(Pets.arrayList(4)); print("21: " + pets); Object[] o = pets.toArray(); print("22: " + o[3]); Pet[] pa = pets.toArray(new Pet[0]); print("23: " + pa[3].id()); }
@Override public void removePlayerByIp(String ip) { lock.writeLock().lock(); try { int index = players.indexOf(findPlayerByIp(ip)); if (index < 0) return; players.remove(index); games.remove(index); } finally { lock.writeLock().unlock(); } }
/** * follows the root by all its children to wrap the all up with all the extra info needed and adds * the tree to the matrix. * * @param currRoot - root to go over tree from * @param entitiesList - entities available * @param relationshipsList - relationship between the given entities * @param currRow - the current row in the matrix we are working on * @param rows - the matrix. */ private void builtTreeFromRoot( GXMoreThanNode currRoot, List<InternalNode> entitiesList, List<InternalRelationship> relationshipsList, List<GXMoreThanNode> currRow, List<List<GXMoreThanNode>> rows) { // this is the first node that comes from the currRoot // we'll use the mark to know where to continue laying out from GXMoreThanNode mark = null; List<InternalRelationship> relationshipsListCopy = new ArrayList<InternalRelationship>(relationshipsList); // Orders the children of the currRoot in the given row (the row under it) for (InternalRelationship rel : relationshipsListCopy) { if (currRoot.getNode().equals(rel.getSource())) { InternalNode destNode = rel.getDestination(); // if the destination node hasn't been laid out yet if (entitiesList.contains(destNode)) { // place it in the row (as in lay it out) GXMoreThanNode currNode = new GXMoreThanNode(destNode, currRoot.getNode()); currRoot.addChild(currNode); currRow.add(currNode); currNode.addedToRow(currRow); entitiesList.remove(destNode); // if this is the first node, save it as a mark. if (mark == null) { mark = currNode; } // remove the relationship since both of its ends have been laid out. relationshipsList.remove(rel); } } } // if new children have been added if (mark != null) { // Create a next row if necessary if (rows.size() - 1 <= rows.indexOf(currRow)) { rows.add(new ArrayList<GXMoreThanNode>()); } List<GXMoreThanNode> nextRow = rows.get(rows.indexOf(currRow) + 1); for (int i = currRow.indexOf(mark); i < currRow.size(); i++) { builtTreeFromRoot(currRow.get(i), entitiesList, relationshipsList, nextRow, rows); } } }
private static void pathto(World world, int i, int j, int k) { List<ChunkCoordinates> blocks = Lists.newLinkedList(); List<ChunkCoordinates> portals = Lists.newLinkedList(); List<ChunkCoordinates> repath = Lists.newLinkedList(); List<ChunkCoordinates> redraw = Lists.newLinkedList(); blocks.add(new ChunkCoordinates(i, j, k)); while ((portals.size() > 0) || (blocks.size() > 0)) { while (blocks.size() > 0) { ChunkCoordinates coords = blocks.remove(0); directPortal(world, coords.posX + 1, coords.posY, coords.posZ, 5, blocks, portals); directPortal(world, coords.posX, coords.posY + 1, coords.posZ, 1, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ + 1, 3, blocks, portals); directPortal(world, coords.posX - 1, coords.posY, coords.posZ, 6, blocks, portals); directPortal(world, coords.posX, coords.posY - 1, coords.posZ, 2, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ - 1, 4, blocks, portals); redraw.add(coords); } if (portals.size() > 0) { ChunkCoordinates coords = portals.remove(0); directPortal(world, coords.posX + 1, coords.posY, coords.posZ, 5, blocks, portals); directPortal(world, coords.posX, coords.posY + 1, coords.posZ, 1, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ + 1, 3, blocks, portals); directPortal(world, coords.posX - 1, coords.posY, coords.posZ, 6, blocks, portals); directPortal(world, coords.posX, coords.posY - 1, coords.posZ, 2, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ - 1, 4, blocks, portals); if (world.getBlock(coords.posX, coords.posY, coords.posZ) == NailedBlocks.portal) { repath.add(coords); } } } while (repath.size() > 0) { ChunkCoordinates coords = repath.remove(0); if (world.getBlock(coords.posX, coords.posY, coords.posZ) == NailedBlocks.portal) { if (!BlockPortal.isValidPortal(world, coords.posX, coords.posY, coords.posZ)) { repathNeighbors(world, coords.posX, coords.posY, coords.posZ); world.setBlock(coords.posX, coords.posY, coords.posZ, Blocks.air, 0, 0); addSurrounding(repath, coords.posX, coords.posY, coords.posZ); } else { redraw.add(coords); } } } for (ChunkCoordinates coords : redraw) { if (world.blockExists(coords.posX, coords.posY, coords.posZ)) { world.markBlockForUpdate(coords.posX, coords.posY, coords.posZ); world.notifyBlocksOfNeighborChange( coords.posX, coords.posY, coords.posZ, world.getBlock(coords.posX, coords.posY, coords.posZ)); } } }
@Override public String readLine() throws IOException { if (buffer.size() > 0) { return buffer.remove(0); } else { String line = super.readLine(); if (line == null) { return null; } buffer.addAll(lineExpander.expandLine(line)); return buffer.remove(0); } }
public static Pair<Phylogeny, Phylogeny> generateIdenticalRandomTrees( int size, boolean randomNames) { Random random = new Random(); List<PhylogenyNode> t1Nodes = new ArrayList<>(); List<PhylogenyNode> t2Nodes = new ArrayList<>(); for (int i = 0; i < size; i++) { PhylogenyNode t1NewNode = new PhylogenyNode(); PhylogenyNode t2NewNode = new PhylogenyNode(); t1NewNode.setName(i + ""); t2NewNode.setName(i + ""); t1Nodes.add(t1NewNode); t2Nodes.add(t2NewNode); } while (t1Nodes.size() > 1) { int i = random.nextInt(t1Nodes.size()); PhylogenyNode t1Child1 = t1Nodes.get(i); PhylogenyNode t2Child1 = t2Nodes.get(i); t1Nodes.remove(i); t2Nodes.remove(i); int j = random.nextInt(t1Nodes.size()); PhylogenyNode t1Child2 = t1Nodes.get(j); PhylogenyNode t2Child2 = t2Nodes.get(j); t1Nodes.remove(j); t2Nodes.remove(j); PhylogenyNode t1NewNode = new PhylogenyNode(); PhylogenyNode t2NewNode = new PhylogenyNode(); t1NewNode.setChild1(t1Child1); t1NewNode.setChild2(t1Child2); t2NewNode.setChild1(t2Child1); t2NewNode.setChild2(t2Child2); t1Nodes.add(t1NewNode); t2Nodes.add(t2NewNode); t1NewNode.setName(t1NewNode.getId() + ""); t2NewNode.setName(t2NewNode.getId() + ""); } Phylogeny tree1 = new Phylogeny(); Phylogeny tree2 = new Phylogeny(); tree1.setRoot(t1Nodes.get(0)); tree2.setRoot(t2Nodes.get(0)); if (!randomNames) { renameTreeLeavesLeftToRight(tree1); renameTreeLeavesLeftToRight(tree2); } return new Pair<>(tree1, tree2); }
private void backwardsConditioning(List<Node> pc, Node target) { for (Node x : new LinkedList<>(pc)) { List<Node> _pc = new LinkedList<>(pc); _pc.remove(x); _pc.remove(target); List<Node> minAssoc = minAssoc(x, target, _pc); numIndTests++; if (independenceTest.isIndependent(x, target, minAssoc)) { pc.remove(x); } } }
public static void removeInactiveMyPet(InactiveMyPet inactiveMyPet) { if (inactiveMyPet == null) { return; } lInactivePets.remove(inactiveMyPet); if (mInctivePets.containsKey(inactiveMyPet.getPetOwner())) { List<InactiveMyPet> myPetList = mInctivePets.get(inactiveMyPet.getPetOwner()); if (myPetList.contains(inactiveMyPet)) { myPetList.remove(inactiveMyPet); } if (myPetList.size() == 0) { mInctivePets.remove(inactiveMyPet.getPetOwner()); } } }
/** * Merge list of expressions into a tree of logical/relational expressions. This is done * recursively in several passes, one per level of precedence starting at the highest precedence * level. Recursion exits when a single expression remains. * * @param listExpressions list of expressions to merge * @param precedenceLevel the precedence level that is to be merged * @return tree of expressions with a single root expression */ private List<Expression> mergeExpressions(List<Expression> listExpressions, int precedenceLevel) { if (listExpressions.size() > 1) { Stack<Expression> stack = new Stack<Expression>(); stack.push(listExpressions.remove(0)); while (!listExpressions.isEmpty()) { Expression exp = stack.pop(); Expression left = stack.empty() ? null : stack.pop(); Expression right = listExpressions.remove(0); stack.addAll(exp.merge(left, right, precedenceLevel)); } return mergeExpressions(new ArrayList<Expression>(stack), precedenceLevel - 1); } return listExpressions; }
public Map<String, List> fetchBibHolding(boolean cursor) throws SQLException { String holdingId = ""; String tempHoldingId = ""; List bibIds = new ArrayList(); Map<String, List> map = null; if (cursor) { while (bibHoldingsResultSet.next()) { holdingId = "who-" + bibHoldingsResultSet.getString("HOLDINGS_ID"); if (StringUtils.isNotEmpty(tempHoldingId) && !tempHoldingId.equals(holdingId)) { if (bibIds.size() > 0) { map = new HashMap<>(); bibIds.remove(0); map.put(tempHoldingId, bibIds); return map; } } bibIds.add("wbm-" + bibHoldingsResultSet.getString("BIB_ID")); tempHoldingId = holdingId; } } else { while (bibHoldingsResultSet.next()) { holdingId = "who-" + bibHoldingsResultSet.getString("HOLDINGS_ID"); if (StringUtils.isNotEmpty(tempHoldingId) && !tempHoldingId.equals(holdingId)) { map = new HashMap<>(); map.put(tempHoldingId, bibIds); return map; } bibIds.add("wbm-" + bibHoldingsResultSet.getString("BIB_ID")); tempHoldingId = holdingId; } } if (bibIds.size() > 0) { map = new HashMap<>(); bibIds.remove(0); map.put(tempHoldingId, bibIds); return map; } else { map = null; } bibHoldingsResultSet.close(); return map; }
/** * Builds the matrix of nodes. each node will be wrapped with necessary innformation such as who * are the direct children and parent (only visually in the graph not the actual relationships) * the returned matrix is organized more or less as the real tree. * * @param entitiesList - entities to place in the matrix * @param relationshipsList - the relationships between the entities given * @return the matrix - (a list of rows of nodes) */ private List<List<GXMoreThanNode>> buildNodeMatrix( List<InternalNode> entitiesList, List<InternalRelationship> relationshipsList) { List<List<GXMoreThanNode>> rows = new ArrayList<List<GXMoreThanNode>>(); while (!entitiesList.isEmpty()) { InternalNode root = getFirstEntity(entitiesList, relationshipsList); // add root row if necessary if (rows.isEmpty()) { rows.add(new ArrayList<GXMoreThanNode>()); rows.add(new ArrayList<GXMoreThanNode>()); } // lay out the current root node and remove it from the list of entities left entitiesList.remove(root); GXMoreThanNode moreThanRoot = new GXMoreThanNode(root, null); rows.get(0).add(moreThanRoot); // build the tree that spreads from this current root. builtTreeFromRoot(moreThanRoot, entitiesList, relationshipsList, rows.get(1), rows); } trimEmptyRows(rows); return rows; }