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:zotmc.collect.FluentPredicate.java
public FluentPredicate<T> and(Predicate<? super T> other) { return from(Predicates.and(unwrap(), other)); }
From source file:org.apache.whirr.service.puppet.functions.ModulePropertiesFromConfiguration.java
public Map<String, String> apply(final Configuration config) { Iterator<String> allKeys = Iterators.transform(config.getKeys(), Functions.toStringFunction()); Set<String> moduleKeys = Sets.newHashSet(Iterators.<String>filter(allKeys, Predicates.and( Predicates.containsPattern(PUPPET + "\\.[^.]+\\." + MODULE_SOURCE_SUBKEY), new Predicate<String>() { @Override//from w w w . ja v a 2s . co m public boolean apply(String arg0) { // TODO not sure that we have to check this return config.getString(arg0, null) != null; } }))); Builder<String, String> builder = ImmutableMap.<String, String>builder(); for (String key : moduleKeys) { builder.put(key, config.getString(key)); } return builder.build(); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.figure.locator.FeedbackDBorderItemLocator.java
@Override protected List<IFigure> getBrotherFigures(IFigure targetBorderItem) { IFigure parentFigure = getParentFigure(); if (parentFigure instanceof BorderedNodeFigure) { parentFigure = ((BorderedNodeFigure) parentFigure).getBorderItemContainer(); }//www . jav a 2s .c o m @SuppressWarnings("unchecked") Iterable<IFigure> brotherFigures = Iterables.filter(parentFigure.getChildren(), Predicates .and(Predicates.instanceOf(IFigure.class), Predicates.not(Predicates.equalTo(targetBorderItem)))); return Lists.newArrayList(brotherFigures); }
From source file:com.google.cloud.bigtable.dataflowimport.DataCellPredicateFactory.java
/** {@inheritDoc} */ @Override//from w ww . j a v a2s.c om public Predicate<Cell> apply(Cell deleteMarker) { checkArgument(CellUtil.isDelete(deleteMarker), "expecting delete marker cell."); switch (KeyValue.Type.codeToType(deleteMarker.getTypeByte())) { case Delete: // Delete specific column by exact timestamp. return Predicates.and(new MatchQualifier(deleteMarker), new MatchExactTimestamp(deleteMarker)); case DeleteFamilyVersion: // Delete all column in family by exact timestamp. return new MatchExactTimestamp(deleteMarker); case DeleteColumn: // Delete specific column up to a timestamp return Predicates.and(new MatchQualifier(deleteMarker), new MatchTimestampRangeByUpperBound(deleteMarker)); case DeleteFamily: // Delete all columns in a family up to a timestamp return new MatchTimestampRangeByUpperBound(deleteMarker); default: throw new IllegalStateException("Unexpected type byte: " + deleteMarker.getTypeByte()); } }
From source file:com.eviware.loadui.ui.fx.control.fields.ValidatableDoubleField.java
public ValidatableDoubleField(final Predicate<String> stringConstraint, final Predicate<Double> doubleConstraint, final Function<String, Double> convertFunction) { super(stringConstraint == null ? CONVERTABLE_TO_DOUBLE : Predicates.and(CONVERTABLE_TO_DOUBLE, stringConstraint), Objects.firstNonNull(convertFunction, STRING_TO_DOUBLE)); constraint = Objects.firstNonNull(doubleConstraint, Predicates.<Double>alwaysTrue()); }
From source file:org.apache.brooklyn.entity.messaging.kafka.KafkaSupport.java
/** * Send a message to the {@link KafkaCluster} on the given topic. *//* ww w .ja v a2 s . c om*/ public void sendMessage(String topic, String message) { Optional<Entity> anyBrokerNodeInCluster = Iterables.tryFind(cluster.getCluster().getChildren(), Predicates.and(Predicates.instanceOf(KafkaBroker.class), EntityPredicates.attributeEqualTo(KafkaBroker.SERVICE_UP, true))); if (anyBrokerNodeInCluster.isPresent()) { KafkaBroker broker = (KafkaBroker) anyBrokerNodeInCluster.get(); Properties props = new Properties(); props.put("metadata.broker.list", format("%s:%d", broker.getAttribute(KafkaBroker.HOSTNAME), broker.getKafkaPort())); props.put("bootstrap.servers", format("%s:%d", broker.getAttribute(KafkaBroker.HOSTNAME), broker.getKafkaPort())); props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); Producer<String, String> producer = new KafkaProducer<>(props); ((KafkaZooKeeper) cluster.getZooKeeper()).createTopic(topic); ProducerRecord<String, String> data = new ProducerRecord<>(topic, message); producer.send(data); producer.close(); } else { throw new InvalidParameterException("No kafka broker node found"); } }
From source file:lodsve.springfox.config.SpringFoxDocket.java
@PostConstruct public void init() throws NoSuchFieldException, IllegalAccessException { apiInfo(apiInfo(properties));/* w ww .j a v a 2 s .c o m*/ forCodeGeneration(true); groupName(groupName); pathProvider(pathProvider); host(getHost()); if (StringUtils.equals(DEFAULT_GROUP_NAME, groupName)) { return; } // apiSelector Field apiSelector = this.getClass().getSuperclass().getDeclaredField("apiSelector"); apiSelector.setAccessible(true); Predicate<String> pathSelector = ApiSelector.DEFAULT.getPathSelector(); pathSelector = Predicates.and(pathSelector, includePath()); apiSelector.set(this, new ApiSelector( combine(ApiSelector.DEFAULT.getRequestHandlerSelector(), pathSelector), pathSelector)); }
From source file:com.googlecode.t7mp.scanner.ModifiedFileTimerTask.java
@Override public void run() { long timeStamp = lastrun; lastrun = System.currentTimeMillis(); Set<File> fileSet = FileUtil.getAllFiles(rootDirectory); Collection<File> changedFiles = Collections2.filter(fileSet, Predicates.and(new ModifiedFilePredicate(timeStamp), new FileSuffixPredicate(suffixe))); for (File file : changedFiles) { String absolutePath = file.getAbsolutePath(); String def = getResourceDef(absolutePath); int endIndex = absolutePath.lastIndexOf(def); String copyFragment = absolutePath.substring(endIndex + def.length()); File copyToFile = new File(webappDirectory, copyFragment); log.debug("CHANGED: " + absolutePath); log.debug("COPY TO : " + copyToFile.getAbsolutePath()); try {//w ww . ja va 2 s .co m FileUtils.copyFile(file, copyToFile); FileUtils.touch(copyToFile); } catch (IOException e) { e.printStackTrace(); } } log.debug("-----------END SCAN-------------"); }
From source file:brooklyn.entity.trait.StartableMethods.java
private static <T extends Entity> Iterable<T> filterStartableManagedEntities(Iterable<T> contenders) { return Iterables.filter(contenders, Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.isManaged())); }
From source file:com.khs.sherpa.processor.RestfulRequestProcessor.java
public String getEndpoint(HttpServletRequest request) { Map<String, Object> map = applicationContext.getEndpointTypes(); Collection<Method> methods = new HashSet<Method>(); for (Entry<String, Object> entry : map.entrySet()) { Collection<Method> m = Reflections.getAllMethods(entry.getValue().getClass(), Predicates.and(ReflectionUtils.withAnnotation(Action.class), SherpaPredicates.withActionMappingPattern(UrlUtil.getPath(request)))); methods.addAll(m);/*from w w w .ja v a2 s . c o m*/ } method = MethodUtil.validateHttpMethods(methods.toArray(new Method[] {}), request.getMethod()); if (method != null) { Class<?> type = method.getDeclaringClass(); if (type.isAnnotationPresent(Endpoint.class)) { if (StringUtils.isNotEmpty(type.getAnnotation(Endpoint.class).value())) { return type.getAnnotation(Endpoint.class).value(); } } return type.getSimpleName(); } throw new SherpaEndpointNotFoundException("no endpoint for url [" + UrlUtil.getPath(request) + "]"); }