Java Code Examples for com.google.common.collect.Iterables#all()

The following examples show how to use com.google.common.collect.Iterables#all() . 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: ConfiguredTargetCycleReporter.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
protected String getAdditionalMessageAboutCycle(
    ExtendedEventHandler eventHandler, SkyKey topLevelKey, CycleInfo cycleInfo) {
  if (Iterables.all(cycleInfo.getCycle(), IS_TRANSITIVE_TARGET_SKY_KEY)) {
    // The problem happened strictly in loading, so delegate the explanation to
    // TransitiveTargetCycleReporter.
    Iterable<SkyKey> pathAsTargetKeys = Iterables.transform(cycleInfo.getPathToCycle(),
        new Function<SkyKey, SkyKey>() {
          @Override
          public SkyKey apply(SkyKey key) {
            return asTransitiveTargetKey(key);
          }
        });
    return targetReporter.getAdditionalMessageAboutCycle(eventHandler,
        asTransitiveTargetKey(topLevelKey),
        new CycleInfo(pathAsTargetKeys, cycleInfo.getCycle()));
  } else {
    return "\nThis cycle occurred because of a configuration option";
  }
}
 
Example 2
Source File: MetadataQueryOptimizer.java    From presto with Apache License 2.0 5 votes vote down vote up
private Optional<TableScanNode> findTableScan(PlanNode source)
{
    while (true) {
        // allow any chain of linear transformations
        if (source instanceof MarkDistinctNode ||
                source instanceof FilterNode ||
                source instanceof LimitNode ||
                source instanceof TopNNode ||
                source instanceof SortNode) {
            source = source.getSources().get(0);
        }
        else if (source instanceof ProjectNode) {
            // verify projections are deterministic
            ProjectNode project = (ProjectNode) source;
            if (!Iterables.all(project.getAssignments().getExpressions(), expression -> isDeterministic(expression, metadata))) {
                return Optional.empty();
            }
            source = project.getSource();
        }
        else if (source instanceof TableScanNode) {
            return Optional.of((TableScanNode) source);
        }
        else {
            return Optional.empty();
        }
    }
}
 
Example 3
Source File: ProjectionalListSynchronizerTest.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
private boolean isSplitHappened() {
  return container.children.size() == 2 && Iterables.all(container.children, new Predicate<Child>() {
    @Override
    public boolean apply(Child child) {
      return child instanceof NonEmptyChild;
    }
  });
}
 
Example 4
Source File: GuavaFilterTransformCollectionsUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCheckingIfAllElementsMatchACondition_thenCorrect() {
    final List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom");

    boolean result = Iterables.all(names, Predicates.containsPattern("n|m"));
    assertTrue(result);

    result = Iterables.all(names, Predicates.containsPattern("a"));
    assertFalse(result);
}
 
Example 5
Source File: ListContainsAll.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void list_contains_all_guava () {
	
	boolean allCamerasOfMediumTelephoto = Iterables.all(cameras, new Predicate<Camera>() {
		public boolean apply(Camera input) {
			return input.focalLength >= 80;
		}
	});
	
	assertTrue(allCamerasOfMediumTelephoto);
}
 
Example 6
Source File: GroupingProjector.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static boolean allTypesKnown(List<? extends DataType> keyTypes) {
    return Iterables.all(keyTypes, new Predicate<DataType>() {
        @Override
        public boolean apply(@Nullable DataType input) {
            return input != null && !input.equals(DataTypes.UNDEFINED);
        }
    });
}
 
Example 7
Source File: PublisherUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Given a {@link Multimap} of {@link Extract}s to {@link WorkUnitState}s, filter out any {@link Extract}s where all
 * of the corresponding {@link WorkUnitState}s do not meet the given {@link Predicate}.
 * <ul>
 *  <li> The filtered {@link Extract}s will be available in {@link SplitExtractsResult#getFiltered()}</li>
 *  <li> The {@link Extract}s satisfying the predicated will be available in {@link SplitExtractsResult#getRetained()}</li>
 * </ul>
 *
 */
public static SplitExtractsResult splitExtractsByPredicate(
    Multimap<Extract, WorkUnitState> extractToWorkUnitStateMap, Predicate<WorkUnitState> predicate) {
  Multimap<Extract, WorkUnitState> retained = ArrayListMultimap.create();
  Multimap<Extract, WorkUnitState> filtered = ArrayListMultimap.create();
  for (Map.Entry<Extract, Collection<WorkUnitState>> entry : extractToWorkUnitStateMap.asMap().entrySet()) {
    if (Iterables.all(entry.getValue(), predicate)) {
      retained.putAll(entry.getKey(), entry.getValue());
    } else {
      filtered.putAll(entry.getKey(), entry.getValue());
    }
  }
  return new SplitExtractsResult(retained, filtered);
}
 
Example 8
Source File: RunSequentiallyTest.java    From havarunner with MIT License 5 votes vote down vote up
private static boolean allEqual(List<String> list, final String expected) {
    return Iterables.all(list, new Predicate<String>() {
        public boolean apply(String input) {
            return input.equals(expected);
        }
    });
}
 
Example 9
Source File: TestHelper.java    From havarunner with MIT License 5 votes vote down vote up
public static <T> boolean allEqual(final T expected, List<T> items) {
    return Iterables.all(items, new Predicate<T>() {
        public boolean apply(T input) {
            return input.equals(expected);
        }
    });
}
 
Example 10
Source File: PerformanceTest.java    From Zebra with Apache License 2.0 5 votes vote down vote up
public void test_performance(boolean useFilter) throws SQLException, InterruptedException {
	ds = new GroupDataSource();
	ds.setJdbcRef("sample.ds.v2");
	if (useFilter) {
		ds.setFilter("mock,stat,wall");
	}
	ds.setConfigManagerType(Constants.CONFIG_MANAGER_TYPE_LOCAL);
	ds.init();
	createTable();
	ds.getConfig();

	List<Thread> threads = new ArrayList<Thread>();
	for (int k = 0; k < 100; k++) {
		threads.add(new Thread(new Executer()));
	}

	long startTime = System.currentTimeMillis();
	for (Thread t : threads) {
		t.start();
	}
	while (Iterables.all(threads, new Predicate<Thread>() {
		@Override public boolean apply(Thread thread) {
			return !thread.isAlive();
		}
	})) {
		Thread.yield();
	}
	System.out.println(System.currentTimeMillis() - startTime);
}
 
Example 11
Source File: CompositeMatchRule.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean test(final RecordedHttpRequest incomingRequest, final RecordedHttpRequest expectedRequest) {
  return Iterables.all(_matchRules, new Predicate<MatchRule>() {
    @Override
    public boolean apply(MatchRule rule) {
      return rule.test(incomingRequest, expectedRequest);
    }
  });
}
 
Example 12
Source File: DefaultDiscoveryHealth.java    From soabase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldBeInDiscovery(HealthCheckRegistry registry)
{
    return Iterables.all(registry.runHealthChecks().values(), new Predicate<HealthCheck.Result>()
    {
        @Override
        public boolean apply(HealthCheck.Result result)
        {
            return result.isHealthy();
        }
    });
}
 
Example 13
Source File: GamlExpressionCompiler.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IExpression caseArray(final Array object) {
	final List<? extends Expression> list = EGaml.getInstance().getExprsOf(object.getExprs());
	// Awkward expression, but necessary to fix Issue #2612
	final boolean allPairs = !list.isEmpty() && Iterables.all(list,
			each -> each instanceof ArgumentPair || "::".equals(EGaml.getInstance().getKeyOf(each)));
	final Iterable<IExpression> result = Iterables.transform(list, input -> compile(input));
	return allPairs ? getFactory().createMap(result) : getFactory().createList(result);
}
 
Example 14
Source File: PublisherUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Given a {@link Multimap} of {@link Extract}s to {@link WorkUnitState}s, filter out any {@link Extract}s where all
 * of the corresponding {@link WorkUnitState}s do not meet the given {@link Predicate}.
 */
public static Multimap<Extract, WorkUnitState> getExtractsForPredicate(
    Multimap<Extract, WorkUnitState> extractToWorkUnitStateMap, Predicate<WorkUnitState> predicate) {
  Multimap<Extract, WorkUnitState> successfulExtracts = ArrayListMultimap.create();
  for (Map.Entry<Extract, Collection<WorkUnitState>> entry : extractToWorkUnitStateMap.asMap().entrySet()) {
    if (Iterables.all(entry.getValue(), predicate)) {
      successfulExtracts.putAll(entry.getKey(), entry.getValue());
    }
  }
  return successfulExtracts;
}
 
Example 15
Source File: QueryExecutionAuthorizer.java    From airpal with Apache License 2.0 4 votes vote down vote up
public boolean isAuthorizedRead(Set<Table> tables)
{
    return Iterables.all(tables, new AuthorizedTablesPredicate(user));
}
 
Example 16
Source File: TransitiveTargetCycleReporter.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean canReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo) {
  return Iterables.all(Iterables.concat(ImmutableList.of(topLevelKey),
      cycleInfo.getPathToCycle(), cycleInfo.getCycle()),
      IS_SUPPORTED_SKY_KEY);
}
 
Example 17
Source File: StreamBucket.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static boolean validStreamers(Streamer<?>[] streamers) {
    if (streamers == null || streamers.length == 0) {
        return true;
    }
    return !Iterables.all(FluentIterable.of(streamers), Predicates.isNull());
}
 
Example 18
Source File: CompositeStorage2UriMapperContribution.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean isRejected(final IFolder folder) {
	return Iterables.all(contributions, c -> c.isRejected(folder));
}
 
Example 19
Source File: WorkInfoUtil.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
public static boolean allDone(List<WorkInfo> info) {
    return Iterables.all(
            transform(info),
            s -> s != null && s != WorkInfo.State.ENQUEUED && s != WorkInfo.State.RUNNING
    );
}
 
Example 20
Source File: TestEqualityInference.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Predicate<Expression> matchesSymbolScope(final Predicate<Symbol> symbolScope)
{
    return expression -> Iterables.all(SymbolsExtractor.extractUnique(expression), symbolScope);
}