List of usage examples for com.google.common.collect Iterables removeIf
public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate)
From source file:eu.interedition.collatex.medite.Matches.java
public SortedSet<SortedSet<VertexMatch.WithTokenIndex>> findMaximalUniqueMatches() { final List<SortedSet<VertexMatch.WithTokenIndex>> allMatches = Lists.newArrayList(this); final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> maximalUniqueMatches = Sets .newTreeSet(VertexMatch.<VertexMatch.WithTokenIndex>setComparator()); while (true) { SortedSet<VertexMatch.WithTokenIndex> nextMum = null; SortedSet<VertexMatch.WithTokenIndex> candidate = null; for (SortedSet<VertexMatch.WithTokenIndex> successor : allMatches) { if (candidate == null) { continue; }/* w w w. j a v a2 s .c om*/ if (candidate.size() > successor.size() || candidate.first().token == successor.first().token) { nextMum = candidate; break; } candidate = successor; } if (nextMum == null) { nextMum = Iterables.getFirst(allMatches, null); } if (nextMum == null) { break; } Preconditions.checkState(maximalUniqueMatches.add(nextMum), "Duplicate MUM"); Iterables.removeIf(allMatches, VertexMatch.filter( new IntegerRangeSet( Range.closed(nextMum.first().vertexRank, nextMum.last().vertexRank)), new IntegerRangeSet(Range.closed(nextMum.first().token, nextMum.last().token)))); } return maximalUniqueMatches; }
From source file:com.ben12.reta.view.buffering.BufferingManager.java
public void purge() { boolean changed = Iterables.removeIf(buffers, br -> (br.get() == null)); if (changed) { rebuildBufferingExpression();/*from w w w . j a v a 2 s .c o m*/ rebuildValidExpression(); } }
From source file:org.apache.hadoop.hive.io.HdfsUtils.java
/** * Removes basic permission acls (unamed acls) from the list of acl entries * @param entries acl entries to remove from. *///w ww. ja v a 2s .c o m private static void removeBaseAclEntries(List<AclEntry> entries) { Iterables.removeIf(entries, new Predicate<AclEntry>() { @Override public boolean apply(AclEntry input) { if (input.getName() == null) { return true; } return false; } }); }
From source file:org.polymap.core.data.operations.feature.CopyFeaturesOperation2.java
public Status execute(IProgressMonitor monitor) throws Exception { monitor.beginTask(context.adapt(FeatureOperationExtension.class).getLabel(), 10); source = (PipelineFeatureSource) context.featureSource(); if (!(source.getSchema() instanceof SimpleFeatureType)) { throw new Exception(i18n.get("notSimpleType")); }/*from w w w. ja v a2 s . c o m*/ // open wizard dialog monitor.subTask("Eingaben vom Nutzer..."); IUndoableOperation op = context.adapt(IUndoableOperation.class); final OperationWizard wizard = new OperationWizard(op, context, monitor) { public boolean doPerformFinish() throws Exception { ((FeatureEditorPage2) getPage(FeatureEditorPage2.ID)).performFinish(); return true; } }; Polymap.getSessionDisplay().asyncExec(new Runnable() { public void run() { wizard.getShell().setMinimumSize(600, 600); wizard.getShell().layout(true); } }); // ChooseLayerPage final ChooseLayerPage chooseLayerPage = new ChooseLayerPage(i18n.get("ChooseLayerPage_title"), i18n.get("ChooseLayerPage_description"), true); ILayer layer = context.adapt(ILayer.class); if (ACLUtils.checkPermission(layer, AclPermission.WRITE, false)) { chooseLayerPage.preset(layer); } chooseLayerPage.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElm, Object elm) { if (elm instanceof ILayer) { return ACLUtils.checkPermission((ILayer) elm, AclPermission.WRITE, false); } return true; } }); wizard.addPage(chooseLayerPage); final FeatureEditorPage2 featureEditorPage = new FeatureEditorPage2(); wizard.addPage(featureEditorPage); DirectCopyPage directCopyPage = new DirectCopyPage(); wizard.addPage(directCopyPage); // get/set chosen layer wizard.addPageChangedListener(new IPageChangedListener() { public void pageChanged(PageChangedEvent ev) { log.info("Page: " + ev.getSelectedPage()); if (featureEditorPage == ev.getSelectedPage()) { dest = chooseLayerPage.getResult(); } } }); monitor.worked(1); // copy features if (OperationWizard.openDialog(wizard)) { final IProgressMonitor copyMonitor = new SubProgressMonitor(monitor, 8, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); destFs = PipelineFeatureSource.forLayer(dest, true); features = context.features(); int featuresSize = features.size(); copyMonitor.beginTask(i18n.get("taskTitle", featuresSize), featuresSize); // direct copy? if (directCopyPage.isDirectCopy()) { Pipeline pipe = destFs.getPipeline(); Iterables.removeIf(pipe, Predicates.instanceOf(FeatureBufferProcessor.class)); } // tranform schema features = featureEditorPage.retyped(features); // transform CRS SimpleFeatureType destSchema = destFs.getSchema(); final CoordinateReferenceSystem destCrs = destSchema.getCoordinateReferenceSystem(); SimpleFeatureType sourceSchema = (SimpleFeatureType) features.getSchema(); // XXX do not use sourceSchema here as featureEditorPage ff. has set CRS to destFs schema CRS CoordinateReferenceSystem sourceCrs = sourceSchema.getCoordinateReferenceSystem(); if (destCrs != null && !destCrs.equals(sourceCrs)) { // features = new ReprojectingFeatureCollection( features, destCrs ); final MathTransform transform = Geometries.transform(sourceCrs, destCrs); final String geomName = sourceSchema.getGeometryDescriptor().getLocalName(); // actually copy features; the above just sets attribute which is not supported by caching data sources final SimpleFeatureType retypedSchema = SimpleFeatureTypeBuilder.retype(sourceSchema, destCrs); features = new RetypingFeatureCollection(features, retypedSchema) { protected Feature retype(Feature feature) { try { SimpleFeatureBuilder fb = new SimpleFeatureBuilder(retypedSchema); fb.init((SimpleFeature) feature); Geometry geom = (Geometry) feature.getProperty(geomName).getValue(); fb.set(geomName, JTS.transform(geom, transform)); return fb.buildFeature(feature.getIdentifier().getID()); } catch (Exception e) { throw new RuntimeException(e); } } }; } // transform geometry types SimpleFeatureType featuresSchema = (SimpleFeatureType) features.getSchema(); final GeometryDescriptor featureGeom = featuresSchema.getGeometryDescriptor(); final GeometryDescriptor destGeom = destSchema.getGeometryDescriptor(); if (featureGeom != null && destGeom != null && !featureGeom.getType().getBinding().equals(destGeom.getType().getBinding())) { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.init(featuresSchema); ftb.remove(featureGeom.getLocalName()); ftb.add(destGeom.getLocalName(), destGeom.getType().getBinding(), destGeom.getCoordinateReferenceSystem()); final SimpleFeatureType retypedSchema = ftb.buildFeatureType(); features = new RetypingFeatureCollection(features, retypedSchema) { protected Feature retype(Feature feature) { try { SimpleFeatureBuilder fb = new SimpleFeatureBuilder(retypedSchema); fb.init((SimpleFeature) feature); Geometry geom = (Geometry) feature.getProperty(featureGeom.getLocalName()).getValue(); // Point -> MultiPolygon if (destGeom.getType().getBinding().equals(MultiPolygon.class) || destGeom.getType().getBinding().equals(Polygon.class)) { geom = Geometries.transform(geom, destCrs, Geometries.crs("EPSG:3857")); geom = geom.buffer(10, 3); geom = Geometries.transform(geom, Geometries.crs("EPSG:3857"), destCrs); fb.set(destGeom.getLocalName(), geom); return fb.buildFeature(feature.getIdentifier().getID()); } // Geometry -> anything else if (geom instanceof Geometry) { fb.set(destGeom.getLocalName(), geom); return fb.buildFeature(feature.getIdentifier().getID()); } else { throw new UnsupportedOperationException( "Unsupported geometry transformation: " + geom.getClass().getSimpleName() + " -> " + destGeom.getType().getBinding().getSimpleName()); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } } }; } createdFeatureIds = destFs.addFeatures(features, new ProgressListenerAdaptor(copyMonitor)); monitor.done(); return Status.OK; } return Status.Cancel; }
From source file:org.solovyev.android.messenger.accounts.connection.DefaultAccountConnections.java
@Override public void removeConnectionFor(@Nonnull Account account) { final List<AccountConnection> removedConnections = new ArrayList<AccountConnection>(); synchronized (this.connections) { // remove account connections belonged to specified realm Iterables.removeIf(this.connections, PredicateSpy.spyOn(new ConnectionFinder(account), removedConnections)); }/*w w w. jav a2 s . co m*/ stopConnections(removedConnections); }
From source file:org.syncany.operations.plugin.PluginOperation.java
private List<String> findUpdateCandidates() throws Exception { List<ExtendedPluginInfo> updateCandidates = executeList().getPluginList(); Iterables.removeIf(updateCandidates, new Predicate<ExtendedPluginInfo>() { @Override/*from ww w . j a v a 2 s .c o m*/ public boolean apply(ExtendedPluginInfo pluginInfo) { return !pluginInfo.isInstalled() || !pluginInfo.canUninstall() || !pluginInfo.isOutdated(); } }); return Lists.transform(updateCandidates, new Function<ExtendedPluginInfo, String>() { @Override public String apply(ExtendedPluginInfo pluginInfo) { return pluginInfo.getLocalPluginInfo().getPluginId(); } }); }
From source file:org.jboss.shrinkwrap.resolver.impl.maven.internal.MavenModelResolver.java
private static void removeMatchingRepository(Iterable<RemoteRepository> repositories, final String id) { Iterables.removeIf(repositories, new Predicate<RemoteRepository>() { @Override//w w w . j a va2 s .c om public boolean apply(RemoteRepository remoteRepository) { return remoteRepository.getId().equals(id); } }); }
From source file:com.eucalyptus.compute.common.internal.network.ExtantNetwork.java
void remove(final PrivateNetworkIndex index) { // Removal works around hibernate issue // https://hibernate.atlassian.net/browse/HHH-3799 int sizeBefore = indexes.size(); if (Iterables.removeIf(indexes, Predicates.equalTo(index)) && sizeBefore == indexes.size()) { List<PrivateNetworkIndex> temp = Lists.newArrayList(indexes); indexes.clear();/*from ww w. j a va2 s.c o m*/ indexes.addAll(temp); indexes.remove(index); } }
From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.MDRCacheServiceBean.java
@Override public boolean combinationExistsInConversionFactorList(List<FLUXLocation> specifiedFLUXLocations, List<CodeType> appliedAAPProcessTypeCodes, CodeType speciesCode) { // clean lists from nulls Iterables.removeIf(specifiedFLUXLocations, Predicates.isNull()); Iterables.removeIf(appliedAAPProcessTypeCodes, Predicates.isNull()); // country column String country = StringUtils.EMPTY; if (CollectionUtils.isNotEmpty(specifiedFLUXLocations)) { for (FLUXLocation location : specifiedFLUXLocations) { final IDType locId = location.getID(); if (locId != null && ("TERRITORY".equals(locId.getSchemeID()) || "MANAGEMENT_AREA".equals(locId.getSchemeID()))) { country = locId.getValue(); }/* w w w . j a v a 2 s .co m*/ } } if (isPresentInMDRList("MEMBER_STATE", country)) { country = "XEU"; } // presentation, state columns String presentation = StringUtils.EMPTY; String state = StringUtils.EMPTY; if (CollectionUtils.isNotEmpty(appliedAAPProcessTypeCodes)) { for (CodeType presPreserv : appliedAAPProcessTypeCodes) { if ("FISH_PRESENTATION".equals(presPreserv.getListId())) { presentation = presPreserv.getValue(); } if ("FISH_PRESERVATION".equals(presPreserv.getListId())) { state = presPreserv.getValue(); } } } List<ObjectRepresentation> finalList = null; if (!(StringUtils.isBlank(country) || StringUtils.isBlank(presentation) || StringUtils.isBlank(state))) { List<ObjectRepresentation> entry = cache.getEntry(MDRAcronymType.CONVERSION_FACTOR); List<ObjectRepresentation> filtered_1_list = filterEntriesByColumn(entry, "placesCode", country); List<ObjectRepresentation> filtered_2_list = filterEntriesByColumn(filtered_1_list, "species", speciesCode != null ? speciesCode.getValue() : StringUtils.EMPTY); List<ObjectRepresentation> filtered_3_list = filterEntriesByColumn(filtered_2_list, "presentation", presentation); finalList = filterEntriesByColumn(filtered_3_list, "state", state); } return CollectionUtils.isNotEmpty(finalList); }
From source file:org.opentestsystem.authoring.testauth.publish.SharedPublisherHelper.java
private List<TestComputationRule> buildTestComputationRulesForLeafNodeRules( final List<ScoringRule> scoringRuleList, final List<BlueprintElement> blueprintElementList) { final List<TestComputationRule> testComputationRuleList = Lists.newArrayList(); if (Iterables.any(scoringRuleList, LEAF_NODE_TYPE_FILTER)) { // winnow blueprintElement list down to parentedChildren only Iterables.removeIf(blueprintElementList, PARENT_KEY_FILTER); // build multimap of bpe keyed by parent key final Multimap<String, BlueprintElement> blueprintElementParentKeyMultimap = Multimaps .index(blueprintElementList, BP_PARENT_KEY_TRANSFORMER); // filter bpe objects that are parents from parentedChildren Iterables.removeIf(blueprintElementList, NON_LEAF_NODE_FILTER.getInstance(blueprintElementParentKeyMultimap.keySet())); // construct each leaf node into a separate scoring rule final List<ScoringRule> leafNodeScoringRules = Lists .newArrayList(Iterables.filter(scoringRuleList, LEAF_NODE_TYPE_FILTER)); for (final ScoringRule scoringRule : leafNodeScoringRules) { final int i = 1; // transform every leaf node bp element into a scoring rule mimicking this scoringRule testComputationRuleList.addAll(Lists.transform(blueprintElementList, LEAF_NODE_LEVEL_SCORING_RULE_TRANSFORMER.getInstance(scoringRule, i))); }// w w w. j a v a 2 s . c o m } return testComputationRuleList; }