List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:com.offbynull.coroutines.instrumenter.asm.SearchUtils.java
/** * Find trycatch blocks within a method that an instruction is apart of. Only includes the try portion, not the catch (handler) portion. * @param insnList instruction list for method * @param tryCatchBlockNodes trycatch blocks in method * @param insnNode instruction within method being searched against * @throws NullPointerException if any argument is {@code null} or contains {@code null} * @throws IllegalArgumentException if arguments aren't all from the same method * @return items from {@code tryCatchBlockNodes} that {@code insnNode} is a part of *///from ww w .j a v a2 s.co m public static List<TryCatchBlockNode> findTryCatchBlockNodesEncompassingInstruction(InsnList insnList, List<TryCatchBlockNode> tryCatchBlockNodes, AbstractInsnNode insnNode) { Validate.notNull(insnList); Validate.notNull(tryCatchBlockNodes); Validate.notNull(insnNode); Validate.noNullElements(tryCatchBlockNodes); Map<LabelNode, Integer> labelPositions = new HashMap<>(); int insnNodeIdx = -1; // Get index of labels and insnNode within method ListIterator<AbstractInsnNode> insnIt = insnList.iterator(); int insnCounter = 0; while (insnIt.hasNext()) { AbstractInsnNode node = insnIt.next(); // If our instruction, save index if (node == insnNode) { if (insnNodeIdx == -1) { insnNodeIdx = insnCounter; } else { throw new IllegalArgumentException(); // insnNode encountered multiple times in methodNode. Should not happen. } } // If label node, save position if (node instanceof LabelNode) { labelPositions.put((LabelNode) node, insnCounter); } // Increment counter insnCounter++; } Validate.isTrue(insnNodeIdx != -1); //throw exception if node not in method list // Find out which trycatch blocks insnNode is within List<TryCatchBlockNode> ret = new ArrayList<>(); for (TryCatchBlockNode tryCatchBlockNode : tryCatchBlockNodes) { Integer startIdx = labelPositions.get(tryCatchBlockNode.start); Integer endIdx = labelPositions.get(tryCatchBlockNode.end); Validate.isTrue(startIdx != null); Validate.isTrue(endIdx != null); if (insnNodeIdx >= startIdx && insnNodeIdx < endIdx) { ret.add(tryCatchBlockNode); } } return ret; }
From source file:com.ettrema.zsync.UploadMakerEx.java
/** * Returns a Range representing a sequence of contiguous server blocks, beginning at blockIndex, that * are to be relocated as a single chunk. * /* w ww. j a v a 2 s . c om*/ * @param iter An iterator positioned immediately after the first match of the sequence * @param localOffset The local byte offset of the first matching block of the sequence * @param blockIndex The server block index of the first matching block of the sequence * @param blockSize The number of bytes in a block * @return A Range of contiguous blocks that are to be relocated to localOffset */ private static Range consecMatchesEx(ListIterator<OffsetPair> iter, long localOffset, long blockIndex, int blockSize) { long currBlock = blockIndex; long currByte = localOffset; while (iter.hasNext()) { OffsetPair pair = iter.next(); currByte += blockSize; currBlock++; if (pair.localOffset != currByte || pair.remoteBlock != currBlock) { iter.previous(); return new Range(blockIndex, currBlock); } } return new Range(blockIndex, currBlock + 1); }
From source file:oct.util.Util.java
public static double[][] getXYArraysFromPoints(List<Point> points) { double[] x = new double[points.size()]; double[] y = new double[points.size()]; ListIterator<Point> pi = points.listIterator(); for (int i = 0; pi.hasNext(); i++) { Point p = pi.next();//from w ww. j a v a 2s . c om x[i] = p.getX(); y[i] = p.getY(); } return new double[][] { x, y }; }
From source file:oct.util.Util.java
/** * * @param points//from ww w.j a va 2s . c om * @return */ public static double[][] getXYArraysFromLinePoints(List<LinePoint> points) { double[] x = new double[points.size()]; double[] y = new double[points.size()]; ListIterator<LinePoint> pi = points.listIterator(); for (int i = 0; pi.hasNext(); i++) { LinePoint p = pi.next(); x[i] = p.getX(); y[i] = p.getY(); } return new double[][] { x, y }; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals, List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited) { log.debug(/*w ww. j av a 2 s.c o m*/ "starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ..."); HashSet<String> range = new HashSet<String>(); for (ObjectPropertyStatement ops : stmts) { if (ops.getPropertyURI().equals(predicateUri)) range.add(ops.getObjectURI()); } int removeCount = 0; ListIterator<Individual> it = individuals.listIterator(); while (it.hasNext()) { Individual ind = it.next(); if (range.contains(ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited))) { it.remove(); ++removeCount; } } log.debug("removed " + removeCount + " duplicate range individuals"); return individuals; }
From source file:annis.visualizers.component.grid.EventExtractor.java
/** * Returns the annotations to display according to the mappings configuration. * * This will check the "annos" and "annos_regex" paramters for determining. * the annotations to display. It also iterates over all nodes of the graph * matching the type.//from w w w . j a v a 2 s .co m * * @param input The input for the visualizer. * @param type Which type of nodes to include * @return */ public static List<String> computeDisplayAnnotations(VisualizerInput input, Class<? extends SNode> type) { if (input == null) { return new LinkedList<String>(); } SDocumentGraph graph = input.getDocument().getSDocumentGraph(); Set<String> annoPool = getAnnotationLevelSet(graph, input.getNamespace(), type); List<String> annos = new LinkedList<String>(annoPool); String annosConfiguration = input.getMappings().getProperty(MAPPING_ANNOS_KEY); if (annosConfiguration != null && annosConfiguration.trim().length() > 0) { String[] split = annosConfiguration.split(","); annos.clear(); for (String s : split) { s = s.trim(); // is regular expression? if (s.startsWith("/") && s.endsWith("/")) { // go over all remaining items in our pool of all annotations and // check if they match Pattern regex = Pattern.compile(StringUtils.strip(s, "/")); LinkedList<String> matchingAnnos = new LinkedList<String>(); for (String a : annoPool) { if (regex.matcher(a).matches()) { matchingAnnos.add(a); } } annos.addAll(matchingAnnos); annoPool.removeAll(matchingAnnos); } else { annos.add(s); annoPool.remove(s); } } } // filter already found annotation names by regular expression // if this was given as mapping String regexFilterRaw = input.getMappings().getProperty(MAPPING_ANNO_REGEX_KEY); if (regexFilterRaw != null) { try { Pattern regexFilter = Pattern.compile(regexFilterRaw); ListIterator<String> itAnnos = annos.listIterator(); while (itAnnos.hasNext()) { String a = itAnnos.next(); // remove entry if not matching if (!regexFilter.matcher(a).matches()) { itAnnos.remove(); } } } catch (PatternSyntaxException ex) { log.warn("invalid regular expression in mapping for grid visualizer", ex); } } return annos; }
From source file:com.qualogy.qafe.core.errorhandling.ErrorProcessor.java
private static List<ErrorHandler> getErrorHandlers(ListIterator<? extends Item> itrItem, ApplicationContext context, Window window) { List<ErrorHandler> errorHandlerList = new ArrayList<ErrorHandler>(); if (itrItem != null) { while (itrItem.hasNext()) { Item item = itrItem.next();// www.j av a 2 s. c o m if (item instanceof ErrorHandler) { errorHandlerList.add((ErrorHandler) item); } else if (item instanceof EventRef) { EventRef eventRef = (EventRef) item; String eventId = eventRef.getEvent(); Event event = getEvent(eventId, context, window); if (event != null) { List<ErrorHandler> errorHandlers = getErrorHandlers(event.getEventItems().listIterator(), context, window); if (errorHandlers != null) { errorHandlerList.addAll(errorHandlers); } } } } } return errorHandlerList; }
From source file:annis.visualizers.component.grid.EventExtractor.java
/** * Splits events of a row if they contain a gap. Gaps are found using the * token index (provided as ANNIS specific {@link SFeature}. Inserted events * have a special style to mark them as gaps. * * @param row/*from w w w.jav a 2s . co m*/ * @param graph * @param startTokenIndex token index of the first token in the match * @param endTokenIndex token index of the last token in the match */ private static void splitRowsOnGaps(Row row, final SDocumentGraph graph, long startTokenIndex, long endTokenIndex) { ListIterator<GridEvent> itEvents = row.getEvents().listIterator(); while (itEvents.hasNext()) { GridEvent event = itEvents.next(); int lastTokenIndex = Integer.MIN_VALUE; // sort the coveredIDs LinkedList<String> sortedCoveredToken = new LinkedList<String>(event.getCoveredIDs()); Collections.sort(sortedCoveredToken, new Comparator<String>() { @Override public int compare(String o1, String o2) { SNode node1 = graph.getSNode(o1); SNode node2 = graph.getSNode(o2); if (node1 == node2) { return 0; } if (node1 == null) { return -1; } if (node2 == null) { return +1; } long tokenIndex1 = node1.getSFeature(ANNIS_NS, FEAT_TOKENINDEX).getSValueSNUMERIC(); long tokenIndex2 = node2.getSFeature(ANNIS_NS, FEAT_TOKENINDEX).getSValueSNUMERIC(); return ((Long) (tokenIndex1)).compareTo(tokenIndex2); } }); // first calculate all gaps List<GridEvent> gaps = new LinkedList<GridEvent>(); for (String id : sortedCoveredToken) { SNode node = graph.getSNode(id); long tokenIndexRaw = node.getSFeature(ANNIS_NS, FEAT_TOKENINDEX).getSValueSNUMERIC(); tokenIndexRaw = clip(tokenIndexRaw, startTokenIndex, endTokenIndex); int tokenIndex = (int) (tokenIndexRaw - startTokenIndex); int diff = tokenIndex - lastTokenIndex; if (lastTokenIndex >= 0 && diff > 1) { // we detected a gap GridEvent gap = new GridEvent(event.getId() + "_gap", lastTokenIndex + 1, tokenIndex - 1, ""); gap.setGap(true); gaps.add(gap); } lastTokenIndex = tokenIndex; } // end for each covered token id for (GridEvent gap : gaps) { // remember the old right value int oldRight = event.getRight(); // shorten last event event.setRight(gap.getLeft() - 1); // insert the real gap itEvents.add(gap); // insert a new event node that covers the rest of the event GridEvent after = new GridEvent(event.getId() + "_after", gap.getRight() + 1, oldRight, event.getValue()); after.getCoveredIDs().addAll(event.getCoveredIDs()); itEvents.add(after); } } }
From source file:LNISmokeTest.java
/** * Do propfind./*from ww w . j av a2 s.c o m*/ * * @param lni the lni * @param handle the handle * @param pf the pf * @param depth the depth * @param types the types * * @throws RemoteException the remote exception * @throws IOException Signals that an I/O exception has occurred. */ private static void doPropfind(LNISoapServlet lni, String handle, String pf, int depth, String types) throws java.rmi.RemoteException, java.io.IOException { String uri = doLookup(lni, handle, null); String result = lni.propfind(uri, pf, depth, types); try { SAXBuilder builder = new SAXBuilder(); Document msDoc = builder.build(new java.io.StringReader(result)); Element ms = msDoc.getRootElement(); ListIterator ri = ms.getChildren("response", NS_DAV).listIterator(); while (ri.hasNext()) { Element resp = (Element) ri.next(); String href = resp.getChildText("href", NS_DAV); System.out.println("Resource = " + href); ListIterator pi = resp.getChildren("propstat", NS_DAV).listIterator(); while (pi.hasNext()) { Element ps = (Element) pi.next(); String status = ps.getChildText("status", NS_DAV); if (status.indexOf("200") >= 0) { System.out.println(" === PROPERTIES Successfully returned:"); } else { System.out.println(" === PROPERTIES with Status=" + status); } // print properties and values Element prop = ps.getChild("prop", NS_DAV); ListIterator ppi = prop.getChildren().listIterator(); while (ppi.hasNext()) { Element e = (Element) ppi.next(); String value = e.getTextTrim(); if (value.equals("")) { List kids = e.getChildren(); if (kids.size() > 0) { value = outputPretty.outputString(kids); } if (value.indexOf('\n') >= 0) { value = "\n" + value; } } else { value = "\"" + value + "\""; } String equals = value.equals("") ? "" : " = "; System.out.println(" " + e.getQualifiedName() + equals + value); } } } } catch (JDOMParseException je) { je.printStackTrace(); die(3, "ERROR: " + je.toString()); } catch (JDOMException je) { je.printStackTrace(); die(4, "ERROR: " + je.toString()); } }
From source file:com.ofalvai.bpinfo.api.bkkinfo.BkkInfoClient.java
/** * Alerts scheduled for the current day (and not yet started) appear in the current alerts list. * We need to find them and move to the future alerts list *//*from w w w . jav a2s .c om*/ private static void fixFutureAlertsInTodayList(List<Alert> alertsToday, List<Alert> alertsFuture) { // Avoiding ConcurrentModificationException when removing from alertsToday ListIterator<Alert> todayIterator = alertsToday.listIterator(); while (todayIterator.hasNext()) { Alert alert = todayIterator.next(); DateTime startTime = new DateTime(alert.getStart() * 1000L); if (startTime.isAfterNow()) { alertsFuture.add(alert); todayIterator.remove(); } } }