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:com.eucalyptus.tags.TagManager.java
public DescribeTagsResponseType describeTags(final DescribeTagsType request) throws Exception { final DescribeTagsResponseType reply = request.getReply(); final Context context = Contexts.lookup(); final Filter filter = Filters.generate(request.getFilterSet(), Tag.class); final Ordering<Tag> ordering = Ordering.natural().onResultOf(Tags.resourceId()) .compound(Ordering.natural().onResultOf(Tags.key())) .compound(Ordering.natural().onResultOf(Tags.value())); Iterables//from ww w . j a v a 2s .co m .addAll(reply.getTagSet(), Iterables .transform( ordering.sortedCopy(Tags.list(context.getUserFullName().asAccountFullName(), Predicates.and(filter.asPredicate(), RestrictedTypes.<Tag>filterPrivileged()), filter.asCriterion(), filter.getAliases())), TypeMappers.lookup(Tag.class, TagInfo.class))); return reply; }
From source file:com.ardor3d.input.control.OrbitCamControl.java
public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) { // Mouse look final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(), Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown())); final Predicate<TwoInputStates> scrollWheelMoved = new MouseWheelMovedCondition(); final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), someMouseDown); final TriggerAction mouseAction = new TriggerAction() { // Test boolean to allow us to ignore first mouse event. First event can wildly vary based on platform. private boolean firstPing = true; 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) { move(_xSpeed * mouse.getDx(), _ySpeed * mouse.getDy()); } else { firstPing = false;// w w w .j a v a2 s. com } } if (mouse.getDwheel() != 0) { zoom(_zoomSpeed * mouse.getDwheel()); } } }; final Predicate<TwoInputStates> predicate = Predicates.or(scrollWheelMoved, dragOnly ? dragged : TriggerConditions.mouseMoved()); _mouseTrigger = new InputTrigger(predicate, mouseAction); layer.registerTrigger(_mouseTrigger); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeISequenceEventsSemanticOrderingOperation.java
private List<EventEnd> getCompoundEnds(ISequenceEvent eventToUpdate, List<EventEnd> ends) { List<ISequenceEvent> compoundEvents = EventEndHelper.getCompoundEvents(eventToUpdate); Predicate<ISequenceEvent> isLogicallyInstantaneousNonReorderedEvent = new Predicate<ISequenceEvent>() { @Override/* w w w .j a va 2s.c o m*/ public boolean apply(ISequenceEvent input) { return input.isLogicallyInstantaneous() && !reordered.contains(input); }; }; Iterable<ISequenceEvent> compoundEventsToReorder = Iterables.filter(compoundEvents, isLogicallyInstantaneousNonReorderedEvent); Iterable<EventEnd> nonReorderedEndsOfCompoundEvents = Iterables .concat(Iterables.transform(compoundEventsToReorder, EventEndHelper.EVENT_ENDS)); Predicate<EventEnd> isCompoundEnd = Predicates.and(Predicates.instanceOf(SingleEventEnd.class), Predicates.not(Predicates.in(ends))); return Lists.newArrayList(Iterables.filter(nonReorderedEndsOfCompoundEvents, isCompoundEnd)); }
From source file:org.eclipse.sirius.diagram.ui.graphical.edit.policies.MoveEdgeGroupManager.java
/** * Determines if the given request is a valid request for this tool.<br/> * Each selected edge should respect the following rules: * <ul>/*from w w w. ja v a2 s . c o m*/ * <li>a border node as source</li> * <li>a border node as target</li> * <li>source node has only one connection: the moved edge.</li> * <li>target node has only one connection: the moved edge.</li> * <li>Both border nodes are on the same axe (Horizontal or Vertical)</li> * </ul> * <br/> * Furthermore, every selected edge group should be in the same direction * and only edges should be selected. * * @return true if the moved edges and border nodes can be activated, * otherwise false. */ @SuppressWarnings("unchecked") private boolean accept() { if (request instanceof BendpointRequest) { ConnectionEditPart connectionEditPart = ((BendpointRequest) request).getSource(); // The selected diagram element should only contain edges otherwise // the move is not valid final Set<Integer> edgeDirections = Sets.newLinkedHashSet(); boolean result = Iterables.all(connectionEditPart.getViewer().getSelectedEditParts(), Predicates .and(Predicates.instanceOf(ConnectionEditPart.class), new Predicate<ConnectionEditPart>() { /** * Determines if the given edge respects the following rules: * <ul> * <li>a border node as source</li> * <li>a border node as target</li> * <li>source node has only one connection: the moved edge.</li> * <li>target node has only one connection: the moved edge.</li> * <li>Both border nodes are on the same axe (Horizontal or * Vertical)</li> * </ul> */ @Override public boolean apply(ConnectionEditPart input) { EditPart sourceEditPart = input.getSource(); EditPart targetEditPart = input.getTarget(); if (sourceEditPart instanceof AbstractDiagramBorderNodeEditPart && targetEditPart instanceof AbstractDiagramBorderNodeEditPart) { if (getAllConnections((AbstractDiagramBorderNodeEditPart) sourceEditPart) .size() == 1 && getAllConnections((AbstractDiagramBorderNodeEditPart) targetEditPart) .size() == 1) { int sourceDirection = getBorderNodeDirection( (AbstractDiagramBorderNodeEditPart) sourceEditPart); int targetDirection = getBorderNodeDirection( (AbstractDiagramBorderNodeEditPart) targetEditPart); if (sourceDirection == targetDirection) { direction = sourceDirection; edgeDirections.add(sourceDirection); return true; } } } return false; } })); // There should be only one kind of direction for every edges to // authorize the move return result && edgeDirections.size() == 1; } return false; }
From source file:forge.deck.generation.DeckGeneratorBase.java
protected Iterable<PaperCard> selectCardsOfMatchingColorForPlayer(boolean forAi) { // start with all cards // remove cards that generated decks don't like Predicate<CardRules> canPlay = forAi ? AI_CAN_PLAY : HUMAN_CAN_PLAY; Predicate<CardRules> hasColor = new MatchColorIdentity(colors); if (useArtifacts) { hasColor = Predicates.or(hasColor, COLORLESS_CARDS); }/* w w w . j a v a 2 s .c o m*/ return Iterables.filter(pool.getAllCards(), Predicates.compose(Predicates.and(canPlay, hasColor), PaperCard.FN_GET_RULES)); }
From source file:org.eclipse.elk.alg.layered.graph.LNode.java
/** * Returns an iterable for all ports of a given type and side. * // w w w .ja va2s .c o m * @param portType a port type. * @param side a port side. * @return an iterable for the ports of the given type and side. */ public Iterable<LPort> getPorts(final PortType portType, final PortSide side) { Predicate<LPort> typePredicate = null; switch (portType) { case INPUT: typePredicate = LPort.INPUT_PREDICATE; break; case OUTPUT: typePredicate = LPort.OUTPUT_PREDICATE; break; } Predicate<LPort> sidePredicate = null; switch (side) { case NORTH: sidePredicate = LPort.NORTH_PREDICATE; break; case EAST: sidePredicate = LPort.EAST_PREDICATE; break; case SOUTH: sidePredicate = LPort.SOUTH_PREDICATE; break; case WEST: sidePredicate = LPort.WEST_PREDICATE; break; } if (typePredicate != null && sidePredicate != null) { return Iterables.filter(ports, Predicates.and(typePredicate, sidePredicate)); } else { return Collections.emptyList(); } }
From source file:io.crate.operation.collect.files.FileReadingCollector.java
private Predicate<URI> generateUriPredicate(FileInput fileInput, @Nullable Predicate<URI> globPredicate) { Predicate<URI> moduloPredicate; boolean sharedStorage = MoreObjects.firstNonNull(shared, fileInput.sharedStorageDefault()); if (sharedStorage) { moduloPredicate = new Predicate<URI>() { @Override/*w ww. j a va 2s. com*/ public boolean apply(URI input) { int hash = input.hashCode(); if (hash == Integer.MIN_VALUE) { hash = 0; // Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE } return Math.abs(hash) % numReaders == readerNumber; } }; } else { moduloPredicate = MATCH_ALL_PREDICATE; } if (globPredicate != null) { return Predicates.and(moduloPredicate, globPredicate); } return moduloPredicate; }
From source file:org.apache.whirr.ClusterController.java
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(ClusterSpec spec, Predicate<NodeMetadata> condition, Statement statement, RunScriptOptions options) throws IOException, RunScriptOnNodesException { LoginCredentials credentials = LoginCredentials.builder().user(spec.getClusterUser()) .privateKey(spec.getPrivateKey()).build(); if (options == null) { options = defaultRunScriptOptionsForSpec(spec); } else if (options.getLoginUser() == null) { options = options.overrideLoginCredentials(credentials); }//w ww. j a v a2 s . co m condition = Predicates.and(runningInGroup(spec.getClusterName()), condition); ComputeServiceContext context = getCompute().apply(spec); return context.getComputeService().runScriptOnNodesMatching(condition, statement, options); }
From source file:org.obeonetwork.dsl.uml2.design.internal.dialogs.ModelElementSelectionDialog.java
/** * Creates the tree viewer./* w w w. ja va 2s .c o m*/ * * @param parent * the parent composite * @return the tree viewer */ protected TreeViewer createTreeViewer(Composite parent) { treeViewer = new TreeViewer(parent); treeViewer.setContentProvider(contentProvider); treeViewer.setLabelProvider(labelProvider); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { private void doSelectionChanged(Object[] array) { setResult(Arrays.asList(array)); } public void selectionChanged(SelectionChangedEvent event) { doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray()); } }); final Collection<EObject> roots = getAllRootsInSessions(); final Collection<Object> inputs = Sets.newHashSet(); inputs.addAll(roots); treeViewer.setInput(inputs); treeViewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { final Predicate<Object> isMatchinExpregPredicate = getRegexpMatchPredicate(); return isOrHasDescendant(element, Predicates.and(isSelectable, isMatchinExpregPredicate)); } }); return treeViewer; }
From source file:org.apache.brooklyn.rest.resources.CatalogResource.java
@Override public List<CatalogEntitySummary> listEntities(String regex, String fragment, boolean allVersions) { Predicate<CatalogItem<Entity, EntitySpec<?>>> filter = Predicates.and(CatalogPredicates.IS_ENTITY, CatalogPredicates.<Entity, EntitySpec<?>>disabled(false)); List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, allVersions);/*ww w . j a va2s . c om*/ return castList(result, CatalogEntitySummary.class); }