List of usage examples for com.google.common.base Functions compose
public static <A, B, C> Function<A, C> compose(Function<B, C> g, Function<A, ? extends B> f)
From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java
private static <T> Function<? super String, Predicate<? super T>> dateFilter( final Function<? super T, Date> extractor) { return dateSetFilter(Functions.compose(FilterSupport.<Date>toSet(), extractor)); }
From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java
private static <T> Function<? super String, Predicate<? super T>> booleanFilter( final Function<? super T, Boolean> extractor) { return booleanSetFilter(Functions.compose(FilterSupport.<Boolean>toSet(), extractor)); }
From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java
private static <T> Function<? super String, Predicate<? super T>> intFilter( final Function<? super T, Integer> extractor) { return intSetFilter(Functions.compose(FilterSupport.<Integer>toSet(), extractor)); }
From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java
private static <T> Function<? super String, Predicate<? super T>> longFilter( final Function<? super T, Long> extractor) { return longSetFilter(Functions.compose(FilterSupport.<Long>toSet(), extractor)); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
private int getMaxTimeBounds(boolean pack, int minTimeBounds) { int max = getSpecifiedMaxTimeBounds(minTimeBounds); if (!pack) {//w ww .ja va 2 s . com Iterable<Lifeline> lifelinesWithoutDestruction = getLifeLinesWithoutDestruction(); // Avoid to handle lifelines to move up for max computation. Predicate<Lifeline> isMaxRangeCandidate = new Predicate<Lifeline>() { public boolean apply(Lifeline input) { InstanceRole irep = input.getInstanceRole(); if (irep != null) { return irep.getBounds().getLocation().y <= LayoutConstants.LIFELINES_START_Y; } return false; } }; Collection<Lifeline> lifelinesToConsider = Lists .newArrayList(Iterables.filter(lifelinesWithoutDestruction, isMaxRangeCandidate)); Ordering<ISequenceEvent> maxOrdering = Ordering.natural() .onResultOf(Functions.compose(RangeHelper.upperBoundFunction(), ISequenceEvent.VERTICAL_RANGE)); if (!lifelinesToConsider.isEmpty()) { Lifeline lep = maxOrdering.max(lifelinesToConsider); max = lep.getVerticalRange().getUpperBound(); } } return max; }
From source file:edu.harvard.med.screensaver.ui.libraries.LibraryCopyPlateSearchResults.java
private void updateReviewMessage() { if (!isBatchEditable() || getRowCount() == 0) { _reviewMessage = ""; }//from w ww. ja va 2s . c o m Set<Plate> plates = Sets.newHashSet(getDataTableModel().iterator()); int nLibraries = Sets .newHashSet(Iterables.transform(plates, Functions.compose(Copy.ToLibrary, Plate.ToCopy))).size(); int nCopies = Sets.newHashSet(Iterables.transform(plates, Plate.ToCopy)).size(); Set<PlateLocation> locations = Sets .newHashSet(Iterables.filter(Iterables.transform(plates, Plate.ToLocation), Predicates.notNull())); int nRooms = Sets.newHashSet(Iterables.transform(locations, PlateLocation.ToRoom)).size(); int nFreezers = Sets.newHashSet(Iterables.transform(locations, PlateLocation.ToRoomFreezer)).size(); int nShelves = Sets.newHashSet(Iterables.transform(locations, PlateLocation.ToRoomFreezerShelf)).size(); StringBuilder msg = new StringBuilder("Updating ").append(getRowCount()).append(" plate"); if (getRowCount() != 1) { msg.append('s'); } msg.append(" from "); msg.append(nLibraries).append(" librar").append(nLibraries == 1 ? "y" : "ies"); msg.append(" and ").append(nCopies).append(" cop").append(nCopies == 1 ? "y" : "ies"); msg.append(" across ").append(locations.size()).append(" bin location") .append(locations.size() == 1 ? "" : "s").append(" on "); msg.append(nShelves).append(" shel").append(nShelves == 1 ? "f" : "ves"); msg.append(" in ").append(nFreezers).append(" freezer").append(nFreezers == 1 ? "" : "s"); msg.append(" in ").append(nRooms).append(" room").append(nRooms == 1 ? "" : "s"); msg.append(". Proceed?"); _reviewMessage = msg.toString(); }
From source file:com.eucalyptus.compute.vpc.VpcManager.java
public CreateSubnetResponseType createSubnet(final CreateSubnetType request) throws EucalyptusCloudException { final CreateSubnetResponseType reply = request.getReply(); final Context ctx = Contexts.lookup(); final AccountFullName accountFullName = ctx.getUserFullName().asAccountFullName(); final String vpcId = Identifier.vpc.normalize(request.getVpcId()); final Optional<String> availabilityZone = Iterables.tryFind(Clusters.getInstance().listValues(), Predicates.and(//from w w w .j a v a 2 s . c o m request.getAvailabilityZone() == null ? Predicates.<RestrictedType>alwaysTrue() : CollectionUtils.propertyPredicate(request.getAvailabilityZone(), CloudMetadatas.toDisplayName()), RestrictedTypes.filterPrivilegedWithoutOwner())) .transform(CloudMetadatas.toDisplayName()); final Optional<Cidr> subnetCidr = Cidr.parse().apply(request.getCidrBlock()); if (!subnetCidr.isPresent()) { throw new ClientComputeException("InvalidParameterValue", "Cidr invalid: " + request.getCidrBlock()); } if (!availabilityZone.isPresent()) { throw new ClientComputeException("InvalidParameterValue", "Availability zone invalid: " + request.getAvailabilityZone()); } final Supplier<Subnet> allocator = new Supplier<Subnet>() { @Override public Subnet get() { try { final Vpc vpc = vpcs.lookupByName(accountFullName, vpcId, Functions.<Vpc>identity()); final Iterable<Subnet> subnetsInVpc = subnets.listByExample( Subnet.exampleWithOwner(accountFullName), CollectionUtils .propertyPredicate(vpc.getDisplayName(), Subnets.FilterStringFunctions.VPC_ID), Functions.<Subnet>identity()); if (Iterables.size(subnetsInVpc) >= VpcConfiguration.getSubnetsPerVpc()) { throw new ClientComputeException("SubnetLimitExceeded", "Subnet limit exceeded for " + vpc.getDisplayName()); } if (!Cidr.parse(vpc.getCidr()).contains(subnetCidr.get())) { throw new ClientComputeException("InvalidParameterValue", "Cidr not valid for vpc " + request.getCidrBlock()); } final Iterable<Cidr> existingCidrs = Iterables.transform(subnetsInVpc, Functions.compose(Cidr.parseUnsafe(), Subnets.FilterStringFunctions.CIDR)); if (Iterables.any(existingCidrs, subnetCidr.get().contains()) || Iterables.any(existingCidrs, subnetCidr.get().containedBy())) { throw new ClientComputeException("InvalidSubnet.Conflict", "Cidr conflict for " + request.getCidrBlock()); } final NetworkAcl networkAcl = networkAcls.lookupDefault(vpc.getDisplayName(), Functions.<NetworkAcl>identity()); return subnets.save(Subnet.create(ctx.getUserFullName(), vpc, networkAcl, Identifier.subnet.generate(), request.getCidrBlock(), availabilityZone.get())); } catch (VpcMetadataNotFoundException ex) { throw Exceptions.toUndeclared(new ClientComputeException("InvalidVpcID.NotFound", "Vpc not found '" + request.getVpcId() + "'")); } catch (Exception ex) { throw new RuntimeException(ex); } } }; reply.setSubnet(allocate(allocator, Subnet.class, SubnetType.class)); invalidate(reply.getSubnet().getSubnetId()); return reply; }
From source file:com.eucalyptus.vm.VmInstances.java
public static Function<VmInstance, String> toInstanceUuid() { return Functions.compose(HasNaturalId.Utils.toNaturalId(), Functions.<VmInstance>identity()); }
From source file:org.dllearner.refinementoperators.RhoDRDown.java
private SortedSet<OWLClassExpression> getClassCandidatesRecursive(OWLClassExpression index, OWLClassExpression upperClass) { SortedSet<OWLClassExpression> candidates = new TreeSet<>(); SortedSet<OWLClassExpression> subClasses = classHierarchy.getSubClasses(upperClass, true); if (reasoner instanceof SPARQLReasoner) { OWLClassExpressionToSPARQLConverter conv = new OWLClassExpressionToSPARQLConverter(); String query = "SELECT DISTINCT ?concept WHERE {"; query += conv.convert("?ind", index); query += "?ind a ?concept . "; query += "VALUES ?concept {" + Joiner.on(" ") .join(FluentIterable.from(subClasses) .transform(Functions.compose(TO_IRI_FUNCTION, OWLCLASS_TRANSFORM_FUNCTION))) + "}"; query += "}"; // System.out.println(query); SortedSet<OWLClassExpression> meaningfulClasses = new TreeSet<>(); QueryExecution qe = ((SPARQLReasoner) reasoner).getQueryExecutionFactory().createQueryExecution(query); ResultSet rs = qe.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); meaningfulClasses.add(df.getOWLClass(IRI.create(qs.getResource("concept").getURI()))); }/*from w w w .j a va 2 s .co m*/ qe.close(); candidates.addAll(meaningfulClasses); // recursive call, i.e. go class hierarchy down for non-meaningful classes // for (OWLClassExpression cls : Sets.difference(superClasses, meaningfulClasses)) { // candidates.addAll(getNegClassCandidatesRecursive(index, cls)); // } } else { // we descend the subsumption hierarchy to ensure that we get // the most general concepts satisfying the criteria for (OWLClassExpression candidate : subClasses) { // System.out.println("testing " + candidate + " ... "); // NamedClass candidate = (OWLClass) d; // check disjointness with index (if not no further traversal downwards is necessary) if (!isDisjoint(candidate, index)) { // System.out.println( " passed disjointness test ... "); // check whether the class is meaningful, i.e. adds something to the index // to do this, we need to make sure that the class is not a superclass of the // index (otherwise we get nothing new) - for instance based disjoints, we // make sure that there is at least one individual, which is not already in the // upper class boolean meaningful; if (instanceBasedDisjoints) { // bug: tests should be performed against the index, not the upper class // SortedSet<OWLIndividual> tmp = rs.getIndividuals(upperClass); SortedSet<OWLIndividual> tmp = reasoner.getIndividuals(index); tmp.removeAll(reasoner.getIndividuals(candidate)); // System.out.println(" instances of " + index + " and not " + candidate + ": " + tmp.size()); meaningful = tmp.size() != 0; } else { meaningful = !isDisjoint(df.getOWLObjectComplementOf(candidate), index); } if (meaningful) { // candidate went successfully through all checks candidates.add(candidate); // System.out.println(" real refinement"); } else { // descend subsumption hierarchy to find candidates // System.out.println(" enter recursion"); candidates.addAll(getClassCandidatesRecursive(index, candidate)); } } // else { // System.out.println(" ruled out, because it is disjoint"); // } } } // System.out.println("cc method exit"); return candidates; }
From source file:org.dllearner.refinementoperators.RhoDRDown.java
private SortedSet<OWLClassExpression> getNegClassCandidatesRecursive(OWLClassExpression index, OWLClassExpression lowerClass, Set<OWLClassExpression> seenClasses) { if (seenClasses == null) { seenClasses = new TreeSet<>(); }/*from w w w .j a v a2 s . c o m*/ SortedSet<OWLClassExpression> candidates = new TreeSet<>(); // System.out.println("index " + index + " lower class " + lowerClass); SortedSet<OWLClassExpression> superClasses = classHierarchy.getSuperClasses(lowerClass); if (reasoner instanceof SPARQLReasoner) { OWLClassExpressionToSPARQLConverter conv = new OWLClassExpressionToSPARQLConverter(); String query = "SELECT DISTINCT ?concept WHERE {"; query += conv.convert("?ind", index); query += "?ind a ?concept . "; query += "VALUES ?concept {" + Joiner.on(" ") .join(FluentIterable.from(superClasses) .transform(Functions.compose(TO_IRI_FUNCTION, OWLCLASS_TRANSFORM_FUNCTION))) + "}"; query += "}"; // System.out.println(query); SortedSet<OWLClassExpression> meaningfulClasses = new TreeSet<>(); QueryExecution qe = ((SPARQLReasoner) reasoner).getQueryExecutionFactory().createQueryExecution(query); ResultSet rs = qe.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); meaningfulClasses.add(df.getOWLClass(IRI.create(qs.getResource("concept").getURI()))); } qe.close(); candidates.addAll(meaningfulClasses); // recursive call, i.e. go class hierarchy up for non-meaningful classes // for (OWLClassExpression cls : Sets.difference(superClasses, meaningfulClasses)) { // candidates.addAll(getNegClassCandidatesRecursive(index, cls)); // } } else { for (OWLClassExpression candidate : superClasses) { if (!candidate.isOWLThing()) { OWLObjectComplementOf negatedCandidate = df.getOWLObjectComplementOf(candidate); // check disjointness with index/range (should not be disjoint otherwise not useful) if (!isDisjoint(negatedCandidate, index)) { boolean meaningful; if (instanceBasedDisjoints) { SortedSet<OWLIndividual> tmp = reasoner.getIndividuals(index); tmp.removeAll(reasoner.getIndividuals(negatedCandidate)); meaningful = tmp.size() != 0; } else { meaningful = !isDisjoint(candidate, index); } if (meaningful) { candidates.add(negatedCandidate); } else if (!seenClasses.contains(candidate)) { seenClasses.add(candidate); candidates.addAll(getNegClassCandidatesRecursive(index, candidate, seenClasses)); } } } } } return candidates; }