List of usage examples for com.google.common.base Predicates alwaysTrue
@GwtCompatible(serializable = true) public static <T> Predicate<T> alwaysTrue()
From source file:com.eucalyptus.autoscaling.common.internal.instances.PersistenceAutoScalingInstances.java
@Override public <T> T lookup(final OwnerFullName ownerFullName, final String instanceId, final Function<? super AutoScalingInstance, T> transform) throws AutoScalingMetadataException { return persistenceSupport.lookupByExample(persistenceSupport.exampleWithName(ownerFullName, instanceId), ownerFullName, instanceId, Predicates.alwaysTrue(), transform); }
From source file:beans.config.ConfigBean.java
private void injectConfiguration(Object obj, Configuration conf) { Set<Field> allFields = ReflectionUtils.getAllFields(obj.getClass(), Predicates.alwaysTrue()); for (Field field : allFields) { String configKey = field.getName(); Config configAnn = null;/*w w w . j a v a 2s . c o m*/ if (field.isAnnotationPresent(Config.class)) { configAnn = field.getAnnotation(Config.class); String playKey = configAnn.playKey(); // use the annotated information only if not empty. configKey = StringUtils.isEmpty(playKey) ? configKey : playKey; } if (handlers.containsKey(field.getType())) { try { Object value = handlers.get(field.getType()).getValue(conf, configKey); if (value != null || !isIgnoreNullValue(configAnn)) { field.set(obj, value); } } catch (Exception e) { logger.error(String.format("unable to set value for field [%s.%s]", field.getDeclaringClass().getName(), field.getName()), e); } } else { // this is probably an Object. need to instantiate try { if (conf.getConfig(configKey) != null) { // important : we assume the field is not null. // this way we will be able to refresh configuration on command. Object value = field.get(obj); injectConfiguration(value, conf.getConfig(configKey)); } } catch (Exception e) { throw new RuntimeException(String.format("unable to populate configuration for key %s.%s", obj.getClass(), field.getName()), e); } } ConfigValueHandler handler = handlers.containsKey(field.getType()) ? handlers.get(field.getType()) : handlers.get(Configuration.class); } }
From source file:org.apache.brooklyn.entity.software.base.lifecycle.ScriptHelper.java
public ScriptHelper failOnNonZeroResultCode(boolean val) { if (val) { failOnNonZeroResultCode();//from w ww . j a va 2s .co m } else { requireResultCode(Predicates.alwaysTrue()); } return this; }
From source file:com.isotrol.impe3.pms.core.obj.SourceMappingsObject.java
/** * Transforms the object to a protocol buffer message with no filter. * @return The PB message./* ww w. j ava 2 s . c om*/ */ public final MappingsPB toPB() { return toPB(Predicates.alwaysTrue()); }
From source file:org.apache.brooklyn.entity.proxy.nginx.NginxControllerImpl.java
@Override public void connectSensors() { super.connectSensors(); ConfigToAttributes.apply(this); // "up" is defined as returning a valid HTTP response from nginx (including a 404 etc) httpFeed = addFeed(//from w w w . j a v a2s . c o m HttpFeed.builder().uniqueTag("nginx-poll").entity(this).period(getConfig(HTTP_POLL_PERIOD)) .baseUri(new UrlInferencer(null)).poll(new HttpPollConfig<Boolean>(NGINX_URL_ANSWERS_NICELY) // Any response from Nginx is good. .checkSuccess(Predicates.alwaysTrue()) // Accept any nginx response (don't assert specific version), so that sub-classing // for a custom nginx build is not strict about custom version numbers in headers .onResult(HttpValueFunctions.containsHeader("Server")).setOnException(false) .suppressDuplicates(true)) .build()); // TODO PERSISTENCE WORKAROUND kept anonymous function in case referenced in persisted state new Function<HttpToolResponse, Boolean>() { @Override public Boolean apply(HttpToolResponse input) { // Accept any nginx response (don't assert specific version), so that sub-classing // for a custom nginx build is not strict about custom version numbers in headers List<String> actual = input.getHeaderLists().get("Server"); return actual != null && actual.size() == 1; } }; if (!Lifecycle.RUNNING.equals(getAttribute(SERVICE_STATE_ACTUAL))) { // TODO when updating the map, if it would change from empty to empty on a successful run // gate with the above check to prevent flashing on ON_FIRE during rebind (this is invoked on rebind as well as during start) ServiceNotUpLogic.updateNotUpIndicator(this, NGINX_URL_ANSWERS_NICELY, "No response from nginx yet"); } enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS) .uniqueTag("not-up-unless-url-answers").from(NGINX_URL_ANSWERS_NICELY) .computing(Functionals.ifNotEquals(true) .value("URL where nginx listens is not answering correctly (with expected header)")) .build()); connectServiceUpIsRunning(); // Can guarantee that parent/managementContext has been set Group urlMappings = getConfig(URL_MAPPINGS); if (urlMappings != null && urlMappingsMemberTrackerPolicy == null) { // Listen to the targets of each url-mapping changing targetAddressesHandler = subscriptions().subscribeToMembers(urlMappings, UrlMapping.TARGET_ADDRESSES, new SensorEventListener<Collection<String>>() { @Override public void onEvent(SensorEvent<Collection<String>> event) { updateNeeded(); } }); // Listen to url-mappings being added and removed urlMappingsMemberTrackerPolicy = policies() .add(PolicySpec.create(UrlMappingsMemberTrackerPolicy.class).configure("group", urlMappings)); } }
From source file:com.eucalyptus.autoscaling.groups.PersistenceAutoScalingGroups.java
@Override public <T> List<T> listRequiringMonitoring(final long interval, final Function<? super AutoScalingGroup, T> transform) throws AutoScalingMetadataException { // We want to select some groups depending on the interval / time int group = (int) ((System.currentTimeMillis() / interval) % 6); final Collection<String> suffixes = Lists.newArrayList(); switch (group) { case 0:// w w w . j a v a 2 s.c o m suffixes.add("0"); suffixes.add("1"); suffixes.add("2"); break; case 1: suffixes.add("3"); suffixes.add("4"); suffixes.add("5"); break; case 2: suffixes.add("6"); suffixes.add("7"); suffixes.add("8"); break; case 3: suffixes.add("9"); suffixes.add("a"); suffixes.add("b"); break; case 4: suffixes.add("c"); suffixes.add("d"); break; default: suffixes.add("e"); suffixes.add("f"); break; } final Junction likeAnyOf = Restrictions.disjunction(); for (final String suffix : suffixes) { likeAnyOf.add(Restrictions.ilike("id", "%" + suffix)); } return persistenceSupport.listByExample(AutoScalingGroup.withOwner(null), Predicates.alwaysTrue(), likeAnyOf, Collections.<String, String>emptyMap(), transform); }
From source file:org.apache.whirr.cli.command.RunScriptCommand.java
private Predicate<NodeMetadata> buildFilterPredicate(String[] ids, String[] roles, ClusterSpec spec) throws IOException { Predicate<NodeMetadata> condition = Predicates.alwaysTrue(); if (ids != null && ids.length > 0) { return Predicates.and(condition, withIds(ids)); } else if (roles != null && roles.length > 0) { List<String> instanceIds = Lists.newArrayList(); Cluster cluster = createClusterStateStore(spec).load(); for (Cluster.Instance instance : cluster .getInstancesMatching(anyRoleIn(Sets.<String>newHashSet(roles)))) { instanceIds.add(instance.getId()); }/* w w w. ja v a 2s . c o m*/ condition = Predicates.and(condition, withIds(instanceIds.toArray(new String[0]))); return condition; } else { return condition; } }
From source file:org.jclouds.trmk.vcloud_0_8.config.DefaultVCloudReferencesModule.java
@Provides @Singleton @org.jclouds.trmk.vcloud_0_8.endpoints.Network protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) { return Predicates.alwaysTrue(); }
From source file:com.isotrol.impe3.pms.core.obj.PortalsObject.java
/** * Returns the tree of portals, excluding the specified node. * @param exclude Portal to exlude. Optional. * @return The requested tree./* www. j a v a 2 s.c o m*/ */ private PortalTreeDTO map2tree(final PortalObject exclude) { final PortalTreeDTO root = new PortalTreeDTO(); root.setNode(null); if (isEmpty()) { root.setChildren(Lists.<PortalTreeDTO>newArrayListWithCapacity(0)); return root; } final Predicate<PortalObject> filter; if (exclude == null) { filter = Predicates.alwaysTrue(); } else { filter = new Predicate<PortalObject>() { public boolean apply(PortalObject input) { return !exclude.getId().equals(input.getId()); } }; } final Function<PortalObject, PortalTreeDTO> tree = new Function<PortalObject, PortalTreeDTO>() { public PortalTreeDTO apply(PortalObject from) { final PortalTreeDTO dto = new PortalTreeDTO(); dto.setNode(from.toSelDTO()); dto.setChildren(Mappers.list(filter(hierarchy.getChildren(from.getId()), filter), this)); return dto; } }; root.setChildren(Mappers.list(filter(hierarchy.getFirstLevel(), filter), tree)); return root; }
From source file:forge.card.BoosterGenerator.java
@SuppressWarnings("unchecked") public static PrintSheet makeSheet(String sheetKey, Iterable<PaperCard> src) { PrintSheet ps = new PrintSheet(sheetKey); String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', 2); Predicate<PaperCard> setPred = (Predicate<PaperCard>) (sKey.length > 1 ? IPaperCard.Predicates.printedInSets(sKey[1].split(" ")) : Predicates.alwaysTrue()); List<String> operators = new LinkedList<>(Arrays.asList(TextUtil.splitWithParenthesis(sKey[0], ':'))); Predicate<PaperCard> extraPred = buildExtraPredicate(operators); // source replacement operators - if one is applied setPredicate will be ignored Iterator<String> itMod = operators.iterator(); while (itMod.hasNext()) { String mainCode = itMod.next(); if (mainCode.regionMatches(true, 0, "fromSheet", 0, 9)) { // custom print sheet String sheetName = StringUtils.strip(mainCode.substring(9), "()\" "); src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList(); setPred = Predicates.alwaysTrue(); } else if (mainCode.startsWith("promo")) { // get exactly the named cards, that's a tiny inlined print sheet String list = StringUtils.strip(mainCode.substring(5), "() "); String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"'); List<PaperCard> srcList = new ArrayList<>(); for (String cardName : cardNames) { srcList.add(StaticData.instance().getCommonCards().getCard(cardName)); }//from w w w. j ava 2s .c o m src = srcList; setPred = Predicates.alwaysTrue(); } else { continue; } itMod.remove(); } // only special operators should remain by now - the ones that could not be turned into one predicate String mainCode = operators.isEmpty() ? null : operators.get(0).trim(); if (null == mainCode || mainCode.equalsIgnoreCase(BoosterSlots.ANY)) { // no restriction on rarity Predicate<PaperCard> predicate = Predicates.and(setPred, extraPred); ps.addAll(Iterables.filter(src, predicate)); } else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE)) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon Predicate<PaperCard> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateRares)); Predicate<PaperCard> predicateUncommon = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred); ps.addAll(Iterables.filter(src, predicateUncommon), 3); } else if (mainCode.equalsIgnoreCase(BoosterSlots.RARE_MYTHIC)) { // Typical ratio of rares to mythics is 53:15, changing to 35:10 in smaller sets. // To achieve the desired 1:8 are all mythics are added once, and all rares added twice per print sheet. Predicate<PaperCard> predicateMythic = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateMythic)); Predicate<PaperCard> predicateRare = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateRare), 2); } else { throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode); } return ps; }