List of usage examples for com.google.common.collect ImmutableList iterator
@Override
public UnmodifiableIterator<E> iterator()
From source file:org.geogit.api.plumbing.diff.MutableTree.java
@Nullable public MutableTree removeChild(String path) { ImmutableList<String> steps = NodeRef.split(path); MutableTree tree = this; for (Iterator<String> childNames = steps.iterator(); childNames.hasNext();) { String childName = childNames.next(); MutableTree child = tree.childTrees.get(childName); if (child == null) { return null; }//from w w w . ja v a 2 s .c om if (!childNames.hasNext()) { MutableTree removed = tree.childTrees.remove(childName); return removed; } else { tree = child; } } return null; }
From source file:org.onosproject.net.intent.impl.compiler.ConnectivityIntentCompiler.java
/** * Computes a path between two ConnectPoints. * * @param intent intent on which behalf path is being computed * @param one start of the path/*from w ww . jav a2s.c o m*/ * @param two end of the path * @return Path between the two * @throws PathNotFoundException if a path cannot be found */ protected Path getPath(ConnectivityIntent intent, ElementId one, ElementId two) { Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints())); final List<Constraint> constraints = intent.constraints(); ImmutableList<Path> filtered = FluentIterable.from(paths).filter(path -> checkPath(path, constraints)) .toList(); if (filtered.isEmpty()) { throw new PathNotFoundException(one, two); } // TODO: let's be more intelligent about this eventually return filtered.iterator().next(); }
From source file:com.forerunnergames.tools.common.Strings.java
/** * Converts a collection of list elements to a string list, separated by separator, in case letterCase. * * @param <T>/*from w w w. j a v a2s.c o m*/ * The type of the list elements. * @param listElements * The collection of list elements to convert, must not be null, must not contain any null elements. * @param separator * The separator that should be added between list elements, must not be null. * @param letterCase * The desired letter case of the list elements, must not be null, choose LetterCase.NONE to leave the list * elements as-is. * @param hasAnd * Whether or not to insert the word 'and ' between the last two elements in the list, one space after the * last separator. * * @return A string list of listElements, separated by separator, in case letterCase, with an optional 'and ' * occurring between the last two elements of the list. */ public static <T> String toStringList(final Collection<T> listElements, final String separator, final LetterCase letterCase, final boolean hasAnd) { Arguments.checkIsNotNull(listElements, "listElements"); Arguments.checkHasNoNullElements(listElements, "listElements"); Arguments.checkIsNotNull(separator, "separator"); Arguments.checkIsNotNull(letterCase, "letterCase"); final ImmutableList.Builder<T> printableListElementsBuilder = ImmutableList.builder(); for (final T element : listElements) { if (isPrintable(element.toString())) printableListElementsBuilder.add(element); } final ImmutableList<T> printableListElements = printableListElementsBuilder.build(); // Handle the first three special cases if (printableListElements.isEmpty()) { return ""; } else if (printableListElements.size() == 1) { return toCase(Iterables.getOnlyElement(printableListElements).toString(), letterCase); } else if (printableListElements.size() == 2) { final Iterator<T> iterator = printableListElements.iterator(); // Here, if the separator is a comma, for example, it's either: // "item1 and item2" or "item1,item2" (if no "and" is desired) // because "item1, and item2" doesn't make sense grammatically, which is // what would happen if we didn't treat this as a special case return toCase(iterator.next().toString() + (hasAnd ? " and " : separator) + iterator.next().toString(), letterCase); } final StringBuilder s = new StringBuilder(); for (final T element : printableListElements) { final String elementString = toCase(element.toString(), letterCase); s.append(elementString).append(separator); } try { // Delete the extra comma at the end of the last element in the list. s.delete(s.length() - separator.length(), s.length()); if (hasAnd && s.lastIndexOf(separator) >= 0) { // Insert the word 'and' between the last two elements in the list, // after the last comma. s.insert(s.lastIndexOf(separator) + 1, "and "); } } catch (final StringIndexOutOfBoundsException ignored) { } return s.toString(); }
From source file:org.onosproject.net.intent.impl.ConnectivityIntentCompiler.java
/** * Computes a path between two ConnectPoints. * * @param intent intent on which behalf path is being computed * @param one start of the path//from ww w . ja va 2s. c om * @param two end of the path * @return Path between the two * @throws PathNotFoundException if a path cannot be found */ protected Path getPath(ConnectivityIntent intent, ElementId one, ElementId two) { Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints())); final List<Constraint> constraints = intent.constraints(); ImmutableList<Path> filtered = FluentIterable.from(paths).filter(new Predicate<Path>() { @Override public boolean apply(Path path) { return checkPath(path, constraints); } }).toList(); if (filtered.isEmpty()) { throw new PathNotFoundException("No packet path from " + one + " to " + two); } // TODO: let's be more intelligent about this eventually return filtered.iterator().next(); }
From source file:com.opengamma.web.analytics.blotter.BlotterLookupResource.java
@GET @Path("exercisetypes") @Produces(MediaType.APPLICATION_JSON)/*ww w. ja v a 2s. com*/ public String getExerciseTypes() { ImmutableList<ExerciseType> exerciseTypes = ImmutableList.<ExerciseType>of(/*new AmericanExerciseType(), new AsianExerciseType(), new BermudanExerciseType(),*/ new EuropeanExerciseType()); return convertToJsonArray(ExerciseType.class, exerciseTypes.iterator()); }
From source file:com.techcavern.pircbotz.Channel.java
/** * Sets the mode of the channel. If there is a getMode() waiting on this, * fire it./*from ww w.j ava2 s. c o m*/ * @param mode */ protected void setMode(String mode, ImmutableList<String> modeParsed) { this.mode = mode; this.modeStale = false; if (modeLatch != null) modeLatch.countDown(); //Parse out mode PeekingIterator<String> params = Iterators.peekingIterator(modeParsed.iterator()); //Process modes letter by letter, grabbing paramaters as needed boolean adding = true; String modeLetters = params.next(); for (int i = 0; i < modeLetters.length(); i++) { char curModeChar = modeLetters.charAt(i); if (curModeChar == '+') adding = true; else if (curModeChar == '-') adding = false; else { ChannelModeHandler modeHandler = bot.getConfiguration().getChannelModeHandlers().get(curModeChar); if (modeHandler != null) modeHandler.handleMode(bot, this, null, params, adding, false); } } }
From source file:org.pircbotx.Channel.java
/** * Sets the mode of the channel. If there is a getMode() waiting on this, * fire it.//from ww w . j a v a2 s . c om * * @param mode */ protected void setMode(String mode, ImmutableList<String> modeParsed) { synchronized (modeChangeLock) { this.mode = mode; //Parse out mode PeekingIterator<String> params = Iterators.peekingIterator(modeParsed.iterator()); //Process modes letter by letter, grabbing paramaters as needed boolean adding = true; String modeLetters = params.next(); for (int i = 0; i < modeLetters.length(); i++) { char curModeChar = modeLetters.charAt(i); if (curModeChar == '+') adding = true; else if (curModeChar == '-') adding = false; else { ChannelModeHandler modeHandler = bot.getConfiguration().getChannelModeHandlers() .get(curModeChar); if (modeHandler != null) modeHandler.handleMode(bot, this, null, null, params, adding, false); } } if (modeChangeLatch != null) modeChangeLatch.countDown(); } }
From source file:org.sosy_lab.cpachecker.cpa.predicate.PredicateCPARefiner.java
/** * Get the block formulas from a path./*from w w w . j a va 2 s . c o m*/ * @param path A list of all abstraction elements * @param initialState The initial element of the analysis (= the root element of the ARG) * @return A list of block formulas for this path. * @throws SolverException */ protected List<BooleanFormula> getFormulasForPath(List<ARGState> path, ARGState initialState) throws CPATransferException, InterruptedException, SolverException { getFormulasForPathTime.start(); try { if (conjunctPreconditionFormulas) { ImmutableList<ARGState> predicateStates = from(path).toList(); List<BooleanFormula> result = Lists.newArrayList(); UnmodifiableIterator<ARGState> abstractionIt = predicateStates.iterator(); final BooleanFormulaManagerView bfmgr = fmgr.getBooleanFormulaManager(); BooleanFormula traceFormula = bfmgr.makeBoolean(true); // each abstraction location has a corresponding block formula while (abstractionIt.hasNext()) { final ARGState argState = abstractionIt.next(); final LocationState locState = AbstractStates.extractStateByType(argState, LocationState.class); final CFANode loc = locState.getLocationNode(); final PredicateAbstractState predState = AbstractStates.extractStateByType(argState, PredicateAbstractState.class); assert predState.isAbstractionState(); final BooleanFormula blockFormula = predState.getAbstractionFormula().getBlockFormula() .getFormula(); final SSAMap blockSsaMap = predState.getAbstractionFormula().getBlockFormula().getSsa(); traceFormula = bfmgr.and(traceFormula, blockFormula); if (!BlockOperator.isFirstLocationInFunctionBody(loc) || solver.isUnsat(traceFormula)) { // Add the precondition only if the trace formula is SAT!! result.add(blockFormula); } else { final BooleanFormula eliminationResult = PredicateVariableElimination .eliminateDeadVariables(fmgr, traceFormula, blockSsaMap); final BooleanFormula blockPrecondition = assumesStore.conjunctAssumeToLocation(loc, fmgr.makeNot(eliminationResult)); result.add(bfmgr.and(blockFormula, blockPrecondition)); } } return result; } else if (sliceBlockFormulas) { BlockFormulaSlicer bfs = new BlockFormulaSlicer(pfmgr); return bfs.sliceFormulasForPath(path, initialState); } else { return from(path).transform(toState(PredicateAbstractState.class)).transform(GET_BLOCK_FORMULA) .toList(); } } finally { getFormulasForPathTime.stop(); } }
From source file:com.mediatek.contacts.editor.SubscriberAccount.java
/** * Insert Raw data to sim card.// w w w .j a v a 2 s . co m * @param rawContacts */ public void insertRawDataToSim(ImmutableList<RawContact> rawContacts) { Log.i(TAG, "[insertRawDataToSim]"); /* * New Feature by Mediatek Begin. Original Android's code: CR * ID:ALPS00101852 Descriptions: insert data to SIM/USIM. */ mSaveModeForSim = MODE_SIM_EDIT; mOldState = new RawContactDeltaList(); mOldState.addAll(rawContacts.iterator()); ContactEditorUtilsEx.showLogContactState(mOldState); }
From source file:org.apache.gobblin.util.AvroFlattener.java
/*** * Flatten Record field, and compute a list of flattened fields * * Note: Lineage represents the source path from root for the flattened field. For. eg. If the original schema is: * {/*from ww w. j a va 2s.co m*/ * "type" : "record", * "name" : "parentRecordName", * "fields" : [ { * "name" : "parentFieldRecord", * "type" : { * "type" : "record", * "name" : "nestedRecordName", * "fields" : [ { * "name" : "nestedFieldString", * "type" : "string" * }, { * "name" : "nestedFieldInt", * "type" : "int" * } ] * } * }] * } * The expected output schema is: * { * "type" : "record", * "name" : "parentRecordName", * "fields" : [ { * "name" : "parentFieldRecord__nestedFieldString", * "type" : "string", * "flatten_source" : "parentFieldRecord.nestedFieldString" * }, { * "name" : "parentFieldRecord__nestedFieldInt", * "type" : "int", * "flatten_source" : "parentFieldRecord.nestedFieldInt" * }, { * "name" : "parentFieldInt", * "type" : "int" * } ] * } * Here, 'flatten_source' and field 'name' has also been modified to represent their origination from nested schema * lineage helps to determine that * * @param f Field to flatten * @param parentLineage Parent's lineage represented as a List of Strings * @param shouldPopulateLineage If lineage information should be tagged in the field, this is true when we are * un-nesting fields * @param flattenComplexTypes Flatten complex types recursively other than Record and Option * @param shouldWrapInOption If the field should be wrapped as an OPTION, if we un-nest fields within an OPTION * we make all the unnested fields as OPTIONs * @return List of flattened Record fields */ private List<Schema.Field> flattenField(Schema.Field f, ImmutableList<String> parentLineage, boolean shouldPopulateLineage, boolean flattenComplexTypes, Optional<Schema> shouldWrapInOption) { Preconditions.checkNotNull(f); Preconditions.checkNotNull(f.schema()); Preconditions.checkNotNull(f.name()); List<Schema.Field> flattenedFields = new ArrayList<>(); ImmutableList<String> lineage = ImmutableList.<String>builder().addAll(parentLineage.iterator()) .add(f.name()).build(); // If field.Type = RECORD, un-nest its fields and return them if (Schema.Type.RECORD.equals(f.schema().getType())) { if (null != f.schema().getFields() && f.schema().getFields().size() > 0) { for (Schema.Field field : f.schema().getFields()) { flattenedFields.addAll( flattenField(field, lineage, true, flattenComplexTypes, Optional.<Schema>absent())); } } } // If field.Type = OPTION, un-nest its fields and return them else { Optional<Schema> optionalRecord = isOfOptionType(f.schema()); if (optionalRecord.isPresent()) { Schema record = optionalRecord.get(); if (record.getFields().size() > 0) { for (Schema.Field field : record.getFields()) { flattenedFields.addAll( flattenField(field, lineage, true, flattenComplexTypes, Optional.of(f.schema()))); } } } // If field.Type = any-other, copy and return it else { // Compute name and source using lineage String flattenName = f.name(); String flattenSource = StringUtils.EMPTY; if (shouldPopulateLineage) { flattenName = StringUtils.join(lineage, flattenedNameJoiner); flattenSource = StringUtils.join(lineage, flattenedSourceJoiner); } // Copy field Schema flattenedFieldSchema = flatten(f.schema(), shouldPopulateLineage, flattenComplexTypes); if (shouldWrapInOption.isPresent()) { boolean isNullFirstMember = Schema.Type.NULL .equals(shouldWrapInOption.get().getTypes().get(0).getType()); // If already Union, just copy it instead of wrapping (Union within Union is not supported) if (Schema.Type.UNION.equals(flattenedFieldSchema.getType())) { List<Schema> newUnionMembers = new ArrayList<>(); if (isNullFirstMember) { newUnionMembers.add(Schema.create(Schema.Type.NULL)); } for (Schema type : flattenedFieldSchema.getTypes()) { if (Schema.Type.NULL.equals(type.getType())) { continue; } newUnionMembers.add(type); } if (!isNullFirstMember) { newUnionMembers.add(Schema.create(Schema.Type.NULL)); } flattenedFieldSchema = Schema.createUnion(newUnionMembers); } // Wrap the Union, since parent Union is an option else { if (isNullFirstMember) { flattenedFieldSchema = Schema.createUnion( Arrays.asList(Schema.create(Schema.Type.NULL), flattenedFieldSchema)); } else { flattenedFieldSchema = Schema.createUnion( Arrays.asList(flattenedFieldSchema, Schema.create(Schema.Type.NULL))); } } } Schema.Field field = new Schema.Field(flattenName, flattenedFieldSchema, f.doc(), f.defaultValue(), f.order()); if (StringUtils.isNotBlank(flattenSource)) { field.addProp(FLATTENED_SOURCE_KEY, flattenSource); } for (Map.Entry<String, JsonNode> entry : f.getJsonProps().entrySet()) { field.addProp(entry.getKey(), entry.getValue()); } flattenedFields.add(field); } } return flattenedFields; }