List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:com.smi.travel.monitor.MonitorGalileo.java
private void buildMap() { listGalileo = mGalileoService.getGalileoList(); ListIterator<MGalileo> iterator = listGalileo.listIterator(); galileoMap = new HashMap(); while (iterator.hasNext()) { MGalileo gali = iterator.next(); galileoMap.put(gali.getName(), gali); }/*from w ww . ja v a 2 s . com*/ }
From source file:chat.viska.commons.pipelines.Pipeline.java
@Nullable private ListIterator<Map.Entry<String, Pipe>> getIteratorOf(final String name) { if (StringUtils.isBlank(name)) { return null; }/*from ww w . j a v a2 s . c o m*/ final ListIterator<Map.Entry<String, Pipe>> iterator = pipes.listIterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); if (entry.getKey().equals(name)) { iterator.previous(); return iterator; } } return null; }
From source file:chat.viska.commons.pipelines.Pipeline.java
@Nullable private ListIterator<Map.Entry<String, Pipe>> getIteratorOf(@Nullable final Pipe pipe) { if (pipe == null) { return null; }//from ww w .java2s .c o m final ListIterator<Map.Entry<String, Pipe>> iterator = pipes.listIterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); if (entry.getValue().equals(pipe)) { iterator.previous(); return iterator; } } return null; }
From source file:com.amalto.core.history.accessor.record.DataRecordAccessor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/* w w w . j a v a 2 s .c o m*/ public String get() { initPath(); DataRecord current = dataRecord; ListIterator<PathElement> listIterator = pathElements.listIterator(); PathElement pathElement = null; while (listIterator.hasNext()) { pathElement = listIterator.next(); if (!listIterator.hasNext()) { break; } if (!pathElement.field.isMany()) { if (pathElement.field instanceof ContainedTypeFieldMetadata || pathElement.field instanceof ReferenceFieldMetadata) { current = (DataRecord) current.get(pathElement.field); } } else { List<Object> list = (List) current.get(pathElement.field); if (list == null) { list = new ArrayList<Object>(); current.set(pathElement.field, list); } while (pathElement.index > list.size() - 1) { // Expand list size list.add(null); } if (pathElement.field instanceof ContainedTypeFieldMetadata) { current = (DataRecord) ((List) current.get(pathElement.field)).get(pathElement.index); } } } if (pathElement != null) { return pathElement.getter.get(current, pathElement); } throw new IllegalArgumentException("Path '" + path + "' does not exist in document."); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:com.amalto.core.history.accessor.record.DataRecordAccessor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/* w ww. j a va 2 s .c o m*/ public void set(String value) { try { initPath(); DataRecord current = dataRecord; ListIterator<PathElement> listIterator = pathElements.listIterator(); PathElement pathElement = null; while (listIterator.hasNext()) { pathElement = listIterator.next(); if (!listIterator.hasNext()) { break; } if (!pathElement.field.isMany()) { if (pathElement.field instanceof ContainedTypeFieldMetadata) { current = (DataRecord) current.get(pathElement.field); } } else { List<Object> list = (List) current.get(pathElement.field); if (list == null) { list = new ArrayList<Object>(); current.set(pathElement.field, list); } while (pathElement.index > list.size() - 1) { // Expand list size list.add(null); } if (pathElement.field instanceof ContainedTypeFieldMetadata) { current = (DataRecord) ((List) current.get(pathElement.field)).get(pathElement.index); } } } if (pathElement != null) { pathElement.setter.set(repository, current, pathElement, value); } } finally { cachedExist = true; } }
From source file:vteaexploration.plottools.panels.XYChartPanel.java
private double getMinimumOfData(ArrayList alVolumes, int x) { ListIterator litr = alVolumes.listIterator(); //ArrayList<Number> al = new ArrayList<Number>(); Number low = getMaximumOfData(alVolumes, x); while (litr.hasNext()) { try {/*from ww w . jav a2s. c o m*/ MicroObjectModel volume = (MicroObjectModel) litr.next(); Number Corrected = processPosition(x, volume); if (Corrected.floatValue() < low.floatValue()) { low = Corrected; } } catch (NullPointerException e) { } } return low.longValue(); }
From source file:com.emc.ecs.sync.target.S3Target.java
protected void putIntermediateVersions(ListIterator<S3ObjectVersion> versions, String key) { while (versions.hasNext()) { S3ObjectVersion version = versions.next(); try {// w w w . j a v a 2s . c om if (!version.isLatest()) { // source has more versions; add any non-current versions that are missing from the target // (current version will be added below) if (version.isDeleteMarker()) { log.debug("[{}#{}]: deleting object in target to replicate delete marker in source.", version.getRelativePath(), version.getVersionId()); s3.deleteObject(bucketName, key); } else { log.debug("[{}#{}]: replicating historical version in target.", version.getRelativePath(), version.getVersionId()); putObject(version, key); } } } catch (RuntimeException e) { throw new RuntimeException( String.format("sync of historical version %s failed", version.getVersionId()), e); } } }
From source file:ch.uzh.phys.ecn.oboma.agents.model.Agent.java
public String getNextWaypoint(String pCurrentNodeId) { ListIterator<Pair<String, Integer>> routeIterator = mRoute.listIterator(); if (mRoute.isEmpty()) { return pCurrentNodeId; }//from w w w . j a v a2s.com if (pCurrentNodeId.contains("-")) { if (mRouteDirection.equals(RouteDirection.FORWARD)) { String[] keys = pCurrentNodeId.split("-"); return keys[1]; } else { // look for correct node to get previous node while (routeIterator.hasNext()) { String connectionKey = routeIterator.next().getKey(); String[] keys = connectionKey.split("-"); if (connectionKey.equals(pCurrentNodeId)) { // get previous node with endId equals startId of pCurrentNodeId ListIterator<Pair<String, Integer>> backwardsIterator = mRoute.listIterator(); while (backwardsIterator.hasNext()) { String previousNodeId = backwardsIterator.next().getKey(); String[] previousKeys = previousNodeId.split("-"); if (previousKeys[1].equals(keys[0])) { if (!routeIterator.hasNext()) { mRouteDirection = RouteDirection.FORWARD; } return previousKeys[0]; } } } } } } else { while (routeIterator.hasNext() && mRouteDirection.equals(RouteDirection.FORWARD)) { String connectionKey = routeIterator.next().getKey(); String[] keys = connectionKey.split("-"); if (keys[0].equals(pCurrentNodeId)) { // target node id return connectionKey; } } mRouteDirection = RouteDirection.BACKWARDS; // set iterator to start of list again routeIterator = mRoute.listIterator(); while (routeIterator.hasNext() && mRouteDirection.equals(RouteDirection.BACKWARDS)) { String connectionKey = routeIterator.next().getKey(); String[] keys = connectionKey.split("-"); if (keys[1].equals(pCurrentNodeId)) { // source node id with currentNodeId as target // -> getNode with sourceNode as target, which represents node before ListIterator<Pair<String, Integer>> backwardsIterator = mRoute.listIterator(); while (backwardsIterator.hasNext()) { String previousNodeKey = backwardsIterator.next().getKey(); String[] prevKeys = previousNodeKey.split("-"); if (prevKeys[1].equals(keys[1])) { if (!routeIterator.hasNext()) { mRouteDirection = RouteDirection.FORWARD; } // return route with direction changed return prevKeys[0] + "-" + prevKeys[1]; } } } } } LOGGER.warning("CurrentNodeId: " + pCurrentNodeId + ", Direction: " + mRouteDirection); throw new IllegalStateException("No route found for given nodeId " + pCurrentNodeId); }
From source file:com.amalto.core.history.accessor.record.DataRecordAccessor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override//ww w. j a va 2s .c om public void delete() { if (!exist()) { return; // Value is already deleted. } try { initPath(); DataRecord current = dataRecord; ListIterator<PathElement> listIterator = pathElements.listIterator(); PathElement pathElement = null; while (listIterator.hasNext()) { pathElement = listIterator.next(); if (!listIterator.hasNext()) { break; } if (!pathElement.field.isMany()) { if (pathElement.field instanceof ContainedTypeFieldMetadata) { current = (DataRecord) current.get(pathElement.field); } } else { if (pathElement.field instanceof ContainedTypeFieldMetadata) { current = (DataRecord) ((List) current.get(pathElement.field)).get(pathElement.index); } else { List<Object> list = (List) dataRecord.get(pathElement.field); if (list == null) { list = new ArrayList<Object>(); dataRecord.set(pathElement.field, list); } } } } if (pathElement != null) { if (pathElement.field.isMany()) { if (pathElement.index < 0) { ((List) current.get(pathElement.field)).clear(); } else { ((List) current.get(pathElement.field)).remove(pathElement.index); } } else { current.set(pathElement.field, null); } } } finally { cachedExist = false; } }
From source file:com.edgenius.wiki.render.macro.CodeMacro.java
@Override protected void replaceHTML(HTMLNode node, ListIterator<HTMLNode> iter, RenderContext context) { if (node.getPair() == null) { log.warn("Unexpect case: No close div tag for " + this.getClass().getName()); return;/*w w w . j a v a2 s .c om*/ } //remove all HTML tag, as any these tag must from RichEditor, which is invalid to add style to code macro part... HTMLNode subnode; StringBuffer sb = new StringBuffer(); //!!! Here changes ListIterator cursor position!!! for (; iter.hasNext();) { subnode = iter.next(); if (subnode == node.getPair()) break; if (!subnode.isTextNode()) { subnode.reset("", true); if (subnode.getPair() != null) subnode.getPair().reset("", true); } else { sb.append(subnode.getText()); } } //do reverse replace, refer to CodeHandler... if (sb.length() > 0) { String code = sb.toString(); code = code.replaceAll("<", "<"); code = code.replaceAll("&", "&"); //if code content is not empty, node must has next() node.next().reset(code, true); String src = ""; if (node.getAttributes() != null && node.getAttributes().get(NameConstants.CLASS) != null) { String srcName = StringUtils.substringAfter(node.getAttributes().get(NameConstants.CLASS), ":"); if (!DEFAULT_CODE.equalsIgnoreCase(srcName)) { src = "|" + NameConstants.SRC + "=" + srcName; } } //as above Iterator cursor already move to end of pair node, so move them back and restore around insertMarkup method moveIteratorCursorTo(node, iter, false); //move from end to start resetMacroMarkup(TIDY_STYLE_BLOCK, node, iter, "{code" + src + "}", "{code}"); moveIteratorCursorTo(node.getPair(), iter, true); // move from start to end } }