Java Code Examples for java.util.ListIterator#nextIndex()
The following examples show how to use
java.util.ListIterator#nextIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * An implementation of {@link List#lastIndexOf(Object)}. */ static int lastIndexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return lastIndexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(list.size()); while (listIterator.hasPrevious()) { if (Objects.equal(element, listIterator.previous())) { return listIterator.nextIndex(); } } return -1; } }
Example 2
Source File: CreateReadCountPanelOfNormals.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static RealMatrix constructReadCountMatrix(final Logger logger, final List<File> inputReadCountFiles, final SAMSequenceDictionary sequenceDictionary, final List<SimpleInterval> intervals) { logger.info("Validating and aggregating input read-counts files..."); final int numSamples = inputReadCountFiles.size(); final int numIntervals = intervals.size(); final RealMatrix readCountMatrix = new Array2DRowRealMatrix(numSamples, numIntervals); final ListIterator<File> inputReadCountFilesIterator = inputReadCountFiles.listIterator(); while (inputReadCountFilesIterator.hasNext()) { final int sampleIndex = inputReadCountFilesIterator.nextIndex(); final File inputReadCountFile = inputReadCountFilesIterator.next(); logger.info(String.format("Aggregating read-counts file %s (%d / %d)", inputReadCountFile, sampleIndex + 1, numSamples)); final SimpleCountCollection readCounts = SimpleCountCollection.read(inputReadCountFile); if (!CopyNumberArgumentValidationUtils.isSameDictionary(readCounts.getMetadata().getSequenceDictionary(), sequenceDictionary)) { logger.warn(String.format("Sequence dictionary for read-counts file %s does not match those in other read-counts files.", inputReadCountFile)); } Utils.validateArg(readCounts.getIntervals().equals(intervals), String.format("Intervals for read-counts file %s do not match those in other read-counts files.", inputReadCountFile)); readCountMatrix.setRow(sampleIndex, readCounts.getCounts()); } return readCountMatrix; }
Example 3
Source File: ConfluenceMarkupBuilder.java From markup-document-builder with Apache License 2.0 | 6 votes |
@Override public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) { Validate.notEmpty(cells, "cells must not be null"); documentBuilder.append(newLine); if (columnSpecs != null && !columnSpecs.isEmpty()) { documentBuilder.append("||"); for (MarkupTableColumn column : columnSpecs) { documentBuilder.append(formatCellContent(defaultString(column.header))).append("||"); } documentBuilder.append(newLine); } for (List<String> row : cells) { documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER); ListIterator<String> cellIterator = row.listIterator(); while (cellIterator.hasNext()) { int cellIndex = cellIterator.nextIndex(); if (columnSpecs != null && columnSpecs.size() > cellIndex && columnSpecs.get(cellIndex).headerColumn) documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER); documentBuilder.append(formatCellContent(cellIterator.next())).append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER); } documentBuilder.append(newLine); } documentBuilder.append(newLine); return this; }
Example 4
Source File: ConfluenceMarkupBuilder.java From swagger2markup with Apache License 2.0 | 6 votes |
@Override public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) { Validate.notEmpty(cells, "cells must not be null"); documentBuilder.append(newLine); if (columnSpecs != null && !columnSpecs.isEmpty()) { documentBuilder.append("||"); for (MarkupTableColumn column : columnSpecs) { documentBuilder.append(formatCellContent(defaultString(column.header))).append("||"); } documentBuilder.append(newLine); } for (List<String> row : cells) { documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER); ListIterator<String> cellIterator = row.listIterator(); while (cellIterator.hasNext()) { int cellIndex = cellIterator.nextIndex(); if (columnSpecs != null && columnSpecs.size() > cellIndex && columnSpecs.get(cellIndex).headerColumn) documentBuilder.append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER); documentBuilder.append(formatCellContent(cellIterator.next())).append(ConfluenceMarkup.TABLE_COLUMN_DELIMITER); } documentBuilder.append(newLine); } documentBuilder.append(newLine); return this; }
Example 5
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * An implementation of {@link List#lastIndexOf(Object)}. */ static int lastIndexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return lastIndexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(list.size()); while (listIterator.hasPrevious()) { if (Objects.equal(element, listIterator.previous())) { return listIterator.nextIndex(); } } return -1; } }
Example 6
Source File: SplitIndexWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Generate separate index files, for each Unicode character, listing all * the members starting with the particular unicode character. * * @param configuration the configuration for this doclet * @param indexbuilder IndexBuilder built by {@link IndexBuilder} * @throws DocFileIOException if there is a problem generating the index files */ public static void generate(ConfigurationImpl configuration, IndexBuilder indexbuilder) throws DocFileIOException { DocPath path = DocPaths.INDEX_FILES; Set<Character> keys = new TreeSet<>(indexbuilder.getIndexMap().keySet()); keys.addAll(configuration.tagSearchIndexKeys); ListIterator<Character> li = new ArrayList<>(keys).listIterator(); while (li.hasNext()) { Object ch = li.next(); DocPath filename = DocPaths.indexN(li.nextIndex()); SplitIndexWriter indexgen = new SplitIndexWriter(configuration, path.resolve(filename), indexbuilder, keys, li.previousIndex(), li.nextIndex()); indexgen.generateIndexFile((Character) ch); if (!li.hasNext()) { indexgen.createSearchIndexFiles(); } } }
Example 7
Source File: CartesianList.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public boolean contains(@Nullable Object o) { if (!(o instanceof List)) { return false; } List<?> list = (List<?>) o; if (list.size() != axes.size()) { return false; } ListIterator<?> itr = list.listIterator(); while (itr.hasNext()) { int index = itr.nextIndex(); if (!axes.get(index).contains(itr.next())) { return false; } } return true; }
Example 8
Source File: CartesianList.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public boolean contains(@Nullable Object o) { if (!(o instanceof List)) { return false; } List<?> list = (List<?>) o; if (list.size() != axes.size()) { return false; } ListIterator<?> itr = list.listIterator(); while (itr.hasNext()) { int index = itr.nextIndex(); if (!axes.get(index).contains(itr.next())) { return false; } } return true; }
Example 9
Source File: XGBoostJsonParser.java From elasticsearch-learning-to-rank with Apache License 2.0 | 5 votes |
Node[] getTrees(FeatureSet set) { Node[] trees = new Node[splitParserStates.size()]; ListIterator<SplitParserState> it = splitParserStates.listIterator(); while(it.hasNext()) { trees[it.nextIndex()] = it.next().toNode(set); } return trees; }
Example 10
Source File: NodeSubregistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private RegistrySearchControl(final ListIterator<PathElement> iterator, final String childName) { final Map<String, AbstractResourceRegistration> snapshot = childRegistriesUpdater.get(NodeSubregistry.this); this.specifiedRegistry = snapshot.get(childName); this.wildCardRegistry = WILDCARD_VALUE.equals(childName) ? null : snapshot.get(WILDCARD_VALUE); this.iterator = iterator; this.restoreIndex = (specifiedRegistry != null && wildCardRegistry != null) ? iterator.nextIndex() : -1; }
Example 11
Source File: TemplateImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public String fillGrades(StudentGrades student) { String output = new String(templateCode); output = output.replaceAll("\\$0\\$", student.getUsername()); ListIterator grades = student.getGrades().listIterator(); while (grades.hasNext()) { int index = grades.nextIndex(); String grade = (String) grades.next(); output = output.replaceAll("\\$" + (index + 1) + "\\" + "$", grade); } return output; }
Example 12
Source File: InterpolatedTSC.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Finds the first resolution of name in the given TimeSeriesCollections. * The cache is used and updated to skip the linear search phase. * * @param c TimeSeriesCollection instances in which to search. * @param name The searched for name. Note that the name must be present in * the collection. * @param cache Cache used and updated during lookups, to skip the linear * search. * @return The first TimeSeriesValue in the list of TSCollections with the * given name. * @throws IllegalStateException if the name was not found. */ private static Map.Entry<DateTime, TimeSeriesValue> findName(List<TimeSeriesCollection> c, GroupName name) { ListIterator<TimeSeriesCollection> iter = c.listIterator(); while (iter.hasNext()) { final int idx = iter.nextIndex(); final TimeSeriesCollection tsdata = iter.next(); final Optional<TimeSeriesValue> found = tsdata.get(name); if (found.isPresent()) return SimpleMapEntry.create(tsdata.getTimestamp(), found.get()); } throw new IllegalStateException("name not present in list of time series collections"); }
Example 13
Source File: Configuration.java From big-c with Apache License 2.0 | 5 votes |
private <T> void toString(List<T> resources, StringBuilder sb) { ListIterator<T> i = resources.listIterator(); while (i.hasNext()) { if (i.nextIndex() != 0) { sb.append(", "); } sb.append(i.next()); } }
Example 14
Source File: ValidatorChain.java From anno4j with Apache License 2.0 | 5 votes |
/** * Returns the human readable value space definitions of the given datatype, i.e. * a list of constraints made by the validators on the datatypes value space. * @param range The datatype to get the definitions for. * @return The definitions in the same order as the validators imposing them. */ public String[] getValueSpaceDefinitions(RDFSClazz range) { String[] definitions = new String[size()]; ListIterator<Validator> iterator = listIterator(); while (iterator.hasNext()) { definitions[iterator.nextIndex()] = iterator.next().getValueSpaceDefinition(range); } return definitions; }
Example 15
Source File: BaseAction.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private Map<Executable, State> decodeMap(List<String> lines) { if (lines == null || lines.size() == 0) { throw new Error("TESTBUG: unexpected lines list"); } Map<Executable, State> stateMap = new HashMap<>(); int startIndex = 0; ListIterator<String> iterator = lines.listIterator(); while (iterator.hasNext()) { int index = iterator.nextIndex(); String next = iterator.next(); switch (next) { case "{" : startIndex = index; break; case "}" : // method name goes after { Executable executable = METHODS_NAMES.get(lines.get( ++startIndex)); // state description starts after method State state = State.fromString(lines.subList(++startIndex, index).toArray(new String[index - startIndex])); stateMap.put(executable, state); break; } } return stateMap; }
Example 16
Source File: Configuration.java From flink with Apache License 2.0 | 5 votes |
private <T> void toString(List<T> resources, StringBuilder sb) { ListIterator<T> i = resources.listIterator(); while (i.hasNext()) { if (i.nextIndex() != 0) { sb.append(", "); } sb.append(i.next()); } }
Example 17
Source File: FilterLineReachabilityAnswerer.java From batfish with Apache License 2.0 | 5 votes |
private static void answerAclReachabilityLine( AclSpecs aclSpec, BDDPacket bddPacket, FilterLineReachabilityRows answerRows) { BDDFactory bddFactory = bddPacket.getFactory(); BDDSourceManager sourceMgr = BDDSourceManager.forInterfaces(bddPacket, aclSpec.acl.getInterfaces()); IpAccessListToBdd ipAccessListToBdd = new IpAccessListToBddImpl( bddPacket, sourceMgr, aclSpec.acl.getDependencies(), ImmutableMap.of()); IpAccessList ipAcl = aclSpec.acl.getSanitizedAcl(); List<AclLine> lines = ipAcl.getLines(); /* Convert every line to permit and deny BDDs. */ List<PermitAndDenyBdds> ipLineToBDDMap = lines.stream().map(ipAccessListToBdd::toPermitAndDenyBdds).collect(Collectors.toList()); /* Pass over BDDs to classify each as unmatchable, unreachable, or (implicitly) reachable. */ BDD unmatchedPackets = bddFactory.one(); // The packets that are not yet matched by the ACL. ListIterator<PermitAndDenyBdds> lineIt = ipLineToBDDMap.listIterator(); while (lineIt.hasNext()) { int lineNum = lineIt.nextIndex(); PermitAndDenyBdds lineBDDs = lineIt.next(); if (lineBDDs.isZero()) { // This line is unmatchable answerRows.addUnmatchableLine(aclSpec, lineNum); } else if (unmatchedPackets.isZero() || !lineBDDs.getMatchBdd().andSat(unmatchedPackets)) { // No unmatched packets in the ACL match this line, so this line is unreachable. BlockingProperties blockingProps = findBlockingPropsForLine(lineNum, ipLineToBDDMap); answerRows.addBlockedLine(aclSpec, lineNum, blockingProps); } unmatchedPackets = unmatchedPackets.diff(lineBDDs.getMatchBdd()); } }
Example 18
Source File: SymbolMatchers.java From crate with Apache License 2.0 | 5 votes |
public static Matcher<Symbol> isFunction(final String name, @Nullable final List<DataType> argumentTypes) { if (argumentTypes == null) { return isFunction(name); } Matcher[] argMatchers = new Matcher[argumentTypes.size()]; ListIterator<DataType> it = argumentTypes.listIterator(); while (it.hasNext()) { int i = it.nextIndex(); DataType type = it.next(); argMatchers[i] = hasDataType(type); } //noinspection unchecked return isFunction(name, argMatchers); }
Example 19
Source File: ValueNumber.java From swift-t with Apache License 2.0 | 4 votes |
private void findCongruencesRec(Program program, Function f, Block block, ExecContext execCx, Congruences state, Map<Block, Congruences> result) throws OptUnsafeError { result.put(block, state); ListIterator<Statement> stmts = block.statementIterator(); while (stmts.hasNext()) { int stmtIndex = stmts.nextIndex(); Statement stmt = stmts.next(); if (stmt.type() == StatementType.INSTRUCTION) { /* First try to see if we can expand instruction sequence */ Instruction inst = stmt.instruction(); if (logger.isTraceEnabled() && inst.op != Opcode.COMMENT) { state.printTraceInfo(logger, program.constants()); logger.trace("-----------------------------"); logger.trace("At instruction: " + inst); } if (switchToImmediate(logger, f, execCx, block, state, inst, stmts, stmtIndex)) { /* * We switched the instruction for a new sequence of instructions. * Restart iteration and *don't* increment statement index to account. */ continue; } findCongruencesInst(program, f, execCx, block, stmts, inst, stmtIndex, state); } else { assert (stmt.type() == StatementType.CONDITIONAL); // handle situations like: // all branches assign future X a local values v1,v2,v3,etc. // in this case should try to create another local value outside of // conditional z which has the value from all branches stored UnifiedValues unified = findCongruencesContRec(program, f, execCx, stmt.conditional(), stmtIndex, state, result); state.addUnifiedValues(program.constants(), f.id().uniqueName(), stmtIndex, unified); } } int stmtCount = block.getStatements().size(); for (Continuation cont: block.getContinuations()) { findCongruencesContRec(program, f, execCx, cont, stmtCount, state, result); } validateState(program.constants(), state); }
Example 20
Source File: ThreadPrevNexListAction.java From jivejdon with Apache License 2.0 | 4 votes |
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { String currentThreadId = request.getParameter("thread"); if ((UtilValidate.isEmpty(currentThreadId)) || (!UtilValidate.isInteger(currentThreadId))) { Debug.logError("require the paramters : currentThreadId "); return actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME); } try { Long currentThreadIdL = new Long(currentThreadId); ForumMessageQueryService forumMessageQueryService = (ForumMessageQueryService) WebAppUtil.getService("forumMessageQueryService", this.servlet.getServletContext()); List threads = forumMessageQueryService.getThreadsPrevNext(currentThreadIdL); int index = -1; if (threads.size() != 0) { ForumThread currentThread = forumMessageQueryService.getThread(currentThreadIdL); index = threads.indexOf(currentThread); } Debug.logVerbose(" found the currentThread the index=" + index, module); // change the iterator for display ListIterator li = threads.listIterator(); if (index != -1) { while (li.nextIndex() != index) { li.next(); } } request.setAttribute("ThreadsPrevNext", li); // for above ListIterator li2 = threads.listIterator(); if (index != -1) { while (li2.nextIndex() != index) { li2.next(); } } request.setAttribute("ThreadsPrevNext2", li2);// for below } catch (Exception e) { Debug.logError(e, module); } return actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME); }