List of usage examples for com.google.common.base Predicates alwaysTrue
@GwtCompatible(serializable = true) public static <T> Predicate<T> alwaysTrue()
From source file:com.sk89q.worldguard.bukkit.commands.WorldGuardCommands.java
@Command(aliases = { "profile" }, usage = "[<minutes>]", desc = "Profile the CPU usage of the server", min = 0, max = 1, flags = "t:p") @CommandPermissions("worldguard.profile") public void profile(final CommandContext args, final CommandSender sender) throws CommandException { Predicate<ThreadInfo> threadFilter; String threadName = args.getFlag('t'); final boolean pastebin; if (args.hasFlag('p')) { plugin.checkPermission(sender, "worldguard.report.pastebin"); pastebin = true;//w w w .j a va 2 s .co m } else { pastebin = false; } if (threadName == null) { threadFilter = new ThreadIdFilter(Thread.currentThread().getId()); } else if (threadName.equals("*")) { threadFilter = Predicates.alwaysTrue(); } else { threadFilter = new ThreadNameFilter(threadName); } int minutes; if (args.argsLength() == 0) { minutes = 5; } else { minutes = args.getInteger(0); if (minutes < 1) { throw new CommandException("You must run the profile for at least 1 minute."); } else if (minutes > 10) { throw new CommandException("You can profile for, at maximum, 10 minutes."); } } Sampler sampler; synchronized (this) { if (activeSampler != null) { throw new CommandException( "A profile is currently in progress! Please use /wg stopprofile to stop the current profile."); } SamplerBuilder builder = new SamplerBuilder(); builder.setThreadFilter(threadFilter); builder.setRunTime(minutes, TimeUnit.MINUTES); sampler = activeSampler = builder.start(); } AsyncCommandHelper.wrap(sampler.getFuture(), plugin, sender).formatUsing(minutes) .registerWithSupervisor("Running CPU profiler for %d minute(s)...") .sendMessageAfterDelay("(Please wait... profiling for %d minute(s)...)") .thenTellErrorsOnly("CPU profiling failed."); sampler.getFuture().addListener(new Runnable() { @Override public void run() { synchronized (WorldGuardCommands.this) { activeSampler = null; } } }, MoreExecutors.sameThreadExecutor()); Futures.addCallback(sampler.getFuture(), new FutureCallback<Sampler>() { @Override public void onSuccess(Sampler result) { String output = result.toString(); try { File dest = new File(plugin.getDataFolder(), "profile.txt"); Files.write(output, dest, Charset.forName("UTF-8")); sender.sendMessage( ChatColor.YELLOW + "CPU profiling data written to " + dest.getAbsolutePath()); } catch (IOException e) { sender.sendMessage(ChatColor.RED + "Failed to write CPU profiling data: " + e.getMessage()); } if (pastebin) { CommandUtils.pastebin(plugin, sender, output, "Profile result: %s.profile"); } } @Override public void onFailure(Throwable throwable) { } }); }
From source file:org.apache.brooklyn.rest.resources.EntityConfigResource.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//w ww . ja va2 s. c o m public void setFromMap(String application, String entityToken, Boolean recurse, Map newValues) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } if (LOG.isDebugEnabled()) LOG.debug("REST user " + Entitlements.getEntitlementContext() + " setting configs " + newValues); for (Object entry : newValues.entrySet()) { String configName = Strings.toString(((Map.Entry) entry).getKey()); Object newValue = ((Map.Entry) entry).getValue(); ConfigKey ck = findConfig(entity, configName); ((EntityInternal) entity).config().set(ck, TypeCoercions.coerce(newValue, ck.getTypeToken())); if (Boolean.TRUE.equals(recurse)) { for (Entity e2 : Entities.descendants(entity, Predicates.alwaysTrue(), false)) { ((EntityInternal) e2).config().set(ck, newValue); } } } }
From source file:org.jclouds.cloudstack.predicates.NetworkPredicates.java
/** * * @return always returns true. */ public static Predicate<Network> any() { return Predicates.alwaysTrue(); }
From source file:org.opensaml.xmlsec.impl.AbstractSecurityParametersResolver.java
/** * Get a predicate which operates according to the effective configured whitelist and blacklist policy. * //from w w w. j av a 2s .c o m * @param criteria the input criteria being evaluated * @param configs the effective list of {@link WhitelistBlacklistConfiguration} instances to consider * * @return a predicate instance which operates accordingly to the effective whitelist and blacklist policy */ @Nonnull protected Predicate<String> resolveWhitelistBlacklistPredicate(@Nonnull final CriteriaSet criteria, @Nonnull @NonnullElements @NotEmpty final List<? extends WhitelistBlacklistConfiguration> configs) { Collection<String> whitelist = resolveEffectiveWhitelist(criteria, configs); log.trace("Resolved effective whitelist: {}", whitelist); Collection<String> blacklist = resolveEffectiveBlacklist(criteria, configs); log.trace("Resolved effective blacklist: {}", blacklist); if (whitelist.isEmpty() && blacklist.isEmpty()) { log.trace("Both empty, returning alwaysTrue predicate"); return Predicates.alwaysTrue(); } if (whitelist.isEmpty()) { log.trace("Whitelist empty, returning BlacklistPredicate"); return new BlacklistPredicate(blacklist); } if (blacklist.isEmpty()) { log.trace("Blacklist empty, returning WhitelistPredicate"); return new WhitelistPredicate(whitelist); } WhitelistBlacklistConfiguration.Precedence precedence = resolveWhitelistBlacklistPrecedence(criteria, configs); log.trace("Resolved effective precedence: {}", precedence); switch (precedence) { case WHITELIST: log.trace("Based on precedence, returning WhitelistPredicate"); return new WhitelistPredicate(whitelist); case BLACKLIST: log.trace("Based on precedence, returning BlacklistPredicate"); return new BlacklistPredicate(blacklist); default: throw new IllegalArgumentException("WhitelistBlacklistPrecedence value is unknown: " + precedence); } }
From source file:org.eclipse.wb.internal.core.xml.model.generic.FlowContainerFactory.java
private Predicate<Object> getHorizontalPredicate(String prefix, boolean def) { String horizontalString = getParameter(prefix + ".horizontal"); if (horizontalString == null) { return Predicates.alwaysTrue(); }/*from www. j av a2 s . c om*/ return new ExpressionPredicate<Object>(horizontalString); }
From source file:com.google.devtools.build.lib.rules.cpp.CppCompileActionBuilder.java
private static Predicate<String> getNocoptPredicate(Collection<Pattern> patterns) { final ImmutableList<Pattern> finalPatterns = ImmutableList.copyOf(patterns); if (finalPatterns.isEmpty()) { return Predicates.alwaysTrue(); } else {/*from w ww . j av a 2 s . c om*/ return new Predicate<String>() { @Override public boolean apply(String option) { for (Pattern pattern : finalPatterns) { if (pattern.matcher(option).matches()) { return false; } } return true; } }; } }
From source file:net.automatalib.util.automata.copy.AutomatonLowLevelCopy.java
/** * Copies an {@link Automaton} to a {@link MutableAutomaton} with a compatible input alphabet, but possibly heterogeneous state and * transition properties. States and transitions will not be filtered. * /*from w ww . j a va2s . c o m*/ * @param <S1> input automaton state type * @param <I> input symbol type * @param <T1> input automaton transition type * @param <S2> output automaton state type * @param <T2> output automaton transition type * @param <SP2> output automaton state property type * @param <TP2> output automaton transition property type * * @param method the copy method to use * @param in the input automaton * @param inputs the inputs to consider * @param out the output automaton * @param spMapping the function for obtaining state properties * @param tpMapping the function for obtaining transition properties * @return a mapping from old to new states */ public static <S1, I, T1, S2, T2, SP2, TP2> Mapping<S1, S2> rawCopy(AutomatonCopyMethod method, Automaton<S1, ? super I, T1> in, Collection<? extends I> inputs, MutableAutomaton<S2, I, T2, SP2, TP2> out, Function<? super S1, ? extends SP2> spMapping, Function<? super T1, ? extends TP2> tpMapping) { return rawCopy(method, in, inputs, out, spMapping, tpMapping, Predicates.alwaysTrue(), TransitionPredicates.alwaysTrue()); }
From source file:org.xkonnex.repo.dsl.servicedsl.service.ui.hierarchy.HierarchyInformationControl.java
/** * {@inheritDoc}/*w w w .j av a2 s. c o m*/ * * */ @Override public void setInput(Object information) { if (!(information instanceof EObject)) { inputChanged(null, null); return; } EObject input = (EObject) information; IEObjectDescription inputDesc = ieDescBuilder.buildDescription(input); super.setTitleText(getHeaderLabel(inputDesc)); try { fLifeCycle.ensureRefreshedTypeHierarchy(inputDesc, workbench.getActiveWorkbenchWindow()); } catch (Exception e) { dispose(); return; } Predicate<IEObjectDescription> memberFilter = Predicates.alwaysTrue(); TraditionalHierarchyContentProvider contentProvider = new TraditionalHierarchyContentProvider(fLifeCycle); contentProvider.setMemberFilter(memberFilter); getTreeViewer().setContentProvider(contentProvider); fOtherContentProvider = new SuperTypeHierarchyContentProvider(fLifeCycle); fOtherContentProvider.setMemberFilter(memberFilter); Object[] topLevelObjects = contentProvider.getElements(fLifeCycle); if (topLevelObjects.length > 0 && contentProvider.getChildren(topLevelObjects[0]).length > 40) { fDoFilter = false; } else { getTreeViewer().addFilter(new NamePatternFilter()); } Object selection = null; if (input instanceof Property) { selection = input; } else if (topLevelObjects.length > 0) { selection = topLevelObjects[0]; } inputChanged(fLifeCycle, selection); }
From source file:com.eucalyptus.entities.Transactions.java
public static <S, T> S one(T search, Function<T, S> f) throws TransactionException { return one(search, Predicates.alwaysTrue(), f); }
From source file:com.tinspx.util.net.FormEncodedBody.java
/** * Returns a modifiable view of the parameters. *///w w w .ja v a2 s .com public ListMultimap<String, String> parameters() { if (paramsView == null) { paramsView = Predicated.listMultimap(Listenable.listMultimap(params, new Listenable.Modification() { @Override public void onModify(Object src, Listenable.Event type) { array = null; } //don't track entries as values can be null }), Predicates.notNull(), Predicates.alwaysTrue(), false); } return paramsView; }