List of usage examples for com.google.common.collect Sets union
public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2)
From source file:org.tensorics.core.tensor.Positions.java
/** * Constructs a position, whose coordinates are the union of the coordinates of the two individual positions. This * is only correctly defined, if the two given positions do not have any dimensional overlap (i.e. Any coordinate of * a certain type (class) is only present in either the left or the right position.) * * @param left the first position to use construct the union position * @param right the second position to construct the union position * @return a position, which contains the union of the coordinates of the two input positions. * @throws NullPointerException if one of the arguments is {@code null} * @throws IllegalArgumentException if the given aguments have an overlap of dimensions and therefor the union of * the position is not well defined *//*from w w w . j a v a 2 s. co m*/ public static Position union(Position left, Position right) { checkNotNull(left, "left position must not be null."); checkNotNull(right, "right position must not be null."); checkArgument(Sets.intersection(left.dimensionSet(), right.dimensionSet()).isEmpty(), "Positions have overlapping dimensions. It is not possible to create the union of them."); SetView<Object> coordinates = Sets.union(left.coordinates(), right.coordinates()); return Position.of(coordinates); }
From source file:springfox.documentation.spring.web.plugins.JacksonSerializerConvention.java
@Override public List<AlternateTypeRule> rules() { List<AlternateTypeRule> rules = newArrayList(); Reflections reflections = new Reflections(packagePrefix); Set<Class<?>> serialized = reflections.getTypesAnnotatedWith(JsonSerialize.class); Set<Class<?>> deserialized = reflections.getTypesAnnotatedWith(JsonDeserialize.class); for (Class<?> type : Sets.union(serialized, deserialized)) { Optional<Type> found = findAlternate(type); if (found.isPresent()) { rules.add(newRule(resolver.resolve(type), resolver.resolve(found.get()), getOrder())); rules.add(newRule(resolver.resolve(ResponseEntity.class, type), resolver.resolve(found.get()), getOrder()));//from ww w. ja v a 2 s .com } } return rules; }
From source file:com.google.devtools.build.lib.analysis.ArtifactsToOwnerLabels.java
public Set<Artifact> getArtifacts() { return Sets.union(artifactsOwnedOnlyByTheirLabels, artifactToMultipleOrDifferentOwnerLabels.keySet()); }
From source file:org.sosy_lab.cpachecker.cfa.ast.c.FileLocationCollectingVisitor.java
@Override public Set<FileLocation> visit(CPointerExpression pE) throws RuntimeException { return Sets.union(Collections.singleton(pE.getFileLocation()), pE.getOperand().accept(this)); }
From source file:org.apache.druid.firehose.kafka.KafkaEightFirehoseFactory.java
@Override public Firehose connect(final InputRowParser<ByteBuffer> firehoseParser, File temporaryDirectory) { Set<String> newDimExclus = Sets.union( firehoseParser.getParseSpec().getDimensionsSpec().getDimensionExclusions(), Sets.newHashSet("feed")); final InputRowParser<ByteBuffer> theParser = firehoseParser .withParseSpec(firehoseParser.getParseSpec().withDimensionsSpec( firehoseParser.getParseSpec().getDimensionsSpec().withDimensionExclusions(newDimExclus))); final ConsumerConnector connector = Consumer.createJavaConsumerConnector(new ConsumerConfig(consumerProps)); final Map<String, List<KafkaStream<byte[], byte[]>>> streams = connector .createMessageStreams(ImmutableMap.of(feed, 1)); final List<KafkaStream<byte[], byte[]>> streamList = streams.get(feed); if (streamList == null || streamList.size() != 1) { return null; }/*from ww w . j a va2 s. c om*/ final KafkaStream<byte[], byte[]> stream = streamList.get(0); final ConsumerIterator<byte[], byte[]> iter = stream.iterator(); return new Firehose() { Iterator<InputRow> nextIterator = Collections.emptyIterator(); @Override public boolean hasMore() { return nextIterator.hasNext() || iter.hasNext(); } @Nullable @Override public InputRow nextRow() { try { if (!nextIterator.hasNext()) { final byte[] message = iter.next().message(); if (message == null) { return null; } nextIterator = theParser.parseBatch(ByteBuffer.wrap(message)).iterator(); } return nextIterator.next(); } catch (InvalidMessageException e) { /* IF the CRC is caused within the wire transfer, this is not the best way to handel CRC. Probably it is better to shutdown the fireHose without commit and start it again. */ log.error(e, "Message failed its checksum and it is corrupt, will skip it"); return null; } } @Override public Runnable commit() { return new Runnable() { @Override public void run() { /* This is actually not going to do exactly what we want, cause it will be called asynchronously after the persist is complete. So, it's going to commit that it's processed more than was actually persisted. This is unfortunate, but good enough for now. Should revisit along with an upgrade of our Kafka version. */ log.info("committing offsets"); connector.commitOffsets(); } }; } @Override public void close() { connector.shutdown(); } }; }
From source file:no.ssb.jsonstat.v2.support.DatasetTableView.java
public DatasetTableView(Dataset dataset, Set<String> rows, Set<String> colums) { this.source = checkNotNull(dataset, "dataset cannot be null"); checkArgument(source.getDimension().keySet().equals(Sets.union(rows, colums)), "invalid row or column dimension names"); this.rows = ImmutableSet.copyOf(rows); this.columns = ImmutableSet.copyOf(colums); checkArgument(dataset.getId().size() == dataset.getSize().size()); checkArgument(dataset.getId().size() >= 2, "need at least two dimensions to " + "represent as a table"); ImmutableMap.Builder<String, Integer> factors = ImmutableMap.builder(); UnmodifiableIterator<Integer> sizeIterator = dataset.getSize().reverse().iterator(); UnmodifiableIterator<String> idIterator = dataset.getId().asList().reverse().iterator(); factors.put(idIterator.next(), 1);// w w w. jav a2 s . c o m //sizeIterator.next(); Integer size = 1; while (sizeIterator.hasNext() && idIterator.hasNext()) { size *= sizeIterator.next(); factors.put(idIterator.next(), size); } this.factors = factors.build(); ImmutableMap.Builder<String, ImmutableList<String>> dimensions = ImmutableMap.builder(); for (Map.Entry<String, Dimension> dimensionEntry : source.getDimension().entrySet()) { String dimensionName = dimensionEntry.getKey(); ImmutableList<String> dimensionIndex = dimensionEntry.getValue().getCategory().getIndex().asList(); dimensions.put(dimensionName, dimensionIndex); } this.dimensions = dimensions.build(); this.rowIndex = computeIndex(rows); this.columnIndex = computeIndex(colums); this.size = source.getSize().stream().reduce(1, (a, b) -> a * b); }
From source file:ddf.catalog.transformer.common.tika.MetacardCreator.java
/** * @param metadata the {@code Metadata} object containing the metadata relevant to the * metacard, must not be null * @param id the value for the {@link Metacard#ID} attribute that should be set in the * generated {@code Metacard}, may be null * @param metadataXml the XML for the {@link Metacard#METADATA} attribute that should be set in * the generated {@code Metacard}, may be null * @param typeName the name to give to the dynamically created {@link MetacardType} * @param extendedAttributes the extra attributes (on top of those already present in * {@link BasicTypes#BASIC_METACARD}) that will be available in the metacard * @return a new {@code Metacard}// w ww . j av a 2s . c o m */ public static Metacard createEnhancedMetacard(final Metadata metadata, final String id, final String metadataXml, final String typeName, final Set<AttributeDescriptor> extendedAttributes) { MetacardTypeImpl metacardType = new MetacardTypeImpl(typeName, Sets.union(BasicTypes.BASIC_METACARD.getAttributeDescriptors(), extendedAttributes)); return createMetacard(metadata, id, metadataXml, metacardType); }
From source file:org.apache.james.jmap.send.MailFactory.java
public Mail build(MetaDataWithContent message, Message jmapMessage) throws MessagingException, IOException { MailAddress sender = jmapMessage.getFrom().map(this::emailerToMailAddress) .orElseThrow(() -> new RuntimeException("Sender is mandatory")); Set<MailAddress> to = emailersToMailAddressSet(jmapMessage.getTo()); Set<MailAddress> cc = emailersToMailAddressSet(jmapMessage.getCc()); Set<MailAddress> bcc = emailersToMailAddressSet(jmapMessage.getBcc()); ImmutableSet<MailAddress> recipients = Sets.union(Sets.union(to, cc), bcc).immutableCopy(); return new MailImpl(jmapMessage.getId().serialize(), sender, recipients, message.getContent()); }
From source file:org.eclipse.milo.examples.server.KeyStoreLoader.java
KeyStoreLoader load(File baseDir) throws Exception { KeyStore keyStore = KeyStore.getInstance("PKCS12"); File serverKeyStore = baseDir.toPath().resolve("example-server.pfx").toFile(); logger.info("Loading KeyStore at {}", serverKeyStore); if (!serverKeyStore.exists()) { keyStore.load(null, PASSWORD);//from www .j a va 2s .c o m KeyPair keyPair = SelfSignedCertificateGenerator.generateRsaKeyPair(2048); String applicationUri = "urn:eclipse:milo:examples:server:" + UUID.randomUUID(); SelfSignedCertificateBuilder builder = new SelfSignedCertificateBuilder(keyPair) .setCommonName("Eclipse Milo Example Server").setOrganization("digitalpetri") .setOrganizationalUnit("dev").setLocalityName("Folsom").setStateName("CA").setCountryCode("US") .setApplicationUri(applicationUri); // Get as many hostnames and IP addresses as we can listed in the certificate. Set<String> hostnames = Sets.union(Sets.newHashSet(HostnameUtil.getHostname()), HostnameUtil.getHostnames("0.0.0.0", false)); for (String hostname : hostnames) { if (IP_ADDR_PATTERN.matcher(hostname).matches()) { builder.addIpAddress(hostname); } else { builder.addDnsName(hostname); } } X509Certificate certificate = builder.build(); keyStore.setKeyEntry(SERVER_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] { certificate }); keyStore.store(new FileOutputStream(serverKeyStore), PASSWORD); } else { keyStore.load(new FileInputStream(serverKeyStore), PASSWORD); } Key serverPrivateKey = keyStore.getKey(SERVER_ALIAS, PASSWORD); if (serverPrivateKey instanceof PrivateKey) { serverCertificate = (X509Certificate) keyStore.getCertificate(SERVER_ALIAS); serverCertificateChain = Arrays.stream(keyStore.getCertificateChain(SERVER_ALIAS)) .map(X509Certificate.class::cast).toArray(X509Certificate[]::new); PublicKey serverPublicKey = serverCertificate.getPublicKey(); serverKeyPair = new KeyPair(serverPublicKey, (PrivateKey) serverPrivateKey); } return this; }
From source file:com.google.enterprise.connector.pusher.ExtractedAclDocumentFilter.java
@Override public Set<String> getPropertyNames(Document source) throws RepositoryException { return Sets.union(source.getPropertyNames(), EXTRACTED_ACL_PROPS); }