下面列出了com.google.common.collect.ImmutableList#iterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void appendPath(ImmutableList<SpecificField> fieldPath, boolean leftSide)
throws IOException {
for (Iterator<SpecificField> it = fieldPath.iterator(); it.hasNext(); ) {
SpecificField specificField = it.next();
FieldDescriptor field = specificField.getField();
if (field != null) {
if (field.isExtension()) {
output.append("(").append(field.getFullName()).append(")");
} else {
output.append(field.getName());
}
} else {
output.append(String.valueOf(specificField.getUnknown().getFieldNumber()));
}
if (leftSide && (specificField.getIndex() >= 0)) {
output.append("[").append(String.valueOf(specificField.getIndex())).append("]");
}
if (!leftSide && (specificField.getNewIndex() >= 0)) {
output.append("[").append(String.valueOf(specificField.getNewIndex())).append("]");
}
if (it.hasNext()) {
output.append(".");
}
}
}
@Test
public void testListTablesRestricted() {
final TableOptions options = new TableOptionsBuilder().setPlacement("my:placement").build();
final ImmutableMap<String, Object> template = ImmutableMap.<String, Object>of("key", "value1");
final TableAvailability availability = new TableAvailability("my:placement", false);
final DefaultTable a1 = new DefaultTable("a-table-1", options, template, availability);
final DefaultTable a2 = new DefaultTable("a-table-2", options, template, availability);
final DefaultTable b1 = new DefaultTable("b-table-1", options, template, availability);
final DefaultTable b2 = new DefaultTable("b-table-2", options, template, availability);
final DefaultTable a3 = new DefaultTable("a-table-3", options, template, availability);
final ImmutableList<Table> tables = ImmutableList.of(a1, a2, b1, b2, a3);
final UnmodifiableIterator<Table> iterator = tables.iterator();
//noinspection unchecked
when(_server.listTables(null, Long.MAX_VALUE)).thenAnswer(invocation -> iterator);
{
final Iterator<Table> tableIterator = sorClient(APIKEY_READ_TABLES_A).listTables(null, 3);
final ImmutableList<Table> result = ImmutableList.copyOf(tableIterator);
assertEquals(ImmutableList.<Table>of(a1, a2, a3), result);
}
verify(_server, times(1)).listTables(null, Long.MAX_VALUE);
}
private FakeIdentityRepository(String domain, ImmutableList<Snapshot> snapshots) {
checkNotNull(domain);
domain = domain.trim();
checkArgument(!domain.isEmpty(), "domain is empty");
checkNotNull(snapshots);
this.domain = domain;
this.snapshotIterator = snapshots.iterator();
checkArgument(snapshotIterator.hasNext(), "no snapshots were provided");
this.snapshots = snapshots;
}
@Override
public void write(final Kryo kryo, final Output output, final ImmutableList<Object> object) {
output.writeInt(object.size(), true);
final UnmodifiableIterator iterator = object.iterator();
while (iterator.hasNext()) {
final Object value = iterator.next();
kryo.writeClassAndObject(output, value);
}
}
DataValueLookupMetadata(ImmutableList<CaseInsensitiveString> keys) {
super();
if (log.isDebugEnabled()) log.debug("New metadata entry: " + keys);
this.keys = keys;
ImmutableMap.Builder<CaseInsensitiveString, Integer> builder = ImmutableMap.builder();
Iterator<CaseInsensitiveString> iterator = keys.iterator();
int i = 0;
while (iterator.hasNext()) {
builder.put(iterator.next(), i++);
}
this.lookups = builder.build();
}
private boolean isSameTypes(ImmutableList<Type> a, ImmutableList<Type> b) {
if (a.size() != b.size()) {
return false;
}
Iterator<Type> ax = a.iterator();
Iterator<Type> bx = b.iterator();
while (ax.hasNext()) {
if (!isSameType(ax.next(), bx.next())) {
return false;
}
}
return true;
}
/**
* Returns the position of the given annotation value {@code toFind}, given a list of annotation
* values corresponding to the element values of a (possibly nested) annotation or an array value,
* and the corresponding expression trees.
*/
private static int locate(
Const toFind, ImmutableList<Const> vx, ImmutableList<Tree.Expression> tx) {
Iterator<Const> vi = vx.iterator();
Iterator<Tree.Expression> ti = tx.iterator();
while (vi.hasNext()) {
int result = locate(toFind, vi.next(), ti.next());
if (result != -1) {
return result;
}
}
return -1;
}
/**
* Parses the given javacopts for {@code --release}, and if found sets turbine's {@code --release}
* flag.
*/
private static void setReleaseFromJavacopts(
TurbineOptions.Builder builder, ImmutableList<String> javacopts) {
Iterator<String> it = javacopts.iterator();
while (it.hasNext()) {
if (it.next().equals("--release") && it.hasNext()) {
builder.setRelease(it.next());
}
}
}
@Test
void getEntriesSeenShouldReturnEmptyWhenNotConsumed() {
ImmutableList<Integer> originalData = ImmutableList.of(1, 2, 3);
IteratorWrapper<Integer> integerIteratorWrapper = new IteratorWrapper<>(originalData.iterator());
assertThat(integerIteratorWrapper.getEntriesSeen()).isEmpty();
}
@Test
void getEntriesSeenShouldReturnViewOfConsumedData() {
ImmutableList<Integer> originalData = ImmutableList.of(1, 2, 3);
IteratorWrapper<Integer> integerIteratorWrapper = new IteratorWrapper<>(originalData.iterator());
consume(integerIteratorWrapper);
assertThat(integerIteratorWrapper.getEntriesSeen())
.containsExactlyElementsOf(originalData);
}
@Test
void getEntriesSeenShouldReturnViewOfConsumedDataWhenPartiallyConsumed() {
ImmutableList<Integer> originalData = ImmutableList.of(1, 2, 3);
IteratorWrapper<Integer> integerIteratorWrapper = new IteratorWrapper<>(originalData.iterator());
integerIteratorWrapper.next();
integerIteratorWrapper.next();
assertThat(integerIteratorWrapper.getEntriesSeen())
.containsOnly(1, 2);
}
@Test
void getEntriesSeenShouldReturnEmptyWhenSuppliedEmpty() {
ImmutableList<Integer> originalData = ImmutableList.of();
IteratorWrapper<Integer> integerIteratorWrapper = new IteratorWrapper<>(originalData.iterator());
consume(integerIteratorWrapper);
assertThat(integerIteratorWrapper.getEntriesSeen())
.containsExactlyElementsOf(originalData);
}
/**
* Returns a distinct immutable Set of SubscribersWithQoS. The set is guaranteed to only contain one entry per
* subscriber string. This entry has the maximum QoS found in the topic tree and the subscription identifiers of all
* subscriptions for the client.
*
* @param subscribers a list of subscribers
* @return a immutable Set of distinct Subscribers with the maximum QoS.
*/
@NotNull
private ImmutableSet<SubscriberWithIdentifiers> createDistinctSubscribers(@NotNull final ImmutableList<SubscriberWithQoS> subscribers) {
final ImmutableSet.Builder<SubscriberWithIdentifiers> newSet = ImmutableSet.builder();
final ImmutableList<SubscriberWithQoS> subscriberWithQoS = ImmutableList.sortedCopyOf((sub1, sub2) -> sub1.compareTo(sub2), subscribers);
final Iterator<SubscriberWithQoS> iterator = subscriberWithQoS.iterator();
SubscriberWithIdentifiers last = null;
// Create a single entry per client id, with the highest QoS an all subscription identifiers
while (iterator.hasNext()) {
final SubscriberWithQoS current = iterator.next();
if (last != null) {
if (!equalSubscription(current, last)) {
newSet.add(last);
last = new SubscriberWithIdentifiers(current);
} else {
last.setQos(current.getQos());
if (current.getSubscriptionIdentifier() != null) {
final ImmutableIntArray subscriptionIds = last.getSubscriptionIdentifier();
final Integer subscriptionId = current.getSubscriptionIdentifier();
final ImmutableIntArray mergedSubscriptionIds = ImmutableIntArray.builder(subscriptionIds.length() + 1)
.addAll(subscriptionIds)
.add(subscriptionId)
.build();
last.setSubscriptionIdentifiers(mergedSubscriptionIds);
}
}
} else {
last = new SubscriberWithIdentifiers(current);
}
if (!iterator.hasNext()) {
newSet.add(last);
}
}
return newSet.build();
}
public Iterator<Right> iterator() {
ImmutableList<Right> rights = ImmutableList.copyOf(value);
return rights.iterator();
}
/**
* Implementation of {@link OptionsParser#getExpansionValueDescriptions(OptionDefinition,
* OptionInstanceOrigin)}
*/
ImmutableList<ParsedOptionDescription> getExpansionValueDescriptions(
OptionDefinition expansionFlagDef, OptionInstanceOrigin originOfExpansionFlag)
throws OptionsParsingException {
ImmutableList.Builder<ParsedOptionDescription> builder = ImmutableList.builder();
// Values needed to correctly track the origin of the expanded options.
OptionPriority nextOptionPriority =
OptionPriority.getChildPriority(originOfExpansionFlag.getPriority());
String source;
ParsedOptionDescription implicitDependent = null;
ParsedOptionDescription expandedFrom = null;
ImmutableList<String> options;
ParsedOptionDescription expansionFlagParsedDummy =
ParsedOptionDescription.newDummyInstance(expansionFlagDef, originOfExpansionFlag);
if (expansionFlagDef.hasImplicitRequirements()) {
options = ImmutableList.copyOf(expansionFlagDef.getImplicitRequirements());
source =
String.format(
"implicitly required by %s (source: %s)",
expansionFlagDef, originOfExpansionFlag.getSource());
implicitDependent = expansionFlagParsedDummy;
} else if (expansionFlagDef.isExpansionOption()) {
options = optionsData.getEvaluatedExpansion(expansionFlagDef);
source =
String.format(
"expanded by %s (source: %s)", expansionFlagDef, originOfExpansionFlag.getSource());
expandedFrom = expansionFlagParsedDummy;
} else {
return ImmutableList.of();
}
Iterator<String> optionsIterator = options.iterator();
while (optionsIterator.hasNext()) {
String unparsedFlagExpression = optionsIterator.next();
ParsedOptionDescription parsedOption =
identifyOptionAndPossibleArgument(
unparsedFlagExpression,
optionsIterator,
nextOptionPriority,
o -> source,
implicitDependent,
expandedFrom);
builder.add(parsedOption);
nextOptionPriority = OptionPriority.nextOptionPriority(nextOptionPriority);
}
return builder.build();
}
@Test
public void userRuleIncludePathsChangedByPCH() {
CxxPreprocessorInput cxxPreprocessorInput =
CxxPreprocessorInput.builder()
.addIncludes(
CxxHeadersDir.of(
CxxPreprocessables.IncludeType.SYSTEM, FakeSourcePath.of("/tmp/sys")))
.build();
BuildTarget lib1Target = newTarget("//some/other/dir:lib1");
CxxSourceRuleFactory lib1Factory =
newFactory(lib1Target, new FakeProjectFilesystem(), ImmutableList.of(cxxPreprocessorInput));
CxxPreprocessAndCompile lib1 =
lib1Factory.requirePreprocessAndCompileBuildRule("lib1.cpp", newSource("lib1.cpp"));
graphBuilder.addToIndex(lib1);
ImmutableList<String> lib1Cmd = lib1.makeMainStep(context, false).getCommand();
BuildTarget pchTarget = newTarget("//test:pch");
CxxPrecompiledHeaderTemplate pch =
newPCH(pchTarget, FakeSourcePath.of("header.h"), ImmutableSortedSet.of(lib1));
graphBuilder.addToIndex(pch);
BuildTarget lib2Target = newTarget("//test:lib2");
CxxSourceRuleFactory lib2Factory =
newFactoryWithPrecompiledHeader(
lib2Target, new FakeProjectFilesystem(), DefaultBuildTargetSourcePath.of(pchTarget));
CxxPreprocessAndCompile lib2 =
lib2Factory.requirePreprocessAndCompileBuildRule("lib2.cpp", newSource("lib2.cpp"));
graphBuilder.addToIndex(lib2);
ImmutableList<String> lib2Cmd = lib2.makeMainStep(context, false).getCommand();
CxxPrecompiledHeader pchInstance = null;
for (BuildRule dep : lib2.getBuildDeps()) {
if (dep instanceof CxxPrecompiledHeader) {
pchInstance = (CxxPrecompiledHeader) dep;
}
}
assertNotNull(pchInstance);
ImmutableList<String> pchCmd =
pchInstance.makeMainStep(context, Paths.get("/tmp/z")).getCommand();
// (pretend that) lib1 has a dep resulting in adding this dir to the include path flags
assertContains(lib1Cmd, ImmutableList.of("-isystem", "/tmp/sys"));
// PCH should inherit those flags
assertContains(pchCmd, ImmutableList.of("-isystem", "/tmp/sys"));
// and because PCH uses them, these should be used in lib2 which uses PCH; also, used *first*
assertContains(lib2Cmd, ImmutableList.of("-isystem", "/tmp/sys"));
Iterator<String> iter = lib2Cmd.iterator();
while (iter.hasNext()) {
if (iter.next().equals("-isystem")) {
break;
}
}
assertTrue(iter.hasNext());
assertEquals("/tmp/sys", iter.next());
}