List of usage examples for com.google.common.base Predicates or
public static <T> Predicate<T> or(Predicate<? super T> first, Predicate<? super T> second)
From source file:net.sourceforge.cilib.algorithm.AbstractAlgorithm.java
/** * Removes a stopping condition./* w ww. j av a 2 s . co m*/ * @param stoppingCondition The {@link net.sourceforge.cilib.stoppingcondition.StoppingCondition} * to be removed. */ @Override public final void removeStoppingCondition(StoppingCondition<Algorithm> stoppingCondition) { stoppingConditions.remove(stoppingCondition); this.stoppingCondition = Predicates.alwaysFalse(); for (StoppingCondition<Algorithm> condition : stoppingConditions) { this.stoppingCondition = Predicates.or(this.stoppingCondition, condition); } }
From source file:com.google.template.soy.jssrc.internal.GenerateSoyUtilsEscapingDirectiveCode.java
/** * Called reflectively when Ant sees {@code <jsdefined>}. *///from ww w.jav a 2s. c o m public void addConfiguredJsdefined(FunctionNamePredicate p) { final Pattern namePattern = p.namePattern; if (namePattern == null) { throw new IllegalStateException("Please specify a pattern attribute for <jsdefined>"); } availableJavaScript = Predicates.or(availableJavaScript, new Predicate<String>() { public boolean apply(String javaScriptFunctionName) { return namePattern.matcher(javaScriptFunctionName).matches(); } }); }
From source file:alien4cloud.webconfiguration.RestDocumentationConfig.java
@Bean public Docket deploymentApiDocket() { Predicate predicate = Predicates.or( PathSelectors.regex("/rest/" + PREFIXED_CURRENT_API_VERSION + "/deployments.*"), PathSelectors.regex("/rest/" + PREFIXED_CURRENT_API_VERSION + "/runtime.*")); predicates.add(predicate);/* ww w . jav a 2s . co m*/ return new Docket(DocumentationType.SWAGGER_2).groupName("applications-deployment-api").select() .paths(predicate).build().apiInfo(apiInfo()); }
From source file:com.ardor3d.input.control.FirstPersonControl.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> 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; 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) { FirstPersonControl.this.rotate(source.getCanvasRenderer().getCamera(), -mouse.getDx(), -mouse.getDy()); } else { firstPing = false;/*ww w. j ava 2 s .c o m*/ } } } }; _mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction); layer.registerTrigger(_mouseTrigger); }
From source file:com.ardor3d.example.canvas.RotatingCubeGame.java
private void registerInputTriggers() { logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.W), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { moveForward(source, tpf);//from w w w .j av a2s .com } })); logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.S), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { moveBack(source, tpf); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.A), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { turnLeft(source, tpf); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.D), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { turnRight(source, tpf); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.Q), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { moveLeft(source, tpf); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.E), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { moveRight(source, tpf); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ESCAPE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { exit.exit(); } })); logicalLayer .registerTrigger(new InputTrigger(new KeyPressedCondition(toggleRotationKey), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { toggleRotation(); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.U), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { toggleRotation(); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { resetCamera(source); } })); logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.NINE), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { lookAtZero(source); } })); final Predicate<TwoInputStates> mouseMovedAndOneButtonPressed = Predicates.and( TriggerConditions.mouseMoved(), Predicates.or(TriggerConditions.leftButtonDown(), TriggerConditions.rightButtonDown())); logicalLayer.registerTrigger(new InputTrigger(mouseMovedAndOneButtonPressed, new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final MouseState mouseState = inputStates.getCurrent().getMouseState(); turn(source, mouseState.getDx() * tpf * -MOUSE_TURN_SPEED); rotateUpDown(source, mouseState.getDy() * tpf * -MOUSE_TURN_SPEED); } })); logicalLayer.registerTrigger(new InputTrigger( new MouseButtonCondition(ButtonState.DOWN, ButtonState.DOWN, ButtonState.UNDEFINED), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { moveForward(source, tpf); } })); logicalLayer.registerTrigger(new InputTrigger(new AnyKeyCondition(), new TriggerAction() { public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final InputState current = inputStates.getCurrent(); System.out .println("Key character pressed: " + current.getKeyboardState().getKeyEvent().getKeyChar()); } })); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.provider.PinnedElementsLayoutProvider.java
/** * Finds the "real" children of the specified edit part that needs to be * laid out./*from w w w .ja v a 2 s . c o m*/ */ private Collection<IGraphicalEditPart> getChildrenOfInterest(final IGraphicalEditPart gep) { final Iterable<IGraphicalEditPart> rawChildren = Iterables.filter(gep.getChildren(), IGraphicalEditPart.class); // Ignore these, which are technically children edit parts but not // "inside" the container. final Predicate<Object> invalidChildKind = Predicates.or( Predicates.instanceOf(IDiagramBorderNodeEditPart.class), Predicates.instanceOf(IDiagramNameEditPart.class)); // These are OK. final Predicate<Object> validChildKind = Predicates.or(Predicates.instanceOf(IDiagramNodeEditPart.class), Predicates.instanceOf(IDiagramContainerEditPart.class), Predicates.instanceOf(IDiagramListEditPart.class)); final Predicate<Object> isProperChild = Predicates.and(validChildKind, Predicates.not(invalidChildKind)); final Collection<IGraphicalEditPart> result = Lists .newArrayList(Iterables.filter(rawChildren, isProperChild)); // Containers have an intermediate level of children edit parts. We // ignore these "wrapper" parts, but must look inside for proper // children of the container. for (IGraphicalEditPart part : Iterables.filter(rawChildren, Predicates.not(isProperChild))) { if (part instanceof DNodeContainerViewNodeContainerCompartmentEditPart || part instanceof DNodeContainerViewNodeContainerCompartment2EditPart) { result.addAll(getChildrenOfInterest(part)); } } return result; }
From source file:org.zoumbox.mh_dla_notifier.Receiver.java
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); Log.d(TAG, String.format("<<< %s#onReceive action=%s", getClass().getName(), intentAction)); boolean connectivityChanged = ConnectivityManager.CONNECTIVITY_ACTION.equals(intentAction); boolean justGotConnection = false; if (connectivityChanged) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); justGotConnection = activeNetwork != null && activeNetwork.isConnected(); Log.d(TAG, "Connectivity change. isConnected=" + justGotConnection); }//from ww w . ja v a2 s . c o m if (connectivityChanged && !justGotConnection) { Log.d(TAG, "Just lost connectivity, nothing to do"); return; } String trollId = intent.getStringExtra(Alarms.EXTRA_TROLL_ID); if (Strings.isNullOrEmpty(trollId)) { Set<String> trollIds = getProfileProxy().getTrollIds(context); if (trollIds.isEmpty()) { Log.d(TAG, "No troll registered, exiting..."); return; } trollId = trollIds.iterator().next(); Log.d(TAG, "TrollId not defined, using the fist one: " + trollId); } if (!getProfileProxy().isPasswordDefined(context, trollId)) { Log.d(TAG, "Troll password is not defined, exiting..."); return; } // If type is provided, request for an update String type = intent.getStringExtra(Alarms.EXTRA_TYPE); boolean requestUpdate = !Strings.isNullOrEmpty(type); // If device just started, request for wakeups registration boolean requestAlarmRegistering = justRestarted().apply(context); // Just go the internet connection back. Update will be necessary if // - device restarted since last update and last update in more than 2 hours ago // - last update failed because of network error if (!requestUpdate && justGotConnection) { // !requestUpdate because no need to check if update is already requested requestUpdate = Predicates .or(shouldUpdateBecauseOfRestart(trollId), shouldUpdateBecauseOfNetworkFailure(trollId)) .apply(context); } Log.d(TAG, String.format("requestUpdate=%b ; requestAlarmRegistering=%b", requestUpdate, requestAlarmRegistering)); // FIXME AThimel 14/02/14 Remove ASAP StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); try { Troll troll = getProfileProxy().fetchTrollWithoutUpdate(context, trollId).left(); if (requestUpdate) { // If the current DLA already has no more PA, skip update boolean skipUpdate = false; if (AlarmType.CURRENT_DLA.name().equals(type)) { skipUpdate = troll.getPa() == 0 && MhDlaNotifierUtils.IS_IN_THE_FUTURE.apply(troll.getDla()); } if (skipUpdate) { trollLoaded(troll, context, false); } else { refreshDla(context, trollId); } } else if (requestAlarmRegistering) { trollLoaded(troll, context, false); } else { Log.d(TAG, "Skip loading Troll"); } } catch (MissingLoginPasswordException mde) { Log.w(TAG, "Missing trollId and/or password, exiting..."); } }
From source file:org.grouplens.lenskit.eval.script.ConfigMethodInvoker.java
/** * Find a method that should be invoked multiple times, if the argument is iterable. The * argument may be iterated multiple times. * * @param self The configurable object./* ww w . ja v a 2s .c om*/ * @param name The method name. * @param args The arguments. * @return A thunk that will invoke the method. */ private Supplier<Object> findMultiMethod(final Object self, String name, final Object[] args) { if (args.length != 1) return null; // the argument is a list final Object arg = args[0]; if (!(arg instanceof Iterable)) { return null; } final Iterable<?> objects = (Iterable<?>) arg; Supplier<Object> result = null; for (final Method method : getOneArgMethods(self, name)) { Class ptype = method.getParameterTypes()[0]; boolean good = Iterables.all(objects, Predicates.or(Predicates.isNull(), Predicates.instanceOf(ptype))); if (good) { if (result != null) { throw new RuntimeException("multiple compatible methods named " + name); } else { result = new Supplier<Object>() { @Override public Object get() { for (Object obj : objects) { try { method.invoke(self, obj); } catch (IllegalAccessException e) { throw Throwables.propagate(e); } catch (InvocationTargetException e) { if (e.getCause() != null) { throw Throwables.propagate(e); } } } return null; } }; } } } return result; }
From source file:org.basepom.mojo.duplicatefinder.classpath.ClasspathDescriptor.java
private ClasspathDescriptor(final boolean useDefaultResourceIgnoreList, final Collection<String> ignoredResourcePatterns, final boolean useDefaultClassIgnoreList, final Collection<String> ignoredClassPatterns) throws MojoExecutionException { final ImmutableList.Builder<Pattern> ignoredResourcePatternsBuilder = ImmutableList.builder(); // build resource predicate... Predicate<String> resourcesPredicate = Predicates.alwaysFalse(); // predicate matching the default ignores if (useDefaultResourceIgnoreList) { resourcesPredicate = Predicates.or(resourcesPredicate, DEFAULT_IGNORED_RESOURCES_PREDICATE); ignoredResourcePatternsBuilder.addAll(DEFAULT_IGNORED_RESOURCES_PREDICATE.getPatterns()); }/*from w w w. j av a2s. co m*/ if (!ignoredResourcePatterns.isEmpty()) { try { // predicate matching the user ignores MatchPatternPredicate ignoredResourcesPredicate = new MatchPatternPredicate( ignoredResourcePatterns); resourcesPredicate = Predicates.or(resourcesPredicate, ignoredResourcesPredicate); ignoredResourcePatternsBuilder.addAll(ignoredResourcesPredicate.getPatterns()); } catch (final PatternSyntaxException pse) { throw new MojoExecutionException("Error compiling resourceIgnore pattern: " + pse.getMessage()); } } this.resourcesPredicate = resourcesPredicate; this.ignoredResourcePatterns = ignoredResourcePatternsBuilder.build(); final ImmutableList.Builder<Pattern> ignoredClassPatternsBuilder = ImmutableList.builder(); // build class predicate. Predicate<String> classPredicate = Predicates.alwaysFalse(); // predicate matching the default ignores if (useDefaultClassIgnoreList) { classPredicate = Predicates.or(classPredicate, DEFAULT_IGNORED_CLASS_PREDICATE); ignoredClassPatternsBuilder.addAll(DEFAULT_IGNORED_CLASS_PREDICATE.getPatterns()); } if (!ignoredClassPatterns.isEmpty()) { try { // predicate matching the user ignores MatchPatternPredicate ignoredPackagePredicate = new MatchPatternPredicate(ignoredClassPatterns); classPredicate = Predicates.or(classPredicate, ignoredPackagePredicate); ignoredClassPatternsBuilder.addAll(ignoredPackagePredicate.getPatterns()); } catch (final PatternSyntaxException pse) { throw new MojoExecutionException("Error compiling classIgnore pattern: " + pse.getMessage()); } } this.classPredicate = classPredicate; this.ignoredClassPatterns = ignoredClassPatternsBuilder.build(); }
From source file:com.b2international.snowowl.snomed.datastore.id.memory.DefaultSnomedIdentifierService.java
@Override public void publish(final Set<String> componentIds) { LOGGER.debug("Publishing {} component IDs.", componentIds.size()); final Map<String, SctId> sctIds = getSctIds(componentIds); final Map<String, SctId> problemSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, Predicates.<SctId>not(Predicates.or(SctId::isAssigned, SctId::isPublished)))); final Map<String, SctId> assignedSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, SctId::isAssigned)); for (final SctId sctId : assignedSctIds.values()) { sctId.setStatus(IdentifierStatus.PUBLISHED.getSerializedName()); }/*www . j av a 2 s. c o m*/ putSctIds(assignedSctIds); if (!problemSctIds.isEmpty()) { LOGGER.warn( "Cannot publish the following component IDs because they are not assigned or already published: {}", problemSctIds); } }