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:org.apache.metron.dataloads.nonbulk.flatfile.SimpleFlatFileSummarizerTest.java

public void testLineByLine(final int numThreads) throws IOException, InvalidWriterOutput {
    ExtractorHandler handler = ExtractorHandler.load(stellarExtractorConfigLineByLine);
    LocalSummarizer summarizer = new MockSummarizer(ImmutableMap.of("input.csv", generateData()));
    final AtomicReference<Object> finalObj = new AtomicReference<>(null);
    EnumMap<SummarizeOptions, Optional<Object>> options = new EnumMap<SummarizeOptions, Optional<Object>>(
            SummarizeOptions.class) {
        {//  w  w w.j  av  a  2s.c  o  m
            put(SummarizeOptions.INPUT, Optional.of("input.csv"));
            put(SummarizeOptions.BATCH_SIZE, Optional.of(5));
            put(SummarizeOptions.QUIET, Optional.of(true));
            put(SummarizeOptions.OUTPUT_MODE, Optional.of(new PeekingWriter(finalObj)));
            put(SummarizeOptions.OUTPUT, Optional.of("out"));
            put(SummarizeOptions.NUM_THREADS, Optional.of(numThreads));
        }
    };
    summarizer.importData(options, handler, new Configuration());
    String expr = "MAP_GET(DOMAIN_REMOVE_TLD(domain), s) > 0";
    for (String domain : domains) {
        Boolean b = (Boolean) StellarProcessorUtils.run(expr,
                ImmutableMap.of("s", finalObj.get(), "domain", domain));
        Assert.assertTrue("Can't find " + domain, b);
    }
}

From source file:fr.free.movierenamer.scrapper.impl.movie.RottenTomatoesScrapper.java

@Override
protected MovieInfo fetchMediaInfo(Movie movie, IdInfo id, AvailableLanguages language) throws Exception {

    URL searchUrl = new URL("http", apiHost,
            "/api/public/v" + version + "/movies/" + id + ".json?apikey=" + apikey);
    JSONObject json = URIRequest.getJsonDocument(searchUrl.toURI());

    final Map<MediaInfo.MediaProperty, String> mediaFields = new EnumMap<MediaInfo.MediaProperty, String>(
            MediaInfo.MediaProperty.class);
    Map<MovieInfo.MovieProperty, String> fields = new EnumMap<MovieInfo.MovieProperty, String>(
            MovieInfo.MovieProperty.class);
    Map<MovieMultipleProperty, List<String>> multipleFields = new EnumMap<MovieMultipleProperty, List<String>>(
            MovieMultipleProperty.class);

    String title = JSONUtils.selectString("title", json);
    String originaleTitle = null;
    if (title.contains("(")) {
        Matcher m = origTitle.matcher(title);
        if (m.find()) {
            title = m.group(1);//from  w w  w  .j  ava 2 s  .c o m
            originaleTitle = StringUtils.removeBrackets(title);
        }
    }
    mediaFields.put(MediaInfo.MediaProperty.title, title);

    if (originaleTitle != null) {
        mediaFields.put(MediaProperty.originalTitle, originaleTitle);
    }

    fields.put(MovieInfo.MovieProperty.overview, JSONUtils.selectString("synopsis", json));
    fields.put(MovieInfo.MovieProperty.runtime, JSONUtils.selectString("runtime", json));
    fields.put(MovieInfo.MovieProperty.tagline, JSONUtils.selectString("critics_consensus", json));

    JSONObject jobject = JSONUtils.selectObject("release_dates", json);
    if (jobject != null) {
        String releaseDate = JSONUtils.selectString("theater", jobject);
        releaseDate = releaseDate == null ? JSONUtils.selectString("dvd", jobject) : releaseDate;

        if (releaseDate != null) {
            fields.put(MovieInfo.MovieProperty.releasedDate, releaseDate);
            Pattern pattern = Pattern.compile("(\\d{4})-\\d{2}-\\d{2}");
            Matcher matcher = pattern.matcher(releaseDate);
            if (matcher.find()) {
                mediaFields.put(MediaInfo.MediaProperty.year, matcher.group(1));
            }
            fields.put(MovieInfo.MovieProperty.releasedDate, releaseDate);
        }

    }

    jobject = JSONUtils.selectObject("ratings", json);
    if (jobject != null) {
        Double rating = JSONUtils.selectInteger("audience_score", jobject).doubleValue() / 10;
        mediaFields.put(MediaInfo.MediaProperty.rating, "" + rating);
    }

    String mpaa = JSONUtils.selectString("mpaa_rating", json);
    if (mpaa != null) {
        if (mpaa.equalsIgnoreCase("UNRATED")) {
            mpaa = "NC-17";
        }
        fields.put(MovieInfo.MovieProperty.certificationCode, mpaa);
    }

    List<IdInfo> ids = new ArrayList<IdInfo>();
    ids.add(new IdInfo(JSONUtils.selectInteger("id", json), ScrapperUtils.AvailableApiIds.ROTTENTOMATOES));
    jobject = JSONUtils.selectObject("alternate_ids", json);
    if (jobject != null) {
        Integer imdbId = JSONUtils.selectInteger("imdb", jobject);
        if (imdbId != null) {
            ids.add(new IdInfo(imdbId, ScrapperUtils.AvailableApiIds.IMDB));
        }
    }

    List<String> genres = new ArrayList<String>();
    String sgenres = JSONUtils.selectString("genres", json);
    if (sgenres != null) {
        for (String genre : sgenres.split(",")) {
            genres.add(genre.replace("\"", ""));
        }
    }

    List<String> studios = new ArrayList<String>();
    studios.add(JSONUtils.selectString("studio", json));

    multipleFields.put(MovieMultipleProperty.studios, studios);
    multipleFields.put(MovieMultipleProperty.genres, genres);

    return new MovieInfo(mediaFields, ids, fields, multipleFields);
}

From source file:ffx.potential.parameters.ForceField.java

/**
 * ForceField Constructor.//ww  w  .  j a va  2s .c  o  m
 *
 * @param properties a
 * {@link org.apache.commons.configuration.CompositeConfiguration} object.
 */
public ForceField(CompositeConfiguration properties) {
    this.properties = properties;
    /**
     * Each force field "type" implements the "Comparator<String>" interface
     * so that passing an "empty" instance of the "type" to its TreeMap
     * constructor will keep the types sorted.
     */
    angleTypes = new TreeMap<>(new AngleType(new int[3], 0, new double[1], null));
    atomTypes = new TreeMap<>(new AtomType(0, 0, null, null, 0, 0, 0));
    bioTypes = new TreeMap<>(new BioType(0, null, null, 0, null));
    bondTypes = new TreeMap<>(new BondType(new int[2], 0, 0, null));
    chargeTypes = new TreeMap<>(new ChargeType(0, 0));
    iSolvRadTypes = new TreeMap<>(new ISolvRadType(0, 0.0));
    multipoleTypes = new TreeMap<>(new MultipoleType(0, new double[3], new double[3][3], null, null));
    outOfPlaneBendTypes = new TreeMap<>(new OutOfPlaneBendType(new int[4], 0));
    piTorsionTypes = new TreeMap<>(new PiTorsionType(new int[2], 0));
    polarizeTypes = new TreeMap<>(new PolarizeType(0, 0, 0, new int[1]));
    stretchBendTypes = new TreeMap<>(new StretchBendType(new int[3], new double[1]));
    torsionTorsionTypes = new TreeMap<>();
    torsionTypes = new TreeMap<>(new TorsionType(new int[4], new double[1], new double[1], new int[1]));
    imptorsTypes = new TreeMap<>(new ImproperTorsionType(new int[4], 0.0, 0.0, 2));
    ureyBradleyTypes = new TreeMap<>(new UreyBradleyType(new int[3], 0, 0));
    vanderWaalsTypes = new TreeMap<>(new VDWType(0, 0, 0, 0));
    relativeSolvationTypes = new TreeMap<>(new RelativeSolvationType("", 0.0));

    forceFieldTypes = new EnumMap<>(ForceFieldType.class);
    forceFieldTypes.put(ForceFieldType.ANGLE, angleTypes);
    forceFieldTypes.put(ForceFieldType.ATOM, atomTypes);
    forceFieldTypes.put(ForceFieldType.BOND, bondTypes);
    forceFieldTypes.put(ForceFieldType.BIOTYPE, bioTypes);
    forceFieldTypes.put(ForceFieldType.CHARGE, chargeTypes);
    forceFieldTypes.put(ForceFieldType.ISOLVRAD, iSolvRadTypes);
    forceFieldTypes.put(ForceFieldType.OPBEND, outOfPlaneBendTypes);
    forceFieldTypes.put(ForceFieldType.MULTIPOLE, multipoleTypes);
    forceFieldTypes.put(ForceFieldType.PITORS, piTorsionTypes);
    forceFieldTypes.put(ForceFieldType.POLARIZE, polarizeTypes);
    forceFieldTypes.put(ForceFieldType.STRBND, stretchBendTypes);
    forceFieldTypes.put(ForceFieldType.TORSION, torsionTypes);
    forceFieldTypes.put(ForceFieldType.IMPTORS, imptorsTypes);
    forceFieldTypes.put(ForceFieldType.TORTORS, torsionTorsionTypes);
    forceFieldTypes.put(ForceFieldType.UREYBRAD, ureyBradleyTypes);
    forceFieldTypes.put(ForceFieldType.VDW, vanderWaalsTypes);
    forceFieldTypes.put(ForceFieldType.RELATIVESOLV, relativeSolvationTypes);
}

From source file:de.javakaffee.kryoserializers.KryoTest.java

@Test(enabled = true)
public void testEnumMap() throws Exception {
    final EnumMap<Gender, String> map = new EnumMap<Gender, String>(Gender.class);
    final String value = "foo";
    map.put(Gender.FEMALE, value);/*  www  . j a v  a  2s.  co m*/
    // Another entry with the same value - to check reference handling
    map.put(Gender.MALE, value);
    @SuppressWarnings("unchecked")
    final EnumMap<Gender, String> deserialized = deserialize(serialize(map), map.getClass());
    assertDeepEquals(deserialized, map);
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.impl.ContextModelAccessImpl.java

private Map<ReasoningOption, OntModelSelector> populateOmsMap() {
    Map<ReasoningOption, OntModelSelector> map = new EnumMap<>(ReasoningOption.class);
    map.put(ASSERTIONS_ONLY, createOntModelSelector(ABOX_ASSERTIONS, TBOX_ASSERTIONS, FULL_ASSERTIONS));
    map.put(INFERENCES_ONLY, createOntModelSelector(ABOX_INFERENCES, TBOX_INFERENCES, FULL_INFERENCES));
    map.put(ASSERTIONS_AND_INFERENCES, createOntModelSelector(ABOX_UNION, TBOX_UNION, FULL_UNION));
    log.debug("OntModelSelectorMap: " + map);
    return Collections.unmodifiableMap(map);
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil.java

/**
 * @see #countEditLogOpTypes(File)/*w  w w  . j a  va  2  s .c om*/
 */
public static EnumMap<FSEditLogOpCodes, Holder<Integer>> countEditLogOpTypes(EditLogInputStream elis)
        throws IOException {
    EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts = new EnumMap<FSEditLogOpCodes, Holder<Integer>>(
            FSEditLogOpCodes.class);

    FSEditLogOp op;
    while ((op = elis.readOp()) != null) {
        Holder<Integer> i = opCounts.get(op.opCode);
        if (i == null) {
            i = new Holder<Integer>(0);
            opCounts.put(op.opCode, i);
        }
        i.held++;
    }
    return opCounts;
}

From source file:io.lavagna.service.ProjectService.java

public Map<ColumnDefinition, BoardColumnDefinition> findMappedColumnDefinitionsByProjectId(int projectId) {
    Map<ColumnDefinition, BoardColumnDefinition> mappedDefinitions = new EnumMap<>(ColumnDefinition.class);
    for (BoardColumnDefinition definition : findColumnDefinitionsByProjectId(projectId)) {
        mappedDefinitions.put(definition.getValue(), definition);
    }/*  w  w  w . jav a  2s. c  o  m*/
    return mappedDefinitions;
}

From source file:org.whitesource.agent.hash.HashCalculator.java

/**
 * Removes all JavaScript comments from the file and calculates SHA-1 checksum.
 *
 * @param file to calculate//from w  w  w  .ja v  a2  s  .  c  om
 * @return Calculated SHA-1 checksums for the given file.
 */
public Map<ChecksumType, String> calculateJavaScriptHashes(File file) throws WssHashException {
    Map<ChecksumType, String> checksums = new EnumMap<>(ChecksumType.class);
    try {
        long fileLength = file.length();
        if (fileLength >= FILE_MAX_SIZE_THRESHOLD) {
            logger.debug("Ignore file {}, ({}): maximum file size  is 2GB", file.getName(),
                    FileUtils.byteCountToDisplaySize(fileLength));
            return checksums;
        }
        checksums = calculateJavaScriptHashes(FileUtils.readFileToByteArray(file));
    } catch (Exception e) {
        throw new WssHashException("Error calculating JavaScript hash: " + e.getMessage());
    }
    return checksums;
}

From source file:de.javakaffee.kryoserializers.KryoTest.java

@Test
public void testCopyEnumMap() throws Exception {
    final EnumMap<Gender, String> map = new EnumMap<Gender, String>(Gender.class);
    final String value = "foo";
    map.put(Gender.FEMALE, value);/*w  w w.j  a v  a  2  s.  c  o m*/
    final EnumMap<Gender, String> copy = _kryo.copy(map);
    assertDeepEquals(copy, map);
}

From source file:org.apache.hadoop.hbase.io.hfile.TestCacheOnWrite.java

private void readStoreFile(boolean useTags) throws IOException {
    AbstractHFileReader reader;/*from   w  w w .  j  ava  2 s.  c om*/
    if (useTags) {
        reader = (HFileReaderV3) HFile.createReader(fs, storeFilePath, cacheConf, conf);
    } else {
        reader = (HFileReaderV2) HFile.createReader(fs, storeFilePath, cacheConf, conf);
    }
    LOG.info("HFile information: " + reader);
    final boolean cacheBlocks = false;
    final boolean pread = false;
    HFileScanner scanner = reader.getScanner(cacheBlocks, pread);
    assertTrue(testDescription, scanner.seekTo());

    long offset = 0;
    HFileBlock prevBlock = null;
    EnumMap<BlockType, Integer> blockCountByType = new EnumMap<BlockType, Integer>(BlockType.class);

    DataBlockEncoding encodingInCache = encoderType.getEncoder().getDataBlockEncoding();
    while (offset < reader.getTrailer().getLoadOnOpenDataOffset()) {
        long onDiskSize = -1;
        if (prevBlock != null) {
            onDiskSize = prevBlock.getNextBlockOnDiskSizeWithHeader();
        }
        // Flags: don't cache the block, use pread, this is not a compaction.
        // Also, pass null for expected block type to avoid checking it.
        HFileBlock block = reader.readBlock(offset, onDiskSize, false, true, false, true, null,
                encodingInCache);
        BlockCacheKey blockCacheKey = new BlockCacheKey(reader.getName(), offset);
        boolean isCached = blockCache.getBlock(blockCacheKey, true, false, true) != null;
        boolean shouldBeCached = cowType.shouldBeCached(block.getBlockType());
        if (shouldBeCached != isCached) {
            throw new AssertionError("shouldBeCached: " + shouldBeCached + "\n" + "isCached: " + isCached + "\n"
                    + "Test description: " + testDescription + "\n" + "block: " + block + "\n"
                    + "encodingInCache: " + encodingInCache + "\n" + "blockCacheKey: " + blockCacheKey);
        }
        prevBlock = block;
        offset += block.getOnDiskSizeWithHeader();
        BlockType bt = block.getBlockType();
        Integer count = blockCountByType.get(bt);
        blockCountByType.put(bt, (count == null ? 0 : count) + 1);
    }

    LOG.info("Block count by type: " + blockCountByType);
    String countByType = blockCountByType.toString();
    BlockType cachedDataBlockType = encoderType.encode ? BlockType.ENCODED_DATA : BlockType.DATA;
    if (useTags) {
        assertEquals("{" + cachedDataBlockType + "=1550, LEAF_INDEX=173, BLOOM_CHUNK=9, INTERMEDIATE_INDEX=20}",
                countByType);
    } else {
        assertEquals("{" + cachedDataBlockType + "=1379, LEAF_INDEX=154, BLOOM_CHUNK=9, INTERMEDIATE_INDEX=18}",
                countByType);
    }
    reader.close();
}