Java Code Examples for java.util.ListIterator#previousIndex()
The following examples show how to use
java.util.ListIterator#previousIndex() .
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: FileMessageLoader.java From sailfish-core with Apache License 2.0 | 6 votes |
@Override protected void retrieveMessages(Queue<FileMessage> forMessages, int count, long lastID) { if(lastID == -1 || lastID == source.size()) { return; } try { ListIterator<FileMessage> it = source.listIterator((int)lastID); while(count > 0 && (ascending ? it.hasNext() : it.hasPrevious())) { FileMessage message = ascending ? it.next() : it.previous(); if(!checkMessage(message, filter)) { continue; } forMessages.add(message); count--; } nextIndex = ascending ? it.nextIndex() : it.previousIndex(); } catch(IndexOutOfBoundsException | NoSuchElementException e) { throw new StorageException("Message list probably have been cleared", e); } }
Example 2
Source File: MultiDex.java From letv with Apache License 2.0 | 6 votes |
private static void install(ClassLoader loader, List<File> additionalClassPathEntries) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, IOException { int extraSize = additionalClassPathEntries.size(); Field pathField = MultiDex.findField(loader, "path"); StringBuilder path = new StringBuilder((String) pathField.get(loader)); String[] extraPaths = new String[extraSize]; File[] extraFiles = new File[extraSize]; ZipFile[] extraZips = new ZipFile[extraSize]; DexFile[] extraDexs = new DexFile[extraSize]; ListIterator<File> iterator = additionalClassPathEntries.listIterator(); while (iterator.hasNext()) { File additionalEntry = (File) iterator.next(); String entryPath = additionalEntry.getAbsolutePath(); path.append(':').append(entryPath); int index = iterator.previousIndex(); extraPaths[index] = entryPath; extraFiles[index] = additionalEntry; extraZips[index] = new ZipFile(additionalEntry); extraDexs[index] = DexFile.loadDex(entryPath, entryPath + ".dex", 0); } pathField.set(loader, path.toString()); MultiDex.expandFieldArray(loader, "mPaths", extraPaths); MultiDex.expandFieldArray(loader, "mFiles", extraFiles); MultiDex.expandFieldArray(loader, "mZips", extraZips); MultiDex.expandFieldArray(loader, "mDexs", extraDexs); }
Example 3
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 4
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * An implementation of {@link List#indexOf(Object)}. */ static int indexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return indexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(); while (listIterator.hasNext()) { if (Objects.equal(element, listIterator.next())) { return listIterator.previousIndex(); } } return -1; } }
Example 5
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * An implementation of {@link List#indexOf(Object)}. */ static int indexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return indexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(); while (listIterator.hasNext()) { if (Objects.equal(element, listIterator.next())) { return listIterator.previousIndex(); } } return -1; } }
Example 6
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * An implementation of {@link List#indexOf(Object)}. */ static int indexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return indexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(); while (listIterator.hasNext()) { if (Objects.equal(element, listIterator.next())) { return listIterator.previousIndex(); } } return -1; } }
Example 7
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * An implementation of {@link List#indexOf(Object)}. */ static int indexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return indexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(); while (listIterator.hasNext()) { if (Objects.equal(element, listIterator.next())) { return listIterator.previousIndex(); } } return -1; } }
Example 8
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void addTypeCastToExplicitReceiver(XAbstractFeatureCall featureCall, IModificationContext context, JvmType declaringType, EReference structuralFeature) throws BadLocationException { List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, structuralFeature); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); INode lastNode = IterableExtensions.last(nodes); int offset = firstNode.getOffset(); int length = lastNode.getEndOffset() - offset; ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, length); appendable.append("("); ListIterator<INode> nodeIter = nodes.listIterator(); while (nodeIter.hasNext()) { String text = nodeIter.next().getText(); if (nodeIter.previousIndex() == 0) appendable.append(Strings.removeLeadingWhitespace(text)); else if (nodeIter.nextIndex() == nodes.size()) appendable.append(Strings.trimTrailingLineBreak(text)); else appendable.append(text); } appendable.append(" as "); appendable.append(declaringType); appendable.append(")"); appendable.commitChanges(); }
Example 9
Source File: PhaseController.java From Cardshifter with Apache License 2.0 | 5 votes |
public boolean insertTemporaryPhaseBefore(Phase phase, Predicate<Phase> beforePhase) { ListIterator<Phase> it = navigateToRecreate(beforePhase); if (it != null) { if (it.previousIndex() >= 0) { it.previous(); } it.add(phase); } return it != null; }
Example 10
Source File: TemporalRowTimeJoinOperator.java From flink with Apache License 2.0 | 5 votes |
private int indexOfFirstElementNewerThanTimer(long timerTimestamp, List<RowData> list) { ListIterator<RowData> iter = list.listIterator(); while (iter.hasNext()) { if (getRightTime(iter.next()) > timerTimestamp) { return iter.previousIndex(); } } return -1; }
Example 11
Source File: CommandLineParser.java From ant-ivy with Apache License 2.0 | 5 votes |
public CommandLine parse(String[] args) throws ParseException { CommandLine line = new CommandLine(); int index = args.length; ListIterator<String> iterator = Arrays.asList(args).listIterator(); while (iterator.hasNext()) { String arg = iterator.next(); if ("--".equals(arg)) { // skip this argument and stop looping index = iterator.nextIndex(); break; } if (!arg.startsWith("-")) { index = iterator.previousIndex(); break; } Option option = options.get(arg.substring(1)); if (option == null) { throw new ParseException("Unrecognized option: " + arg); } line.addOptionValues(arg.substring(1), option.parse(iterator)); } // left over args String[] leftOverArgs = new String[args.length - index]; System.arraycopy(args, index, leftOverArgs, 0, leftOverArgs.length); line.setLeftOverArgs(leftOverArgs); return line; }
Example 12
Source File: RichLazyDataModel.java From development with Apache License 2.0 | 5 votes |
@Override public int getRowIndex() { if (cachedList != null) { ListIterator<T> it = cachedList.listIterator(); while (it.hasNext()) { T t = it.next(); if (getKey(t).equals(this.getRowKey())) { return it.previousIndex() + cachedRange.getFirstRow(); } } } return -1; }
Example 13
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** * An implementation of {@link List#indexOf(Object)}. */ static int indexOfImpl(List<?> list, @Nullable Object element) { if (list instanceof RandomAccess) { return indexOfRandomAccess(list, element); } else { ListIterator<?> listIterator = list.listIterator(); while (listIterator.hasNext()) { if (Objects.equal(element, listIterator.next())) { return listIterator.previousIndex(); } } return -1; } }
Example 14
Source File: TemporalRowTimeJoinOperator.java From flink with Apache License 2.0 | 5 votes |
private int indexOfFirstElementNewerThanTimer(long timerTimestamp, List<BaseRow> list) { ListIterator<BaseRow> iter = list.listIterator(); while (iter.hasNext()) { if (getRightTime(iter.next()) > timerTimestamp) { return iter.previousIndex(); } } return -1; }
Example 15
Source File: Histogram.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the value at a given position. */ public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); // Undo position change made by mid.next(). if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); // Undo position change made by b.next(). final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; }
Example 16
Source File: JRDesignDataset.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * Inserts a variable at specified position into the dataset. * * @param index the variable position * @param variable the variable to insert * @param system whether the variable should be inserted before user defined variables * or at the end of the variables list * @throws JRException */ protected void addVariable(int index, JRDesignVariable variable, boolean system) throws JRException { if (variablesMap.containsKey(variable.getName())) { throw new JRException( EXCEPTION_MESSAGE_KEY_DUPLICATE_VARIABLE, new Object[]{variable.getName()}); } if (system) { // add the variable before the first non-system variable ListIterator<JRVariable> it = variablesList.listIterator(); while (it.hasNext()) { JRVariable var = it.next(); if (!var.isSystemDefined()) { it.previous(); break; } } it.add(variable); index = it.previousIndex(); } else { variablesList.add(index, variable); } variablesMap.put(variable.getName(), variable); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_VARIABLES, variable, index); }
Example 17
Source File: EpoxyController.java From epoxy with Apache License 2.0 | 5 votes |
private void filterDuplicatesIfNeeded(List<EpoxyModel<?>> models) { if (!filterDuplicates) { return; } timer.start("Duplicates filtered"); Set<Long> modelIds = new HashSet<>(models.size()); ListIterator<EpoxyModel<?>> modelIterator = models.listIterator(); while (modelIterator.hasNext()) { EpoxyModel<?> model = modelIterator.next(); if (!modelIds.add(model.id())) { int indexOfDuplicate = modelIterator.previousIndex(); modelIterator.remove(); int indexOfOriginal = findPositionOfDuplicate(models, model); EpoxyModel<?> originalModel = models.get(indexOfOriginal); if (indexOfDuplicate <= indexOfOriginal) { // Adjust for the original positions of the models before the duplicate was removed indexOfOriginal++; } onExceptionSwallowed( new IllegalEpoxyUsage("Two models have the same ID. ID's must be unique!" + "\nOriginal has position " + indexOfOriginal + ":\n" + originalModel + "\nDuplicate has position " + indexOfDuplicate + ":\n" + model) ); } } timer.stop(); }
Example 18
Source File: BufferCache.java From conga with Apache License 2.0 | 5 votes |
@Override public int indexOf(Object o) { ListIterator<ByteBuffer> it = listIterator(getMinimumAvailableIndex()); while (it.hasNext()) { if (o.equals(it.next())) return it.previousIndex(); } return -1; }
Example 19
Source File: SqlScriptMigrationTask.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Executes the passed sql in the passed context. * * @param ctx the <code>MigrationContext> to execute the SQL in * @param sqlToExec the SQL to execute * @throws MigrationException thrown if there is an error when executing the SQL */ private void executeSql(MigrationContext ctx, String sqlToExec) throws MigrationException { JdbcMigrationContext context = (JdbcMigrationContext) ctx; Connection conn = null; Statement stmt = null; String sqlStatement = ""; ListIterator listIterator = null; try { conn = context.getConnection(); // cleaning the slate before we execute the patch. // This was inspired by a Sybase ASE server that did not allow // ALTER TABLE statements in multi-statement transactions. Instead of putting // a if(sybase) conditional, we decided to clean the slate for everyone. context.commit(); List sqlStatements = getSqlStatements(context, sqlToExec); for (listIterator = sqlStatements.listIterator(); listIterator.hasNext();) { sqlStatement = (String) listIterator.next(); log.debug(getName() + ": Attempting to execute: " + sqlStatement); stmt = conn.createStatement(); // handle sybase special case with illegal commands in multi // command transactions if (isSybase(context) && SybaseUtil.containsIllegalMultiStatementTransactionCommand(sqlStatement)) { log.warn("Committing current transaction since patch " + getName() + " contains commands that are not allowed in multi statement" + " transactions. If the patch contains errors, this patch may" + " not be rolled back cleanly."); context.commit(); stmt.execute(sqlStatement); context.commit(); } else // regular case { stmt.execute(sqlStatement); } SqlUtil.close(null, stmt, null); } context.commit(); } catch (Exception e) { String message = getName() + ": Error running SQL at statement number " + listIterator.previousIndex() + " \"" + sqlStatement + "\""; log.error(message, e); if (e instanceof SQLException) { if (((SQLException) e).getNextException() != null) { log.error("Chained SQL Exception", ((SQLException) e).getNextException()); } } context.rollback(); throw new MigrationException(message, e); } finally { SqlUtil.close(null, stmt, null); } }