Example usage for java.util EnumMap entrySet

List of usage examples for java.util EnumMap entrySet

Introduction

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

Prototype

Set entrySet

To view the source code for java.util EnumMap entrySet.

Click Source Link

Document

This field is initialized to contain an instance of the entry set view the first time this view is requested.

Usage

From source file:Tutorial.java

public static void main(String[] args) {
    EnumMap<Tutorial, String> map = new EnumMap<Tutorial, String>(Tutorial.class);

    map.put(Tutorial.CSS, "1");
    map.put(Tutorial.Python, "2");
    map.put(Tutorial.PHP, "3");
    map.put(Tutorial.Java, "4");

    System.out.println(map);//from   w  w  w .  j a  va  2s . co m

    Set<Map.Entry<Tutorial, String>> set = map.entrySet();

    System.out.println("Set: " + set);
}

From source file:eu.crisis_economics.utilities.EnumDistribution.java

static public void main(String[] args) {
    try {//from  w ww  .j  ava 2s  .  c  o m
        EnumDistribution<ScheduleIntervals> dice = EnumDistribution.create(ScheduleIntervals.class,
                "./test.dat");
        EnumMap<ScheduleIntervals, Integer> tallies = new EnumMap<ScheduleIntervals, Integer>(
                ScheduleIntervals.class);
        for (ScheduleIntervals value : ScheduleIntervals.values())
            tallies.put(value, 0);
        final int numSamples = 10000000;
        for (int i = 0; i < numSamples; ++i) {
            ScheduleIntervals value = dice.sample();
            tallies.put(value, tallies.get(value) + 1);
        }
        for (Entry<ScheduleIntervals, Integer> record : tallies.entrySet()) {
            ScheduleIntervals value = record.getKey();
            int tally = tallies.get(value);
            System.out.printf("%20s %16.10g\n", value.name(), tally / (double) numSamples);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java

/**
 * Converts an {@link EnumMap} of/* w  ww. j ava  2  s  .co  m*/
 * {@link org.fourthline.cling.support.model.dlna.DLNAAttribute}s to a
 * {@link TreeMap} of {@link ProtocolInfoAttribute}s.
 *
 * @param dlnaAttributes the {@link EnumMap} of
 *            {@link org.fourthline.cling.support.model.dlna.DLNAAttribute}s
 *            to convert.
 * @return A {@link TreeMap} containing the converted
 *         {@link ProtocolInfoAttribute}s.
 */
public static TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> dlnaAttributesToAttributes(
        EnumMap<DLNAAttribute.Type, DLNAAttribute<?>> dlnaAttributes) {
    TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> attributes = createEmptyAttributesMap();
    for (Entry<DLNAAttribute.Type, DLNAAttribute<?>> entry : dlnaAttributes.entrySet()) {
        try {
            ProtocolInfoAttribute attribute = ProtocolInfoAttribute.FACTORY.createAttribute(
                    entry.getKey().getAttributeName(), entry.getValue().getString(), Protocol.HTTP_GET);
            if (attribute != null) {
                attributes.put(attribute.getName(), attribute);
            }
        } catch (ParseException e) {
            LOGGER.debug("Couldn't parse DLNAAttribute \"{}\" = \"{}\": {}", entry.getKey().getAttributeName(),
                    entry.getValue().getString(), e.getMessage());
            LOGGER.trace("", e);
        }
    }
    return attributes;
}

From source file:org.apache.metron.pcapservice.PcapReceiverImplRestEasy.java

/**
 * Enable filtering PCAP results by fixed properties and start/end packet TS
 *
 * @param srcIp filter value// w  ww .  ja v  a2  s.c  o  m
 * @param dstIp filter value
 * @param protocol filter value
 * @param srcPort filter value
 * @param dstPort filter value
 * @param startTime filter value
 * @param endTime filter value
 * @param numReducers Specify the number of reducers to use when executing the mapreduce job
 * @param includeReverseTraffic Indicates if filter should check swapped src/dest addresses and IPs
 * @param servlet_response
 * @return REST response
 * @throws IOException
 */
@GET
@Path("/pcapGetter/getPcapsByIdentifiers")
public Response getPcapsByIdentifiers(@QueryParam("srcIp") String srcIp, @QueryParam("dstIp") String dstIp,
        @QueryParam("protocol") String protocol, @QueryParam("srcPort") String srcPort,
        @QueryParam("dstPort") String dstPort, @DefaultValue("-1") @QueryParam("startTime") long startTime,
        @DefaultValue("-1") @QueryParam("endTime") long endTime,
        @DefaultValue("10") @QueryParam("numReducers") int numReducers,
        @DefaultValue("false") @QueryParam("includeReverseTraffic") boolean includeReverseTraffic,
        @Context HttpServletResponse servlet_response)

        throws IOException {

    if (!isValidPort(srcPort)) {
        return Response.serverError().status(Response.Status.NO_CONTENT)
                .entity("'srcPort' must not be null, empty or a non-integer").build();
    }

    if (!isValidPort(dstPort)) {
        return Response.serverError().status(Response.Status.NO_CONTENT)
                .entity("'dstPort' must not be null, empty or a non-integer").build();
    }

    final boolean includeReverseTrafficF = includeReverseTraffic;
    PcapsResponse response = new PcapsResponse();
    SequenceFileIterable results = null;
    try {
        if (startTime < 0) {
            startTime = 0L;
        }
        if (endTime < 0) {
            endTime = System.currentTimeMillis();
        }

        //convert to nanoseconds since the epoch
        startTime = TimestampConverters.MILLISECONDS.toNanoseconds(startTime);
        endTime = TimestampConverters.MILLISECONDS.toNanoseconds(endTime);
        EnumMap<Constants.Fields, String> query = new EnumMap<Constants.Fields, String>(
                Constants.Fields.class) {
            {
                if (srcIp != null) {
                    put(Constants.Fields.SRC_ADDR, srcIp);
                }
                if (dstIp != null) {
                    put(Constants.Fields.DST_ADDR, dstIp);
                }
                if (srcPort != null) {
                    put(Constants.Fields.SRC_PORT, srcPort);
                }
                if (dstPort != null) {
                    put(Constants.Fields.DST_PORT, dstPort);
                }
                if (protocol != null) {
                    put(Constants.Fields.PROTOCOL, protocol);
                }
                put(Constants.Fields.INCLUDES_REVERSE_TRAFFIC, "" + includeReverseTrafficF);
            }
        };
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Query received: " + Joiner.on(",").join(query.entrySet()));
        }
        results = getQueryUtil().query(new org.apache.hadoop.fs.Path(ConfigurationUtil.getPcapOutputPath()),
                new org.apache.hadoop.fs.Path(ConfigurationUtil.getTempQueryOutputPath()), startTime, endTime,
                numReducers, query, CONFIGURATION.get(), FileSystem.get(CONFIGURATION.get()),
                new FixedPcapFilter.Configurator());
        response.setPcaps(results != null ? Lists.newArrayList(results) : null);

    } catch (Exception e) {
        LOGGER.error("Exception occurred while fetching Pcaps by identifiers :", e);
        throw new WebApplicationException("Unable to fetch Pcaps via MR job", e);
    } finally {
        if (null != results) {
            results.cleanup();
        }
    }

    // return http status '200 OK' along with the complete pcaps response file,
    // and headers
    return Response.ok(response.getPcaps(), MediaType.APPLICATION_OCTET_STREAM).status(200).build();
}

From source file:org.artifactory.search.ArtifactSearcher.java

/**
 * Searches for artifacts by their checksum values
 *
 * @param searchControls Search controls
 * @return Set of repo paths that comply with the given checksums
 *///from  www. j av  a2  s  .  co m
public Collection<ItemInfo> searchArtifactsByChecksum(ChecksumSearchControls searchControls) {
    Map<RepoPath, ItemInfo> results = Maps.newHashMap();

    EnumMap<ChecksumType, String> checksums = searchControls.getChecksums();
    for (Map.Entry<ChecksumType, String> checksumEntry : checksums.entrySet()) {
        if (results.isEmpty() && StringUtils.isNotBlank(checksumEntry.getValue())) {
            findArtifactsByChecksum(checksumEntry.getKey(), checksumEntry.getValue(), searchControls, results);
        }
    }
    return results.values();
}

From source file:org.janusgraph.graphdb.database.log.TransactionLogHeader.java

private DataOutput serializeHeader(Serializer serializer, int capacity, LogTxStatus status,
        EnumMap<LogTxMeta, Object> meta) {
    Preconditions.checkArgument(status != null && meta != null, "Invalid status or meta");
    DataOutput out = serializer.getDataOutput(capacity);
    out.putLong(times.getTime(txTimestamp));
    VariableLong.writePositive(out, transactionId);
    out.writeObjectNotNull(status);// w  ww.  j  a va 2  s . c  o m

    Preconditions.checkArgument(meta.size() < Byte.MAX_VALUE, "Too much meta data: %s", meta.size());
    out.putByte(VariableLong.unsignedByte(meta.size()));
    for (Map.Entry<LogTxMeta, Object> metaentry : meta.entrySet()) {
        assert metaentry.getValue() != null;
        out.putByte(VariableLong.unsignedByte(metaentry.getKey().ordinal()));
        out.writeObjectNotNull(metaentry.getValue());
    }
    return out;
}

From source file:org.jgrades.config.service.UserPreferencesUpdater.java

private void updateRoleData(EnumMap<JgRole, RoleDetails> updatedRoles,
        EnumMap<JgRole, RoleDetails> persistRoles) throws IllegalAccessException {
    if (!persistRoles.containsKey(JgRole.ADMINISTRATOR)
            && !CollectionUtils.isEqualCollection(updatedRoles.keySet(), persistRoles.keySet())) {
        throw new UserPreferencesException("Roles cannot be modified by user itself");
    }//from  w ww.j  a va 2 s.c o  m
    Set<Map.Entry<JgRole, RoleDetails>> entries = updatedRoles.entrySet();
    for (Map.Entry<JgRole, RoleDetails> entry : entries) {
        mapNewValues(entry.getValue().getClass(), updatedRoles.get(entry.getKey()), entry.getValue());
    }

}

From source file:org.zanata.client.commands.FileMappingRuleHandler.java

/**
 * Apply the rule and return relative path of the translation file.
 *
 * @param docNameWithExt//  w ww .  jav  a 2  s  . c o m
 *            source document name with extension
 * @param localeMapping
 *            locale mapping
 * @return relative path (relative to trans-dir) for the translation file
 */
public String getRelativeTransFilePathForSourceDoc(DocNameWithExt docNameWithExt,
        @Nonnull LocaleMapping localeMapping, Optional<String> translationFileExtension) {
    EnumMap<Placeholders, String> map = parseToMap(docNameWithExt.getFullName(), localeMapping,
            translationFileExtension);

    String transFilePath = mappingRule.getRule();
    for (Map.Entry<Placeholders, String> entry : map.entrySet()) {
        transFilePath = transFilePath.replace(entry.getKey().holder, entry.getValue());
        log.debug("replaced with {}, now is: {}", entry.getKey(), transFilePath);
    }
    return FileUtil.simplifyPath(transFilePath);
}