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:org.eclipse.xtext.formatting2.regionaccess.internal.AbstractSemanticRegionsFinder.java
@Override public List<Pair<ISemanticRegion, ISemanticRegion>> keywordPairs(Keyword kw1, Keyword kw2) { Preconditions.checkNotNull(kw1);// w w w. ja v a 2 s .co m Preconditions.checkNotNull(kw2); Preconditions.checkArgument(kw1 != kw2); Predicate<ISemanticRegion> p1 = createPredicate(kw1); Predicate<ISemanticRegion> p2 = createPredicate(kw2); List<ISemanticRegion> all = findAll(Predicates.or(p1, p2)); Builder<Pair<ISemanticRegion, ISemanticRegion>> result = ImmutableList.builder(); LinkedList<ISemanticRegion> stack = new LinkedList<ISemanticRegion>(); for (ISemanticRegion region : all) { if (p1.apply(region)) stack.push(region); else if (!stack.isEmpty()) result.add(Pair.of(stack.pop(), region)); } return result.build(); }
From source file:io.druid.client.HttpServerInventoryView.java
private void runSegmentCallbacks(final Function<SegmentCallback, CallbackAction> fn) { for (final Map.Entry<SegmentCallback, Executor> entry : segmentCallbacks.entrySet()) { entry.getValue().execute(new Runnable() { @Override/* ww w. j a va 2 s . com*/ public void run() { if (CallbackAction.UNREGISTER == fn.apply(entry.getKey())) { segmentCallbacks.remove(entry.getKey()); if (segmentPredicates.remove(entry.getKey()) != null) { finalPredicate = Predicates.or(defaultFilter, Predicates.or(segmentPredicates.values())); } } } }); } }
From source file:org.eclipse.xtext.formatting2.regionaccess.internal.AbstractSemanticRegionsFinder.java
@Override public List<Pair<ISemanticRegion, ISemanticRegion>> keywordPairs(String kw1, String kw2) { Preconditions.checkNotNull(kw1);/*w w w .j av a 2 s . c o m*/ Preconditions.checkNotNull(kw2); Preconditions.checkArgument(!kw1.equals(kw2)); Predicate<ISemanticRegion> p1 = new KeywordPredicate(kw1); Predicate<ISemanticRegion> p2 = new KeywordPredicate(kw2); List<ISemanticRegion> all = findAll(Predicates.or(p1, p2)); Builder<Pair<ISemanticRegion, ISemanticRegion>> result = ImmutableList.builder(); LinkedList<ISemanticRegion> stack = new LinkedList<ISemanticRegion>(); for (ISemanticRegion region : all) { if (p1.apply(region)) stack.push(region); else { AbstractRule regionRule = GrammarUtil.containingRule(region.getGrammarElement()); while (!stack.isEmpty()) { ISemanticRegion candidate = stack.pop(); if (region.getSemanticElement() == candidate.getSemanticElement()) { AbstractRule candidateRule = GrammarUtil.containingRule(candidate.getGrammarElement()); if (regionRule == candidateRule) { result.add(Pair.of(candidate, region)); break; } } } } } return result.build(); }
From source file:clocker.docker.entity.DockerInfrastructureImpl.java
@Override public void init() { String version = config().get(DOCKER_VERSION); if (VersionComparator.getInstance().compare("1.9", version) > 1) { throw new IllegalStateException("Requires libnetwork capable Docker > 1.9"); }//w w w. j a va 2 s .c o m LOG.info("Starting Docker infrastructure id {}", getId()); registerLocationResolver(); super.init(); int initialSize = config().get(DOCKER_HOST_CLUSTER_MIN_SIZE); Map<String, String> runtimeFiles = ImmutableMap.of(); if (!config().get(DOCKER_GENERATE_TLS_CERTIFICATES)) { runtimeFiles = ImmutableMap.<String, String>builder() .put(config().get(DOCKER_SERVER_CERTIFICATE_PATH), "cert.pem") .put(config().get(DOCKER_SERVER_KEY_PATH), "key.pem") .put(config().get(DOCKER_CA_CERTIFICATE_PATH), "ca.pem").build(); } // Try and set the registry URL if configured and not starting local registry if (!config().get(DOCKER_SHOULD_START_REGISTRY)) { ConfigToAttributes.apply(this, DOCKER_IMAGE_REGISTRY_URL); } try { String caCertPath = config().get(DOCKER_CA_CERTIFICATE_PATH); try (InputStream caCert = ResourceUtils.create().getResourceFromUrl(caCertPath)) { X509Certificate certificate = (X509Certificate) CertificateFactory.getInstance("X.509") .generateCertificate(caCert); KeyStore store = SecureKeys.newKeyStore(); store.setCertificateEntry("ca", certificate); X509TrustManager trustManager = SecureKeys.getTrustManager(certificate); // TODO incorporate this trust manager into jclouds SSL context } } catch (IOException | KeyStoreException | CertificateException e) { Exceptions.propagate(e); } EntitySpec<?> dockerHostSpec = EntitySpec.create(config().get(DOCKER_HOST_SPEC)); dockerHostSpec.configure(DockerHost.DOCKER_INFRASTRUCTURE, this) .configure(DockerHost.RUNTIME_FILES, runtimeFiles) .configure(SoftwareProcess.CHILDREN_STARTABLE_MODE, ChildStartableMode.BACKGROUND_LATE); String dockerVersion = config().get(DOCKER_VERSION); if (Strings.isNonBlank(dockerVersion)) { dockerHostSpec.configure(SoftwareProcess.SUGGESTED_VERSION, dockerVersion); } if (Boolean.TRUE.equals(config().get(SdnAttributes.SDN_DEBUG))) { dockerHostSpec.configure(DockerAttributes.DOCKERFILE_URL, DockerUtils.UBUNTU_NETWORKING_DOCKERFILE); } sensors().set(DOCKER_HOST_SPEC, dockerHostSpec); DynamicCluster hosts = addChild( EntitySpec.create(DynamicCluster.class).configure(Cluster.INITIAL_SIZE, initialSize) .configure(DynamicCluster.QUARANTINE_FAILED_ENTITIES, true) .configure(DynamicCluster.MEMBER_SPEC, dockerHostSpec) .configure(DynamicCluster.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .configure(DynamicCluster.UP_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .configure(BrooklynCampConstants.PLAN_ID, "docker-hosts").displayName("Docker Hosts")); EntitySpec<?> etcdNodeSpec = EntitySpec.create(config().get(EtcdCluster.ETCD_NODE_SPEC)); String etcdVersion = config().get(ETCD_VERSION); if (Strings.isNonBlank(etcdVersion)) { etcdNodeSpec.configure(SoftwareProcess.SUGGESTED_VERSION, etcdVersion); } sensors().set(EtcdCluster.ETCD_NODE_SPEC, etcdNodeSpec); EtcdCluster etcd = addChild(EntitySpec.create(EtcdCluster.class).configure(Cluster.INITIAL_SIZE, 0) .configure(EtcdCluster.ETCD_NODE_SPEC, etcdNodeSpec).configure(EtcdCluster.CLUSTER_NAME, "docker") .configure(EtcdCluster.CLUSTER_TOKEN, "etcd-docker") .configure(DynamicCluster.QUARANTINE_FAILED_ENTITIES, true) .configure(DynamicCluster.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .configure(DynamicCluster.UP_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .displayName("Etcd Cluster")); sensors().set(ETCD_CLUSTER, etcd); DynamicGroup fabric = addChild(EntitySpec.create(DynamicGroup.class) .configure(DynamicGroup.ENTITY_FILTER, Predicates.and(Predicates.instanceOf(DockerContainer.class), EntityPredicates.attributeEqualTo(DockerContainer.DOCKER_INFRASTRUCTURE, this))) .displayName("All Docker Containers")); if (config().get(SDN_ENABLE) && config().get(SDN_PROVIDER_SPEC) != null) { EntitySpec entitySpec = EntitySpec.create(config().get(SDN_PROVIDER_SPEC)); entitySpec.configure(DockerAttributes.DOCKER_INFRASTRUCTURE, this); Entity sdn = addChild(entitySpec); sensors().set(SDN_PROVIDER, sdn); } sensors().set(DOCKER_HOST_CLUSTER, hosts); sensors().set(DOCKER_CONTAINER_FABRIC, fabric); hosts.enrichers().add(Enrichers.builder().aggregating(DockerHost.CPU_USAGE).computingAverage().fromMembers() .publishing(MachineAttributes.AVERAGE_CPU_USAGE).valueToReportIfNoSensors(0d).build()); hosts.enrichers().add(Enrichers.builder().aggregating(DOCKER_CONTAINER_COUNT).computingSum().fromMembers() .publishing(DOCKER_CONTAINER_COUNT).build()); enrichers().add(Enrichers.builder().propagating(DOCKER_CONTAINER_COUNT, MachineAttributes.AVERAGE_CPU_USAGE) .from(hosts).build()); enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(DynamicCluster.GROUP_SIZE, DOCKER_HOST_COUNT)).from(hosts).build()); Integer headroom = config().get(ContainerHeadroomEnricher.CONTAINER_HEADROOM); Double headroomPercent = config().get(ContainerHeadroomEnricher.CONTAINER_HEADROOM_PERCENTAGE); if ((headroom != null && headroom > 0) || (headroomPercent != null && headroomPercent > 0d)) { enrichers().add(EnricherSpec.create(ContainerHeadroomEnricher.class) .configure(ContainerHeadroomEnricher.CONTAINER_HEADROOM, headroom) .configure(ContainerHeadroomEnricher.CONTAINER_HEADROOM_PERCENTAGE, headroomPercent)); hosts.enrichers() .add(Enrichers.builder() .propagating(ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_COLD, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_HOT, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_OK) .from(this).build()); hosts.policies() .add(PolicySpec.create(AutoScalerPolicy.class) .configure(AutoScalerPolicy.POOL_COLD_SENSOR, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_COLD) .configure(AutoScalerPolicy.POOL_HOT_SENSOR, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_HOT) .configure(AutoScalerPolicy.POOL_OK_SENSOR, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_OK) .configure(AutoScalerPolicy.MIN_POOL_SIZE, initialSize) .configure(AutoScalerPolicy.RESIZE_UP_STABILIZATION_DELAY, Duration.THIRTY_SECONDS) .configure(AutoScalerPolicy.RESIZE_DOWN_STABILIZATION_DELAY, Duration.FIVE_MINUTES) .displayName("Headroom Auto Scaler")); } sensors().set(Attributes.MAIN_URI, URI.create("/clocker")); // Override the health-check: just interested in the docker infrastructure/SDN, rather than // the groups that show the apps. Entity sdn = sensors().get(SDN_PROVIDER); enrichers() .add(EnricherSpec.create(ComputeServiceIndicatorsFromChildrenAndMembers.class) .uniqueTag(ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.FROM_CHILDREN, true) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER, Predicates.or( Predicates.<Entity>equalTo(hosts), (sdn == null ? Predicates.<Entity>alwaysFalse() : Predicates.equalTo(sdn))))); }
From source file:com.google.errorprone.scanner.BuiltInCheckerSuppliers.java
/** * Returns a {@link ScannerSupplier} with the {@link BugChecker}s that are in the ENABLED lists. *///ww w .j a v a2s. c o m public static ScannerSupplier defaultChecks() { return allChecks().filter(Predicates.or(Predicates.in(ENABLED_ERRORS), Predicates.in(ENABLED_WARNINGS))); }
From source file:brooklyn.networking.sdn.mesos.CalicoModuleImpl.java
@Override public void provisionNetwork(VirtualNetwork network) { String networkId = network.sensors().get(VirtualNetwork.NETWORK_ID); Cidr subnetCidr = SdnUtils.provisionNetwork(this, network); boolean ipip = config().get(CalicoModule.USE_IPIP); boolean nat = config().get(CalicoModule.USE_NAT); String addPool = String.format("calicoctl pool add %s %s %s", subnetCidr, ipip ? "--ipip" : "", nat ? "--nat-outgoing" : ""); MesosSlave slave = (MesosSlave) getMesosCluster().sensors().get(MesosCluster.MESOS_SLAVES).getMembers() .iterator().next();/* ww w . ja v a2s .c om*/ execCalicoCommand(slave, addPool); // Create a DynamicGroup with all attached entities EntitySpec<DynamicGroup> networkSpec = EntitySpec.create(DynamicGroup.class) .configure(DynamicGroup.ENTITY_FILTER, Predicates.and( Predicates.not(Predicates.or(Predicates.instanceOf(MarathonTask.class), Predicates.instanceOf(DelegateEntity.class))), MesosUtils.sameCluster(getMesosCluster()), SdnUtils.attachedToNetwork(networkId))) .displayName(network.getDisplayName()); DynamicGroup subnet = sensors().get(SDN_APPLICATIONS).addMemberChild(networkSpec); subnet.sensors().set(VirtualNetwork.NETWORK_ID, networkId); network.sensors().set(VirtualNetwork.NETWORKED_APPLICATIONS, subnet); sensors().get(SDN_NETWORKS).addMember(network); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.outline.QuickOutlineControl.java
/** * Creates the outline's tree viewer.// ww w.j a v a 2 s . c o m * * @param parent * parent composite. */ protected void createTreeViewer(Composite parent) { filteredTree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter(), true); treeViewer = filteredTree.getViewer(); final Tree tree = treeViewer.getTree(); tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (event.character == SWT.ESC) { dispose(); } if (event.keyCode == 0x0D) { gotoSelectedElement(); } if (event.keyCode == SWT.ARROW_DOWN) { tree.setFocus(); } if (event.keyCode == SWT.ARROW_UP) { tree.setFocus(); } if (event.character == 0x1B) { dispose(); } } }); tree.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { // do nothing } public void widgetDefaultSelected(SelectionEvent e) { gotoSelectedElement(); } }); treeViewer.setContentProvider(new FilteredTreeContentProvider(getAdapterFactory(), Predicates.or(Predicates.instanceOf(DDiagramElement.class), Predicates.instanceOf(AbstractDDiagramElementLabelItemProvider.class)))); treeViewer.setLabelProvider(new OutlineLabelProvider()); // We want to remove everything that's not "top level elements" from the // outline view treeViewer.addFilter(new ViewerFilter() { /** * {@inheritDoc} * * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, * java.lang.Object, java.lang.Object) */ @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return element instanceof DDiagramElement; } }); }
From source file:com.xebialabs.deployit.ci.server.DeployitDescriptorRegistryImpl.java
private Iterable<Descriptor> getAllDeployableDescriptors() { LOCK.enter();/*from www. j a v a 2 s . c om*/ try { if (allDeployableDescriptors == null) { Predicate<Descriptor> predicate = Predicates.or( new DescriptorPredicate(typeForName(UDM_DEPLOYABLE)), new DescriptorPredicate(typeForName(UDM_EMBEDDED_DEPLOYABLE))); allDeployableDescriptors = FluentIterable.from(getDescriptors()).filter(predicate); } } finally { LOCK.leave(); } return allDeployableDescriptors; }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeISequenceEventsSemanticOrderingOperation.java
private Set<EventEnd> selectEndsToIgnore(ISequenceEvent ise, List<EventEnd> endsBySemanticOrder, final List<EventEnd> iseEnds, final List<EventEnd> compoundEnds) { final Iterable<ISequenceEvent> movedElements = Iterables.filter(allElementsToReorder, Predicates.not(Predicates.in(reordered))); final Set<EObject> semanticLinked = Sets.newHashSet(Iterables.filter( Iterables.transform(movedElements, ISequenceElement.SEMANTIC_TARGET), Predicates.notNull())); final Predicate<EObject> isLinkedSubEventEnd = new Predicate<EObject>() { @Override//from w w w. j a v a2s.com public boolean apply(EObject input) { return semanticLinked.contains(input); } }; final Set<EObject> semanticDescendants = Sets .newHashSet(Iterables.filter(Iterables.transform(new ISequenceEventQuery(ise).getAllDescendants(), ISequenceElement.SEMANTIC_TARGET), Predicates.notNull())); final Predicate<EObject> isSemanticSubEventEnd = new Predicate<EObject>() { @Override public boolean apply(EObject input) { return semanticDescendants.contains(input); } }; Predicate<EventEnd> toIgnore = new Predicate<EventEnd>() { @Override public boolean apply(EventEnd input) { return !iseEnds.contains(input) && (Iterables.any(EventEndHelper.getSemanticEvents(input), Predicates.or(isSemanticSubEventEnd, isLinkedSubEventEnd)) || compoundEnds.contains(input)); } }; HashSet<EventEnd> newHashSet = Sets.newHashSet(Iterables.filter(endsBySemanticOrder, toIgnore)); return newHashSet; }
From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java
/** * Tests whether the dDiagramElement is explicitly or indirectly folded. * //from w ww. jav a 2 s. co m * @return <code>true</code> if the dDiagramElement is folded (explicitly or * indirectly). */ public boolean isFolded() { return Iterables.any(element.getGraphicalFilters(), Predicates .or(Predicates.instanceOf(FoldingPointFilter.class), Predicates.instanceOf(FoldingFilter.class))); }