Example usage for com.google.common.collect Sets immutableEnumSet

List of usage examples for com.google.common.collect Sets immutableEnumSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets immutableEnumSet.

Prototype


@GwtCompatible(serializable = true)
public static <E extends Enum<E>> ImmutableSet<E> immutableEnumSet(Iterable<E> elements) 

Source Link

Document

Returns an immutable set instance containing the given enum elements.

Usage

From source file:com.android.build.gradle.internal.pipeline.IntermediateFolderUtils.java

private static void parseScopeLevelFolders(@NonNull File rootFolder, @NonNull Set<ContentType> types,
        @NonNull Set<Scope> requiredScopes, @NonNull InputGenerator generator) {
    File[] files = rootFolder.listFiles(File::isDirectory);

    if (files != null && files.length > 0) {
        for (File file : files) {
            Set<Scope> scopes = stringToScopes(file.getName());
            if (scopes != null) {
                // we need up to the requiredScopes, but no more.
                // content that only contains unwanted Scope can be safely dropped, however
                // content that is both in and out of Scope will trigger a runtime error.
                // check these are the scope we want, and only pass down scopes we care about.
                Set<Scope> limitedScopes = Sets.newHashSetWithExpectedSize(requiredScopes.size());
                boolean foundUnwanted = false;
                for (Scope scope : scopes) {
                    if (requiredScopes.contains(scope)) {
                        limitedScopes.add(scope);
                    } else {
                        foundUnwanted = true;
                    }//from  w  w w  .  j a  v  a2 s .  com
                }
                if (!limitedScopes.isEmpty()) {
                    if (foundUnwanted) {
                        throw new RuntimeException("error");
                    }
                    parseContentLevelFolders(file, types, Sets.immutableEnumSet(limitedScopes), generator);
                }
            }
        }
    }
}

From source file:com.google.template.soy.jssrc.internal.JsType.java

private JsType(Builder builder) {
    // Sort for determinism, order doesn't matter.
    this.typeExpressions = builder.typeExpressions.build();
    checkArgument(!typeExpressions.isEmpty());
    this.coercionStrategies = Sets.immutableEnumSet(builder.coercionStrategies);
    this.extraRequires = builder.extraRequires.build();
    this.predicate = checkNotNull(builder.predicate);
}

From source file:com.android.build.gradle.internal.pipeline.IntermediateFolderUtils.java

@Nullable
private static Set<Scope> stringToScopes(String folderName) {
    int value;//from  w w  w .ja v  a 2s . c  o m
    try {
        value = Integer.parseInt(folderName, 16);
    } catch (NumberFormatException e) {
        return null;
    }

    Set<Scope> scopes = Sets.newHashSet();

    for (Scope scope : Scope.values()) {
        if ((scope.getValue() & value) != 0) {
            scopes.add(scope);
        }
    }

    if (scopes.isEmpty()) {
        return null;
    }

    return Sets.immutableEnumSet(scopes);
}

From source file:org.trnltk.model.morpheme.MorphemeContainer.java

private ImmutableSet<LexemeAttribute> findLexemeAttributes() {
    // return lexeme attributes to consider while parsing
    // -> if there is no transition or if there are only blank transitions, then return the attributes of the lexeme
    // ...... since nothing changed since lexeme in terms of phonetics
    // -> otherwise, return no lexeme attributes since all the attributes are invalid because of added suffix transitions
    // -> except when last state is Verb and last transition is derivational.
    // ...... then voicing is not applicable. (e.g. yurut+uyor != yuruduyor)
    // ...... then return NoVoicing

    if (CollectionUtils.isEmpty(this.suffixTransitions))
        return Sets.immutableEnumSet(this.root.getLexeme().getAttributes());

    final SuffixTransition lastNonBlankSuffixTransition = this.getLastNonBlankSuffixTransition();
    if (lastNonBlankSuffixTransition == null) {
        return Sets.immutableEnumSet(this.root.getLexeme().getAttributes());
    } else {/*from   w  w  w  .j  a  v  a 2s  . co  m*/
        //TODO:!!!!  necessary for the case yurutemeyecekmisim !-> yurudemeyecekmisim
        final SuffixGraphState lastState = this.getLastState();
        final boolean lastStateIsVerb = PrimaryPos.Verb.equals(lastState.getPrimaryPos());

        if (!lastStateIsVerb) {
            return ImmutableSet.of();
        } else {
            final boolean lastStateIsDerivational = SuffixGraphStateType.DERIVATIONAL
                    .equals(lastState.getType());
            final boolean lastSuffixIsBlank = StringUtils
                    .isBlank(this.getLastSuffixTransition().getSuffixFormApplication().getActualSuffixForm());

            if (lastStateIsDerivational || lastSuffixIsBlank)
                return ImmutableSet.of(LexemeAttribute.NoVoicing);
            else
                return ImmutableSet.of();
        }
    }

}

From source file:org.trnltk.model.morpheme.MorphemeContainer.java

private ImmutableSet<PhoneticAttribute> findPhoneticAttributes() {
    // if there are no transitions or no non-blank transitions or only non-alphanumeric transitions
    // ...then use the phonetic attributes of the root (no need to calculate them using LexemeAttributes and root sequence)
    // otherwise, calculate the phonetic attributes from the sequence built so far and the lexeme attributes of the container
    if (this.hasTransitions()) {
        final String suffixSoFar = this.surfaceSoFar.substring(this.root.getSequence().length());
        if (StringUtils.isBlank(suffixSoFar) || !StringUtils.isAlphanumeric(suffixSoFar))
            return Sets.immutableEnumSet(this.root.getPhoneticAttributes());
        else/*from w  w w . j a  v  a2  s  . c o m*/
            return Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(this.getSurfaceSoFar(),
                    this.getLexemeAttributes()));
    } else {
        return Sets.immutableEnumSet(root.getPhoneticAttributes());
    }
}

From source file:com.linecorp.armeria.server.thrift.THttpService.java

THttpService(Service<ThriftCall, ThriftReply> delegate, SerializationFormat defaultSerializationFormat,
        Set<SerializationFormat> allowedSerializationFormats) {

    requireNonNull(delegate, "delegate");
    requireNonNull(defaultSerializationFormat, "defaultSerializationFormat");
    requireNonNull(allowedSerializationFormats, "allowedSerializationFormats");

    this.delegate = delegate;
    thriftService = findThriftService(delegate);

    this.defaultSerializationFormat = defaultSerializationFormat;
    this.allowedSerializationFormats = Sets.immutableEnumSet(allowedSerializationFormats);
}

From source file:org.jasig.portal.events.aggr.JpaBaseAggregationDao.java

@Override
public final Set<AggregationInterval> getAggregationIntervals() {
    final TypedQuery<AggregationInterval> query = this.createQuery(this.findAggregationIntervalsQuery);
    return Sets.immutableEnumSet(query.getResultList());
}

From source file:org.apache.drill.exec.rpc.user.UserClient.java

@Override
protected List<String> validateHandshake(BitToUserHandshake inbound) throws RpcException {
    //    logger.debug("Handling handshake from bit to user. {}", inbound);
    List<String> serverAuthMechanisms = null;

    if (inbound.hasServerInfos()) {
        serverInfos = inbound.getServerInfos();
    }//from  w  w  w. jav  a2  s  .c om
    supportedMethods = Sets.immutableEnumSet(inbound.getSupportedMethodsList());

    switch (inbound.getStatus()) {
    case SUCCESS:
        break;
    case AUTH_REQUIRED:
        serverAuthMechanisms = ImmutableList.copyOf(inbound.getAuthenticationMechanismsList());
        setAuthComplete(false);
        connection.setEncryption(inbound.hasEncrypted() && inbound.getEncrypted());

        if (inbound.hasMaxWrappedSize()) {
            connection.setMaxWrappedSize(inbound.getMaxWrappedSize());
        }
        logger.trace(
                String.format("Server requires authentication with encryption context %s before proceeding.",
                        connection.getEncryptionCtxtString()));
        break;
    case AUTH_FAILED:
    case RPC_VERSION_MISMATCH:
    case UNKNOWN_FAILURE:
        final String errMsg = String.format("Status: %s, Error Id: %s, Error message: %s", inbound.getStatus(),
                inbound.getErrorId(), inbound.getErrorMessage());
        logger.error(errMsg);
        throw new NonTransientRpcException(errMsg);
    }

    // Before starting SASL handshake validate if both client and server are compatible in their security
    // requirements for the connection
    validateSaslCompatibility(properties, serverAuthMechanisms);
    return serverAuthMechanisms;
}

From source file:org.lanternpowered.server.entity.living.player.LanternPlayer.java

@Override
public boolean setLocationAndRotation(Location<World> location, Vector3d rotation,
        EnumSet<RelativePositions> relativePositions) {
    final World oldWorld = getWorld();
    final boolean success = super.setLocationAndRotation(location, rotation, relativePositions);
    if (success) {
        final World world = location.getExtent();
        // Only send this if the world isn't changed, otherwise will the position be resend anyway
        if (oldWorld == world) {
            final Vector3d pos = location.getPosition();
            final MessagePlayOutPlayerPositionAndLook message = new MessagePlayOutPlayerPositionAndLook(
                    pos.getX(), pos.getY(), pos.getZ(), (float) rotation.getX(), (float) rotation.getY(),
                    Sets.immutableEnumSet(relativePositions), 0);
            this.session.send(message);
        }/*from   w w w  . ja  v  a 2s .  c om*/
    }
    return success;
}