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

The following examples show how to use com.google.common.collect.Iterables#all() . These examples are extracted from open source projects. 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
@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 Project: presto   File: MetadataQueryOptimizer.java    License: 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
@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 4
@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 5
Source Project: Elasticsearch   File: GroupingProjector.java    License: 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 6
Source Project: havarunner   File: RunSequentiallyTest.java    License: 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 7
Source Project: havarunner   File: TestHelper.java    License: 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 8
Source Project: Zebra   File: PerformanceTest.java    License: 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 9
@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 10
Source Project: soabase   File: DefaultDiscoveryHealth.java    License: 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 11
@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 12
/**
 * 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 13
/**
 * 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 14
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 15
Source Project: presto   File: TestEqualityInference.java    License: 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);
}
 
Example 16
Source Project: lttrs-android   File: WorkInfoUtil.java    License: 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 17
@Override
public boolean isRejected(final IFolder folder) {
	return Iterables.all(contributions, c -> c.isRejected(folder));
}
 
Example 18
Source Project: Elasticsearch   File: StreamBucket.java    License: 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 19
@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 20
Source Project: airpal   File: QueryExecutionAuthorizer.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isAuthorizedRead(Set<Table> tables)
{
    return Iterables.all(tables, new AuthorizedTablesPredicate(user));
}