List of usage examples for java.util LinkedList remove
public E remove(int index)
From source file:msearch.filmeSuchen.sender.MediathekReader.java
static void listeSort(LinkedList<String[]> liste, int stelle) { //Stringliste alphabetisch sortieren GermanStringSorter sorter = GermanStringSorter.getInstance(); if (liste != null) { String str1;/*from ww w . j a v a2 s .co m*/ String str2; for (int i = 1; i < liste.size(); ++i) { for (int k = i; k > 0; --k) { str1 = liste.get(k - 1)[stelle]; str2 = liste.get(k)[stelle]; // if (str1.compareToIgnoreCase(str2) > 0) { if (sorter.compare(str1, str2) > 0) { liste.add(k - 1, liste.remove(k)); } else { break; } } } } }
From source file:jp.co.ctc_g.jse.vid.ViewId.java
private static void is(ViewId self, ViewIdStore store) { Args.checkNotNull(self);//from w w w .ja va 2 s. c o m self.freeze(); synchronized (store.semaphore()) { LinkedList<ViewId> ids = store.find(); assert ids != null; if (ids.contains(self)) { int index = ids.indexOf(self); for (int i = ids.size() - 1; i > index; i--) { ids.remove(i); } if (OVERRIDE_THE_SAME_ONE) { ids.set(index, self); } } else { ids.add(self); } store.store(ids); } }
From source file:ubic.gemma.core.datastructure.matrix.ExpressionDataMatrixColumnSort.java
/** * Sort biomaterials according to a list of ordered factors * * @param start biomaterials to sort/*from w w w .j av a2 s.c o m*/ * @param factors sorted list of factors to define sort order for biomaterials, cannot be null */ private static List<BioMaterial> orderBiomaterialsBySortedFactors(List<BioMaterial> start, List<ExperimentalFactor> factors) { if (start.size() == 1) { return start; } if (start.size() == 0) { throw new IllegalArgumentException("Must provide some biomaterials"); } if (factors == null) { throw new IllegalArgumentException("Must provide sorted factors, or at least an empty list"); } if (factors.isEmpty()) { // we're done. return start; } ExperimentalFactor simplest = factors.get(0); if (simplest == null) { // we're done. return start; } /* * Order this chunk by the selected factor */ Map<FactorValue, List<BioMaterial>> fv2bms = ExpressionDataMatrixColumnSort.buildFv2BmMap(start); List<BioMaterial> ordered = ExpressionDataMatrixColumnSort.orderByFactor(simplest, fv2bms, start); // Abort ordering, so we are ordered only by the first continuous factor. if (ExperimentalDesignUtils.isContinuous(simplest)) { assert ordered != null; return ordered; } LinkedList<ExperimentalFactor> factorsStillToDo = new LinkedList<>(); factorsStillToDo.addAll(factors); factorsStillToDo.remove(simplest); if (factorsStillToDo.size() == 0) { /* * No more ordering is necessary. */ return ordered; } ExpressionDataMatrixColumnSort.log.debug("Factors: " + factors.size()); /* * Recurse in and order each chunk. First split it up, but retaining the order we just made. */ LinkedHashMap<FactorValue, List<BioMaterial>> chunks = ExpressionDataMatrixColumnSort .chunkOnFactor(simplest, ordered); if (chunks == null) { // this means we should bail, gracefully. return start; } /* * Process each chunk. */ List<BioMaterial> result = new ArrayList<>(); for (FactorValue fv : chunks.keySet()) { List<BioMaterial> chunk = chunks.get(fv); if (chunk.size() < 2) { result.addAll(chunk); } else { List<BioMaterial> orderedChunk = ExpressionDataMatrixColumnSort .orderBiomaterialsBySortedFactors(chunk, factorsStillToDo); if (orderedChunk != null) { result.addAll(orderedChunk); } } } return result; }
From source file:data_gen.Data_gen.java
private static void multi_enum_json(HashMap<String, Object> fields, String key, String value) { try {//from w w w .ja v a 2 s .c om String[] values = value.split(":"); String trim_val = values[1].substring(1, values[1].length() - 1); String[] possible_values = trim_val.split(","); LinkedList<String> all = new LinkedList(Arrays.asList(possible_values)); Random rand = new Random(); Random rand2 = new Random(); String result = ""; int r = rand.nextInt(possible_values.length - 1); if (r == 0) { r = 1; } String[] words = new String[r]; for (int i = 0; i < r; i++) { int r2 = rand.nextInt(all.size() - 1); words[i] = all.get(r2); all.remove(r2); } List<String> myList = new ArrayList<>(Arrays.asList(words)); fields.put(key, myList); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Make sure you have the right multi value enumeration format in configration file"); System.out.println("example: multi:[science,sport,art,literature,politics]" + "\n"); System.exit(0); } }
From source file:data_gen.Data_gen.java
private static void multi_enum_dat(HashMap<String, Object> fields, String key, String value) { try {/*from ww w . ja v a2 s . co m*/ String[] values = value.split(":"); String trim_val = values[1].substring(1, values[1].length() - 1); String[] possible_values = trim_val.split(","); LinkedList<String> all = new LinkedList(Arrays.asList(possible_values)); Random rand = new Random(); Random rand2 = new Random(); String result = ""; int r = rand.nextInt(possible_values.length - 1); if (r == 0) { r = 1; } String[] words = new String[r]; for (int i = 0; i < r; i++) { int r2 = rand.nextInt(all.size() - 1); words[i] = all.get(r2); all.remove(r2); } String multi_values = ""; for (int i = 0; i < words.length; i++) { multi_values += words[i] + (char) 59; } multi_values = multi_values.substring(0, multi_values.length() - 1); fields.put(key, multi_values); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Make sure you have the right multi value enumeration format in configration file"); System.out.println("example: multi:[science,sport,art,literature,politics]" + "\n"); System.exit(0); } }
From source file:syndeticlogic.memento.LfuStrategy.java
@Override public void revalueNode(Cache.CacheNode node) { assert node != null && node instanceof LfuNode; LfuNode n = (LfuNode) node;/*from w ww . ja va 2 s. c om*/ LinkedListNode lln = n.lfuNode; LinkedList currBucket = lru(n.numUsages); LinkedList nextBucket = lru(++n.numUsages); currBucket.remove(lln); n.lfuNode = nextBucket.addFirst(lln.getValue()); }
From source file:org.objectrepository.instruction.InstructionAutocreateService.java
/** * objid//ww w . j a v a 2 s . c om * * Add an object ID based on the folder structure: * /a/b/c/d becomes [na]/a.b.c.d * * @param instruction * @param stagingfileType */ private void objid(InstructionType instruction, StagingfileType stagingfileType) { if (instruction.getObjid() == null) { LinkedList list = new LinkedList(Arrays.asList(stagingfileType.getLocation().split("/"))); list.remove(list.size() - 1); list.remove(0); String objid = instruction.getNa() + "/" + StringUtils.join(list, '.'); stagingfileType.setObjid(objid); } }
From source file:io.github.jeddict.jpa.spec.extend.cache.Cache.java
public void addClass(String _class, LinkedList<String> collection) { if (StringUtils.isEmpty(_class)) { return;//from ww w.j a va2 s . c o m } if (collection.contains(_class)) { collection.remove(_class); } while (COLLECTION_SIZE < collection.size()) { collection.removeLast(); } collection.addFirst(_class); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java
private static Pair<Boolean, Boolean> pushThroughOp(HashSet<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef2, ILogicalOperator initialOp, IOptimizationContext context) throws AlgebricksException { List<LogicalVariable> initProjectList = new ArrayList<LogicalVariable>(toPush); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); do {//from w w w. j a v a 2s. c o m if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE || op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE || op2.getOperatorTag() == LogicalOperatorTag.PROJECT || op2.getOperatorTag() == LogicalOperatorTag.REPLICATE || op2.getOperatorTag() == LogicalOperatorTag.UNIONALL) { return new Pair<Boolean, Boolean>(false, false); } if (!op2.isMap()) { break; } LinkedList<LogicalVariable> usedVars = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(op2, usedVars); toPush.addAll(usedVars); LinkedList<LogicalVariable> producedVars = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, producedVars); toPush.removeAll(producedVars); // we assume pipelineable ops. have only one input opRef2 = op2.getInputs().get(0); op2 = (AbstractLogicalOperator) opRef2.getValue(); } while (true); LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, produced2); LinkedList<LogicalVariable> used2 = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(op2, used2); boolean canCommuteProjection = initProjectList.containsAll(toPush) && initProjectList.containsAll(produced2) && initProjectList.containsAll(used2); // if true, we can get rid of the initial projection // get rid of useless decor vars. if (!canCommuteProjection && op2.getOperatorTag() == LogicalOperatorTag.GROUP) { boolean gbyChanged = false; GroupByOperator gby = (GroupByOperator) op2; List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> newDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) { LogicalVariable decorVar = GroupByOperator.getDecorVariable(p); if (!toPush.contains(decorVar)) { used2.remove(decorVar); gbyChanged = true; } else { newDecorList.add(p); } } gby.getDecorList().clear(); gby.getDecorList().addAll(newDecorList); if (gbyChanged) { context.computeAndSetTypeEnvironmentForOperator(gby); } } used2.clear(); VariableUtilities.getUsedVariables(op2, used2); toPush.addAll(used2); // remember that toPush is a Set toPush.removeAll(produced2); if (toPush.isEmpty()) { return new Pair<Boolean, Boolean>(false, false); } boolean smthWasPushed = false; for (Mutable<ILogicalOperator> c : op2.getInputs()) { if (pushNeededProjections(toPush, c, context, initialOp)) { smthWasPushed = true; } } if (op2.hasNestedPlans()) { AbstractOperatorWithNestedPlans n = (AbstractOperatorWithNestedPlans) op2; for (ILogicalPlan p : n.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { if (pushNeededProjections(toPush, r, context, initialOp)) { smthWasPushed = true; } } } } return new Pair<Boolean, Boolean>(smthWasPushed, canCommuteProjection); }
From source file:io.hops.common.INodeUtil.java
public static void findPathINodesById(long inodeId, boolean inTree, LinkedList<INode> preTxResolvedINodes, boolean[] isPreTxPathFullyResolved) throws StorageException { if (inTree) { INode inode = indexINodeScanById(inodeId); if (inode == null) { isPreTxPathFullyResolved[0] = false; return; }/*w w w. ja va2s . c om*/ preTxResolvedINodes.add(inode); readFromLeafToRoot(inode, preTxResolvedINodes); } isPreTxPathFullyResolved[0] = true; //reverse the list int firstCounter = 0; int lastCounter = preTxResolvedINodes.size() - 1 - firstCounter; INode firstNode = null; INode lastNode = null; while (firstCounter < (preTxResolvedINodes.size() / 2)) { firstNode = preTxResolvedINodes.get(firstCounter); lastNode = preTxResolvedINodes.get(lastCounter); preTxResolvedINodes.remove(firstCounter); preTxResolvedINodes.add(firstCounter, lastNode); preTxResolvedINodes.remove(lastCounter); preTxResolvedINodes.add(lastCounter, firstNode); firstCounter++; lastCounter = preTxResolvedINodes.size() - 1 - firstCounter; } }