List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.elk.alg.layered.p3order.LayerSweepTypeDecider.java
private boolean hasNoWesternPorts(final LNode node) { List<LPort> westPorts = node.getPortSideView(PortSide.WEST); return westPorts.isEmpty() || !Iterables.any(westPorts, p -> p.getConnectedEdges().iterator().hasNext()); }
From source file:org.apache.druid.query.groupby.strategy.GroupByStrategyV1.java
@Override public Sequence<Row> processSubqueryResult(GroupByQuery subquery, GroupByQuery query, GroupByQueryResource resource, Sequence<Row> subqueryResult) { final Set<AggregatorFactory> aggs = Sets.newHashSet(); // Nested group-bys work by first running the inner query and then materializing the results in an incremental // index which the outer query is then run against. To build the incremental index, we use the fieldNames from // the aggregators for the outer query to define the column names so that the index will match the query. If // there are multiple types of aggregators in the outer query referencing the same fieldName, we will try to build // multiple columns of the same name using different aggregator types and will fail. Here, we permit multiple // aggregators of the same type referencing the same fieldName (and skip creating identical columns for the // subsequent ones) and return an error if the aggregator types are different. final Set<String> dimensionNames = Sets.newHashSet(); for (DimensionSpec dimension : subquery.getDimensions()) { dimensionNames.add(dimension.getOutputName()); }//from ww w . ja va 2 s.co m for (AggregatorFactory aggregatorFactory : query.getAggregatorSpecs()) { for (final AggregatorFactory transferAgg : aggregatorFactory.getRequiredColumns()) { if (dimensionNames.contains(transferAgg.getName())) { // This transferAgg is already represented in the subquery's dimensions. Assume that the outer aggregator // *probably* wants the dimension and just ignore it. This is a gross workaround for cases like having // a cardinality aggregator in the outer query. It is necessary because what this block of code is trying to // do is use aggregators to "transfer" values from the inner results to an incremental index, but aggregators // can't transfer all kinds of values (strings are a common one). If you don't like it, use groupBy v2, which // doesn't have this problem. continue; } if (Iterables.any(aggs, new Predicate<AggregatorFactory>() { @Override public boolean apply(AggregatorFactory agg) { return agg.getName().equals(transferAgg.getName()) && !agg.equals(transferAgg); } })) { throw new IAE( "Inner aggregator can currently only be referenced by a single type of outer aggregator" + " for '%s'", transferAgg.getName()); } aggs.add(transferAgg); } } // We need the inner incremental index to have all the columns required by the outer query final GroupByQuery innerQuery = new GroupByQuery.Builder(subquery) .setAggregatorSpecs(ImmutableList.copyOf(aggs)).setInterval(subquery.getIntervals()) .setPostAggregatorSpecs(Lists.newArrayList()).build(); final GroupByQuery outerQuery = new GroupByQuery.Builder(query) .setLimitSpec(query.getLimitSpec().merge(subquery.getLimitSpec())).build(); final IncrementalIndex innerQueryResultIndex = GroupByQueryHelper.makeIncrementalIndex( innerQuery.withOverriddenContext(ImmutableMap.of(GroupByQueryHelper.CTX_KEY_SORT_RESULTS, true)), configSupplier.get(), bufferPool, subqueryResult, false); //Outer query might have multiple intervals, but they are expected to be non-overlapping and sorted which //is ensured by QuerySegmentSpec. //GroupByQueryEngine can only process one interval at a time, so we need to call it once per interval //and concatenate the results. final IncrementalIndex outerQueryResultIndex = GroupByQueryHelper.makeIncrementalIndex(outerQuery, configSupplier.get(), bufferPool, Sequences.concat(Sequences .map(Sequences.simple(outerQuery.getIntervals()), new Function<Interval, Sequence<Row>>() { @Override public Sequence<Row> apply(Interval interval) { return process( outerQuery.withQuerySegmentSpec( new MultipleIntervalSegmentSpec(ImmutableList.of(interval))), new IncrementalIndexStorageAdapter(innerQueryResultIndex)); } })), true); innerQueryResultIndex.close(); return Sequences.withBaggage( outerQuery.postProcess(GroupByQueryHelper.postAggregate(query, outerQueryResultIndex)), outerQueryResultIndex); }
From source file:org.lightadmin.core.persistence.support.DynamicDomainObjectMerger.java
private boolean mathesAny(Collection<Object> collection, final Object item) { final PersistentEntity<?, ?> persistentEntity = configuration.forManagedDomainType(item.getClass()) .getPersistentEntity();/* w w w. j a v a2 s . c o m*/ final PersistentProperty<?> idProperty = persistentEntity.getIdProperty(); return Iterables.any(collection, new Predicate<Object>() { @Override public boolean apply(Object object) { return itemsEqual(object, item, idProperty); } }); }
From source file:org.gradle.plugins.ide.idea.internal.IdeaScalaConfigurer.java
private static boolean containsLibraryWithSameName(Set<ProjectLibrary> libraries, final String name) { return Iterables.any(libraries, new Predicate<ProjectLibrary>() { @Override//from ww w . ja v a 2s . co m public boolean apply(ProjectLibrary library) { return Objects.equal(library.getName(), name); } }); }
From source file:org.apache.cassandra.db.Directories.java
/** * Create Directories of given ColumnFamily. * SSTable directories are created under data_directories defined in cassandra.yaml if not exist at this time. * * @param metadata metadata of ColumnFamily *//* w w w . j a v a 2 s . c om*/ public Directories(final CFMetaData metadata) { this.metadata = metadata; String cfId = ByteBufferUtil.bytesToHex(ByteBufferUtil.bytes(metadata.cfId)); int idx = metadata.cfName.indexOf(SECONDARY_INDEX_NAME_SEPARATOR); String cfName = idx >= 0 ? metadata.cfName.substring(0, idx) : metadata.cfName; String indexNameWithDot = idx >= 0 ? metadata.cfName.substring(idx) : null; this.dataPaths = new File[dataDirectories.length]; // If upgraded from version less than 2.1, use existing directories String oldSSTableRelativePath = join(metadata.ksName, cfName); for (int i = 0; i < dataDirectories.length; ++i) { // check if old SSTable directory exists dataPaths[i] = new File(dataDirectories[i].location, oldSSTableRelativePath); } boolean olderDirectoryExists = Iterables.any(Arrays.asList(dataPaths), new Predicate<File>() { public boolean apply(File file) { return file.exists(); } }); if (!olderDirectoryExists) { // use 2.1+ style String newSSTableRelativePath = join(metadata.ksName, cfName + '-' + cfId); for (int i = 0; i < dataDirectories.length; ++i) dataPaths[i] = new File(dataDirectories[i].location, newSSTableRelativePath); } // if index, then move to its own directory if (indexNameWithDot != null) { for (int i = 0; i < dataDirectories.length; ++i) dataPaths[i] = new File(dataPaths[i], indexNameWithDot); } for (File dir : dataPaths) { try { FileUtils.createDirectory(dir); } catch (FSError e) { // don't just let the default exception handler do this, we need the create loop to continue logger.error("Failed to create {} directory", dir); FileUtils.handleFSError(e); } } // if index, move existing older versioned SSTable files to new directory if (indexNameWithDot != null) { for (File dataPath : dataPaths) { File[] indexFiles = dataPath.getParentFile().listFiles(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) return false; Pair<Descriptor, Component> pair = SSTable.tryComponentFromFilename(file.getParentFile(), file.getName()); return pair != null && pair.left.ksname.equals(metadata.ksName) && pair.left.cfname.equals(metadata.cfName); } }); for (File indexFile : indexFiles) { File destFile = new File(dataPath, indexFile.getName()); logger.trace("Moving index file {} to {}", indexFile, destFile); FileUtils.renameWithConfirm(indexFile, destFile); } } } }
From source file:org.eclipse.sirius.diagram.business.internal.helper.display.DisplayServiceImpl.java
private boolean isFold(final DDiagramElement element) { return Iterables.any(element.getGraphicalFilters(), new Predicate<GraphicalFilter>() { public boolean apply(GraphicalFilter input) { return DiagramPackage.eINSTANCE.getFoldingFilter().isInstance(input) || DiagramPackage.eINSTANCE.getFoldingPointFilter().isInstance(input); }/*from w w w . ja va 2 s.c o m*/ }); }
From source file:org.solovyev.android.messenger.accounts.DefaultAccountService.java
@Nonnull @Override/*from ww w . jav a2 s.c o m*/ public <A extends Account> A saveAccount(@Nonnull AccountBuilder<A> accountBuilder) throws InvalidCredentialsException, AccountAlreadyExistsException { syncService.waitWhileSyncFinished(); A result; try { final AccountConfiguration configuration = accountBuilder.getConfiguration(); final Account oldAccount = accountBuilder.getEditedAccount(); final boolean sameCredentials = oldAccount != null && oldAccount.getConfiguration().isSameCredentials(configuration); if (sameCredentials) { // new account configuration is exactly the same => we need just to save new configuration updateAccountConfiguration(oldAccount, configuration); result = (A) oldAccount; } else { // saving account (account either new or changed) accountBuilder.connect(); accountBuilder.loginUser(null); final String newAccountId; if (oldAccount != null) { newAccountId = oldAccount.getId(); } else { newAccountId = generateAccountId(accountBuilder.getRealm()); } final A newAccount = accountBuilder.build(new AccountBuilder.Data(newAccountId)); synchronized (accounts) { final boolean alreadyExists = Iterables.any(accounts.values(), new Predicate<Account>() { @Override public boolean apply(@Nullable Account account) { return account != null && account.getState() != removed && newAccount.same(account); } }); if (alreadyExists) { throw new AccountAlreadyExistsException(); } else { createOrUpdateAccount(oldAccount, newAccount); } } result = newAccount; } } catch (AccountBuilder.ConnectionException e) { throw new InvalidCredentialsException(e); } catch (AccountException e) { App.getExceptionHandler().handleException(e); throw new InvalidCredentialsException(e); } finally { try { accountBuilder.disconnect(); } catch (AccountBuilder.ConnectionException e) { Log.e(TAG, e.getMessage(), e); } } return result; }
From source file:org.eclipse.viatra.addon.validation.runtime.annotation.ConstraintAnnotationValidator.java
private List<Variable> validateKeys(Annotation annotation, IIssueCallback validator, final Pattern pattern) { List<Variable> keyList = Lists.newArrayList(); ValueReference keyRef = PatternLanguageHelper.getFirstAnnotationParameter(annotation, KEY_PARAMETER.getName());//ww w . jav a 2 s.c o m if (keyRef instanceof ListValue) { keyList = computeVariableListFromListValue(validator, pattern, keyRef, INVALID_KEY_PARAMETERS); } if (keyList.isEmpty()) { validator.error("No key defined!", keyRef, null, INVALID_KEY_PARAMETERS); } else { boolean atLeastOneEClassKey = Iterables.any(keyList, key -> (typeInferrer.getType(key) instanceof EClassTransitiveInstancesKey)); if (!atLeastOneEClassKey) { validator.warning("At least one key should be EClass to make location possible!", keyRef, null, INVALID_KEY_PARAMETERS); } } return keyList; }
From source file:org.eclipse.viatra.query.patternlanguage.emf.types.EMFPatternTypeProvider.java
private Set<EClassifier> minimizeClassifiersList(Set<EClassifier> classifierList) { final Set<EClassifier> resultList = new HashSet<EClassifier>(classifierList); if (resultList.size() > 1) { for (EClassifier classifier : classifierList) { if ("EObject".equals(classifier.getName()) && EcorePackage.eNS_URI.equals(classifier.getEPackage().getNsURI())) { resultList.remove(classifier); } else if (classifier instanceof EClass) { for (EClass eClass : ((EClass) classifier).getEAllSuperTypes()) { if (resultList.contains(eClass)) { resultList.remove(eClass); }/*from w w w . j a v a2 s . com*/ } } else if (classifier instanceof EDataType) { final EDataType eDataType = (EDataType) classifier; if (Iterables.any(Iterables.filter(resultList, EDataType.class), new Predicate<EDataType>() { @Override public boolean apply(EDataType dataType) { if (dataType == null) { return false; } else if (dataType.equals(eDataType)) { return false; } else if (dataType.getInstanceClassName() != null && eDataType.getInstanceClassName() != null) { return dataType.getInstanceClassName().equals(eDataType.getInstanceClassName()) && resultList.contains(eDataType); } return false; } })) { resultList.remove(eDataType); } } } } return resultList; }
From source file:org.eclipse.emf.compare.internal.utils.Graph.java
/** * Checks if the given element is a parent of the given potential child, directly or not. * /*from w ww . j a v a 2 s . c om*/ * @param parent * Element that could be a parent of <code>potentialChild</code>. * @param potentialChild * The potential child of <code>parent</code>. * @return <code>true</code> if <code>parent</code> is an ancestor of <code>potentialChild</code>. */ public boolean hasChild(E parent, E potentialChild) { lock.lock(); try { final Node<E> node = nodes.get(potentialChild); if (node != null) { return Iterables.any(node.getAllParents(), is(parent)); } return false; } finally { lock.unlock(); } }