List of usage examples for java.util ListIterator previous
E previous();
From source file:jp.aegif.nemaki.tracker.CoreTracker.java
/** * * @param events/*from ww w . j a v a2 s . c om*/ * @return */ private List<ChangeEvent> extractChangeEvent(List<ChangeEvent> events) { List<ChangeEvent> list = new ArrayList<ChangeEvent>(); Set<String> objectIds = new HashSet<String>(); int size = events.size(); ListIterator<ChangeEvent> iterator = events.listIterator(size); while (iterator.hasPrevious()) { ChangeEvent event = iterator.previous(); if (objectIds.contains(event.getObjectId())) { continue; } else { objectIds.add(event.getObjectId()); list.add(event); } } Collections.reverse(list); return list; }
From source file:hu.ppke.itk.nlpg.purepos.model.internal.NGramModel.java
@Override public void addWord(List<Integer> context, W word) { ListIterator<Integer> iterator = context.listIterator(context.size()); IntTrieNode<W> act = root;//from w w w. jav a 2 s . c o m int i = 0; int size = n - 1; act.addWord(word); while (iterator.hasPrevious() && i < size) { act = (IntTrieNode<W>) act.addChild(iterator.previous()); act.addWord(word); i++; } }
From source file:org.apache.storm.metricstore.rocksdb.RocksDbMetricsWriter.java
/** * Performs the actual metric insert, and aggregates over all bucket times. * * @param metric Metric to store//from w w w .j a va2 s.c o m * @throws MetricException if database write fails */ private void processInsert(Metric metric) throws MetricException { // convert all strings to numeric Ids for the metric key and add to the metadata cache long metricTimestamp = metric.getTimestamp(); Integer topologyId = storeMetadataString(KeyType.TOPOLOGY_STRING, metric.getTopologyId(), metricTimestamp); Integer metricId = storeMetadataString(KeyType.METRIC_STRING, metric.getMetricName(), metricTimestamp); Integer componentId = storeMetadataString(KeyType.COMPONENT_STRING, metric.getComponentId(), metricTimestamp); Integer executorId = storeMetadataString(KeyType.EXEC_ID_STRING, metric.getExecutorId(), metricTimestamp); Integer hostId = storeMetadataString(KeyType.HOST_STRING, metric.getHostname(), metricTimestamp); Integer streamId = storeMetadataString(KeyType.STREAM_ID_STRING, metric.getStreamId(), metricTimestamp); RocksDbKey key = RocksDbKey.createMetricKey(AggLevel.AGG_LEVEL_NONE, topologyId, metric.getTimestamp(), metricId, componentId, executorId, hostId, metric.getPort(), streamId); // save metric key/value to be batched RocksDbValue value = new RocksDbValue(metric); insertBatch.put(key, value); // Aggregate matching metrics over bucket timeframes. // We'll process starting with the longest bucket. If the metric for this does not exist, we don't have to // search for the remaining bucket metrics. ListIterator li = aggBuckets.listIterator(aggBuckets.size()); boolean populate = true; while (li.hasPrevious()) { AggLevel bucket = (AggLevel) li.previous(); Metric aggMetric = new Metric(metric); aggMetric.setAggLevel(bucket); long msToBucket = 1000L * 60L * bucket.getValue(); long roundedToBucket = msToBucket * (metric.getTimestamp() / msToBucket); aggMetric.setTimestamp(roundedToBucket); RocksDbKey aggKey = RocksDbKey.createMetricKey(bucket, topologyId, aggMetric.getTimestamp(), metricId, componentId, executorId, hostId, aggMetric.getPort(), streamId); if (populate) { // retrieve any existing aggregation matching this one and update the values if (store.populateFromKey(aggKey, aggMetric)) { aggMetric.addValue(metric.getValue()); } else { // aggregating metric did not exist, don't look for further ones with smaller timestamps populate = false; } } // save metric key/value to be batched RocksDbValue aggVal = new RocksDbValue(aggMetric); insertBatch.put(aggKey, aggVal); } processBatchInsert(insertBatch); insertBatch.clear(); }
From source file:org.broadinstitute.gatk.tools.walkers.haplotypecaller.graphs.Path.java
/** * Checks whether a given path is a suffix of this path. *//w w w . ja va2 s . c o m * @param other the path to compare against. * @throws IllegalArgumentException if <code>other</code> is <code>null</code>, or the come from * different graphs. * @return true if <code>other</code> is a suffix of this path. */ public boolean isSuffix(final Path<T, E> other) { if (other == null) throw new IllegalArgumentException("path cannot be null"); if (other.getGraph() != this.getGraph()) throw new IllegalArgumentException("the other path most belong to the same path"); if (!lastVertex.equals(other.lastVertex)) return false; final ListIterator<E> myIt = edgesInOrder.listIterator(edgesInOrder.size()); final ListIterator<E> otherIt = other.edgesInOrder.listIterator(other.edgesInOrder.size()); while (myIt.hasPrevious() && otherIt.hasPrevious()) if (otherIt.previous() != myIt.previous()) return false; return !otherIt.hasPrevious(); }
From source file:samples.com.axiomine.largecollections.util.KryoListSample.java
public static void workOnKryoList(KryoList<Integer> lst) { try {// w ww .ja v a 2 s .c o m ListIterator<Integer> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(i); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { int i = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = lst.remove(9); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(9); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(9); Assert.assertEquals(true, b); i = lst.set(9, 99); Assert.assertEquals(99, i); i = lst.set(5, 55); Assert.assertEquals(55, i); i = lst.set(0, 100); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Integer> iter = lst.iterator(); try { while (iter.hasNext()) { i = iter.next(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Integer> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = lstIter.previous(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (KryoList<Integer>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(0); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }
From source file:org.mbari.aved.ui.classifier.knowledgebase.SearchableConceptTreePanel.java
/** * Loads the branch of a particular concept. This method does the following * <ol>/*from ww w.j a va2 s. c om*/ * <li>Walks from the concept up the tree to the root concept, storing * the concepts in a list. (This is very fast)</li> * <li>Starts walking from the root down (using lazyExpand), searching each * childnode for a matching primary name (which was stored in the first * step</li> * <li>If a matching primary name is found this stops otherwise * it opens the next level and searches for the next mathc in the list.</li> * <li></li> * </ol> * @param concept */ private void openNode(final Concept concept) { if (log.isDebugEnabled()) { log.debug("Opening node containing " + concept); } if (concept == null) { return; } // Get the list of concepts up to root final LinkedList conceptList = new LinkedList(); Concept c = concept; while (c != null) { conceptList.add(c); c = (Concept) c.getParentConcept(); } // Walk the tree from root on down opening nodes as we go final ListIterator i = conceptList.listIterator(conceptList.size()); // Skip the root i.previous(); final JTree tree = getJTree(); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); TreePath path = new TreePath(rootNode.getPath()); tree.setSelectionPath(path); DefaultMutableTreeNode parentNode = rootNode; while (i.hasPrevious()) { c = (Concept) i.previous(); final TreeConcept parentTreeConcept = (TreeConcept) parentNode.getUserObject(); parentTreeConcept.lazyExpand(parentNode); // treeModel.reload(parentNode); final Enumeration enm = parentNode.children(); while (enm.hasMoreElements()) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) enm.nextElement(); final TreeConcept tc = (TreeConcept) node.getUserObject(); if (tc.getName().equals(c.getPrimaryConceptNameAsString())) { parentNode = node; break; } } } final TreeNode _parentNode = parentNode; SwingUtilities.invokeLater(new Runnable() { public void run() { treeModel.reload(_parentNode); tree.scrollPathToVisible(new TreePath(_parentNode)); } }); }
From source file:samples.com.axiomine.largecollections.util.TurboListSample.java
public static void workOnTurboList(TurboList<Integer> lst) { try {//from w ww .j a va 2 s.c o m ListIterator<Integer> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(i); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { int i = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = lst.remove(9); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(9); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(9); Assert.assertEquals(true, b); i = lst.set(9, 99); Assert.assertEquals(99, i); i = lst.set(5, 55); Assert.assertEquals(55, i); i = lst.set(0, 100); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Integer> iter = lst.iterator(); try { while (iter.hasNext()) { i = iter.next(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Integer> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = lstIter.previous(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (TurboList<Integer>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(0); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }
From source file:org.apache.atlas.model.typedef.AtlasEnumDef.java
public void setElementDefs(List<AtlasEnumElementDef> elementDefs) { if (elementDefs != null && this.elementDefs == elementDefs) { return;//from w ww . ja v a2 s . co m } if (CollectionUtils.isEmpty(elementDefs)) { this.elementDefs = new ArrayList<>(); } else { // if multiple elements with same value are present, keep only the last entry List<AtlasEnumElementDef> tmpList = new ArrayList<>(elementDefs.size()); Set<String> elementValues = new HashSet<>(); ListIterator<AtlasEnumElementDef> iter = elementDefs.listIterator(elementDefs.size()); while (iter.hasPrevious()) { AtlasEnumElementDef elementDef = iter.previous(); String elementValue = elementDef != null ? elementDef.getValue() : null; if (elementValue != null) { elementValue = elementValue.toLowerCase(); if (!elementValues.contains(elementValue)) { tmpList.add(new AtlasEnumElementDef(elementDef)); elementValues.add(elementValue); } } } Collections.reverse(tmpList); this.elementDefs = tmpList; } }
From source file:org.netflux.core.RecordMetadata.java
/** * Removes from this metadata all the field metadata with names included in the supplied collection. * //from ww w. j a v a 2 s . c o m * @param fieldNames the names of the field metadata to remove. * @throws NullPointerException if the specified collection is <code>null</code>. */ public void remove(Collection<String> fieldNames) { LinkedHashMap<String, Integer> fieldsToRemove = (LinkedHashMap<String, Integer>) this.fieldIndexes.clone(); fieldsToRemove.keySet().retainAll(fieldNames); List<FieldMetadata> newFieldMetadata = (List<FieldMetadata>) this.fieldMetadata.clone(); ListIterator<Integer> fieldIndexIterator = new ArrayList<Integer>(fieldsToRemove.values()) .listIterator(fieldsToRemove.size()); while (fieldIndexIterator.hasPrevious()) { newFieldMetadata.remove(fieldIndexIterator.previous()); } this.setFieldMetadata(newFieldMetadata); }
From source file:com.neatresults.mgnltweaks.ui.field.ComponentTemplateSelectFieldFactory.java
private Map<String, TemplateDefinition> getAreaHierarchy(Node parentArea) throws RepositoryException, RegistrationException { Map<String, TemplateDefinition> areaHierarchy = new LinkedHashMap<String, TemplateDefinition>(); List<String> areaNamesHierarchy = new ArrayList<String>(); Node parentParentArea = parentArea; while (parentParentArea != null) { String areaName = parentParentArea.getName(); areaNamesHierarchy.add(areaName); parentParentArea = NodeUtil.getNearestAncestorOfType(parentParentArea, NodeTypes.Area.NAME); }//w ww.ja v a2 s.c om Node parentPage = NodeUtil.getNearestAncestorOfType(parentArea, NodeTypes.Page.NAME); templateId = parentPage.getProperty(NodeTypes.Renderable.TEMPLATE).getString(); TemplateDefinition templateDef = registry.getTemplateDefinition(templateId); templateDef = mergeDefinition(templateDef); ListIterator<String> iter = areaNamesHierarchy.listIterator(areaNamesHierarchy.size()); Node componentOrArea = parentPage; while (iter.hasPrevious()) { String name = iter.previous(); // subnode component is typically indication of having area type single if (!componentOrArea.hasNode(name) && (componentOrArea.hasNode("component") || (templateDef instanceof AreaDefinition && "single".equals(((AreaDefinition) templateDef).getType())))) { componentOrArea = componentOrArea.getNode("component/" + name); // so we know component is single, and we neeed to look if it has any sub areas String id = componentOrArea.getParent().getProperty(NodeTypes.Renderable.TEMPLATE).getString(); TemplateDefinition componentDef = registry.getTemplateDefinition(id); if (componentDef != null) { templateDef = componentDef; } } else { componentOrArea = componentOrArea.getNode(name); } // do we really need to merge here already? AreaDefinition area = templateDef.getAreas().get(name); if (area != null) { AreaDefinition areaDef = (AreaDefinition) mergeDefinition(area); templateDef = areaDef; } else { AreaDefinition maybeHit = templateDef.getAreas().get(name); if (maybeHit != null) { areaHierarchy.put(name, maybeHit); templateDef = maybeHit; } else { // get subareas of the area? what the hack was i thinking when writing this? How does it work anyway? for (Entry<String, AreaDefinition> tempAreaEntry : templateDef.getAreas().entrySet()) { AreaDefinition tempArea = tempAreaEntry.getValue(); maybeHit = tempArea.getAreas().get(name); if (maybeHit != null) { areaHierarchy.put(tempAreaEntry.getKey(), tempAreaEntry.getValue()); templateDef = maybeHit; } } } // noComponent area ... how do i read those? } areaHierarchy.put(name, templateDef); } return areaHierarchy; }