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:com.t3.macro.api.views.TokenView.java

/**
 * Returns a set of the parts of a token that can be seen by this token.
 * @param target the token of which we want to check what this token can see
 * @return the set of visible token parts
 *//*  www. java2  s  .c o m*/
public EnumSet<TokenPart> getVisibleTokenParts(TokenView target) {
    if (!token.getHasSight())
        return EnumSet.noneOf(TokenPart.class);

    ZoneRenderer zr = TabletopTool.getFrame().getZoneRenderer(token.getZone());
    Zone zone = zr.getZone();
    Area tokensVisibleArea = zr.getZoneView().getVisibleArea(token);
    if (tokensVisibleArea == null)
        return EnumSet.noneOf(TokenPart.class);
    if (target == null)
        throw new NullPointerException();
    if (!target.isVisible() || (target.token.isVisibleOnlyToOwner() && !AppUtil.playerOwns(target.token))) {
        return EnumSet.noneOf(TokenPart.class);
    }
    Grid grid = zone.getGrid();

    Rectangle bounds = target.token.getFootprint(grid).getBounds(grid,
            grid.convert(new ZonePoint(target.token.getX(), target.token.getY())));
    if (!target.token.isSnapToGrid())
        bounds = target.token.getBounds(zone);

    EnumSet<TokenPart> ret = EnumSet.noneOf(TokenPart.class);

    int x = (int) bounds.getX();
    int y = (int) bounds.getY();
    int w = (int) bounds.getWidth();
    int h = (int) bounds.getHeight();

    int halfX = x + (w) / 2;
    int halfY = y + (h) / 2;
    if (tokensVisibleArea.intersects(bounds)) {
        if (tokensVisibleArea.contains(new Point(x, y)))
            ret.add(TokenPart.TOP_LEFT);
        if (tokensVisibleArea.contains(new Point(x, y + h)))
            if (tokensVisibleArea.contains(new Point(x + w, y)))
                ret.add(TokenPart.TOP_RIGHT);
        if (tokensVisibleArea.contains(new Point(x + w, y + h)))
            ret.add(TokenPart.BOTTOM_LEFT);
        if (tokensVisibleArea.contains(new Point(halfX, halfY)))
            ret.add(TokenPart.BOTTOM_RIGHT);
    }
    return ret;
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java

/**
 * Returns all nodes in the cluster. If the states param is given, returns
 * all nodes that are in the comma-separated list of states.
 *//*from   ww w .j  av a  2  s. co  m*/
@GET
@Path("/nodes")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public NodesInfo getNodes(@QueryParam("states") String states) {
    init();
    ResourceScheduler sched = this.rm.getResourceScheduler();
    if (sched == null) {
        throw new NotFoundException("Null ResourceScheduler instance");
    }

    EnumSet<NodeState> acceptedStates;
    if (states == null) {
        acceptedStates = EnumSet.allOf(NodeState.class);
    } else {
        acceptedStates = EnumSet.noneOf(NodeState.class);
        for (String stateStr : states.split(",")) {
            acceptedStates.add(NodeState.valueOf(StringUtils.toUpperCase(stateStr)));
        }
    }

    Collection<RMNode> rmNodes = RMServerUtils.queryRMNodes(this.rm.getRMContext(), acceptedStates);
    NodesInfo nodesInfo = new NodesInfo();
    for (RMNode rmNode : rmNodes) {
        NodeInfo nodeInfo = new NodeInfo(rmNode, sched);
        if (EnumSet.of(NodeState.LOST, NodeState.DECOMMISSIONED, NodeState.REBOOTED)
                .contains(rmNode.getState())) {
            nodeInfo.setNodeHTTPAddress(EMPTY);
        }
        nodesInfo.add(nodeInfo);
    }

    return nodesInfo;
}

From source file:main.java.RMDupper.java

public static void checkForDuplication(DupStats dupStats, OccurenceCounterMerged occurenceCounterMerged,
        SAMFileWriter outputSam, Boolean allReadsAsMerged,
        PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>> recordBuffer,
        PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>> duplicateBuffer, Set<String> discardSet) {
    // At this point recordBuffer contains all alignments that overlap with its first entry
    // Therefore the task here is to de-duplicate for the first entry in recordBuffer
    duplicateBuffer.clear();/*  ww w.j  a  v a 2s . c o  m*/

    Iterator<ImmutableTriple<Integer, Integer, SAMRecord>> it = recordBuffer.iterator();
    while (it.hasNext()) {
        ImmutableTriple<Integer, Integer, SAMRecord> maybeDuplicate = it.next();

        if (allReadsAsMerged) {
            if (recordBuffer.peek().left.equals(maybeDuplicate.left)
                    && recordBuffer.peek().middle.equals(maybeDuplicate.middle)) {
                duplicateBuffer.add(maybeDuplicate);
            }
        } else {
            // We build a logic table
            EnumSet<DL> testConditon = EnumSet.noneOf(DL.class);
            if (recordBuffer.peek().right.getReadName().startsWith("M_")) {
                testConditon.add(DL.buffer_read_merged);
            } else if (recordBuffer.peek().right.getReadName().startsWith("F_")) {
                testConditon.add(DL.buffer_read_one);
            } else if (recordBuffer.peek().right.getReadName().startsWith("R_")) {
                testConditon.add(DL.buffer_read_two);
            } else {
                throw new RuntimeException("Unlabelled read '" + recordBuffer.peek().right.getReadName()
                        + "' read name must start with one of M_,F_,R when not treating all reads as merged");
            }

            if (maybeDuplicate.right.getReadName().startsWith("M_")) {
                testConditon.add(DL.maybed_read_merged);
            } else if (maybeDuplicate.right.getReadName().startsWith("F_")) {
                testConditon.add(DL.maybed_read_one);
            } else if (maybeDuplicate.right.getReadName().startsWith("R_")) {
                testConditon.add(DL.maybed_read_two);
            } else {
                System.err.println("Unlabelled read '" + maybeDuplicate.right.getReadName()
                        + "' read name must start with one of M_,F_,R when not treating all reads as merged");
            }

            if (recordBuffer.peek().left.equals(maybeDuplicate.left)) {
                testConditon.add(DL.equal_alignment_start);
            }
            if (recordBuffer.peek().middle.equals(maybeDuplicate.middle)) {
                testConditon.add(DL.equal_alignment_end);
            }

            boolean duplicateIsShorterOrEqual = maybeDuplicate.middle
                    - maybeDuplicate.left <= recordBuffer.peek().middle - recordBuffer.peek().left;
            boolean duplicateIsLongerOrEqual = recordBuffer.peek().middle
                    - recordBuffer.peek().left <= maybeDuplicate.middle - maybeDuplicate.left;

            if (duplicateIsShorterOrEqual) {
                testConditon.add(DL.maybed_shorter_or_equal);
            }
            if (duplicateIsLongerOrEqual) {
                testConditon.add(DL.maybed_longer_or_equal);
            }

            if (recordBuffer.peek().right.getReadNegativeStrandFlag()) {
                testConditon.add(DL.buffer_reverse_strand);
            } else {
                testConditon.add(DL.buffer_forward_strand);
            }
            if (maybeDuplicate.right.getReadNegativeStrandFlag()) {
                testConditon.add(DL.maybed_reverse_strand);
            } else {
                testConditon.add(DL.maybed_forward_strand);
            }

            //System.out.println("Testing for duplication: "+testConditon);
            //System.out.println(recordBuffer.peek().right.getReadName()+"\t"+recordBuffer.peek().right.getAlignmentStart()+"\t"+recordBuffer.peek().right.getAlignmentEnd());
            //System.out.println(maybeDuplicate.right.getReadName()+"\t"+maybeDuplicate.right.getAlignmentStart()+"\t"+maybeDuplicate.right.getAlignmentEnd());

            //for ( EnumSet<DL> match : duplicateConditionSet.stream().filter(dc -> testConditon.containsAll(dc) ).collect(Collectors.toList()) ) {
            //  System.out.println("Match to: "+match);
            //}
            //for ( EnumSet<DL> match : duplicateConditionSet.stream().collect(Collectors.toList()) ) {
            //  System.out.println("Try to match: "+match);
            //  if ( match.containsAll(testConditon) )
            //  {
            //    System.out.println("success");
            //  }
            //}

            // Test for Duplication
            if (duplicateConditionSet.stream().anyMatch(dc -> testConditon.containsAll(dc))) {
                duplicateBuffer.add(maybeDuplicate);
            }
        }
    }
    //START DEBUG
    /*
    System.out.println ("recordBuffer");
            
    Comparator<SAMRecord> samRecordComparatorForRecordBuffer = new SAMRecordPositionAndQualityComparator();
    ArrayList<ImmutableTriple<Integer, Integer, SAMRecord>> sortedRecordBuffer = new ArrayList<ImmutableTriple<Integer, Integer, SAMRecord>>(recordBuffer.size());
    Iterator<ImmutableTriple<Integer, Integer, SAMRecord>> rit = recordBuffer.iterator();
            
    while (rit.hasNext()) {
    sortedRecordBuffer.add(rit.next());
    }
    sortedRecordBuffer.sort(Comparator.comparing(ImmutableTriple<Integer, Integer, SAMRecord>::getRight, samRecordComparatorForRecordBuffer));
            
    for ( ImmutableTriple<Integer, Integer, SAMRecord> currTriple : sortedRecordBuffer ) {
    System.out.println(" srb: "+(currTriple.right.getReadNegativeStrandFlag()?"-":"+")+" "+currTriple+" "+SAMRecordQualityComparator.getQualityScore(currTriple.right.getBaseQualityString()));
    }
            
    System.out.println ("duplicateBuffer");
    ArrayList<ImmutableTriple<Integer, Integer, SAMRecord>> sortedDuplicateBuffer = new ArrayList<ImmutableTriple<Integer, Integer, SAMRecord>>(duplicateBuffer.size());
    Iterator<ImmutableTriple<Integer, Integer, SAMRecord>> dit = duplicateBuffer.iterator();
    while (dit.hasNext()) {
    sortedDuplicateBuffer.add(dit.next());
    }
    sortedDuplicateBuffer.sort(Comparator.comparing(ImmutableTriple<Integer, Integer, SAMRecord>::getMiddle));
            
    for ( ImmutableTriple<Integer, Integer, SAMRecord> currTriple : sortedDuplicateBuffer ) {
    System.out.println(" dbe: "+(currTriple.right.getReadNegativeStrandFlag()?"-":"+")+" "+currTriple+" "+SAMRecordQualityComparator.getQualityScore(currTriple.right.getBaseQualityString()));
    }
            
    // Sort again with priority queue order
    sortedDuplicateBuffer.sort(Comparator.comparing(ImmutableTriple<Integer, Integer, SAMRecord>::getRight, samRecordComparator.reversed()));
    for ( ImmutableTriple<Integer, Integer, SAMRecord> currTriple : sortedDuplicateBuffer ) {
    System.out.println("sdbe: "+(currTriple.right.getReadNegativeStrandFlag()?"-":"+")+" "+currTriple+" "+SAMRecordQualityComparator.getQualityScore(currTriple.right.getBaseQualityString()));
    }
    */
    //END DEBUG
    if (!duplicateBuffer.isEmpty() && !discardSet.contains(duplicateBuffer.peek().right.getReadName())) {
        //System.out.println("WRITE "+duplicateBuffer.peek());
        decrementDuplicateStats(dupStats, allReadsAsMerged, duplicateBuffer.peek().right.getReadName());
        occurenceCounterMerged.putValue(Long
                .valueOf(duplicateBuffer.stream()
                        .filter(d -> allReadsAsMerged || d.right.getReadName().startsWith("M_")).count())
                .intValue() - 1);
        outputSam.addAlignment(duplicateBuffer.peek().right);
    }
    while (!duplicateBuffer.isEmpty()) {
        discardSet.add(duplicateBuffer.poll().right.getReadName());
    }
    // Maintain the invariant that the first item in recordBuffer may have duplicates
    while (!recordBuffer.isEmpty() && discardSet.contains(recordBuffer.peek().right.getReadName())) {
        String duplicateReadName = recordBuffer.poll().right.getReadName();
        incrementDuplicateStats(dupStats, allReadsAsMerged, duplicateReadName);
        discardSet.remove(duplicateReadName);
    }
}

From source file:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Get all the commands configured for a given cluster.
 *
 * @param id       The id of the cluster to get the command files for. Not
 *                 NULL/empty/blank./*from   ww  w  .j  av a  2s . c  o  m*/
 * @param statuses The various statuses to return commands for.
 * @return The active set of commands for the cluster.
 * @throws GenieException For any error
 */
@GET
@Path("/{id}/commands")
@ApiOperation(value = "Get the commands for a cluster", notes = "Get the commands for the cluster with the supplied id.", response = Command.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public List<Command> getCommandsForCluster(
        @ApiParam(value = "Id of the cluster to get commands for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses)
        throws GenieException {
    LOG.info("Called with id " + id + " status " + statuses);

    Set<CommandStatus> enumStatuses = null;
    if (!statuses.isEmpty()) {
        enumStatuses = EnumSet.noneOf(CommandStatus.class);
        for (final String status : statuses) {
            if (StringUtils.isNotBlank(status)) {
                enumStatuses.add(CommandStatus.parse(status));
            }
        }
    }

    return this.clusterConfigService.getCommandsForCluster(id, enumStatuses);
}

From source file:org.forgerock.openidm.servlet.internal.ServletConnectionFactory.java

/**
 * Create a Filter from the filter configuration.
 *
 * @param config/*from ww  w  . j a  va  2s. c  o  m*/
 *            the configuration describing a single filter.
 * @return a Filter
 * @throws org.forgerock.json.JsonValueException
 *             TODO.
 */
private Filter newFilter(JsonValue config) throws JsonValueException, ScriptException {
    FilterCondition filterCondition = null;

    final Pair<JsonPointer, ScriptEntry> condition = getScript(config.get("condition"));
    final Pair<JsonPointer, ScriptEntry> onRequest = getScript(config.get("onRequest"));
    final Pair<JsonPointer, ScriptEntry> onResponse = getScript(config.get("onResponse"));
    final Pair<JsonPointer, ScriptEntry> onFailure = getScript(config.get("onFailure"));

    // Require at least one of the following
    if (null == onRequest && null == onResponse && null == onFailure) {
        return null;
    }

    // Check for condition on pattern
    Pattern pattern = config.get("pattern").asPattern();
    if (null != pattern) {
        filterCondition = Filters.matchResourcePath(pattern);
    }

    // Check for condition on type
    final EnumSet<RequestType> requestTypes = EnumSet.noneOf(RequestType.class);
    for (JsonValue method : config.get("methods").expect(List.class)) {
        requestTypes.add(method.asEnum(RequestType.class));
    }
    if (!requestTypes.isEmpty()) {
        filterCondition = (null == filterCondition) ? Filters.matchRequestType(requestTypes)
                : Filters.and(filterCondition, Filters.matchRequestType(requestTypes));
    }

    // Create the filter
    Filter filter = (null == filterCondition) ? new ScriptedFilter(onRequest, onResponse, onFailure)
            : Filters.conditionalFilter(filterCondition, new ScriptedFilter(onRequest, onResponse, onFailure));

    // Check for a condition script
    if (null != condition) {
        FilterCondition conditionFilterCondition = new FilterCondition() {
            @Override
            public boolean matches(final Context context, final Request request) {
                try {
                    final Script script = condition.getValue().getScript(context);
                    script.put("request", request);
                    script.put("context", context);
                    return (Boolean) script.eval();
                } catch (ScriptException e) {
                    logger.warn("Failed to evaluate filter condition: ", e.getMessage(), e);
                }
                return false;
            }
        };
        filter = Filters.conditionalFilter(conditionFilterCondition, filter);
    }
    return filter;
}

From source file:com.netflix.genie.web.controllers.ApplicationRestController.java

/**
 * Get all the commands this application is associated with.
 *
 * @param id       The id of the application to get the commands for. Not
 *                 NULL/empty/blank.//from  w  w w.j  av  a2  s . c  o  m
 * @param statuses The various statuses of the commands to retrieve
 * @return The set of commands.
 * @throws GenieException For any error
 */
@GetMapping(value = "/{id}/commands", produces = MediaTypes.HAL_JSON_VALUE)
public Set<CommandResource> getCommandsForApplication(@PathVariable("id") final String id,
        @RequestParam(value = "status", required = false) final Set<String> statuses) throws GenieException {
    log.debug("Called with id {}", id);

    Set<CommandStatus> enumStatuses = null;
    if (statuses != null) {
        enumStatuses = EnumSet.noneOf(CommandStatus.class);
        for (final String status : statuses) {
            enumStatuses.add(CommandStatus.parse(status));
        }
    }

    return this.applicationService.getCommandsForApplication(id, enumStatuses).stream()
            .map(this.commandResourceAssembler::toResource).collect(Collectors.toSet());
}

From source file:org.apache.hive.hcatalog.api.HCatTable.java

/**
 * Method to compare the attributes of 2 HCatTable instances.
 * @param rhs The other table being compared against. Can't be null.
 * @param attributesToCheck The list of TableAttributes being compared.
 * @return {@code EnumSet<TableAttribute>} containing all the attribute that differ between {@code this} and rhs.
 * Subset of {@code attributesToCheck}./*from  w w  w .j a  v a 2 s  .c o  m*/
 */
public EnumSet<TableAttribute> diff(HCatTable rhs, EnumSet<TableAttribute> attributesToCheck) {
    EnumSet<TableAttribute> theDiff = EnumSet.noneOf(TableAttribute.class);

    for (TableAttribute attribute : attributesToCheck) {

        if (attribute.equals(TableAttribute.COLUMNS)) {
            if (!rhs.getCols().containsAll(getCols()) || !getCols().containsAll(rhs.getCols())) {
                theDiff.add(TableAttribute.COLUMNS);
            }
        }

        if (attribute.equals(TableAttribute.INPUT_FORMAT)) {
            if ((getInputFileFormat() == null && rhs.getInputFileFormat() != null)
                    || (getInputFileFormat() != null && (rhs.getInputFileFormat() == null
                            || !rhs.getInputFileFormat().equals(getInputFileFormat())))) {
                theDiff.add(TableAttribute.INPUT_FORMAT);
            }
        }

        if (attribute.equals(TableAttribute.OUTPUT_FORMAT)) {
            if ((getOutputFileFormat() == null && rhs.getOutputFileFormat() != null)
                    || (getOutputFileFormat() != null && (rhs.getOutputFileFormat() == null
                            || !rhs.getOutputFileFormat().equals(getOutputFileFormat())))) {
                theDiff.add(TableAttribute.OUTPUT_FORMAT);
            }
        }

        if (attribute.equals(TableAttribute.STORAGE_HANDLER)) {
            if ((getStorageHandler() == null && rhs.getStorageHandler() != null)
                    || (getStorageHandler() != null && (rhs.getStorageHandler() == null
                            || !rhs.getStorageHandler().equals(getStorageHandler())))) {
                theDiff.add(TableAttribute.STORAGE_HANDLER);
            }
        }

        if (attribute.equals(TableAttribute.SERDE)) {
            if ((getSerdeLib() == null && rhs.getSerdeLib() != null) || (getSerdeLib() != null
                    && (rhs.getSerdeLib() == null || !rhs.getSerdeLib().equals(getSerdeLib())))) {
                theDiff.add(TableAttribute.SERDE);
            }
        }

        if (attribute.equals(TableAttribute.SERDE_PROPERTIES)) {
            if (!equivalent(sd.getSerdeInfo().getParameters(), rhs.sd.getSerdeInfo().getParameters())) {
                theDiff.add(TableAttribute.SERDE_PROPERTIES);
            }
        }

        if (attribute.equals(TableAttribute.TABLE_PROPERTIES)) {
            if (!equivalent(tblProps, rhs.tblProps)) {
                theDiff.add(TableAttribute.TABLE_PROPERTIES);
            }
        }

    }

    return theDiff;
}

From source file:icom.jpa.bdk.dao.EmailMessageDAO.java

private void updateNewOrOldObjectState(ManagedIdentifiableProxy obj, DAOContext context) {
    MessageUpdater messageUpdater = (MessageUpdater) context.getUpdater();
    Persistent pojoUnifiedMessage = obj.getPojoIdentifiable();

    /*//from w  w w  . java 2s. com
    if (isChanged(obj, UnifiedMessageInfo.Attributes.subject.name())) {
       String subject = (String) getAttributeValue(pojoUnifiedMessage, UnifiedMessageInfo.Attributes.subject.name());
       messageUpdater.setName(subject);
    }
    */

    if (messageUpdater instanceof EmailMessageUpdater) {
        EmailMessageUpdater emailMessageUpdater = (EmailMessageUpdater) messageUpdater;

        if (isChanged(obj, UnifiedMessageInfo.Attributes.flags.name())) {
            EnumSet<MessageFlag> bdkMessageFlags = EnumSet.noneOf(MessageFlag.class);
            EnumSet<? extends Enum<?>> pojoFlags = getEnumSet(pojoUnifiedMessage,
                    UnifiedMessageInfo.Attributes.flags.name());
            if (pojoFlags != null) {
                for (Enum<?> pojoFlag : pojoFlags) {
                    String pojoFlagName = pojoFlag.name();
                    String bdkFlagName = pojoToBdkFlagNameMap.get(pojoFlagName);
                    bdkMessageFlags.add(MessageFlag.valueOf(bdkFlagName));
                }
            }
            emailMessageUpdater.getFlags().addAll(bdkMessageFlags);
        }
        // emailMessageUpdater.getContentTrimmer() TODO
    } else if (messageUpdater instanceof EmailDraftUpdater) {
        EmailDraftUpdater emailDraftUpdater = (EmailDraftUpdater) messageUpdater;
        emailDraftUpdater.setType(EmailMessageType.EMAIL);

        if (isChanged(obj, UnifiedMessageInfo.Attributes.flags.name())) {
            EnumSet<MessageFlag> bdkMessageFlags = EnumSet.noneOf(MessageFlag.class);
            EnumSet<? extends Enum<?>> pojoFlags = getEnumSet(pojoUnifiedMessage,
                    UnifiedMessageInfo.Attributes.flags.name());
            if (pojoFlags != null) {
                for (Enum<?> pojoFlag : pojoFlags) {
                    String pojoFlagName = pojoFlag.name();
                    String bdkFlagName = pojoToBdkFlagNameMap.get(pojoFlagName);
                    bdkMessageFlags.add(MessageFlag.valueOf(bdkFlagName));
                }
                emailDraftUpdater.getFlags().addAll(bdkMessageFlags);
            }
        }

        if (isChanged(obj, UnifiedMessageInfo.Attributes.channel.name())) {
            String pojoChannelName = EmailMessageDAO.getEnumName(pojoUnifiedMessage,
                    UnifiedMessageInfo.Attributes.channel.name());
            if (pojoChannelName != null) {
                String bdkChannelName = EmailMessageDAO.pojoToBdkChannelTypeNameMap.get(pojoChannelName);
                emailDraftUpdater.setType(EmailMessageType.valueOf(bdkChannelName));
            } else {
                emailDraftUpdater.setType(EmailMessageType.EMAIL);
            }
        }

        EmailMessageContentUpdater emailMessageContentUpdater = emailDraftUpdater.getContentUpdater();
        DAOContext childContext = new DAOContext(emailMessageContentUpdater);
        updateEmailMessageContentState(obj, childContext);
    }
}

From source file:com.netflix.genie.web.controllers.ClusterRestController.java

/**
 * Get all the commandIds configured for a given cluster.
 *
 * @param id       The id of the cluster to get the command files for. Not
 *                 NULL/empty/blank./*  w  w w.j  a  v  a2  s. c  o  m*/
 * @param statuses The various statuses to return commandIds for.
 * @return The active set of commandIds for the cluster.
 * @throws GenieException For any error
 */
@GetMapping(value = "/{id}/commands", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<CommandResource> getCommandsForCluster(@PathVariable("id") final String id,
        @RequestParam(value = "status", required = false) final Set<String> statuses) throws GenieException {
    log.debug("Called with id {} status {}", id, statuses);

    Set<CommandStatus> enumStatuses = null;
    if (statuses != null) {
        enumStatuses = EnumSet.noneOf(CommandStatus.class);
        for (final String status : statuses) {
            enumStatuses.add(CommandStatus.parse(status));
        }
    }

    return this.clusterService.getCommandsForCluster(id, enumStatuses).stream()
            .map(this.commandResourceAssembler::toResource).collect(Collectors.toList());
}

From source file:org.apache.sqoop.connector.jdbc.oracle.util.OracleQueries.java

private static List<OracleTable> getTables(Connection connection, String owner, String tableName,
        TableNameQueryType tableNameQueryType) throws SQLException {

    EnumSet<GetTablesOptions> options = EnumSet.noneOf(GetTablesOptions.class);

    if (owner != null && !owner.isEmpty()) {
        options.add(GetTablesOptions.Owner);
    }// ww w  .ja  v a 2s  .c  om

    if (tableName != null && !tableName.isEmpty()) {
        options.add(GetTablesOptions.Table);
    }

    String sql = "SELECT owner, table_name " + " FROM dba_tables" + " %s %s %s %s "
            + " ORDER BY owner, table_name";

    String tableComparitor = null;
    switch (tableNameQueryType) {
    case Equals:
        tableComparitor = "=";
        break;
    case Like:
        tableComparitor = "LIKE";
        break;
    default:
        throw new RuntimeException("Operator not implemented.");
    }

    sql = String.format(sql, options.isEmpty() ? "" : "WHERE",
            options.contains(GetTablesOptions.Owner) ? "owner = ?" : "",
            options.containsAll(EnumSet.of(GetTablesOptions.Owner, GetTablesOptions.Table)) ? "AND" : "",
            options.contains(GetTablesOptions.Table) ? String.format("table_name %s ?", tableComparitor) : "");

    PreparedStatement statement = connection.prepareStatement(sql);

    if (options.containsAll(EnumSet.of(GetTablesOptions.Owner, GetTablesOptions.Table))) {
        statement.setString(1, owner);
        statement.setString(2, tableName);
    } else {
        if (options.contains(GetTablesOptions.Owner)) {
            statement.setString(1, owner);
        } else if (options.contains(GetTablesOptions.Table)) {
            statement.setString(1, tableName);
        }
    }

    ResultSet resultSet = statement.executeQuery();

    ArrayList<OracleTable> result = new ArrayList<OracleTable>();
    while (resultSet.next()) {
        result.add(new OracleTable(resultSet.getString("owner"), resultSet.getString("table_name")));
    }

    resultSet.close();
    statement.close();

    return result;
}