下面列出了java.nio.channels.CancelledKeyException#java.util.ListIterator 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void deleteInstrumentationConfigs(String agentId, List<String> versions)
throws Exception {
synchronized (writeLock) {
List<InstrumentationConfig> configs =
Lists.newArrayList(configService.getInstrumentationConfigs());
List<String> remainingVersions = Lists.newArrayList(versions);
for (ListIterator<InstrumentationConfig> i = configs.listIterator(); i.hasNext();) {
InstrumentationConfig loopConfig = i.next();
String loopVersion = Versions.getVersion(loopConfig.toProto());
if (remainingVersions.contains(loopVersion)) {
i.remove();
remainingVersions.remove(loopVersion);
}
}
if (!remainingVersions.isEmpty()) {
throw new OptimisticLockException();
}
configService.updateInstrumentationConfigs(configs);
}
}
@Override
protected int scoreTrail(List<String> trail, List<String> hintTrail) {
int score = 0;
ListIterator<String> hintIt = hintTrail.listIterator(hintTrail.size());
int lastTrailMatchIndex = trail.size();
while(hintIt.hasPrevious()) {
String hintCatId = hintIt.previous();
int matchIndex = SeoCatalogUrlWorker.lastIndexOf(trail, hintCatId, lastTrailMatchIndex - 1);
if (matchIndex > 0) {
score++;
lastTrailMatchIndex = matchIndex;
} else if (matchIndex == 0) {
score++;
break;
}
}
return score;
}
/**
* Modify the list of actions by adding in the new action, along with curation of the list due to the changes
* caused by adding the new action. The existing list is appended to with each new action (so oldest first).
*
* @param added new action
* @param actions existing list of actions.
*/
void curateActionList(@NotNull ActionStore.PendingAction added, @NotNull List<ActionStore.PendingAction> actions) {
// Curate the pending list of actions.
// Curation MUST be done in reverse order of the existing pending actions.
final ListIterator<ActionStore.PendingAction> iter = actions.listIterator(actions.size());
while (iter.hasPrevious()) {
final ActionStore.PendingAction existingAction = iter.previous();
PendingActionCurator.CurateResult result = curate(added, existingAction);
added = result.replacedAdded(added);
if (result.removeExisting) {
iter.remove();
} else {
iter.set(result.replacedExisting(existingAction));
}
if (result.removeAdded) {
// Halt the add operation
return;
}
if (result.stopSearch) {
// Don't look further for curation.
break;
}
}
actions.add(added);
}
void remove(final Lock lock) {
if (lock == null || lock == Locked.inst) {
return;
}
List<SLock> list = locks.get();
if (list == null || list.isEmpty()) {
return;
}
ListIterator<SLock> it = list.listIterator(list.size());
while (it.hasPrevious()) {
SLock lock2 = it.previous();
if (lock2.getId().equals(lock.getId())) {
it.remove();
}
}
}
/**
* @see org.apache.uima.ResourceFactory#produceResource(java.lang.Class,
* org.apache.uima.resource.ResourceSpecifier, java.util.Map)
*/
public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier,
Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
// check for factories registered for this resource specifier type
// (most recently registered first)
ListIterator<Registration> it = mRegisteredFactories.listIterator(mRegisteredFactories.size());
Resource result = null;
while (it.hasPrevious()) {
Registration reg = it.previous();
if (reg.resourceSpecifierInterface.isAssignableFrom(aSpecifier.getClass())) {
result = reg.factory.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
if (result != null) {
return result;
}
}
}
return null;
}
/**
* Switch to passing values directly.
* Do this before function inlining since function inlining
* will clean it up.
* @param logger
* @param program
*/
@Override
public void optimize(Logger logger, Program program) {
Set<FnID> usedFnIDs = new HashSet<FnID>(program.getFunctionMap().keySet());
Map<FnID, Function> toInline = new HashMap<FnID, Function>();
ListIterator<Function> fnIt = program.functionIterator();
while (fnIt.hasNext()) {
Function fn = fnIt.next();
Function newFn = switchToValuePassing(logger, program.foreignFunctions(),
fn, usedFnIDs);
if (newFn != null) {
fnIt.remove(); // Remove old function
fnIt.add(newFn);
usedFnIDs.add(newFn.id());
// We should inline
toInline.put(fn.id(), fn);
}
}
// Inline all calls to the old function
FunctionInline.inlineAllOccurrences(logger, program, toInline);
}
@Test
public void listIteratorHasNextAndHasPreviousOnThreeElementsList_shouldReturnTrueForEachElement() {
final ObservableArrayList<String> list = new ObservableArrayList<>("1", "2", "3");
final ListIterator<String> iterator = list.listIterator();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(false));
iterator.next();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(true));
iterator.next();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(true));
iterator.next();
assertThat(iterator.hasNext(), is(false));
assertThat(iterator.hasPrevious(), is(true));
iterator.previous();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(true));
iterator.previous();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(true));
iterator.previous();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(false));
}
void add(DelimiterProcessor dp) {
final int len = dp.getMinLength();
ListIterator<DelimiterProcessor> it = processors.listIterator();
boolean added = false;
while (it.hasNext()) {
DelimiterProcessor p = it.next();
int pLen = p.getMinLength();
if (len > pLen) {
it.previous();
it.add(dp);
added = true;
break;
} else if (len == pLen) {
throw new IllegalArgumentException("Cannot add two delimiter processors for char '" + delim + "' and minimum length " + len);
}
}
if (!added) {
processors.add(dp);
this.minLength = len;
}
}
protected void processWhile(WhileStmtToken result, ListIterator<Token> iterator){
analyzer.addScope().setLevelForGoto(true);
ExprStmtToken condition = getInBraces(BraceExprToken.Kind.SIMPLE, iterator);
if (condition == null)
unexpectedToken(iterator);
BodyStmtToken body = analyzer.generator(BodyGenerator.class).getToken(
nextToken(iterator), iterator, EndwhileStmtToken.class
);
if (body != null && body.isAlternativeSyntax())
iterator.next();
result.setCondition(condition);
result.setBody(body);
result.setLocal(analyzer.removeScope().getVariables());
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof GroupbyKey)) {
return false;
}
GroupbyKey that = (GroupbyKey)obj;
ListIterator<BytesWritable> e1 = this.value.listIterator();
ListIterator<BytesWritable> e2 = that.value.listIterator();
while (e1.hasNext() && e2.hasNext()) {
if (!Arrays.equals(e1.next().getBytes(), e2.next().getBytes())) {
return false;
}
}
return !(e1.hasNext() || e2.hasNext());
}
@Test
public void testIteration() {
final int n = 50000;
final int from = 10000;
final int to = 40000;
Integer[] arr = new Integer[n];
for(int i=0; i<n; ++i) arr[i] = i;
List<Integer> list = Arrays.asList(arr);
List<Integer> treeList = FingerTree.mkTree(list).asList();
list = list.subList(from, to);
treeList = treeList.subList(from, to);
ListIterator<Integer> it = treeList.listIterator();
List<Integer> fwRes = new ArrayList<>(treeList.size());
while(it.hasNext()) fwRes.add(it.next());
assertEquals(list, fwRes);
List<Integer> bwRes = new ArrayList<>(treeList.size());
while(it.hasPrevious()) bwRes.add(it.previous());
Collections.reverse(bwRes);
assertEquals(list, bwRes);
}
@Test
public void testIt() {
ListenableArrayList<String> list = new ListenableArrayList<>();
ArrayListListener listener = new ArrayListListener();
list.addListener(listener);
assertEquals(0,listener.invoked);
list.add("a");
assertEquals(1,listener.invoked);
list.add(0,"b");
assertEquals(2,listener.invoked);
list.addAll(Arrays.asList(new String[]{"c", "d"}));
assertEquals(3,listener.invoked);
list.addAll(1,Arrays.asList(new String[]{"e", "f"}));
assertEquals(4,listener.invoked);
list.set(0,"g");
assertEquals(5,listener.invoked);
ListIterator<String> i = list.listIterator();
i.add("h");
assertEquals(6,listener.invoked);
i.next();
i.set("i");
assertEquals(7,listener.invoked);
}
/**
* 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;
}
}
public Iterator<U> reversedIterator() {
final ListIterator<U> iterator = list.listIterator(list.size());
return new Iterator<U>() {
@Override
public boolean hasNext() {
return iterator.hasPrevious();
}
@Override
public U next() {
return iterator.previous();
}
};
}
private static void tryInline(Logger logger, Program prog,
Function contextFunction, Block block,
ListMultimap<FnID, FnID> inlineLocations,
Map<FnID, Function> toInline,
Set<FnID> alwaysInline, Set<Pair<FnID, FnID>> blacklist,
ListIterator<Statement> it, FunctionCall fcall) {
if (toInline.containsKey(fcall.functionID()) ||
alwaysInline.contains(fcall.functionID())) {
boolean canInlineHere;
if (inlineLocations == null) {
canInlineHere = true;
} else {
// Check that location is marked for inlining
List<FnID> inlineCallers = inlineLocations.get(fcall.functionID());
canInlineHere = inlineCallers.contains(contextFunction.id());
}
if (canInlineHere) {
// Do the inlining. Note that the iterator will be positioned
// after any newly inlined instructions.
inlineCall(logger, prog, contextFunction, block, it, fcall,
toInline.get(fcall.functionID()),
alwaysInline, blacklist);
}
}
}
/**
* Shuffles the entries of the given array, using the
* <a href="http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm">
* Fisher-Yates</a> algorithm.
*
* <p>
* Sampling uses {@link UniformRandomProvider#nextInt(int)}.
* </p>
*
* @param <T> Type of the list items.
* @param rng Random number generator.
* @param list List whose entries will be shuffled (in-place).
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static <T> void shuffle(UniformRandomProvider rng,
List<T> list) {
if (list instanceof RandomAccess || list.size() < RANDOM_ACCESS_SIZE_THRESHOLD) {
// Shuffle list in-place
for (int i = list.size(); i > 1; i--) {
swap(list, i - 1, rng.nextInt(i));
}
} else {
// Shuffle as an array
final Object[] array = list.toArray();
for (int i = array.length; i > 1; i--) {
swap(array, i - 1, rng.nextInt(i));
}
// Copy back. Use raw types.
final ListIterator it = list.listIterator();
for (final Object item : array) {
it.next();
it.set(item);
}
}
}
@Test
public void indexedListIteratorAtEndHasNextAndHasPreviousOnThreeElementsList_shouldReturnTrueForEachElement() {
final ObservableArrayList<String> list = new ObservableArrayList<>("1", "2", "3");
final ListIterator<String> iterator = list.listIterator(3);
assertThat(iterator.hasNext(), is(false));
assertThat(iterator.hasPrevious(), is(true));
iterator.previous();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(true));
iterator.previous();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(true));
iterator.previous();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.hasPrevious(), is(false));
}
@Test (expectedExceptions = NoSuchElementException.class)
public void indexedListIteratorAtEndPreviousOnThreeElements_shouldThrowExceptionAtTheBeginning() {
final ObservableArrayList<String> list = new ObservableArrayList<>("1", "2", "3");
final ListIterator<String> iterator = list.listIterator(3);
iterator.previous();
iterator.next();
iterator.previous();
iterator.previous();
iterator.next();
iterator.previous();
iterator.previous();
iterator.next();
iterator.previous();
iterator.previous();
}
public int nodeCount(String s, LinkedList linkedlist, boolean flag) {
int i = 0;
if (linkedlist == null)
return 0;
for (ListIterator listiterator = linkedlist.listIterator(0); listiterator.hasNext(); ) {
XMLNode xmlnode = (XMLNode) listiterator.next();
if (xmlnode != null)
switch (xmlnode.XMLType) {
default:
break;
case 0: // '\0'
case 1: // '\001'
if (xmlnode.XMLData.equals(s) || flag)
i++;
break;
}
}
return i;
}
@Override
@SuppressWarnings("unchecked")
public @NonNull B mapChildrenDeep(final @NonNull Function<BuildableComponent<? ,?>, ? extends BuildableComponent<? ,?>> function) {
if(this.children == AbstractComponent.EMPTY_COMPONENT_LIST) {
return (B) this;
}
final ListIterator<Component> it = this.children.listIterator();
while(it.hasNext()) {
final Component child = it.next();
if(!(child instanceof BuildableComponent<?, ?>)) {
continue;
}
final BuildableComponent<?, ?> mappedChild = function.apply((BuildableComponent<?, ?>) child);
if(mappedChild.children().isEmpty()) {
if(child == mappedChild) {
continue;
}
it.set(mappedChild);
} else {
final ComponentBuilder<?, ?> builder = mappedChild.toBuilder();
builder.mapChildrenDeep(function);
it.set(builder.build());
}
}
return (B) this;
}
private void loadFromDocument(Document nameSet) throws DataConversionException
{
Element generator = nameSet.getRootElement();
java.util.List<?> rulesets = generator.getChildren("RULESET");
java.util.List<?> lists = generator.getChildren("LIST");
ListIterator<?> listIterator = lists.listIterator();
while (listIterator.hasNext())
{
Element list = (Element) listIterator.next();
loadList(list);
}
for (final Object ruleset : rulesets)
{
Element ruleSet = (Element) ruleset;
RuleSet rs = loadRuleSet(ruleSet);
allVars.addDataElement(rs);
}
}
public void dismiss() {
if (mPlugins.isEmpty()) {
getOriginal().super_dismiss();
return;
}
final ListIterator<DialogFragmentPlugin> iterator = mPlugins.listIterator(mPlugins.size());
final CallVoid0 superCall = new CallVoid0("dismiss()") {
@Override
public void call() {
if (iterator.hasPrevious()) {
iterator.previous().dismiss(this);
} else {
getOriginal().super_dismiss();
}
}
};
superCall.call();
}
public void testListIterator() {
final SortedList<String> list = createList();
list.add("b");
list.add("c");
final ListIterator<String> iterator = list.listIterator();
assertEquals("b", iterator.next());
assertEquals("c", iterator.next());
assertEquals("c", iterator.previous());
assertEquals("b", iterator.previous());
iterator.add("a");
assertEquals(3, list.size());
list.add("d");
assertEquals(4, list.size());
assertEquals("a", list.get(0));
assertEquals("b", list.get(1));
assertEquals("c", list.get(2));
assertEquals("d", list.get(3));
}
@Override
public List<E> basicList() {
return new DerivedEObjectEList<E>(dataClass, owner, featureID,
sourceFeatureIDs) {
@Override
public ListIterator<E> listIterator(int index) {
return basicListIterator(index);
}
};
}
/**
* Removes a custom hyperlink parameter.
* <p>
* If multiple parameters having the specified name exist, all of them
* will be removed
* </p>
*
* @param parameterName the parameter name
*/
public void removeHyperlinkParameter(String parameterName)
{
for (ListIterator<JRHyperlinkParameter> it = hyperlinkParameters.listIterator(); it.hasNext();)
{
JRHyperlinkParameter parameter = it.next();
if (parameter.getName() != null && parameter.getName().equals(parameterName))
{
it.remove();
getEventSupport().fireCollectionElementRemovedEvent(JRDesignHyperlink.PROPERTY_HYPERLINK_PARAMETERS,
parameter, it.nextIndex());
}
}
}
protected int findGroupCellIndex(List<GroupCell> groupCells, String groupName)
{
int idx = -1;
for (ListIterator<GroupCell> it = groupCells.listIterator(); it.hasNext();)
{
GroupCell groupCell = it.next();
if (groupName.equals(groupCell.getGroupName()))
{
idx = it.previousIndex();
}
}
return idx;
}
private void calculateCoupling() {
ListIterator<ClassObject> classIterator = system.getClassListIterator();
while(classIterator.hasNext()) {
ClassObject classObject = classIterator.next();
LinkedHashMap<String, Integer> map = importCouplingMap.get(classObject.getName());
ListIterator<MethodObject> methodIterator = classObject.getMethodIterator();
while(methodIterator.hasNext()) {
MethodObject method = methodIterator.next();
if(method.getMethodBody() != null) {
List<MethodInvocationObject> methodInvocations = method.getMethodInvocations();
for(MethodInvocationObject methodInvocation : methodInvocations) {
String methodInvocationOrigin = methodInvocation.getOriginClassName();
if(map.keySet().contains(methodInvocationOrigin)) {
ClassObject originClass = system.getClassObject(methodInvocationOrigin);
MethodObject originMethod = originClass.getMethod(methodInvocation);
if(!originMethod.isStatic())
map.put(methodInvocationOrigin, map.get(methodInvocationOrigin)+1);
}
}
List<FieldInstructionObject> fieldInstructions = method.getFieldInstructions();
for(FieldInstructionObject fieldInstruction : fieldInstructions) {
String fieldInstructionOrigin = fieldInstruction.getOwnerClass();
if(map.keySet().contains(fieldInstructionOrigin) && !fieldInstruction.isStatic()) {
map.put(fieldInstructionOrigin, map.get(fieldInstructionOrigin)+1);
}
}
}
}
}
}
public static Boolean getLogFiles(Connection conn,String sql,Long currScn) throws SQLException{
int i = 0;
String option;
List<String> logFiles=null;
String pSql = sql.replace(":vcurrscn",currScn.toString());
PreparedStatement ps = conn.prepareCall(pSql);
log.info(pSql);
log.info("################################# Scanning Log Files for SCN :{}",currScn);
ResultSet rs = ps.executeQuery();
while (rs.next()){
logFiles = Arrays.asList(rs.getString("NAME").split(" "));
}
if (logFiles != null){
ListIterator<String> iterator = logFiles.listIterator();
while (iterator.hasNext()){
String logFile = iterator.next();
log.info("Log file will be mined {}",logFile);
if (i==0){
option = "DBMS_LOGMNR.NEW";
i++;
}else {
option = "DBMS_LOGMNR.ADDFILE";
}
executeCallableStmt(conn, OracleConnectorSQL.LOGMINER_ADD_LOGFILE.replace(":logfilename",logFile).replace(":option", option));
}
}
log.info("#################################");
rs.close();
ps.close();
return i>0 ? true : false;
}
static List<CompositionTimeToSample.Entry> getCompositionTimeEntries(List<CompositionTimeToSample.Entry> origSamples, long fromSample, long toSample) {
if (origSamples != null && !origSamples.isEmpty()) {
long current = 0;
ListIterator<CompositionTimeToSample.Entry> e = origSamples.listIterator();
ArrayList<CompositionTimeToSample.Entry> nuList = new ArrayList<CompositionTimeToSample.Entry>();
// Skip while not yet reached:
CompositionTimeToSample.Entry currentEntry;
while ((currentEntry = e.next()).getCount() + current <= fromSample) {
current += currentEntry.getCount();
}
// Take just a bit from the next
if (currentEntry.getCount() + current >= toSample) {
nuList.add(new CompositionTimeToSample.Entry((int) (toSample - fromSample), currentEntry.getOffset()));
return nuList; // done in one step
} else {
nuList.add(new CompositionTimeToSample.Entry((int) (currentEntry.getCount() + current - fromSample), currentEntry.getOffset()));
}
current += currentEntry.getCount();
while (e.hasNext() && (currentEntry = e.next()).getCount() + current < toSample) {
nuList.add(currentEntry);
current += currentEntry.getCount();
}
nuList.add(new CompositionTimeToSample.Entry((int) (toSample - current), currentEntry.getOffset()));
return nuList;
} else {
return null;
}
}
public void testRemoveThenSet() {
ListIterator it = makeFullListIterator();
if (supportsRemove() && supportsSet()) {
it.next();
it.remove();
try {
it.set(addSetValue());
fail("IllegalStateException must be thrown from set after remove");
} catch (IllegalStateException e) {
}
}
}