Java Code Examples for com.google.common.collect.ImmutableSet.Builder#add()

The following examples show how to use com.google.common.collect.ImmutableSet.Builder#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardMessenger.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public Set<PluginMessageListenerRegistration> getIncomingChannelRegistrations(Plugin plugin, String channel) {
    if (plugin == null) {
        throw new IllegalArgumentException("Plugin cannot be null");
    }
    validateChannel(channel);

    synchronized (incomingLock) {
        Set<PluginMessageListenerRegistration> registrations = incomingByPlugin.get(plugin);

        if (registrations != null) {
            Builder<PluginMessageListenerRegistration> builder = ImmutableSet.builder();

            for (PluginMessageListenerRegistration registration : registrations) {
                if (registration.getChannel().equals(channel)) {
                    builder.add(registration);
                }
            }

            return builder.build();
        } else {
            return ImmutableSet.of();
        }
    }
}
 
Example 2
Source File: GssResourceGenerator.java    From gss.gwt with Apache License 2.0 6 votes vote down vote up
private Set<String> getPermutationsConditions(ResourceContext context,
    List<String> permutationAxes) {
  Builder<String> setBuilder = ImmutableSet.builder();
  PropertyOracle oracle = context.getGeneratorContext().getPropertyOracle();

  for (String permutationAxis : permutationAxes) {
    String propValue = null;
    try {
      SelectionProperty selProp = oracle.getSelectionProperty(null,
          permutationAxis);
      propValue = selProp.getCurrentValue();
    } catch (BadPropertyValueException e) {
      try {
        ConfigurationProperty confProp = oracle.getConfigurationProperty(permutationAxis);
        propValue = confProp.getValues().get(0);
      } catch (BadPropertyValueException e1) {
        e1.printStackTrace();
      }
    }

    if (propValue != null) {
      setBuilder.add(permutationAxis + ":" + propValue);
    }
  }
  return setBuilder.build();
}
 
Example 3
Source File: PacketAddOrUpdateTrain.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void fromBytes(ByteBuf b){
    trainID = b.readInt();

    int ids = b.readInt();
    PacketBuffer pb = new PacketBuffer(b);
    Builder<UUID> cartIDs = new ImmutableSet.Builder<>();
    for(int i = 0; i < ids; i++) {
        cartIDs.add(pb.readUniqueId());
    }
    this.cartIDs = cartIDs.build();

    int posCount = b.readInt();
    Builder<MCPos> positions = new ImmutableSet.Builder<>();
    for(int i = 0; i < posCount; i++) {
        positions.add(new MCPos(b));
    }
    this.positions = positions.build();
}
 
Example 4
Source File: CumulusNcluConfiguration.java    From batfish with Apache License 2.0 6 votes vote down vote up
private void convertLoopback() {
  Optional.ofNullable(_interfaces.get(LOOPBACK_INTERFACE_NAME))
      .ifPresent(iface -> populateLoInInterfacesToLoopback(iface, _loopback));

  org.batfish.datamodel.Interface newIface = createVIInterfaceForLo();

  if (!_loopback.getAddresses().isEmpty()) {
    newIface.setAddress(_loopback.getAddresses().get(0));
  }
  Builder<ConcreteInterfaceAddress> allAddresses = ImmutableSet.builder();
  allAddresses.addAll(_loopback.getAddresses());
  if (_loopback.getClagVxlanAnycastIp() != null) {
    // Just assume CLAG is correctly configured and comes up
    allAddresses.add(
        ConcreteInterfaceAddress.create(
            _loopback.getClagVxlanAnycastIp(), Prefix.MAX_PREFIX_LENGTH));
  }
  newIface.setAllAddresses(allAddresses.build());
  _c.getAllInterfaces().put(LOOPBACK_INTERFACE_NAME, newIface);
}
 
Example 5
Source File: SupportedOptions.java    From Mixin with MIT License 6 votes vote down vote up
/**
 * Return all supported options
 */
public static Set<String> getAllOptions() {
    Builder<String> options = ImmutableSet.<String>builder();
    options.add(
        SupportedOptions.TOKENS,
        SupportedOptions.OUT_REFMAP_FILE,
        SupportedOptions.DISABLE_TARGET_VALIDATOR,
        SupportedOptions.DISABLE_TARGET_EXPORT,
        SupportedOptions.DISABLE_OVERWRITE_CHECKER,
        SupportedOptions.OVERWRITE_ERROR_LEVEL,
        SupportedOptions.DEFAULT_OBFUSCATION_ENV,
        SupportedOptions.DEPENDENCY_TARGETS_FILE,
        SupportedOptions.MAPPING_TYPES,
        SupportedOptions.PLUGIN_VERSION
    );
    options.addAll(
        ObfuscationServices.getInstance().getSupportedOptions()
    );
    return options.build();
}
 
Example 6
Source File: SearchServiceTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public Matcher<Map<ParamsProperty, Object>> matchesSearchResult(final String query,
    final WaveId waveId, final String title, final ParticipantId author,
    final Set<ParticipantId> participants, final int unreadCount, final int blipCount) {
  return new BaseMatcher<Map<ParamsProperty, Object>>() {
    @SuppressWarnings("unchecked")
    @Override
    public boolean matches(Object item) {
      Map<ParamsProperty, Object> map = (Map<ParamsProperty, Object>) item;
      assertTrue(map.containsKey(ParamsProperty.SEARCH_RESULTS));

      Object resultsObj = map.get(ParamsProperty.SEARCH_RESULTS);
      SearchResult results = (SearchResult) resultsObj;

      assertEquals(query, results.getQuery());
      assertEquals(1, results.getNumResults());

      Digest digest = results.getDigests().get(0);
      assertEquals(title, digest.getTitle());
      assertEquals(ApiIdSerializer.instance().serialiseWaveId(waveId), digest.getWaveId());

      Builder<ParticipantId> participantIds = ImmutableSet.builder();
      for (String name : digest.getParticipants()) {
        participantIds.add(ParticipantId.ofUnsafe(name));
      }
      assertEquals(participants, participantIds.build());

      assertEquals(unreadCount, digest.getUnreadCount());
      assertEquals(blipCount, digest.getBlipCount());
      return true;
    }

    @Override
    public void describeTo(Description description) {
      description.appendText("Check digests match expected data");
    }
  };
}
 
Example 7
Source File: JPAResource.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Set<ConstraintReportId> constraintReports() {
	Set<String> currentFailures=null;
	synchronized(this) {
		currentFailures=ImmutableSet.copyOf(this.failures);
	}
	Builder<ConstraintReportId> builder=ImmutableSet.builder();
	for(String failure:currentFailures) {
		builder.add(ConstraintReportId.create(this.id,failure));
	}
	return builder.build();
}
 
Example 8
Source File: KeyStatementSupport.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ImmutableSet<QName> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
    final Builder<QName> builder = ImmutableSet.builder();
    int tokens = 0;
    for (String keyToken : LIST_KEY_SPLITTER.split(value)) {
        builder.add(StmtContextUtils.parseNodeIdentifier(ctx, keyToken));
        tokens++;
    }

    // Throws NPE on nulls, retains first inserted value, cannot be modified
    final ImmutableSet<QName> ret = builder.build();
    SourceException.throwIf(ret.size() != tokens, ctx.getStatementSourceReference(),
            "Key argument '%s' contains duplicates", value);
    return ret;
}
 
Example 9
Source File: BitsSerializationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static ImmutableSet<String> fillBits(final int size) {
    final Builder<String> builder = ImmutableSet.builderWithExpectedSize(size);
    for (int i = 0; i < size; ++i) {
        builder.add(Integer.toHexString(i));
    }
    final ImmutableSet<String> ret = builder.build();
    Assert.assertEquals(size, ret.size());
    return ret;
}
 
Example 10
Source File: AbstractOffsetMap.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public final T with(final K key) {
    // TODO: we could make this faster if we had an array-backed Set and requiring
    //       the caller to give us the result of offsetOf() -- as that indicates
    //       where to insert the new routerId while maintaining the sorted nature
    //       of the array
    final Builder<K> builder = ImmutableSet.builderWithExpectedSize(size() + 1);
    builder.add(keys);
    builder.add(key);
    return instanceForKeys(builder.build());
}
 
Example 11
Source File: Directories.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public TrueFilesSizeVisitor()
{
    super();
    Builder<String> builder = ImmutableSet.builder();
    for (File file: sstableLister().listFiles())
        builder.add(file.getName());
    alive = builder.build();
}
 
Example 12
Source File: DefaultProjectFilesystemFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
private static void addPathMatcherRelativeToRepo(
    Path root, Builder<PathMatcher> builder, Path pathToAdd) {
  if (!pathToAdd.isAbsolute()
      || pathToAdd.normalize().startsWith(root.toAbsolutePath().normalize())) {
    if (pathToAdd.isAbsolute()) {
      pathToAdd = root.relativize(pathToAdd);
    }
    builder.add(RecursiveFileMatcher.of(RelPath.of(pathToAdd)));
  }
}
 
Example 13
Source File: GetAnnotationCommandParser.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void consumeKeys(ImapRequestLineReader requestReader, GetAnnotationRequest.Builder builder) throws DecodingException {
    Builder<MailboxAnnotationKey> keys = ImmutableSet.builder();

    do {
        keys.add(new MailboxAnnotationKey(requestReader.atom()));
    } while (requestReader.nextWordChar() != ')');

    builder.keys(keys.build());

    requestReader.consumeChar(')');
    requestReader.eol();
}
 
Example 14
Source File: SymbolProto.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public SymbolProto(final Class clazz, final boolean hasSequence, final boolean hasArgs, final int kind,
		final boolean doesNotHaveScope, final FacetProto[] possibleFacets, final String omissible,
		final String[] contextKeywords, final int[] parentKinds, final boolean isRemoteContext,
		final boolean isUniqueInContext, final boolean nameUniqueInContext, final ISymbolConstructor constr,
		final IValidator validator, final SymbolSerializer serializer, final String name, final String plugin) {
	super(name, clazz, plugin);
	factory = DescriptionFactory.getFactory(kind);
	this.validator = validator;
	this.serializer = serializer;
	constructor = constr;
	this.isRemoteContext = isRemoteContext;
	this.hasSequence = hasSequence;
	this.isPrimitive = IKeyword.PRIMITIVE.equals(name);
	this.hasArgs = hasArgs;
	this.omissibleFacet = omissible;
	this.isUniqueInContext = isUniqueInContext;
	this.kind = kind;
	this.isVar = ISymbolKind.Variable.KINDS.contains(kind);
	this.hasScope = !doesNotHaveScope;
	if (possibleFacets != null) {
		final Builder<String> builder = ImmutableSet.builder();
		this.possibleFacets = GamaMapFactory.createUnordered();
		for (final FacetProto f : possibleFacets) {
			this.possibleFacets.put(f.name, f);
			f.setOwner(getTitle());
			if (!f.optional) {
				builder.add(f.name);
			}
		}
		mandatoryFacets = builder.build();
	} else {
		this.possibleFacets = null;
		mandatoryFacets = null;
	}
	this.contextKeywords = ImmutableSet.copyOf(contextKeywords);
	Arrays.fill(this.contextKinds, false);
	for (final int i : parentKinds) {
		contextKinds[i] = true;
	}
}
 
Example 15
Source File: CraftEnderDragon.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public Set<ComplexEntityPart> getParts() {
    Builder<ComplexEntityPart> builder = ImmutableSet.builder();

    for (EntityDragonPart part : getHandle().dragonPartArray) {
        builder.add((ComplexEntityPart) part.getBukkitEntity());
    }

    return builder.build();
}
 
Example 16
Source File: JdbcAssert.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static Set<String> toStringSet(ResultSet resultSet) throws SQLException {
  Builder<String> builder = ImmutableSet.builder();
  final List<Ord<String>> columns = columnLabels(resultSet);
  while (resultSet.next()) {
    StringBuilder buf = new StringBuilder();
    for (Ord<String> column : columns) {
      buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i));
    }
    builder.add(buf.toString());
    buf.setLength(0);
  }
  return builder.build();
}
 
Example 17
Source File: ReflectiveDaoAdapter.java    From microorm with Apache License 2.0 5 votes vote down vote up
private static <T> ImmutableSet<T> findDuplicates(T[] array) {
  final Builder<T> result = ImmutableSet.builder();
  final Set<T> uniques = Sets.newHashSet();

  for (T element : array) {
    if (!uniques.add(element)) {
      result.add(element);
    }
  }

  return result.build();
}
 
Example 18
Source File: LinkageMonitor.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a message on {@code snapshotSymbolProblems} that do not exist in {@code
 * baselineProblems}.
 */
@VisibleForTesting
static String messageForNewErrors(
    ImmutableSetMultimap<SymbolProblem, ClassFile> snapshotSymbolProblems,
    Set<SymbolProblem> baselineProblems,
    ClassPathResult classPathResult) {
  Set<SymbolProblem> newProblems =
      Sets.difference(snapshotSymbolProblems.keySet(), baselineProblems);
  StringBuilder message =
      new StringBuilder("Newly introduced problem" + (newProblems.size() > 1 ? "s" : "") + ":\n");
  Builder<ClassPathEntry> problematicJars = ImmutableSet.builder();
  for (SymbolProblem problem : newProblems) {
    message.append(problem + "\n");

    // This is null for ClassNotFound error.
    ClassFile containingClass = problem.getContainingClass();
    if (containingClass != null) {
      problematicJars.add(containingClass.getClassPathEntry());
    }

    for (ClassFile classFile : snapshotSymbolProblems.get(problem)) {
      message.append(
          String.format(
              "  referenced from %s (%s)\n",
              classFile.getBinaryName(), classFile.getClassPathEntry()));
      problematicJars.add(classFile.getClassPathEntry());
    }
  }

  message.append("\n");
  message.append(classPathResult.formatDependencyPaths(problematicJars.build()));

  return message.toString();
}
 
Example 19
Source File: CraftEnderDragon.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public Set<ComplexEntityPart> getParts() {
    Builder<ComplexEntityPart> builder = ImmutableSet.builder();

    for (MultiPartEntityPart part : getHandle().dragonPartArray) {
        builder.add((ComplexEntityPart) part.getBukkitEntity());
    }

    return builder.build();
}
 
Example 20
Source File: ImmutableNegotiationResult.java    From ldp4j with Apache License 2.0 4 votes vote down vote up
private static <T> void addEntityIfPresent(Builder<T> builder, T entity) {
	if(entity!=null) {
		builder.add(entity);
	}
}