List of usage examples for java.util List listIterator
ListIterator<E> listIterator();
From source file:Alias2.java
public static void verifyAtLeast(List output, List expected) { verifyLength(output.size(), expected.size(), Test.AT_LEAST); if (!output.containsAll(expected)) { ListIterator it = expected.listIterator(); while (output.contains(it.next())) { }//from w w w. ja va 2s .c o m throw new SimpleTestException("expected: <" + it.previous().toString() + ">"); } }
From source file:com.act.lcms.MzMLParser.java
protected static <K, V> List<Pair<K, V>> zipLists(List<K> keys, List<V> vals) { if (keys.size() != vals.size()) { throw new RuntimeException(String.format("Mismatched list sizes: %d vs %d", keys.size(), vals.size())); }//from w w w .j av a 2 s . c o m List<Pair<K, V>> res = new ArrayList<>(keys.size()); Iterator<K> ki = keys.listIterator(); Iterator<V> vi = vals.listIterator(); while (ki.hasNext() && vi.hasNext()) { // Length check should ensure these are exhausted simultaneously. K k = ki.next(); V v = vi.next(); res.add(Pair.of(k, v)); } return res; }
From source file:Alias2.java
public static void verify(List output, List expected) { verifyLength(output.size(), expected.size(), Test.EXACT); if (!expected.equals(output)) { //find the line of mismatch ListIterator it1 = expected.listIterator(); ListIterator it2 = output.listIterator(); while (it1.hasNext() && it2.hasNext() && it1.next().equals(it2.next())) ;// w w w.j a va 2 s . c om throw new LineMismatchException(it1.nextIndex(), it1.previous().toString(), it2.previous().toString()); } }
From source file:org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLAuthorizationUtils.java
/** * Calls getValidatedPrincipal on each principal in list and updates the list * @param hivePrincipals// w w w .j a va2 s . c om * @return * @return * @throws HiveAuthzPluginException */ public static List<HivePrincipal> getValidatedPrincipals(List<HivePrincipal> hivePrincipals) throws HiveAuthzPluginException { ListIterator<HivePrincipal> it = hivePrincipals.listIterator(); while (it.hasNext()) { it.set(getValidatedPrincipal(it.next())); } return hivePrincipals; }
From source file:Main.java
/** * Copies all of the elements from one list into another. After the * operation, the index of each copied element in the destination list will * be identical to its index in the source list. The destination list must * be at least as long as the source list. If it is longer, the remaining * elements in the destination list are unaffected. * <p>//from w w w. j av a2 s. co m * This method runs in linear time. * @param <T> . * @param dest The destination list. * @param src The source list. * * @return boolean isCopyValide */ public static <T> Boolean copy(List<? super T> dest, List<? extends T> src) { Boolean isCopyValide = null; int srcSize = src.size(); if (srcSize > dest.size()) { isCopyValide = false; throw new IndexOutOfBoundsException("Source does not fit in dest"); } if (srcSize < COPY_THRESHOLD || (src instanceof RandomAccess && dest instanceof RandomAccess)) { for (int i = 0; i < srcSize; i++) { dest.set(i, src.get(i)); } } else { ListIterator<? super T> di = dest.listIterator(); ListIterator<? extends T> si = src.listIterator(); for (int i = 0; i < srcSize; i++) { di.next(); di.set(si.next()); } } isCopyValide = true; return isCopyValide; }
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 ww w . ja v a2 s .c o m*/ x[i] = p.getX(); y[i] = p.getY(); } return new double[][] { x, y }; }
From source file:exm.stc.ic.ICUtil.java
public static void replaceVarsInList(Map<Var, Arg> replacements, List<Var> vars, boolean removeDupes, boolean removeMapped) { // Remove new duplicates ArrayList<Var> alreadySeen = null; if (removeDupes) { alreadySeen = new ArrayList<Var>(vars.size()); }/* w w w . j a va 2 s.c om*/ ListIterator<Var> it = vars.listIterator(); while (it.hasNext()) { Var v = it.next(); if (replacements.containsKey(v)) { Arg oa = replacements.get(v); if (oa.isVar()) { if (removeDupes && alreadySeen.contains(oa.getVar())) { it.remove(); } else { it.set(oa.getVar()); if (removeDupes) { alreadySeen.add(oa.getVar()); } } } } else { if (removeDupes) { if (alreadySeen.contains(v)) { it.remove(); } else { alreadySeen.add(v); } } } } }
From source file:oct.util.Util.java
/** * * @param points//from w w w . j av a 2 s .c o m * @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:com.ettrema.zsync.UploadMakerEx.java
/** * Determines the instructions needed by the server to relocate blocks of data already contained * in its version of the file./*from ww w .ja v a2s .c o m*/ * * @param reverseMap The List of block-matches obtained from MakeContextEx * @param blockSize The block size used to generate reverseMap * @param fileLength The length of the client file being uploaded * @param combineRanges Whether to combine consecutive block matches into a single RelocateRange * @return The InputStream of RelocateRanges that need to be sent to the server * @throws IOException * @throws UnsupportedEncodingException * @see {@link UploadMaker#serversRelocationRanges} */ public static InputStream serversRelocationRangesEx(List<OffsetPair> reverseMap, int blockSize, long fileLength, boolean combineRanges) throws UnsupportedEncodingException, IOException { RelocWriter relocRanges = new RelocWriter(16384); Collections.sort(reverseMap, new OffsetPair.RemoteSort()); for (ListIterator<OffsetPair> iter = reverseMap.listIterator(); iter.hasNext();) { OffsetPair pair = iter.next(); long localOffset = pair.localOffset; long blockIndex = pair.remoteBlock; /*If the local offset and server offset of a given matching block * are the same, then no instruction is sent. */ if (localOffset >= 0 && localOffset != blockIndex * blockSize) { if (localOffset > fileLength - blockSize) { //out of range continue; } Range blockRange; if (combineRanges == true) { blockRange = consecMatchesEx(iter, localOffset, blockIndex, blockSize); } else { blockRange = new Range(blockIndex, blockIndex + 1); } RelocateRange relocRange = new RelocateRange(blockRange, localOffset); //System.out.println("new relocate range: " + relocRange); relocRanges.add(relocRange); } } return relocRanges.getInputStream(); }
From source file:org.apache.axis2.jaxws.spi.migrator.ApplicationContextMigratorUtil.java
/** * @param contextMigratorListID/*from w w w . j ava 2 s . co m*/ * @param requestContext * @param messageContext */ public static void performMigrationToMessageContext(String contextMigratorListID, Map<String, Object> requestContext, MessageContext messageContext) { if (messageContext == null) { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("nullMsgCtxErr")); } ServiceDescription sd = messageContext.getEndpointDescription().getServiceDescription(); if (sd != null) { ConfigurationContext configCtx = sd.getAxisConfigContext(); List<ApplicationContextMigrator> migratorList = (List<ApplicationContextMigrator>) configCtx .getProperty(contextMigratorListID); if (migratorList != null) { // Create copy to avoid using shared list List listCPM = null; // synchronize on non-null migratorList synchronized (migratorList) { listCPM = new ArrayList(migratorList); } ListIterator<ApplicationContextMigrator> itr = listCPM.listIterator(); // Iterate over non-shared list while (itr.hasNext()) { ApplicationContextMigrator cpm = itr.next(); if (log.isDebugEnabled()) { log.debug("migrator: " + cpm.getClass().getName() + ".migratePropertiesToMessageContext"); } // TODO: Synchronizing here is expensive too. // If a cpm requires synchronization, it should provide it inside of its migratePropertiesFromMessageContext implementation. cpm.migratePropertiesToMessageContext( new ApplicationPropertyMapReader(requestContext, messageContext.getMEPContext()), messageContext); } } } }