Example usage for java.util EnumMap EnumMap

List of usage examples for java.util EnumMap EnumMap

Introduction

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

Prototype

public EnumMap(Map<K, ? extends V> m) 

Source Link

Document

Creates an enum map initialized from the specified map.

Usage

From source file:dk.netarkivet.viewerproxy.ViewerProxyTester.java

@After
public void tearDown() throws NoSuchFieldException, IllegalAccessException {
    if (proxy != null) {
        proxy.cleanup();/*from  w w w  . j a v  a2  s .  c  om*/
    }
    FileUtils.removeRecursively(TestInfo.WORKING_DIR);
    TestRemoteFile.removeRemainingFiles();
    Field f = ReflectUtils.getPrivateField(IndexRequestClient.class, "clients");
    f.set(null, new EnumMap<RequestType, IndexRequestClient>(RequestType.class));
    f = ReflectUtils.getPrivateField(IndexRequestClient.class, "synchronizer");
    f.set(null, null);
    rs.tearDown();
}

From source file:nl.strohalm.cyclos.dao.members.ReferenceDAOImpl.java

public Map<Level, Integer> countReferencesByLevel(final Reference.Nature nature, final Period period,
        final Member member, final Collection<MemberGroup> memberGroups, final boolean received) {
    final Map<Level, Integer> countGivenReferences = new EnumMap<Level, Integer>(Level.class);
    for (final Level level : Level.values()) {
        countGivenReferences.put(level, 0);
    }/*from ww  w .j a va 2  s .  c  o m*/
    final Map<String, Object> namedParameters = new HashMap<String, Object>();
    final Class<? extends Reference> type = typeForNature(nature);
    final StringBuilder hql = new StringBuilder("select r.level, count(r.id) from ").append(type.getName())
            .append(" r where 1=1 ");
    HibernateHelper.addParameterToQuery(hql, namedParameters, (received ? "r.to" : "r.from"), member);
    if (memberGroups != null && !memberGroups.isEmpty()) {
        hql.append(" and " + (received ? "r.to" : "r.from") + ".group in (:memberGroups) ");
        namedParameters.put("memberGroups", memberGroups);
    }
    HibernateHelper.addPeriodParameterToQuery(hql, namedParameters, "r.date", period);
    hql.append(" group by r.level order by r.level");
    final List<Object[]> rows = list(hql.toString(), namedParameters);
    for (final Object[] row : rows) {
        countGivenReferences.put((Level) row[0], (Integer) row[1]);
    }
    return countGivenReferences;
}

From source file:edu.osu.ling.pep.Pep.java

/**
 * Invokes Pep from the command line./*from  w w  w  . ja v a  2  s  .  c  o  m*/
 * <p>
 * The main work this method does, apart from tokenizing the arguments and
 * input tokens, is to load and parse the XML grammar file (as specified by
 * <code>-g</code> or <code>--grammar</code>). If any of the arguments
 * <code>-g</code>, <code>--grammar</code>, <code>-s</code>,
 * <code>--seed</code>, <code>-o</code>, <code>--option</code>, occur with
 * no argument following, this method prints an error notifying the user.
 * 
 * @param args
 *            The expected arguments are as follows, and can occur in any
 *            particular order:
 *            <ul>
 *            <li><code>-g|--grammar &lt;grammar file&gt;</code></li> <li>
 *            <code>-s|--seed &lt;seed category&gt;</code></li> <li><code>
 *            -v|--verbose {verbosity level}</code></li> <li><code>
 *            -o|--option &lt;OPTION_NAME=value&gt;</code></li> <li><code>
 *            -h|--help (prints usage information)</code></li> <li><code>
 *            &lt;token1 ... token<em>n</em>&gt;</code> (or <code>-</code>
 *            for standard input)</li>
 *            </ul>
 *            <code>OPTION_NAME</code> must be the name of one of the
 *            recognized {@link ParserOption options}. If <code>-h</code> or
 *            <code>--help</code> occur anywhere in the arguments, usage
 *            information is printed and no parsing takes place.
 */
@SuppressWarnings("static-access")
public static final void main(final String[] args) {
    try {
        final Options opts = new Options();

        opts.addOption(OptionBuilder.withLongOpt("grammar").withDescription("the grammar to use").hasArg()
                .isRequired().withArgName("grammar file").create('g'));

        opts.addOption(OptionBuilder.withLongOpt("seed").withDescription("the seed category to parse for")
                .hasArg().isRequired().withArgName("seed category").create('s'));

        opts.addOption(OptionBuilder.withLongOpt("verbose").withDescription("0-3").hasOptionalArg()
                .withArgName("verbosity level").create('v'));

        opts.addOption(OptionBuilder.withLongOpt("option").withDescription("sets parser options")
                .withArgName("OPTION=value").hasArgs(2).withValueSeparator()
                .withDescription("use value for given property").create("o"));

        opts.addOption(OptionBuilder.withLongOpt("help").withDescription("prints this message").create('h'));

        final CommandLineParser parser = new GnuParser();
        try {
            final CommandLine line = parser.parse(opts, args);
            if (line.hasOption('h')) {
                Pep.printHelp(opts);
            } else {
                final int v = Integer.parseInt(line.getOptionValue('v', Integer.toString(Pep.V_PARSE)));
                if (v < 0) {
                    throw new PepException("verbosity < 0: " + v);
                }

                Pep.verbosity = v;
                final Map<ParserOption, Boolean> options = new EnumMap<ParserOption, Boolean>(
                        ParserOption.class);

                final Properties props = line.getOptionProperties("o");
                for (final Object key : props.keySet()) {
                    try {
                        options.put(ParserOption.valueOf(key.toString()),
                                Boolean.valueOf(props.get(key).toString()));
                    } catch (final IllegalArgumentException iae) {
                        Pep.printError("no option named " + key.toString());
                        Pep.printHelp(opts);
                        return;
                    }
                }

                final Pep pep = new Pep(options);
                // final Grammar grammar =
                // new GrammarParser(Pep.findGrammar(line
                // .getOptionValue('g'))).t.parse();

                final List<?> ts = line.getArgList();
                List<String> tokens = null;
                if (ts.isEmpty() || ts.get(0).equals("-")) {
                    tokens = Pep.readTokens(new Scanner(System.in));
                } else {
                    tokens = new ArrayList<String>(ts.size());
                    for (final Object t : ts) {
                        tokens.add(t.toString());
                    }
                }

                pep.lastParseStart = System.currentTimeMillis();
                // try {
                // pep.parse(grammar, tokens,
                // new Category(line.getOptionValue('s')));
                // } catch (final PepException ignore) {
                // // ignore here, we're listening
                // }
            }
        } catch (final ParseException pe) {
            Pep.printError("command-line syntax problem: " + pe.getMessage());
            Pep.printHelp(opts);
        }
    } catch (final PepException pe) {
        final Throwable cause = pe.getCause();
        Pep.printError((cause == null) ? pe : cause);
    } catch (final RuntimeException re) {
        Pep.printError(re);
    }
}

From source file:org.yamj.common.model.YamjInfo.java

@SuppressWarnings("rawtypes")
public YamjInfo(Class myClass) {
    // YAMJ Stuff
    this.projectName = myClass.getPackage().getImplementationVendor();
    this.projectVersion = myClass.getPackage().getImplementationVersion();
    this.moduleName = myClass.getPackage().getImplementationTitle();
    this.moduleDescription = myClass.getPackage().getSpecificationTitle();
    if (myClass.getPackage().getSpecificationVendor() != null) {
        this.buildDateTime = DateTimeTools.parseDate(myClass.getPackage().getSpecificationVendor(),
                DateTimeTools.BUILD_FORMAT);
    } else {//from  www.java 2  s.com
        this.buildDateTime = new DateTime();
    }
    this.buildRevision = myClass.getPackage().getSpecificationVersion();

    // System Stuff
    this.processorCores = Runtime.getRuntime().availableProcessors();
    this.javaVersion = SystemUtils.JAVA_VERSION;
    this.osArch = SystemUtils.OS_ARCH;
    this.osName = SystemUtils.OS_NAME;
    this.osVersion = SystemUtils.OS_VERSION;

    // Times
    this.startUpDateTime = new DateTime(ManagementFactory.getRuntimeMXBean().getStartTime());

    // Counts
    this.counts = new EnumMap<MetaDataType, Long>(MetaDataType.class);

    // IP Address
    this.coreIp = SystemTools.getIpAddress(Boolean.TRUE);

    // Core Port
    this.corePort = 8888; // TODO: Get this from jetty!

    // Database IP & Name
    findDatabaseInfo();

    this.baseArtworkUrl = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.artwork", ""));
    this.baseMediainfoUrl = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.mediainfo", ""));
    this.basePhotoUrl = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.photo", ""));
    this.skinDir = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.skins", "./skins/"));
}

From source file:org.nuxeo.ecm.restapi.server.jaxrs.QueryObject.java

@Override
public void initialize(Object... args) {
    pageProviderService = Framework.getLocalService(PageProviderService.class);
    // Query Enum Parameters Map
    queryParametersMap = new EnumMap<>(QueryParams.class);
    queryParametersMap.put(QueryParams.PAGE_SIZE, PAGE_SIZE);
    queryParametersMap.put(QueryParams.CURRENT_PAGE_INDEX, CURRENT_PAGE_INDEX);
    queryParametersMap.put(QueryParams.MAX_RESULTS, MAX_RESULTS);
    queryParametersMap.put(QueryParams.SORT_BY, SORT_BY);
    queryParametersMap.put(QueryParams.SORT_ORDER, SORT_ORDER);
    queryParametersMap.put(QueryParams.QUERY, QUERY);
    queryParametersMap.put(QueryParams.ORDERED_PARAMS, ORDERED_PARAMS);
    queryParametersMap.put(QueryParams.QUICK_FILTERS, QUICK_FILTERS);
    // Lang Path Enum Map
    langPathMap = new EnumMap<>(LangParams.class);
    langPathMap.put(LangParams.NXQL, NXQL);
}

From source file:org.owasp.dependencycheck.Engine.java

/**
 * Creates a new Engine using the specified classloader to dynamically load Analyzer and Update services.
 *
 * @param serviceClassLoader the ClassLoader to use when dynamically loading Analyzer and Update services
 * @throws DatabaseException thrown if there is an error connecting to the database
 *//*ww  w  . j  a  va 2s.c om*/
public Engine(ClassLoader serviceClassLoader) throws DatabaseException {
    this.dependencies = new ArrayList<Dependency>();
    this.analyzers = new EnumMap<AnalysisPhase, List<Analyzer>>(AnalysisPhase.class);
    this.fileTypeAnalyzers = new HashSet<FileTypeAnalyzer>();
    this.serviceClassLoader = serviceClassLoader;

    ConnectionFactory.initialize();

    boolean autoUpdate = true;
    try {
        autoUpdate = Settings.getBoolean(Settings.KEYS.AUTO_UPDATE);
    } catch (InvalidSettingException ex) {
        LOGGER.log(Level.FINE, "Invalid setting for auto-update; using true.");
    }
    if (autoUpdate) {
        doUpdates();
    }
    loadAnalyzers();
}

From source file:com.linroid.pushapp.ui.home.DeviceTokenDialog.java

private Bitmap generateQrcode(String content, int size) {
    QRCodeWriter writer = new QRCodeWriter();
    try {//from w ww.  j  av a 2 s.  c  om
        EnumMap<EncodeHintType, Object> hint = new EnumMap<>(EncodeHintType.class);
        hint.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, size, size, hint);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        int[] pixels = new int[width * height];
        for (int y = 0; y < height; y++) {
            int offset = y * width;
            for (int x = 0; x < width; x++) {
                // pixels[offset + x] = bitMatrix.get(x, y) ? 0xFF000000
                // : 0xFFFFFFFF;
                pixels[offset + x] = bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF;
            }
        }

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        return bitmap;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.qualinsight.plugins.sonarqube.smell.plugin.extension.SmellMeasurer.java

private Map<SmellType, Integer> parseAnnotations(final String fileContent) {
    final Pattern pattern = Pattern.compile(SMELL_ANNOTATION_TYPE_DETECTION_REGULAR_EXPRESSION,
            Pattern.MULTILINE);//from   w w  w . ja v a  2s .  c o m
    final Matcher matcher = pattern.matcher(fileContent);
    final Map<SmellType, Integer> fileMeasures = new EnumMap<>(SmellType.class);
    while (matcher.find()) {
        final SmellType type = SmellType.valueOf(matcher.group(3));
        if (fileMeasures.containsKey(type)) {
            fileMeasures.put(type, fileMeasures.get(type) + 1);
        } else {
            fileMeasures.put(type, 1);
        }
    }
    return fileMeasures;
}

From source file:de.xaniox.heavyspleef.core.flag.FlagManager.java

public void addFlag(AbstractFlag<?> flag, boolean disable) {
    Class<?> clazz = flag.getClass();
    String path;/*from   w w  w .java  2 s . c o m*/

    if (flag instanceof UnloadedFlag) {
        UnloadedFlag unloadedFlag = (UnloadedFlag) flag;
        path = unloadedFlag.getFlagName();

        for (UnloadedFlag unloaded : unloadedFlags) {
            if (unloaded.getFlagName().equals(path)) {
                throw new IllegalStateException("Unloaded flag with name " + path + " already registered");
            }
        }

        if (flags.containsKey(path) || disabledFlags.contains(path)) {
            return;
        }

        unloadedFlags.add(unloadedFlag);
    } else {
        Validate.isTrue(clazz.isAnnotationPresent(Flag.class),
                "Flag class " + clazz.getCanonicalName() + " must annotate " + Flag.class.getCanonicalName());
        Flag flagAnnotation = clazz.getAnnotation(Flag.class);
        path = generatePath(flagAnnotation);

        if (flags.containsKey(path) || disabledFlags.contains(path)) {
            return;
        }

        if (disable) {
            disabledFlags.add(path);
        } else {
            flags.put(path, flag);

            if (clazz.isAnnotationPresent(BukkitListener.class) && !migrateManager) {
                Bukkit.getPluginManager().registerEvents(flag, plugin);
            }

            if (flagAnnotation.hasGameProperties()) {
                Map<GameProperty, Object> flagGamePropertiesMap = new EnumMap<GameProperty, Object>(
                        GameProperty.class);
                flag.defineGameProperties(flagGamePropertiesMap);

                if (!flagGamePropertiesMap.isEmpty()) {
                    GamePropertyBundle properties = new GamePropertyBundle(flag, flagGamePropertiesMap);
                    propertyBundles.add(properties);
                }
            }

            if (flagAnnotation.parent() != NullFlag.class) {
                AbstractFlag<?> parent = getFlag(flagAnnotation.parent());
                flag.setParent(parent);
            }
        }
    }
}

From source file:net.sourceforge.cobertura.metrics.model.coverage.scope.AbstractCoverageScope.java

/**
 * {@inheritDoc}/*from w ww.  j av a  2  s  .  c  o  m*/
 */
@Override
public Pattern get(final LocationScope scope) {

    if (patternMap == null) {

        // Re-generate the patternMap
        this.patternMap = new EnumMap<LocationScope, Pattern>(LocationScope.class);

        for (int i = 0; i < Math.min(patterns.size(), LocationScope.values().length); i++) {

            // Patterns should not contain null elements.
            patternMap.put(LocationScope.values()[i], Pattern.compile(patterns.get(i)));
        }
    }

    // All done.
    return patternMap.get(scope);
}