List of usage examples for com.google.common.base Predicates and
public static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T> second)
From source file:org.auraframework.util.ServiceLoaderImpl.java
@Override public <T extends AuraServiceProvider> T get(Class<T> type, final String name) { try {/*from ww w . j av a2 s . c om*/ Predicate<? super Method> predicate = Predicates.and(ServiceLoaderImpl.predicate, new Predicate<Method>() { @Override public boolean apply(Method input) { return input.getAnnotation(Impl.class).name().equals(name); } }); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(AuraConfiguration.class); // First try those marked with primary T ret = get(type, classes, true, predicate); if (ret != null) { return ret; } return get(type, classes, false, predicate); } catch (Throwable t) { throw new ServiceLocatorException(t); } }
From source file:org.apache.brooklyn.rest.resources.TypeResource.java
@Override public List<TypeSummary> listVersions(String nameOrAlias) { Predicate<RegisteredType> filter = Predicates.and(RegisteredTypePredicates.entitledToSee(mgmt()), RegisteredTypePredicates.nameOrAlias(nameOrAlias)); ImmutableList<RegisteredType> sortedItems = FluentIterable .from(brooklyn().getTypeRegistry().getMatching(filter)) .toSortedList(RegisteredTypes.RegisteredTypeNameThenBestFirstComparator.INSTANCE); return toTypeSummary(brooklyn(), sortedItems, ui.getBaseUriBuilder()); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.util.EditPartQuery.java
/** * Return the list of {@link BorderItemEditPart}s that are on the expected * side./* w w w . j a v a 2s. co m*/ * * @param expectedSide * The side ({@link org.eclipse.draw2d.PositionConstants}) where * the children must be * @return the list of {@link BorderItemEditPart}s that are on the expected * side. */ public List<IBorderItemEditPart> getBorderNodeEditParts(final int expectedSide) { if (part instanceof IBorderedShapeEditPart) { Iterable<IBorderItemEditPart> bordersItemPart = Iterables.filter(part.getChildren(), Predicates .and(Predicates.instanceOf(IBorderItemEditPart.class), new Predicate<IBorderItemEditPart>() { @Override public boolean apply(IBorderItemEditPart input) { int currentSide = input.getBorderItemLocator().getCurrentSideOfParent(); return expectedSide == currentSide; } })); return Lists.newArrayList(bordersItemPart); } return new ArrayList<IBorderItemEditPart>(); }
From source file:org.polarsys.reqcycle.traceability.cache.AbstractCachedTraceabilityEngine.java
@Override public Iterator<Pair<Link, Reachable>> getTraceability(Request... requests) throws EngineException { long timeInNanos = 0; boolean debug = logger.isDebug(Activator.OPTIONS_DEBUG, Activator.getDefault()); if (debug) {// w w w .j a v a 2 s . c o m timeInNanos = System.nanoTime(); } if (requests == null) { throw new EngineException("request can not be null"); } boolean checkCache = isCacheCheckNeeded(requests); if (checkCache) { checkScope(getScope(requests)); } if (debug) { if (checkCache) { long timeInMsc = (System.nanoTime() - timeInNanos) / 1000000; logger.trace(String.format("Cache checked in %d ms", timeInMsc)); } else { logger.trace(String.format("Cache checked disabled via request")); } } Iterator<Pair<Link, Reachable>> result = Iterators.emptyIterator(); for (Request request : requests) { // Scope and Filter are used to validate or invalidate paths so // they can be combined Predicate<Pair<Link, Reachable>> requestPredicate = new IsInScopePredicate(request.getScope()); if (request.getFilter() != null) { requestPredicate = Predicates.and(new FilterPredicate(request.getFilter()), requestPredicate); } Iterable<Couple> couples = request.getCouples(); if (!couples.iterator().hasNext()) { if (request.getDepth() == DEPTH.ONE) { throw new EngineException( "for a couple with source equals to null the request shall be infinite"); } else { result = Iterators.concat(result, doGetAllTraceability(request.getDirection(), requestPredicate)); } } // for each couple an traceability iterable is computed for (Couple c : couples) { // if the source is null it means the engine needs to return all // the traceability and the request depth shall be equals to // INFINITE if (c.getSource() == null) { if (request.getDepth() == DEPTH.ONE) { throw new EngineException( "for a couple with source equals to null the request shall be infinite"); } else { result = Iterators.concat(result, doGetAllTraceability(request.getDirection(), requestPredicate)); } } else { // when the target is equals to null it is a prospective // analysis if (c.getStopCondition() == null) { // for a depth equals to infinite the traceability shall // be // complete if (request.getDepth() == DEPTH.INFINITE) { result = Iterators.concat(result, doGetTraceability(c.getSource(), request.getDirection(), requestPredicate)); // otherwise just the first level shall be complete } else if (request.getDepth() == DEPTH.ONE) { result = Iterators.concat(result, doGetOneLevelTraceability(c.getSource(), request.getDirection(), requestPredicate)); } // when the target is different to null a search shall // be // performed } else { if (request.getDepth() == DEPTH.INFINITE) { result = Iterators.concat(result, doGetTraceability(c.getSource(), c.getStopCondition(), request.getDirection(), requestPredicate)); } else { // except when the depth is equals to one in this // case // it can be computed using a filter result = Iterators.concat(result, doGetTraceability(c.getSource(), c.getStopCondition(), request.getDirection(), Predicates.and(requestPredicate, new TargetEqualsPredicate(c.getStopCondition())))); } } } } } if (debug) { timeInNanos = System.nanoTime() - timeInNanos; long timeInMsc = timeInNanos / 1000000; logger.trace(String.format("Traceability computed in %d ms (including cache check)", timeInMsc)); } return result; }
From source file:org.eclipse.sirius.diagram.business.internal.experimental.sync.AbstractSynchronizerHelper.java
/** * .//from w ww . j a v a 2 s. c o m * * @param container * . * @param mapping * . * @return . */ protected Collection<EObject> getPreviousSemanticsElements(DragAndDropTarget container, DiagramElementMapping mapping) { Collection<EObject> transformed = Collections2.transform( sync.getPreviousDiagramElements(container, mapping), new Function<DDiagramElement, EObject>() { public EObject apply(final DDiagramElement from) { return from.getTarget(); } }); return ImmutableSet.copyOf( Collections2.filter(transformed, Predicates.and(Predicates.notNull(), new Predicate<EObject>() { // We don't keep semantic element that is invalid public boolean apply(final EObject input) { return (input.eContainer() != null && input.eContainer().eResource() != null) || input.eResource() != null; } }))); }
From source file:org.jclouds.providers.Providers.java
/** * Returns the providers that have at least one common ISO 3166 code and are of the given * viewableAs.//from w w w. j ava 2 s.c om * * @param providerMetadata * the provider metadata to use to filter providers by * @param viewableAs * the viewableAs to filter providers by * * @return the providers that share at least one common ISO 3166 code and of the given * viewableAs */ public static Iterable<ProviderMetadata> collocatedWith(ProviderMetadata providerMetadata, TypeToken<? extends View> viewableAs) { return filter(all(), Predicates.and(ProviderPredicates.intersectingIso3166Code(providerMetadata), ProviderPredicates.viewableAs(viewableAs))); }
From source file:com.ardorcraft.control.FlyControl.java
public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) { final FlyControl control = this; // Mouse look final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(), Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown())); final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), someMouseDown); final TriggerAction dragAction = new TriggerAction() { // Test boolean to allow us to ignore first mouse event. First event // can wildly vary based on platform. private boolean firstPing = true; @Override/*from www . j a v a 2 s . co m*/ public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final MouseState mouse = inputStates.getCurrent().getMouseState(); if (mouse.getDx() != 0 || mouse.getDy() != 0) { if (!firstPing) { control.rotate(-mouse.getDx(), -mouse.getDy()); } else { firstPing = false; } } } }; _mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction); layer.registerTrigger(_mouseTrigger); }
From source file:ezbake.data.graph.blueprints.visibility.VisibilityFilterQuery.java
/** * Create a Guava predicate from a Blueprints predicate. * * @param key element property key to check * @param predicate predicate to check element property value * @param value value as other argument to predicate * @return Guava predicate wrapping Blueprints predicate *//* w w w . j a v a 2s. c om*/ private <T extends Element> Predicate<T> blueprintsPredicate(final String key, final com.tinkerpop.blueprints.Predicate predicate, final Object value) { return new Predicate<T>() { @Override public boolean apply(T element) { List<Map<String, Object>> values = element.getProperty(key); if (values == null) { return false; } Iterable<Map<String, Object>> it = Iterables .filter(values, Predicates.and( permissionContext.getPropertyFilter() .hasAnyPermissionPredicate(Permission.DISCOVER, Permission.READ), blueprintsValuePredicate(predicate, value))); return !Iterables.isEmpty(it); } }; }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.util.EventFinder.java
/** * Returns the deepest event in the hierarchy of sub-event starting from * this finder's context which includes completely the specified range. * //ww w . ja v a 2 s . c o m * @param range * the range to look for. * @return the deepest event, starting from this finder's context, which * includes the specified range, or <code>null</code>. */ public ISequenceEvent findMostSpecificEvent(Range range) { if (context instanceof Message) { return null; } ISequenceEvent result = null; if (contextIncludesRange(range)) { if (context != null && !shouldIgnore().apply(context)) { boolean okForReconnection = !isReconnection() || !Message.NO_RECONNECTABLE_EVENTS.apply(context); boolean okForReparent = !isReparent() || !AbstractNodeEvent.NO_REPARENTABLE_EVENTS.apply(context); if (okForReconnection && okForReparent) { result = context; } } } if (contextIncludesRange(range) || isReparent()) { Predicate<ISequenceEvent> sameLifeline = new SameLifelinePredicate(lifeline); List<ISequenceEvent> eventsToInspect = Lists.newArrayList(); if ((reconnect || reparent) && (context instanceof AbstractNodeEvent || context instanceof Lifeline)) { for (View view : Iterables.filter(context.getNotationView().getChildren(), View.class)) { Option<ISequenceEvent> ise = ISequenceElementAccessor.getISequenceEvent(view); if (ise != null && ise.some() && !reparented.containsKey(ise.get())) { eventsToInspect.add(ise.get()); } } // handle reparented events // look for new child for (Entry<AbstractNodeEvent, ISequenceEvent> entry : reparented.entrySet()) { if (entry.getValue() == context) { eventsToInspect.add(entry.getKey()); } } } else { eventsToInspect.addAll(context.getSubEvents()); } for (ISequenceEvent child : Iterables.filter(eventsToInspect, Predicates.and(sameLifeline, Predicates.not(shouldIgnore())))) { EventFinder childFinder = new EventFinder(child, lifeline); childFinder.setReconnection(isReconnection()); childFinder.setReparent(isReparent()); childFinder.setEventsToIgnore(eventsToIgnore); childFinder.setExpansionZone(expansionZone); childFinder.setVerticalRangefunction(verticalRangeFunction); childFinder.setReparented(reparented); ISequenceEvent moreSpecific = childFinder.findMostSpecificEvent(range); if (moreSpecific != null) { result = moreSpecific; break; } } } return result; }
From source file:org.apache.brooklyn.rest.resources.BundleResource.java
@Override public TypeDetail getTypeExplicitVersion(String symbolicName, String version, String typeSymbolicName, String typeVersion) {/*from w ww . j a v a2 s. c o m*/ ManagedBundle b = lookup(symbolicName, version); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_CATALOG_ITEM, typeSymbolicName + ":" + typeVersion)) { // TODO best to default to "not found" - unless maybe they have permission to "see null" throw WebResourceUtils.forbidden( "User '%s' not permitted to see info on this type (including whether or not installed)", Entitlements.getEntitlementContext().user()); } Predicate<RegisteredType> pred = RegisteredTypePredicates.nameOrAlias(typeSymbolicName); pred = Predicates.and(pred, RegisteredTypePredicates.containingBundle(b.getVersionedName())); if (!LATEST.equalsIgnoreCase(typeVersion)) { pred = Predicates.and(pred, RegisteredTypePredicates.version(typeVersion)); } Iterable<RegisteredType> items = mgmt().getTypeRegistry().getMatching(pred); if (Iterables.isEmpty(items)) { throw WebResourceUtils.notFound("Entity with id '%s:%s' not found", typeSymbolicName, typeVersion); } RegisteredType item = RegisteredTypes.getBestVersion(items); return TypeTransformer.detail(brooklyn(), item, ui.getBaseUriBuilder()); }