List of usage examples for java.util EnumMap get
public V get(Object key)
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.ja v a 2 s .co m*/ // get the value for Tutorial.CSS String value = map.get(Tutorial.CSS); System.out.println("Tutorial.CSS value:" + value); System.out.println("Tutorial.Javascript value:" + map.get(Tutorial.Javascript)); }
From source file:Main.java
public static void main(String[] args) { EnumMap<Size, String> sizeMap = new EnumMap<Size, String>(Size.class); sizeMap.put(Size.S, "S"); sizeMap.put(Size.M, "M"); sizeMap.put(Size.L, "L"); sizeMap.put(Size.XL, "XL"); sizeMap.put(Size.XXL, "XXL"); sizeMap.put(Size.XXXL, "XXXL"); for (Size size : Size.values()) { System.out.println(size + ":" + sizeMap.get(size)); }//www .j a v a2 s. co m }
From source file:eu.crisis_economics.utilities.EnumDistribution.java
static public void main(String[] args) { try {//from www .j a v a2s. c om 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:org.apache.metron.utils.PcapInspector.java
public static void main(String... argv) throws IOException { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, argv).getRemainingArgs(); CommandLine cli = InspectorOptions.parse(new PosixParser(), otherArgs); Path inputPath = new Path(InspectorOptions.INPUT.get(cli)); int n = -1;// ww w .j a v a2 s. co m if (InspectorOptions.NUM.has(cli)) { n = Integer.parseInt(InspectorOptions.NUM.get(cli)); } SequenceFile.Reader reader = new SequenceFile.Reader(new Configuration(), SequenceFile.Reader.file(inputPath)); LongWritable key = new LongWritable(); BytesWritable value = new BytesWritable(); for (int i = 0; (n < 0 || i < n) && reader.next(key, value); ++i) { long millis = Long.divideUnsigned(key.get(), 1000000); String ts = DATE_FORMAT.format(new Date(millis)); for (PacketInfo pi : PcapHelper.toPacketInfo(value.copyBytes())) { EnumMap<Constants.Fields, Object> result = PcapHelper.packetToFields(pi); List<String> fieldResults = new ArrayList<String>() { { add("TS: " + ts); } }; for (Constants.Fields field : Constants.Fields.values()) { if (result.containsKey(field)) { fieldResults.add(field.getName() + ": " + result.get(field)); } } System.out.println(Joiner.on(",").join(fieldResults)); } } }
From source file:org.libreplan.business.calendars.entities.Capacity.java
private static String asString(EffortDuration duration) { if (duration == null) { return ""; }//from www . j a va 2 s. c o m EnumMap<Granularity, Integer> values = duration.decompose(); Integer hours = values.get(Granularity.HOURS); Integer minutes = values.get(Granularity.MINUTES); return hours + ":" + minutes; }
From source file:fr.avianey.androidsvgdrawable.QualifiedResource.java
/** * Create a {@link QualifiedResource} from an input SVG file. * @param file//from w w w. j ava 2s. c o m * @return */ public static final QualifiedResource fromFile(final File file) { Preconditions.checkNotNull(file); final String fileName = FilenameUtils.getBaseName(file.getAbsolutePath()); Preconditions.checkArgument(fileName.length() > 0); Preconditions.checkArgument(fileName.indexOf("-") > 0); // unqualified name final String unqualifiedName = fileName.substring(0, fileName.indexOf("-")); Preconditions.checkArgument(unqualifiedName != null && unqualifiedName.matches("\\w+")); // qualifiers final EnumMap<Type, String> typedQualifiers = Qualifier .fromQualifiedString(fileName.substring(fileName.indexOf("-") + 1)); // a density qualifier must be provided Preconditions.checkNotNull(typedQualifiers.get(Type.density)); return new QualifiedResource(file, unqualifiedName, typedQualifiers); }
From source file:org.graphwalker.restful.Util.java
/** * Will create a JSON formatted string representing the statistics of the current * execution of the machine./*from w ww . j a v a 2 s.c o m*/ * * @param machine * @return The execution statistics in JSON format. */ public static JSONObject getStatisticsAsJSON(Machine machine) { EnumMap<Statistics, Integer> map = getStatistics(machine.getCurrentContext()); JSONObject object = new JSONObject(); object.put("totalNumberOfEdges", map.get(Statistics.TOTAL_NUMBER_OF_EDGES)); object.put("totalNumberOfUnvisitedEdges", map.get(Statistics.TOTAL_NUMBER_OF_UNVISITED_EDGES)); object.put("totalNumberOfVisitedEdges", map.get(Statistics.TOTAL_NUMBER_OF_EDGES) - map.get(Statistics.TOTAL_NUMBER_OF_UNVISITED_EDGES)); object.put("edgeCoverage", 100 * (map.get(Statistics.TOTAL_NUMBER_OF_EDGES) - map.get(Statistics.TOTAL_NUMBER_OF_UNVISITED_EDGES)) / map.get(Statistics.TOTAL_NUMBER_OF_EDGES)); object.put("totalNumberOfVertices", map.get(Statistics.TOTAL_NUMBER_OF_VERTICES)); object.put("totalNumberOfUnvisitedVertices", map.get(Statistics.TOTAL_NUMBER_OF_UNVISITED_VERTICES)); object.put("totalNumberOfVisitedVertices", map.get(Statistics.TOTAL_NUMBER_OF_VERTICES) - map.get(Statistics.TOTAL_NUMBER_OF_UNVISITED_VERTICES)); object.put("vertexCoverage", 100 * (map.get(Statistics.TOTAL_NUMBER_OF_VERTICES) - map.get(Statistics.TOTAL_NUMBER_OF_UNVISITED_VERTICES)) / map.get(Statistics.TOTAL_NUMBER_OF_VERTICES)); if (map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS) > 0) { object.put("totalNumberOfRequirement", map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS)); object.put("totalNumberOfUncoveredRequirement", map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS_NOT_COVERED)); object.put("totalNumberOfPassedRequirement", map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS_PASSED)); object.put("totalNumberOfFailedRequirement", map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS_FAILED)); object.put("requirementCoverage", 100 * (map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS) - map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS_NOT_COVERED)) / map.get(Statistics.TOTAL_NUMBER_OF_REQUIREMENTS)); JSONArray jsonElements = new JSONArray(); for (Requirement r : machine.getCurrentContext().getRequirements(RequirementStatus.NOT_COVERED)) { JSONObject jsonElement = new JSONObject(); jsonElement.put("requirementKey", r.getKey()); jsonElements.put(jsonElement); } object.put("requirementsNotCovered", jsonElements); jsonElements = new JSONArray(); for (Requirement r : machine.getCurrentContext().getRequirements(RequirementStatus.PASSED)) { JSONObject jsonElement = new JSONObject(); jsonElement.put("requirementKey", r.getKey()); jsonElements.put(jsonElement); } object.put("requirementsPassed", jsonElements); jsonElements = new JSONArray(); for (Requirement r : machine.getCurrentContext().getRequirements(RequirementStatus.FAILED)) { JSONObject jsonElement = new JSONObject(); jsonElement.put("RequirementKey", r.getKey()); jsonElements.put(jsonElement); } object.put("requirementsFailed", jsonElements); } return object; }
From source file:org.gradle.jvm.toolchain.internal.JavaInstallationProbe.java
private static String computeJdkName(InstallType result, EnumMap<SysProp, String> metadata) { String basename = result == InstallType.IS_JDK ? "JDK" : "JRE"; String vendor = metadata.get(JavaInstallationProbe.SysProp.VENDOR); if (vendor == null) { return basename; } else {/*from w w w . ja v a2 s. co m*/ vendor = vendor.toLowerCase(); } if (vendor.contains("apple")) { return "Apple " + basename; } else if (vendor.contains("oracle") || vendor.contains("sun")) { String vm = metadata.get(JavaInstallationProbe.SysProp.VM); if (vm != null && vm.contains("OpenJDK")) { return result == InstallType.IS_JDK ? "OpenJDK" : "OpenJDK JRE"; } return "Oracle " + basename; } else if (vendor.contains("ibm")) { return "IBM " + basename; } else if (vendor.contains("azul systems")) { return "Zulu " + basename; } else if (vendor.contains("hewlett-packard")) { return "HP-UX " + basename; } return basename; }
From source file:org.libreplan.business.workingday.EffortDuration.java
private static int roundHalfUpToHours(EnumMap<Granularity, Integer> components) { int seconds = components.get(Granularity.SECONDS); int minutes = components.get(Granularity.MINUTES) + (seconds < 30 ? 0 : 1); int hours = components.get(Granularity.HOURS) + (minutes < 30 ? 0 : 1); return hours; }
From source file:org.sonar.java.checks.verifier.CheckVerifier.java
private static void updateEndLine(int expectedLine, EnumMap<IssueAttribute, String> attr) { if (attr.containsKey(IssueAttribute.END_LINE)) { String endLineStr = attr.get(IssueAttribute.END_LINE); if (endLineStr.charAt(0) == '+') { int endLine = Integer.parseInt(endLineStr); attr.put(IssueAttribute.END_LINE, Integer.toString(expectedLine + endLine)); } else {/*from ww w .j a v a 2 s .c o m*/ Fail.fail("endLine attribute should be relative to the line and must be +N with N integer"); } } }