Example usage for java.util EnumSet noneOf

List of usage examples for java.util EnumSet noneOf

Introduction

In this page you can find the example usage for java.util EnumSet noneOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) 

Source Link

Document

Creates an empty enum set with the specified element type.

Usage

From source file:org.apache.hadoop.security.AccessTokenHandler.java

/** Check if access should be allowed. userID is not checked if null */
public Boolean checkAccess(AccessToken token, String userID, long blockID, AccessMode mode) throws IOException {
    long oExpiry = 0;
    long oKeyID = 0;
    String oUserID = null;/*from w  w w .j a v  a2s  . c om*/
    long oBlockID = 0;
    EnumSet<AccessMode> oModes = EnumSet.noneOf(AccessMode.class);

    try {
        ByteArrayInputStream buf = new ByteArrayInputStream(token.getTokenID().getBytes());
        DataInputStream in = new DataInputStream(buf);
        oExpiry = WritableUtils.readVLong(in);
        oKeyID = WritableUtils.readVLong(in);
        oUserID = WritableUtils.readString(in);
        oBlockID = WritableUtils.readVLong(in);
        int length = WritableUtils.readVInt(in);
        for (int i = 0; i < length; ++i) {
            oModes.add(WritableUtils.readEnum(in, AccessMode.class));
        }
    } catch (IOException e) {
        throw (IOException) new IOException("Unable to parse access token for user=" + userID + ", blockID="
                + blockID + ", access mode=" + mode).initCause(e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Verifying access token for user=" + userID + ", blockID=" + blockID + ", access mode=" + mode
                + ", keyID=" + oKeyID);
    }
    return (userID == null || userID.equals(oUserID)) && oBlockID == blockID
            && System.currentTimeMillis() < oExpiry && oModes.contains(mode) && verifyToken(oKeyID, token);
}

From source file:com.netflix.genie.core.jpa.specifications.JpaClusterSpecsUnitTests.java

/**
 * Test the find specification.//ww w . j  a v  a 2  s  .c o  m
 */
@Test
public void testFindEmptyStatuses() {
    final Specification<ClusterEntity> spec = JpaClusterSpecs.find(NAME, EnumSet.noneOf(ClusterStatus.class),
            TAGS, MIN_UPDATE_TIME, MAX_UPDATE_TIME);

    spec.toPredicate(this.root, this.cq, this.cb);
    Mockito.verify(this.cb, Mockito.times(1)).equal(this.root.get(ClusterEntity_.name), NAME);
    Mockito.verify(this.cb, Mockito.times(1)).greaterThanOrEqualTo(this.root.get(ClusterEntity_.updated),
            MIN_UPDATE_TIME);
    Mockito.verify(this.cb, Mockito.times(1)).lessThan(this.root.get(ClusterEntity_.updated), MAX_UPDATE_TIME);
    Mockito.verify(this.cb, Mockito.times(1)).like(this.root.get(ClusterEntity_.tags), this.tagLikeStatement);
    for (final ClusterStatus status : STATUSES) {
        Mockito.verify(this.cb, Mockito.never()).equal(this.root.get(ClusterEntity_.status), status);
    }
}

From source file:org.apache.hadoop.hdfs.security.AccessTokenHandler.java

/** Check if access should be allowed. userID is not checked if null */
public boolean checkAccess(BlockAccessToken token, String userID, long blockID, AccessMode mode)
        throws IOException {
    long oExpiry = 0;
    long oKeyID = 0;
    String oUserID = null;//from   w w  w  .  j  av  a 2 s.  c om
    long oBlockID = 0;
    EnumSet<AccessMode> oModes = EnumSet.noneOf(AccessMode.class);

    try {
        ByteArrayInputStream buf = new ByteArrayInputStream(token.getTokenID().getBytes());
        DataInputStream in = new DataInputStream(buf);
        oExpiry = WritableUtils.readVLong(in);
        oKeyID = WritableUtils.readVLong(in);
        oUserID = WritableUtils.readString(in);
        oBlockID = WritableUtils.readVLong(in);
        int length = WritableUtils.readVInt(in);
        for (int i = 0; i < length; ++i) {
            oModes.add(WritableUtils.readEnum(in, AccessMode.class));
        }
    } catch (IOException e) {
        throw (IOException) new IOException("Unable to parse access token for user=" + userID + ", blockID="
                + blockID + ", access mode=" + mode).initCause(e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Verifying access token for user=" + userID + ", blockID=" + blockID + ", access mode=" + mode
                + ", keyID=" + oKeyID);
    }
    return (userID == null || userID.equals(oUserID)) && oBlockID == blockID && !isExpired(oExpiry)
            && oModes.contains(mode) && verifyToken(oKeyID, token);
}

From source file:net.xy.jcms.controller.configurations.parser.UsecaseParser.java

/**
 * parses the controller itself/*from   www.  j  ava 2 s . co m*/
 * 
 * @param parser
 * @return
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 */
private static Controller parseController(final XMLStreamReader parser, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    if (parser.getAttributeCount() != 2 && parser.getAttributeCount() != 1) {
        throw new IllegalArgumentException(
                "There are to much or few attributes specified for class. [" + parser.getLocation() + "]");
    }
    String path = null;
    final EnumSet<ConfigurationType> obmitedConfigurations = EnumSet.noneOf(ConfigurationType.class);
    for (int i = 0; i < parser.getAttributeCount(); i++) {
        if (parser.getAttributeLocalName(i).equals("path")) {
            path = parser.getAttributeValue(i);
        } else if (parser.getAttributeLocalName(i).equals("obmitConfig")) {
            final String[] configs = parser.getAttributeValue(i).split(",");
            for (final String config : configs) {
                obmitedConfigurations.add(ConfigurationType.valueOf(config.trim()));
            }
        }
    }
    if (StringUtils.isBlank(path)) {
        throw new IllegalArgumentException("Classpath must be set [" + parser.getLocation() + "]");
    }
    parser.nextTag();
    return new Controller(ControllerPool.get(path, loader), obmitedConfigurations);
}

From source file:com.twofortyfouram.locale.sdk.host.ui.fragment.AbstractSupportPluginEditFragment.java

/**
 * Internal implementation to handle when a plug-in is ready to be saved.
 *
 * @param newBundle The new plug-in Bundle.
 * @param newBlurb  The new plug-in blurb.
 * @param oldBundle The old plug-in Bundle. This parameter may be
 *                  {@code null} if this is a new plug-in instance, and not
 *                  {@code null} if this is an old plug-in instance that is being
 *                  edited./*from w  w w .  j  a  v a  2  s.com*/
 * @param oldBlurb  The old plug-in blurb. This parameter may be {@code null}
 *                  if this is a new plug-in instance, and not {@code null} if
 *                  this is an old plug-in instance that is being edited.
 */
private void handleSaveInternal(@NonNull final Bundle newBundle, @NonNull final String newBlurb,
        @Nullable final Bundle oldBundle, @Nullable final String oldBlurb) {

    if (!newBlurb.equals(oldBlurb) || !BundleComparer.areBundlesEqual(newBundle, oldBundle)) {
        final EnumSet<PluginErrorEdit> errors = EnumSet.noneOf(PluginErrorEdit.class);
        final byte[] serializedBundle = PluginEditDelegate.serializeBundle(newBundle, errors);
        if (null != serializedBundle) {
            handleSave(mPlugin, new PluginInstanceData(mPlugin.getType(), mPlugin.getRegistryName(),
                    serializedBundle, newBlurb));
            removeSelf();
        } else {
            handleErrorsInternal(mPlugin, errors);
        }
    } else {
        removeSelf();
    }
}

From source file:org.apache.hadoop.yarn.client.cli.ApplicationCLI.java

@Override
public int run(String[] args) throws Exception {
    Options opts = new Options();
    String title = null;/*  w  ww  . jav  a 2 s  .c  om*/
    if (args.length > 0 && args[0].equalsIgnoreCase(APPLICATION)) {
        title = APPLICATION;
        opts.addOption(STATUS_CMD, true, "Prints the status of the application.");
        opts.addOption(LIST_CMD, false,
                "List applications. " + "Supports optional use of -appTypes to filter applications "
                        + "based on application type, "
                        + "and -appStates to filter applications based on application state.");
        opts.addOption(MOVE_TO_QUEUE_CMD, true, "Moves the application to a " + "different queue.");
        opts.addOption(QUEUE_CMD, true,
                "Works with the movetoqueue command to" + " specify which queue to move an application to.");
        opts.addOption(HELP_CMD, false, "Displays help for all commands.");
        Option appTypeOpt = new Option(APP_TYPE_CMD, true, "Works with -list to "
                + "filter applications based on " + "input comma-separated list of application types.");
        appTypeOpt.setValueSeparator(',');
        appTypeOpt.setArgs(Option.UNLIMITED_VALUES);
        appTypeOpt.setArgName("Types");
        opts.addOption(appTypeOpt);
        Option appStateOpt = new Option(APP_STATE_CMD, true,
                "Works with -list " + "to filter applications based on input comma-separated list of "
                        + "application states. " + getAllValidApplicationStates());
        appStateOpt.setValueSeparator(',');
        appStateOpt.setArgs(Option.UNLIMITED_VALUES);
        appStateOpt.setArgName("States");
        opts.addOption(appStateOpt);
        opts.addOption(APP_ID, true, "Specify Application Id to be operated");
        opts.addOption(UPDATE_PRIORITY, true,
                "update priority of an application. ApplicationId can be" + " passed using 'appId' option.");
        Option killOpt = new Option(KILL_CMD, true,
                "Kills the application. " + "Set of applications can be provided separated with space");
        killOpt.setValueSeparator(' ');
        killOpt.setArgs(Option.UNLIMITED_VALUES);
        killOpt.setArgName("Application ID");
        opts.addOption(killOpt);
        opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID");
        opts.getOption(QUEUE_CMD).setArgName("Queue Name");
        opts.getOption(STATUS_CMD).setArgName("Application ID");
        opts.getOption(APP_ID).setArgName("Application ID");
        opts.getOption(UPDATE_PRIORITY).setArgName("Priority");
    } else if (args.length > 0 && args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
        title = APPLICATION_ATTEMPT;
        opts.addOption(STATUS_CMD, true, "Prints the status of the application attempt.");
        opts.addOption(LIST_CMD, true, "List application attempts for application.");
        opts.addOption(FAIL_CMD, true, "Fails application attempt.");
        opts.addOption(HELP_CMD, false, "Displays help for all commands.");
        opts.getOption(STATUS_CMD).setArgName("Application Attempt ID");
        opts.getOption(LIST_CMD).setArgName("Application ID");
        opts.getOption(FAIL_CMD).setArgName("Application Attempt ID");
    } else if (args.length > 0 && args[0].equalsIgnoreCase(CONTAINER)) {
        title = CONTAINER;
        opts.addOption(STATUS_CMD, true, "Prints the status of the container.");
        opts.addOption(LIST_CMD, true, "List containers for application attempt.");
        opts.addOption(HELP_CMD, false, "Displays help for all commands.");
        opts.getOption(STATUS_CMD).setArgName("Container ID");
        opts.getOption(LIST_CMD).setArgName("Application Attempt ID");
        opts.addOption(SIGNAL_CMD, true,
                "Signal the container. The available signal commands are "
                        + java.util.Arrays.asList(SignalContainerCommand.values())
                        + " Default command is OUTPUT_THREAD_DUMP.");
        opts.getOption(SIGNAL_CMD).setArgName("container ID [signal command]");
        opts.getOption(SIGNAL_CMD).setArgs(3);
    }

    int exitCode = -1;
    CommandLine cliParser = null;
    try {
        cliParser = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        sysout.println("Missing argument for options");
        printUsage(title, opts);
        return exitCode;
    }

    if (cliParser.hasOption(STATUS_CMD)) {
        if (args.length != 3) {
            printUsage(title, opts);
            return exitCode;
        }
        if (args[0].equalsIgnoreCase(APPLICATION)) {
            exitCode = printApplicationReport(cliParser.getOptionValue(STATUS_CMD));
        } else if (args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
            exitCode = printApplicationAttemptReport(cliParser.getOptionValue(STATUS_CMD));
        } else if (args[0].equalsIgnoreCase(CONTAINER)) {
            exitCode = printContainerReport(cliParser.getOptionValue(STATUS_CMD));
        }
        return exitCode;
    } else if (cliParser.hasOption(LIST_CMD)) {
        if (args[0].equalsIgnoreCase(APPLICATION)) {
            allAppStates = false;
            Set<String> appTypes = new HashSet<String>();
            if (cliParser.hasOption(APP_TYPE_CMD)) {
                String[] types = cliParser.getOptionValues(APP_TYPE_CMD);
                if (types != null) {
                    for (String type : types) {
                        if (!type.trim().isEmpty()) {
                            appTypes.add(StringUtils.toUpperCase(type).trim());
                        }
                    }
                }
            }

            EnumSet<YarnApplicationState> appStates = EnumSet.noneOf(YarnApplicationState.class);
            if (cliParser.hasOption(APP_STATE_CMD)) {
                String[] states = cliParser.getOptionValues(APP_STATE_CMD);
                if (states != null) {
                    for (String state : states) {
                        if (!state.trim().isEmpty()) {
                            if (state.trim().equalsIgnoreCase(ALLSTATES_OPTION)) {
                                allAppStates = true;
                                break;
                            }
                            try {
                                appStates.add(
                                        YarnApplicationState.valueOf(StringUtils.toUpperCase(state).trim()));
                            } catch (IllegalArgumentException ex) {
                                sysout.println("The application state " + state + " is invalid.");
                                sysout.println(getAllValidApplicationStates());
                                return exitCode;
                            }
                        }
                    }
                }
            }
            listApplications(appTypes, appStates);
        } else if (args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
            if (args.length != 3) {
                printUsage(title, opts);
                return exitCode;
            }
            listApplicationAttempts(cliParser.getOptionValue(LIST_CMD));
        } else if (args[0].equalsIgnoreCase(CONTAINER)) {
            if (args.length != 3) {
                printUsage(title, opts);
                return exitCode;
            }
            listContainers(cliParser.getOptionValue(LIST_CMD));
        }
    } else if (cliParser.hasOption(KILL_CMD)) {
        if (args.length < 3 || hasAnyOtherCLIOptions(cliParser, opts, KILL_CMD)) {
            printUsage(title, opts);
            return exitCode;
        }
        return killApplication(cliParser.getOptionValues(KILL_CMD));
    } else if (cliParser.hasOption(MOVE_TO_QUEUE_CMD)) {
        if (!cliParser.hasOption(QUEUE_CMD)) {
            printUsage(title, opts);
            return exitCode;
        }
        moveApplicationAcrossQueues(cliParser.getOptionValue(MOVE_TO_QUEUE_CMD),
                cliParser.getOptionValue(QUEUE_CMD));
    } else if (cliParser.hasOption(FAIL_CMD)) {
        if (!args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
            printUsage(title, opts);
            return exitCode;
        }
        failApplicationAttempt(cliParser.getOptionValue(FAIL_CMD));
    } else if (cliParser.hasOption(HELP_CMD)) {
        printUsage(title, opts);
        return 0;
    } else if (cliParser.hasOption(UPDATE_PRIORITY)) {
        if (!cliParser.hasOption(APP_ID)) {
            printUsage(title, opts);
            return exitCode;
        }
        updateApplicationPriority(cliParser.getOptionValue(APP_ID), cliParser.getOptionValue(UPDATE_PRIORITY));
    } else if (cliParser.hasOption(SIGNAL_CMD)) {
        if (args.length < 3 || args.length > 4) {
            printUsage(title, opts);
            return exitCode;
        }
        final String[] signalArgs = cliParser.getOptionValues(SIGNAL_CMD);
        final String containerId = signalArgs[0];
        SignalContainerCommand command = SignalContainerCommand.OUTPUT_THREAD_DUMP;
        if (signalArgs.length == 2) {
            command = SignalContainerCommand.valueOf(signalArgs[1]);
        }
        signalToContainer(containerId, command);
    } else {
        syserr.println("Invalid Command Usage : ");
        printUsage(title, opts);
    }
    return 0;
}

From source file:com.compomics.pride_asa_pipeline.core.logic.modification.PTMMapper.java

/**
 * Map a ModificationItem onto the pipeline Modification
 *
 * @param modificationItem the ModificationItem
 * @param peptideSequence the peptide sequence
 * @return the mapped modification/*from  w  ww  .j av  a 2  s.  c  o m*/
 */
public static Modification mapModification(uk.ac.ebi.pride.jaxb.model.ModificationItem modificationItem,
        String peptideSequence) {

    Integer modificationLocation = modificationItem.getModLocation().intValue();
    Modification.Location location;
    int sequenceIndex;
    if (modificationLocation == 0) {
        location = Modification.Location.N_TERMINAL;
        sequenceIndex = 0;
    } else if (0 < modificationLocation && modificationLocation < (peptideSequence.length() + 1)) {
        location = Modification.Location.NON_TERMINAL;
        sequenceIndex = modificationLocation - 1;
    } else if (modificationLocation == (peptideSequence.length() + 1)) {
        location = Modification.Location.C_TERMINAL;
        sequenceIndex = peptideSequence.length() - 1;
    } else {
        //in this case, return null for the modification
        return null;
    }

    double monoIsotopicMassShift = (modificationItem.getModMonoDelta().isEmpty()) ? 0.0
            : Double.parseDouble(modificationItem.getModMonoDelta().get(0));
    //if average mass shift is empty, use the monoisotopic mass.
    double averageMassShift = (modificationItem.getModAvgDelta().isEmpty()) ? monoIsotopicMassShift
            : Double.parseDouble(modificationItem.getModAvgDelta().get(0));
    String accessionValue = (modificationItem.getAdditional()
            .getCvParamByAcc(modificationItem.getModAccession()) == null) ? modificationItem.getModAccession()
                    : modificationItem.getAdditional().getCvParamByAcc(modificationItem.getModAccession())
                            .getName();

    Modification modification = new Modification(accessionValue, monoIsotopicMassShift, averageMassShift,
            location, EnumSet.noneOf(AminoAcid.class), modificationItem.getModAccession(), accessionValue);
    modification.getAffectedAminoAcids()
            .add(AminoAcid.getAA(peptideSequence.substring(sequenceIndex, sequenceIndex + 1)));
    modification.setOrigin(Modification.Origin.PRIDE);
    return modification;
}

From source file:com.couchbase.lite.router.Router.java

private EnumSet<TDContentOptions> getContentOptions() {
    EnumSet<TDContentOptions> result = EnumSet.noneOf(TDContentOptions.class);
    if (getBooleanQuery("attachments")) {
        result.add(TDContentOptions.TDIncludeAttachments);
    }/*  w w  w  . j  a  va  2 s . c o m*/
    if (getBooleanQuery("local_seq")) {
        result.add(TDContentOptions.TDIncludeLocalSeq);
    }
    if (getBooleanQuery("conflicts")) {
        result.add(TDContentOptions.TDIncludeConflicts);
    }
    if (getBooleanQuery("revs")) {
        result.add(TDContentOptions.TDIncludeRevs);
    }
    if (getBooleanQuery("revs_info")) {
        result.add(TDContentOptions.TDIncludeRevsInfo);
    }
    return result;
}

From source file:fr.ritaly.dungeonmaster.champion.Party.java

/**
 * Tries adding the given champion to the party and if the operation
 * succeeded returns the location where the champion was added.
 *
 * @param champion//from w ww  .  j a v a  2 s. c om
 *            the champion to add to the party. Can't be null.
 * @return a location representing where the champion was successfully
 *         added.
 */
public Location addChampion(Champion champion) {
    Validate.notNull(champion, "The given champion is null");
    Validate.isTrue(!champions.containsValue(champion), "The given champion has already joined the party");
    if (isFull()) {
        throw new IllegalStateException("The party is already full");
    }

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s is joigning the party ...", champion.getName()));
    }

    final boolean wasEmpty = isEmpty(true);

    // Which locations are already occupied ?
    final EnumSet<Location> occupied;

    if (champions.isEmpty()) {
        occupied = EnumSet.noneOf(Location.class);
    } else {
        occupied = EnumSet.copyOf(champions.keySet());
    }

    // Free locations ?
    final EnumSet<Location> free = EnumSet.complementOf(occupied);

    if (log.isDebugEnabled()) {
        log.debug("Free locations = " + free);
    }

    // Get the first free location
    final Location location = free.iterator().next();

    champions.put(location, champion);

    // Listen to the events fired by the champion
    champion.addChangeListener(this);

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s.Location: %s", champion.getName(), location));
    }

    // Assign a color to this champion
    final Color color = pickColor();

    if (log.isDebugEnabled()) {
        log.debug(String.format("%s.Color: %s", champion.getName(), color));
    }

    champion.setColor(color);
    champion.setParty(this);

    if (wasEmpty) {
        // This champion become the new leader
        setLeader(champion);
    }

    fireChangeEvent();

    if (log.isInfoEnabled()) {
        log.info(String.format("%s joined the party", champion.getName()));
    }

    return location;
}