List of usage examples for java.util EnumMap get
public V get(Object key)
From source file:org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil.java
/** * @see #countEditLogOpTypes(File)//from w ww . j a v a 2s .com */ 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:org.openecomp.sdc.asdctool.impl.DataMigration.java
public static AuditingGenericEvent createAuditRecord(EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) throws ParseException { AuditingActionEnum actionEnum = AuditingActionEnum .getActionByName((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_ACTION)); String tableName = actionEnum.getAuditingEsType(); AuditingGenericEvent event = null;/*ww w . j a va 2 s .c om*/ Date date = null; switch (tableName) { case AuditingTypesConstants.USER_ADMIN_EVENT_TYPE: UserAdminEvent userAdminEvent = new UserAdminEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); userAdminEvent.setTimestamp1(date); event = userAdminEvent; break; case AuditingTypesConstants.AUTH_EVENT_TYPE: AuthEvent authEvent = new AuthEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); authEvent.setTimestamp1(date); event = authEvent; break; case AuditingTypesConstants.CATEGORY_EVENT_TYPE: CategoryEvent categoryEvent = new CategoryEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); categoryEvent.setTimestamp1(date); event = categoryEvent; break; case AuditingTypesConstants.RESOURCE_ADMIN_EVENT_TYPE: ResourceAdminEvent resourceAdminEvent = new ResourceAdminEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); resourceAdminEvent.setTimestamp1(date); event = resourceAdminEvent; break; case AuditingTypesConstants.USER_ACCESS_EVENT_TYPE: event = new UserAccessEvent(auditingFields); UserAccessEvent userAccessEvent = new UserAccessEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); userAccessEvent.setTimestamp1(date); event = userAccessEvent; break; case AuditingTypesConstants.DISTRIBUTION_STATUS_EVENT_TYPE: DistributionStatusEvent distributionStatusEvent = new DistributionStatusEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); distributionStatusEvent.setTimestamp1(date); event = distributionStatusEvent; break; case AuditingTypesConstants.DISTRIBUTION_DOWNLOAD_EVENT_TYPE: DistributionDownloadEvent distributionDownloadEvent = new DistributionDownloadEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); distributionDownloadEvent.setTimestamp1(date); event = distributionDownloadEvent; break; case AuditingTypesConstants.DISTRIBUTION_ENGINE_EVENT_TYPE: DistributionEngineEvent distributionEngineEvent = new DistributionEngineEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); distributionEngineEvent.setTimestamp1(date); event = distributionEngineEvent; break; case AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE: DistributionNotificationEvent distributionNotificationEvent = new DistributionNotificationEvent( auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); distributionNotificationEvent.setTimestamp1(date); event = distributionNotificationEvent; break; case AuditingTypesConstants.DISTRIBUTION_DEPLOY_EVENT_TYPE: DistributionDeployEvent distributionDeployEvent = new DistributionDeployEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); distributionDeployEvent.setTimestamp1(date); event = distributionDeployEvent; break; case AuditingTypesConstants.DISTRIBUTION_GET_UEB_CLUSTER_EVENT_TYPE: AuditingGetUebClusterEvent auditingGetUebClusterEvent = new AuditingGetUebClusterEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); auditingGetUebClusterEvent.setTimestamp1(date); event = auditingGetUebClusterEvent; break; case AuditingTypesConstants.CONSUMER_EVENT_TYPE: ConsumerEvent consumerEvent = new ConsumerEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); consumerEvent.setTimestamp1(date); event = consumerEvent; break; case AuditingTypesConstants.GET_USERS_LIST_EVENT_TYPE: GetUsersListEvent getUsersListEvent = new GetUsersListEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); getUsersListEvent.setTimestamp1(date); event = getUsersListEvent; break; case AuditingTypesConstants.GET_CATEGORY_HIERARCHY_EVENT_TYPE: GetCategoryHierarchyEvent getCategoryHierarchyEvent = new GetCategoryHierarchyEvent(auditingFields); date = simpleDateFormat.parse((String) auditingFields.get(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP)); getCategoryHierarchyEvent.setTimestamp1(date); event = getCategoryHierarchyEvent; break; } return event; }
From source file:org.apache.metron.performance.load.LoadOptionsTest.java
@Test public void testCsvMissing() throws Exception { CommandLine cli = LoadOptions.parse(new PosixParser(), new String[] {}); EnumMap<LoadOptions, Optional<Object>> results = LoadOptions.createConfig(cli); Assert.assertFalse(results.get(LoadOptions.CSV).isPresent()); }
From source file:de.zib.scalaris.examples.wikipedia.bliki.MyWikiModel.java
/** * Gets the localised variants for the given special page. * /*from w w w. j a va 2s. c o m*/ * @param page * the special page * @param language * the language to get the variants for * * @return localised variants including the English names */ public static Collection<String> getLocalisedSpecialPageNames(SpecialPage page, String language) { ArrayList<String> result = new ArrayList<String>(4); String localisedPrefix = SPECIAL_PREFIX.get("en"); EnumMap<SpecialPage, String> localisedSuffix = SPECIAL_SUFFIX.get("en"); result.add(MyWikiModel.createFullPageName(localisedPrefix, localisedSuffix.get(page))); localisedPrefix = SPECIAL_PREFIX.get(language); localisedSuffix = SPECIAL_SUFFIX.get(language); if (localisedPrefix != null && localisedSuffix != null) { result.add(MyWikiModel.createFullPageName(localisedPrefix, localisedSuffix.get(page))); } return result; }
From source file:org.libreplan.web.planner.tabs.TabOnModeType.java
private boolean handleAtLeatOneCase(EnumMap<ModeType, ITab> tabs) { for (ModeType modeType : ModeType.values()) { if (tabs.get(modeType) != null) { return true; }// www . j ava 2 s .c o m } return false; }
From source file:it.units.malelab.sse.MyGeneticAlgorithm.java
private EnumMap<Evaluator.ResultType, Double> mean(List<EnumMap<Evaluator.ResultType, Double>> statsList) { EnumMap<Evaluator.ResultType, Double> meanStats = new EnumMap<>(Evaluator.ResultType.class); for (Evaluator.ResultType type : Evaluator.ResultType.values()) { double s = 0; double c = 0; for (EnumMap<Evaluator.ResultType, Double> stats : statsList) { if (stats.containsKey(type)) { s = s + stats.get(type); c = c + 1;//from w w w . ja v a 2 s .co m } } if (c > 0) { meanStats.put(type, s / c); } } return meanStats; }
From source file:org.apache.hadoop.hdfs.server.namenode.TestEditLogFileInputStream.java
@Test public void testReadURL() throws Exception { HttpURLConnection conn = mock(HttpURLConnection.class); doReturn(new ByteArrayInputStream(FAKE_LOG_DATA)).when(conn).getInputStream(); doReturn(HttpURLConnection.HTTP_OK).when(conn).getResponseCode(); doReturn(Integer.toString(FAKE_LOG_DATA.length)).when(conn).getHeaderField("Content-Length"); URLConnectionFactory factory = mock(URLConnectionFactory.class); doReturn(conn).when(factory).openConnection(Mockito.<URL>any(), anyBoolean()); URL url = new URL("http://localhost/fakeLog"); EditLogInputStream elis = EditLogFileInputStream.fromUrl(factory, url, HdfsConstants.INVALID_TXID, HdfsConstants.INVALID_TXID, false); // Read the edit log and verify that we got all of the data. EnumMap<FSEditLogOpCodes, Holder<Integer>> counts = FSImageTestUtil.countEditLogOpTypes(elis); assertThat(counts.get(FSEditLogOpCodes.OP_ADD).held, is(1)); assertThat(counts.get(FSEditLogOpCodes.OP_SET_GENSTAMP_V1).held, is(1)); assertThat(counts.get(FSEditLogOpCodes.OP_CLOSE).held, is(1)); // Check that length header was picked up. assertEquals(FAKE_LOG_DATA.length, elis.length()); elis.close();//from w w w . j a va2 s .com }
From source file:de.zib.scalaris.examples.wikipedia.bliki.MyWikiModel.java
/** * Gets all localised variants for the given special page. * /*from w w w . j ava 2s. c o m*/ * @param page * the special page * * @return localised variants including the English names */ public static Collection<String> getLocalisedSpecialPageNames(SpecialPage page) { ArrayList<String> result = new ArrayList<String>(); for (Entry<String, String> prefix : SPECIAL_PREFIX.entrySet()) { EnumMap<SpecialPage, String> localisedSuffix = SPECIAL_SUFFIX.get(prefix.getKey()); if (localisedSuffix != null) { result.add(MyWikiModel.createFullPageName(prefix.getValue(), localisedSuffix.get(page))); } // Also add the English suffix for the localised prefix. EnumMap<SpecialPage, String> englishSuffix = SPECIAL_SUFFIX.get("en"); if (englishSuffix != null) { result.add(MyWikiModel.createFullPageName(prefix.getValue(), englishSuffix.get(page))); } } return result; }
From source file:it.units.malelab.sse.MyGeneticAlgorithm.java
@Override public Population evolve(Population initial, StoppingCondition condition) { Population current = initial;//ww w . j a v a 2s . c o m generationsEvolved = 0; while (!condition.isSatisfied(current)) { current = nextGeneration(current); generationsEvolved++; //obtain stats List<EnumMap<Evaluator.ResultType, Double>> statsList = new ArrayList<>(current.getPopulationSize()); Iterator<Chromosome> iterator = current.iterator(); while (iterator.hasNext()) { OperationsChromosome chromosome = (OperationsChromosome) iterator.next(); EnumMap<Evaluator.ResultType, Double> stats = chromosome.getStats(); if (stats.containsKey(Evaluator.ResultType.OVERLAPNESS)) { statsList.add(stats); } } Collections.sort(statsList, new Comparator<EnumMap<Evaluator.ResultType, Double>>() { @Override public int compare(EnumMap<Evaluator.ResultType, Double> stats1, EnumMap<Evaluator.ResultType, Double> stats2) { return Double.compare(stats1.get(Evaluator.ResultType.OVERLAPNESS), stats2.get(Evaluator.ResultType.OVERLAPNESS)); } }); EnumMap<Evaluator.ResultType, Double> bestStats = statsList.get(0); EnumMap<Evaluator.ResultType, Double> top10Stats = mean(statsList.subList(0, 10)); EnumMap<Evaluator.ResultType, Double> allStats = mean(statsList); System.out.printf("ovp=%5.3f/%5.3f/%5.3f ", bestStats.get(Evaluator.ResultType.OVERLAPNESS), top10Stats.get(Evaluator.ResultType.OVERLAPNESS), allStats.get(Evaluator.ResultType.OVERLAPNESS)); System.out.printf("ops=%4.0f/%4.0f/%4.0f ", bestStats.get(Evaluator.ResultType.AVG_OPS), top10Stats.get(Evaluator.ResultType.AVG_OPS), allStats.get(Evaluator.ResultType.AVG_OPS)); System.out.printf("mfp=%4.0f/%4.0f/%4.0f ", bestStats.get(Evaluator.ResultType.AVG_FOOTPRINT), top10Stats.get(Evaluator.ResultType.AVG_FOOTPRINT), allStats.get(Evaluator.ResultType.AVG_FOOTPRINT)); System.out.printf("err=%5.3f/%5.3f/%5.3f ", bestStats.get(Evaluator.ResultType.ERROR_RATIO), top10Stats.get(Evaluator.ResultType.ERROR_RATIO), allStats.get(Evaluator.ResultType.ERROR_RATIO)); System.out.printf("size=%3.0f/%3.0f/%3.0f ", bestStats.get(Evaluator.ResultType.SIZE), top10Stats.get(Evaluator.ResultType.SIZE), allStats.get(Evaluator.ResultType.SIZE)); System.out.printf("evals=%8d\n", evaluator.getEvaluatedCount()); //System.out.println(evaluator.getErrorCodes()); } return current; }
From source file:org.gradle.jvm.toolchain.internal.JavaInstallationProbe.java
public ProbeResult checkJdk(File jdkPath) { if (!jdkPath.exists()) { return ProbeResult.failure(InstallType.NO_SUCH_DIRECTORY, "No such directory: " + jdkPath); }/* w w w .ja v a 2 s . c o m*/ EnumMap<SysProp, String> metadata = cache.getUnchecked(jdkPath); String version = metadata.get(SysProp.VERSION); if (UNKNOWN.equals(version)) { return ProbeResult.failure(InstallType.INVALID_JDK, metadata.get(SysProp.Z_ERROR)); } try { JavaVersion.toVersion(version); } catch (IllegalArgumentException ex) { // if the version string cannot be parsed return ProbeResult.failure(InstallType.INVALID_JDK, "Cannot parse version number: " + version); } if (javaExe(jdkPath, "javac").exists()) { return ProbeResult.success(InstallType.IS_JDK, metadata); } return ProbeResult.success(InstallType.IS_JRE, metadata); }