Search in sources :

Example 86 with EnumSet

use of java.util.EnumSet in project kotlin by JetBrains.

the class ResourceEvaluator method getResourceTypes.

/**
     * Evaluates the given node and returns the resource types applicable to the
     * node, if any.
     *
     * @param element the element to compute the types for
     * @return the corresponding resource types
     */
@Nullable
public EnumSet<ResourceType> getResourceTypes(@Nullable UElement element) {
    if (element == null) {
        return null;
    }
    if (element instanceof UIfExpression) {
        UIfExpression expression = (UIfExpression) element;
        Object known = ConstantEvaluator.evaluate(null, expression.getCondition());
        if (known == Boolean.TRUE && expression.getThenExpression() != null) {
            return getResourceTypes(expression.getThenExpression());
        } else if (known == Boolean.FALSE && expression.getElseExpression() != null) {
            return getResourceTypes(expression.getElseExpression());
        } else {
            EnumSet<ResourceType> left = getResourceTypes(expression.getThenExpression());
            EnumSet<ResourceType> right = getResourceTypes(expression.getElseExpression());
            if (left == null) {
                return right;
            } else if (right == null) {
                return left;
            } else {
                EnumSet<ResourceType> copy = EnumSet.copyOf(left);
                copy.addAll(right);
                return copy;
            }
        }
    } else if (element instanceof UParenthesizedExpression) {
        UParenthesizedExpression parenthesizedExpression = (UParenthesizedExpression) element;
        return getResourceTypes(parenthesizedExpression.getExpression());
    } else if ((element instanceof UQualifiedReferenceExpression && mAllowDereference) || element instanceof UCallExpression) {
        UElement probablyCallExpression = element;
        if (element instanceof UQualifiedReferenceExpression) {
            UQualifiedReferenceExpression qualifiedExpression = (UQualifiedReferenceExpression) element;
            probablyCallExpression = qualifiedExpression.getSelector();
        }
        if ((probablyCallExpression instanceof UCallExpression)) {
            UCallExpression call = (UCallExpression) probablyCallExpression;
            PsiMethod method = call.resolve();
            PsiClass containingClass = UastUtils.getContainingClass(method);
            if (method != null && containingClass != null) {
                EnumSet<ResourceType> types = getTypesFromAnnotations(method);
                if (types != null) {
                    return types;
                }
                String qualifiedName = containingClass.getQualifiedName();
                String name = call.getMethodName();
                if ((CLASS_RESOURCES.equals(qualifiedName) || CLASS_CONTEXT.equals(qualifiedName) || CLASS_FRAGMENT.equals(qualifiedName) || CLASS_V4_FRAGMENT.equals(qualifiedName) || CLS_TYPED_ARRAY.equals(qualifiedName)) && name != null && name.startsWith("get")) {
                    List<UExpression> args = call.getValueArguments();
                    if (!args.isEmpty()) {
                        types = getResourceTypes(args.get(0));
                        if (types != null) {
                            return types;
                        }
                    }
                }
            }
        }
    }
    if (element instanceof UReferenceExpression) {
        ResourceUrl url = getResourceConstant(element);
        if (url != null) {
            return EnumSet.of(url.type);
        }
        PsiElement resolved = ((UReferenceExpression) element).resolve();
        if (resolved instanceof PsiVariable) {
            PsiVariable variable = (PsiVariable) resolved;
            UElement lastAssignment = UastLintUtils.findLastAssignment(variable, element, mContext);
            if (lastAssignment != null) {
                return getResourceTypes(lastAssignment);
            }
            return null;
        }
    }
    return null;
}
Also used : PsiVariable(com.intellij.psi.PsiVariable) PsiMethod(com.intellij.psi.PsiMethod) UParenthesizedExpression(org.jetbrains.uast.UParenthesizedExpression) UQualifiedReferenceExpression(org.jetbrains.uast.UQualifiedReferenceExpression) EnumSet(java.util.EnumSet) PsiClass(com.intellij.psi.PsiClass) ResourceType(com.android.resources.ResourceType) UCallExpression(org.jetbrains.uast.UCallExpression) UExpression(org.jetbrains.uast.UExpression) UElement(org.jetbrains.uast.UElement) UReferenceExpression(org.jetbrains.uast.UReferenceExpression) ResourceUrl(com.android.ide.common.resources.ResourceUrl) PsiElement(com.intellij.psi.PsiElement) UIfExpression(org.jetbrains.uast.UIfExpression) Nullable(com.android.annotations.Nullable)

Example 87 with EnumSet

use of java.util.EnumSet in project kotlin by JetBrains.

the class IssueRegistry method createDetectors.

/**
     * Creates a list of detectors applicable to the given scope, and with the
     * given configuration.
     *
     * @param client the client to report errors to
     * @param configuration the configuration to look up which issues are
     *            enabled etc from
     * @param scope the scope for the analysis, to filter out detectors that
     *            require wider analysis than is currently being performed
     * @param scopeToDetectors an optional map which (if not null) will be
     *            filled by this method to contain mappings from each scope to
     *            the applicable detectors for that scope
     * @return a list of new detector instances
     */
@NonNull
final List<? extends Detector> createDetectors(@NonNull LintClient client, @NonNull Configuration configuration, @NonNull EnumSet<Scope> scope, @Nullable Map<Scope, List<Detector>> scopeToDetectors) {
    List<Issue> issues = getIssuesForScope(scope);
    if (issues.isEmpty()) {
        return Collections.emptyList();
    }
    Set<Class<? extends Detector>> detectorClasses = new HashSet<Class<? extends Detector>>();
    Map<Class<? extends Detector>, EnumSet<Scope>> detectorToScope = new HashMap<Class<? extends Detector>, EnumSet<Scope>>();
    for (Issue issue : issues) {
        Implementation implementation = issue.getImplementation();
        Class<? extends Detector> detectorClass = implementation.getDetectorClass();
        EnumSet<Scope> issueScope = implementation.getScope();
        if (!detectorClasses.contains(detectorClass)) {
            // Determine if the issue is enabled
            if (!configuration.isEnabled(issue)) {
                continue;
            }
            // Ensured by getIssuesForScope above
            assert implementation.isAdequate(scope);
            detectorClass = client.replaceDetector(detectorClass);
            assert detectorClass != null : issue.getId();
            detectorClasses.add(detectorClass);
        }
        if (scopeToDetectors != null) {
            EnumSet<Scope> s = detectorToScope.get(detectorClass);
            if (s == null) {
                detectorToScope.put(detectorClass, issueScope);
            } else if (!s.containsAll(issueScope)) {
                EnumSet<Scope> union = EnumSet.copyOf(s);
                union.addAll(issueScope);
                detectorToScope.put(detectorClass, union);
            }
        }
    }
    List<Detector> detectors = new ArrayList<Detector>(detectorClasses.size());
    for (Class<? extends Detector> clz : detectorClasses) {
        try {
            Detector detector = clz.newInstance();
            detectors.add(detector);
            if (scopeToDetectors != null) {
                EnumSet<Scope> union = detectorToScope.get(clz);
                for (Scope s : union) {
                    List<Detector> list = scopeToDetectors.get(s);
                    if (list == null) {
                        list = new ArrayList<Detector>();
                        scopeToDetectors.put(s, list);
                    }
                    list.add(detector);
                }
            }
        } catch (Throwable t) {
            //$NON-NLS-1$
            client.log(t, "Can't initialize detector %1$s", clz.getName());
        }
    }
    return detectors;
}
Also used : Issue(com.android.tools.klint.detector.api.Issue) HashMap(java.util.HashMap) EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList) Implementation(com.android.tools.klint.detector.api.Implementation) Detector(com.android.tools.klint.detector.api.Detector) Scope(com.android.tools.klint.detector.api.Scope) HashSet(java.util.HashSet) NonNull(com.android.annotations.NonNull)

Example 88 with EnumSet

use of java.util.EnumSet in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class GridTools method getMutuallyConnectedObjects.

public static Set<IElectricGrid> getMutuallyConnectedObjects(IElectricGrid gridObject) {
    Set<IElectricGrid> connectedObjects = new HashSet<IElectricGrid>();
    WorldCoordinate myPos = new WorldCoordinate(gridObject.getTile());
    for (Map.Entry<WorldCoordinate, EnumSet<ConnectType>> position : gridObject.getChargeHandler().getPossibleConnectionLocations().entrySet()) {
        IElectricGrid otherObj = getGridObjectAt(gridObject.getTile().getWorldObj(), position.getKey());
        if (otherObj != null && position.getValue().contains(otherObj.getChargeHandler().getType())) {
            EnumSet<ConnectType> otherType = otherObj.getChargeHandler().getPossibleConnectionLocations().get(myPos);
            if (otherType != null && otherType.contains(gridObject.getChargeHandler().getType()))
                connectedObjects.add(otherObj);
        }
    }
    return connectedObjects;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) EnumSet(java.util.EnumSet) Map(java.util.Map) HashSet(java.util.HashSet) ConnectType(mods.railcraft.api.electricity.IElectricGrid.ChargeHandler.ConnectType)

Example 89 with EnumSet

use of java.util.EnumSet in project camel by apache.

the class QueueServiceProducer method updateMessage.

private void updateMessage(Exchange exchange) throws Exception {
    CloudQueue client = QueueServiceUtil.createQueueClient(getConfiguration());
    QueueServiceRequestOptions opts = QueueServiceUtil.getRequestOptions(exchange);
    CloudQueueMessage message = getCloudQueueMessage(exchange);
    LOG.trace("Updating the message in the queue [{}] from exchange [{}]...", getConfiguration().getQueueName(), exchange);
    EnumSet<MessageUpdateFields> fields = null;
    Object fieldsObject = exchange.getIn().getHeader(QueueServiceConstants.MESSAGE_UPDATE_FIELDS);
    if (fieldsObject instanceof EnumSet) {
        @SuppressWarnings("unchecked") EnumSet<MessageUpdateFields> theFields = (EnumSet<MessageUpdateFields>) fieldsObject;
        fields = theFields;
    } else if (fieldsObject instanceof MessageUpdateFields) {
        fields = EnumSet.of((MessageUpdateFields) fieldsObject);
    }
    client.updateMessage(message, getConfiguration().getMessageVisibilityDelay(), fields, opts.getRequestOpts(), opts.getOpContext());
}
Also used : EnumSet(java.util.EnumSet) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) MessageUpdateFields(com.microsoft.azure.storage.queue.MessageUpdateFields) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 90 with EnumSet

use of java.util.EnumSet in project hadoop by apache.

the class ApplicationCLI method run.

@Override
public int run(String[] args) throws Exception {
    Options opts = new Options();
    String title = null;
    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, -appStates to filter applications " + "based on application state and -appTags to filter applications " + "based on application tag.");
        opts.addOption(MOVE_TO_QUEUE_CMD, true, "Moves the application to a " + "different queue. Deprecated command. Use 'changeQueue' instead.");
        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);
        Option appTagOpt = new Option(APP_TAG_CMD, true, "Works with -list to " + "filter applications based on input comma-separated list of " + "application tags.");
        appTagOpt.setValueSeparator(',');
        appTagOpt.setArgs(Option.UNLIMITED_VALUES);
        appTagOpt.setArgName("Tags");
        opts.addOption(appTagOpt);
        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.");
        opts.addOption(UPDATE_LIFETIME, true, "update timeout of an application from NOW. ApplicationId can be" + " passed using 'appId' option. Timeout value is in seconds.");
        opts.addOption(CHANGE_APPLICATION_QUEUE, true, "Moves application to a new queue. ApplicationId can be" + " passed using 'appId' option. 'movetoqueue' command is" + " deprecated, this new command 'changeQueue' performs same" + " functionality.");
        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");
        opts.getOption(UPDATE_LIFETIME).setArgName("Timeout");
        opts.getOption(CHANGE_APPLICATION_QUEUE).setArgName("Queue Name");
    } 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;
                            }
                        }
                    }
                }
            }
            Set<String> appTags = new HashSet<String>();
            if (cliParser.hasOption(APP_TAG_CMD)) {
                String[] tags = cliParser.getOptionValues(APP_TAG_CMD);
                if (tags != null) {
                    for (String tag : tags) {
                        if (!tag.trim().isEmpty()) {
                            appTags.add(tag.trim());
                        }
                    }
                }
            }
            listApplications(appTypes, appStates, appTags);
        } 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(UPDATE_LIFETIME)) {
        if (!cliParser.hasOption(APP_ID)) {
            printUsage(title, opts);
            return exitCode;
        }
        long timeoutInSec = Long.parseLong(cliParser.getOptionValue(UPDATE_LIFETIME));
        updateApplicationTimeout(cliParser.getOptionValue(APP_ID), ApplicationTimeoutType.LIFETIME, timeoutInSec);
    } else if (cliParser.hasOption(CHANGE_APPLICATION_QUEUE)) {
        if (!cliParser.hasOption(APP_ID)) {
            printUsage(title, opts);
            return exitCode;
        }
        moveApplicationAcrossQueues(cliParser.getOptionValue(APP_ID), cliParser.getOptionValue(CHANGE_APPLICATION_QUEUE));
    } 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;
}
Also used : Options(org.apache.commons.cli.Options) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) EnumSet(java.util.EnumSet) GnuParser(org.apache.commons.cli.GnuParser) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) CommandLine(org.apache.commons.cli.CommandLine) SignalContainerCommand(org.apache.hadoop.yarn.api.records.SignalContainerCommand) Option(org.apache.commons.cli.Option)

Aggregations

EnumSet (java.util.EnumSet)151 Set (java.util.Set)44 ArrayList (java.util.ArrayList)43 Map (java.util.Map)30 List (java.util.List)29 HashMap (java.util.HashMap)27 HashSet (java.util.HashSet)27 Collection (java.util.Collection)22 Test (org.junit.Test)20 Collectors (java.util.stream.Collectors)19 IOException (java.io.IOException)16 Collections (java.util.Collections)14 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)13 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)12 TreeSet (java.util.TreeSet)11 File (java.io.File)10 Arrays (java.util.Arrays)10 LinkedHashSet (java.util.LinkedHashSet)10 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)9 TreeMap (java.util.TreeMap)8