List of usage examples for java.util EnumMap EnumMap
public EnumMap(Map<K, ? extends V> m)
From source file:org.gradle.jvm.toolchain.internal.JavaInstallationProbe.java
private static EnumMap<SysProp, String> error(String message) { EnumMap<SysProp, String> result = new EnumMap<SysProp, String>(SysProp.class); for (SysProp type : SysProp.values()) { result.put(type, UNKNOWN); }/*ww w. j a v a2 s.c o m*/ result.put(SysProp.Z_ERROR, message); return result; }
From source file:com.amalto.core.storage.services.SystemModels.java
@POST @Path("{model}") @ApiOperation("Get impacts of the model update with the new XSD provided as request content. Changes will not be performed !") public String analyzeModelChange(@ApiParam("Model name") @PathParam("model") String modelName, @ApiParam("Optional language to get localized result") @QueryParam("lang") String locale, InputStream dataModel) {//from ww w . j a v a 2 s. c om Map<ImpactAnalyzer.Impact, List<Change>> impacts; List<String> typeNamesToDrop = new ArrayList<String>(); if (!isSystemStorageAvailable()) { impacts = new EnumMap<>(ImpactAnalyzer.Impact.class); for (ImpactAnalyzer.Impact impact : impacts.keySet()) { impacts.put(impact, Collections.<Change>emptyList()); } } else { StorageAdmin storageAdmin = ServerContext.INSTANCE.get().getStorageAdmin(); Storage storage = storageAdmin.get(modelName, StorageType.MASTER); if (storage == null) { LOGGER.warn( "Container '" + modelName + "' does not exist. Skip impact analyzing for model change."); //$NON-NLS-1$//$NON-NLS-2$ return StringUtils.EMPTY; } if (storage.getType() == StorageType.SYSTEM) { LOGGER.debug("No model update for system storage"); //$NON-NLS-1$ return StringUtils.EMPTY; } // Compare new data model with existing data model MetadataRepository previousRepository = storage.getMetadataRepository(); MetadataRepository newRepository = new MetadataRepository(); newRepository.load(dataModel); Compare.DiffResults diffResults = Compare.compare(previousRepository, newRepository); // Analyzes impacts on the select storage impacts = storage.getImpactAnalyzer().analyzeImpacts(diffResults); List<ComplexTypeMetadata> typesToDrop = storage.findSortedTypesToDrop(diffResults, true); Set<String> tableNamesToDrop = storage.findTablesToDrop(typesToDrop); for (String tableName : tableNamesToDrop) { if (previousRepository.getInstantiableTypes() .contains(previousRepository.getComplexType(tableName))) { typeNamesToDrop.add(tableName); } } } // Serialize results to XML StringWriter resultAsXml = new StringWriter(); XMLStreamWriter writer = null; try { writer = XMLOutputFactory.newFactory().createXMLStreamWriter(resultAsXml); writer.writeStartElement("result"); //$NON-NLS-1$ { for (Map.Entry<ImpactAnalyzer.Impact, List<Change>> category : impacts.entrySet()) { writer.writeStartElement(category.getKey().name().toLowerCase()); List<Change> changes = category.getValue(); for (Change change : changes) { writer.writeStartElement("change"); //$NON-NLS-1$ { writer.writeStartElement("message"); //$NON-NLS-1$ { Locale messageLocale; if (StringUtils.isEmpty(locale)) { messageLocale = Locale.getDefault(); } else { messageLocale = new Locale(locale); } writer.writeCharacters(change.getMessage(messageLocale)); } writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } writer.writeStartElement("entitiesToDrop"); //$NON-NLS-1$ for (String typeName : typeNamesToDrop) { writer.writeStartElement("entity"); //$NON-NLS-1$ writer.writeCharacters(typeName); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { if (writer != null) { try { writer.flush(); } catch (XMLStreamException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Could not flush XML content.", e); //$NON-NLS-1$ } } } } return resultAsXml.toString(); }
From source file:SearchApiExample.java
/** * *//*from w ww.j av a 2 s.c om*/ private static Map<SearchParameter, String> getSearchParameters(CommandLine line) { Map<SearchParameter, String> searchParameters = new EnumMap<SearchParameter, String>(SearchParameter.class); if (line.hasOption(KEYWORDS_OPTION)) { searchParameters.put(SearchParameter.KEYWORDS, line.getOptionValue(KEYWORDS_OPTION)); } if (line.hasOption(NAME_OPTION)) { searchParameters.put(SearchParameter.FIRST_NAME, line.getOptionValue(NAME_OPTION)); } if (line.hasOption(COMPANY_OPTION)) { searchParameters.put(SearchParameter.COMPANY_NAME, line.getOptionValue(COMPANY_OPTION)); } if (line.hasOption(CURRENT_COMPANY_OPTION)) { searchParameters.put(SearchParameter.CURRENT_COMPANY, line.getOptionValue(CURRENT_COMPANY_OPTION)); } if (line.hasOption(TITLE_OPTION)) { searchParameters.put(SearchParameter.TITLE, line.getOptionValue(TITLE_OPTION)); } if (line.hasOption(CURRENT_TITLE_OPTION)) { searchParameters.put(SearchParameter.CURRENT_TITLE, line.getOptionValue(CURRENT_TITLE_OPTION)); } if (line.hasOption(COUNTRY_CODE_OPTION)) { searchParameters.put(SearchParameter.COUNTRY_CODE, line.getOptionValue(COUNTRY_CODE_OPTION)); } if (line.hasOption(POSTAL_CODE_OPTION)) { searchParameters.put(SearchParameter.POSTAL_CODE, line.getOptionValue(POSTAL_CODE_OPTION)); } return searchParameters; }
From source file:fr.ritaly.dungeonmaster.ai.CreatureManager.java
private final void _addCreature(Creature creature, Sector sector) { Validate.notNull(creature, "The given creature is null"); Validate.notNull(sector, "The given sector is null"); if (!Creature.Size.ONE.equals(creature.getSize())) { throw new IllegalArgumentException("The given creature <" + creature + "> has an invalid size (actual: " + creature.getSize() + ", expected: " + Creature.Size.ONE + ")"); }/*from w w w.j a v a 2s . c om*/ // L'emplacement doit initialement tre vide if ((creatures != null) && (creatures.get(sector) != null)) { throw new IllegalArgumentException("The cell " + sector + " of element " + position + " is already occupied by a creature (" + creatures.get(sector) + ")"); } // Il doit y avoir la place d'accueillir la crature if (!canHost(creature)) { throw new IllegalArgumentException("Unable to install creature " + creature + " on cell " + sector + " of element " + position + " because the remaining room is " + getFreeSectors().size()); } if (creatures == null) { creatures = new EnumMap<Sector, Creature>(Sector.class); } creatures.put(sector, creature); if (log.isDebugEnabled()) { log.debug(creature + " stepped on " + position + " (" + sector + ")"); } }
From source file:org.codehaus.mojo.license.RemoveFileHeaderMojo.java
@Override public void doAction() throws Exception { long t0 = System.nanoTime(); processedFiles = new HashSet<File>(); result = new EnumMap<FileState, Set<File>>(FileState.class); try {/*from ww w . j a v a2s.c om*/ for (Map.Entry<String, List<File>> commentStyleFiles : filesToTreatByCommentStyle.entrySet()) { String commentStyle = commentStyleFiles.getKey(); List<File> files = commentStyleFiles.getValue(); processCommentStyle(commentStyle, files); } } finally { int nbFiles = processedFiles.size(); if (nbFiles == 0 && !ignoreNoFileToScan) { getLog().warn("No file to scan."); } else { String delay = MojoHelper.convertTime(System.nanoTime() - t0); String message = String.format("Scan %s file%s header done in %s.", nbFiles, nbFiles > 1 ? "s" : "", delay); getLog().info(message); } Set<FileState> states = result.keySet(); if (states.size() == 1 && states.contains(FileState.uptodate)) { // all files where up to date getLog().info("All files are up-to-date."); } else { StringBuilder buffer = new StringBuilder(); for (FileState state : FileState.values()) { reportType(result, state, buffer); } getLog().info(buffer.toString()); } } }
From source file:gov.nih.nci.firebird.service.messages.TemplateServiceImplTest.java
private Map<FirebirdTemplateParameter, Object> getRequiredValues(List<FirebirdTemplateParameter> requirements) { Map<FirebirdTemplateParameter, Object> values = new EnumMap<FirebirdTemplateParameter, Object>( FirebirdTemplateParameter.class); AbstractProtocolRegistration registration = null; for (FirebirdTemplateParameter req : requirements) { switch (req) { case REGISTRATION: registration = RegistrationFactory.getInstance().createInvestigatorRegistration(); values.put(REGISTRATION, registration); break; case INVESTIGATOR_REGISTRATION: registration = RegistrationFactory.getInstance().createInvestigatorRegistration(); values.put(INVESTIGATOR_REGISTRATION, registration); break; case SUBINVESTIGATOR_REGISTRATION: registration = RegistrationFactory.getInstance().createSubinvestigatorRegistration(); values.put(SUBINVESTIGATOR_REGISTRATION, registration); break; case FIREBIRD_LINK: values.put(FIREBIRD_LINK, TEST_LINK); break; case PROTOCOL_REVISION: ProtocolRevision revision = new ProtocolRevision(); revision.setDate(new Date()); revision.setComment("This is a sponsor comment."); ProtocolModification modification = new ProtocolModification("Something changed.", "Something changed."); revision.addModification(modification); values.put(PROTOCOL_REVISION, revision); break; case FIREBIRD_USER: values.put(FIREBIRD_USER, FirebirdUserFactory.getInstance().createInvestigator("username")); break; case REGISTRATION_COORDINATOR: values.put(REGISTRATION_COORDINATOR, PersonFactory.getInstance().create()); break; case SPONSOR: values.put(SPONSOR, PersonFactory.getInstance().create()); break; case MANAGED_INVESTIGATOR: FirebirdUser coordinstor = FirebirdUserFactory.getInstance().createRegistrationCoordinator(); ManagedInvestigator managedInvestigator = coordinstor.getRegistrationCoordinatorRole() .addManagedInvestigator(InvestigatorProfileFactory.getInstance().create()); values.put(MANAGED_INVESTIGATOR, managedInvestigator); break; case INVESTIGATOR: values.put(INVESTIGATOR, PersonFactory.getInstance().create()); break; case ACCOUNT_DATA: AccountConfigurationData configurationData = AccountConfigurationDataFactory.getInstance().create(); configurationData.setUsername("username"); values.put(ACCOUNT_DATA, configurationData); break; case FIREBIRD_SUPPORT_EMAIL: values.put(FIREBIRD_SUPPORT_EMAIL, "firebird-support@5amsolutions.com"); break; case SPONSOR_EMAIL_ADDRESS: values.put(SPONSOR_EMAIL_ADDRESS, getUniqueEmailAddress()); break; case SPONSOR_ROLE: values.put(SPONSOR_ROLE, getSponsorRole()); break; case REGISTRATIONS: values.put(REGISTRATIONS,/* w w w.j a va 2 s. c o m*/ Lists.newArrayList(RegistrationFactory.getInstance().createSubinvestigatorRegistration(), RegistrationFactory.getInstance().createSubinvestigatorRegistration())); break; case TIMESTAMP: values.put(TIMESTAMP, new Date().toString()); break; case REQUEST_URL: values.put(REQUEST_URL, TEST_LINK); break; case REQUEST_PARAMETERS: values.put(REQUEST_PARAMETERS, getUniqueString()); break; case STACKTRACE: values.put(STACKTRACE, getUniqueString()); break; case COMMENTS: values.put(COMMENTS, getUniqueString()); break; case ANNUAL_REGISTRATION: AnnualRegistration annualRegistration = AnnualRegistrationFactory.getInstance().create(); annualRegistration.setStatus(RegistrationStatus.SUBMITTED); annualRegistration.getProfile().getPerson().setCtepId("1234"); annualRegistration.setRenewalDate(DateUtils.addYears(new Date(), 1)); values.put(ANNUAL_REGISTRATION, annualRegistration); break; } } return values; }
From source file:org.gradle.jvm.toolchain.internal.JavaInstallationProbe.java
private static EnumMap<SysProp, String> current() { EnumMap<SysProp, String> result = new EnumMap<SysProp, String>(SysProp.class); for (SysProp type : SysProp.values()) { result.put(type, System.getProperty(type.sysProp, UNKNOWN)); }// w ww . j a v a2s.c o m return result; }
From source file:com.example.app.support.address.AddressStandardizer.java
/** * Normalize the input parsedAddr map into a standardize format * * @param parsedAddr the parsed address. * * @return normalized address in a map/* w ww . j a va 2s . c o m*/ */ public static Map<AddressComponent, String> normalizeParsedAddress(Map<AddressComponent, String> parsedAddr) { Map<AddressComponent, String> ret = new EnumMap<>(AddressComponent.class); //just take the digits from the number component for (Map.Entry<AddressComponent, String> e : parsedAddr.entrySet()) { String v = StringUtils.upperCase(e.getValue()); switch (e.getKey()) { case PREDIR: ret.put(PREDIR, normalizeDir(v)); break; case POSTDIR: ret.put(POSTDIR, normalizeDir(v)); break; case TYPE: ret.put(TYPE, normalizeStreetType(v)); break; case PREDIR2: ret.put(PREDIR2, normalizeDir(v)); break; case POSTDIR2: ret.put(POSTDIR2, normalizeDir(v)); break; case TYPE2: ret.put(TYPE2, normalizeStreetType(v)); break; case NUMBER: ret.put(NUMBER, normalizeNum(v)); break; case STATE: ret.put(STATE, normalizeState(v)); break; case ZIP: ret.put(ZIP, normalizeZip(v)); break; case LINE2: ret.put(LINE2, normalizeLine2(v)); break; case CITY: ret.put(CITY, saintAbbrExpansion(v)); break; case STREET: ret.put(STREET, normalizeOrdinal(saintAbbrExpansion(v))); break; case STREET2: ret.put(STREET2, normalizeOrdinal(saintAbbrExpansion(v))); break; default: ret.put(e.getKey(), v); break; } } ret.put(CITY, resolveCityAlias(ret.get(CITY), ret.get(STATE))); return ret; }
From source file:org.apache.hadoop.corona.CoronaConf.java
/** * Determine the cpu to resource partitioning for a configuration * * @param conf Configuration with the cpu to resource partitioning * @return Mapping of cpu to resources/*from w w w . j av a 2 s. c o m*/ */ public static Map<Integer, Map<ResourceType, Integer>> getUncachedCpuToResourcePartitioning( Configuration conf) { String jsonStr = conf.get(CPU_TO_RESOURCE_PARTITIONING, ""); Map<Integer, Map<ResourceType, Integer>> ret = new HashMap<Integer, Map<ResourceType, Integer>>(); try { ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readValue(jsonStr, JsonNode.class); Iterator<String> iter = rootNode.getFieldNames(); while (iter.hasNext()) { String field = iter.next(); Integer numCpu = Integer.parseInt(field); if ((numCpu < 0) || (numCpu > 64)) { throw new RuntimeException("Number of CPUs: " + numCpu + " is not in range 0-64"); } JsonNode val = rootNode.get(field); if (!val.isObject()) { throw new RuntimeException("Resource Partitioning: " + val.toString() + " is not a object"); } Map<ResourceType, Integer> resourcePartition = null; Iterator<String> valIter = val.getFieldNames(); while (valIter.hasNext()) { String resourceTypeString = valIter.next(); JsonNode resourceVal = val.get(resourceTypeString); int resourceSlots = 0; if (!resourceVal.isInt() || ((resourceSlots = resourceVal.getIntValue()) < 0) || resourceSlots > 64) { throw new RuntimeException( "Resource Partition value: " + resourceVal.toString() + " is not a valid number"); } if (resourcePartition == null) { resourcePartition = new EnumMap<ResourceType, Integer>(ResourceType.class); } try { ResourceType resourceType = ResourceType.valueOf(resourceTypeString); resourcePartition.put(resourceType, new Integer(resourceSlots)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Cannot correctly parse resource type " + resourceTypeString + ", must be one of " + Arrays.toString(ResourceType.values())); } } if (resourcePartition != null) { ret.put(numCpu, resourcePartition); } } return ret; } catch (JsonParseException e) { LOG.error(jsonStr + " is not a valid value for option: " + CPU_TO_RESOURCE_PARTITIONING); throw new RuntimeException(e); } catch (JsonMappingException e) { LOG.error(jsonStr + " is not a valid value for option: " + CPU_TO_RESOURCE_PARTITIONING); throw new RuntimeException(e); } catch (IOException e) { LOG.error(jsonStr + " is not a valid value for option: " + CPU_TO_RESOURCE_PARTITIONING); throw new RuntimeException(e); } }
From source file:de.tuebingen.uni.sfs.germanet.api.GermaNet.java
/** * Constructs a new <code>GermaNet</code> object by loading the the data * files in the specified directory/archive File. * @param dir location of the GermaNet data files * @param ignoreCase if true ignore case on lookups, otherwise do case * sensitive searches/*from w ww . j a v a2 s . c o m*/ * @throws java.io.FileNotFoundException * @throws javax.xml.stream.XMLStreamException * @throws javax.xml.stream.IOException */ public GermaNet(File dir, boolean ignoreCase) throws FileNotFoundException, XMLStreamException, IOException { checkMemory(); this.ignoreCase = ignoreCase; this.inputStreams = null; this.synsets = new TreeSet<Synset>(); this.iliRecords = new ArrayList<IliRecord>(); this.wiktionaryParaphrases = new ArrayList<WiktionaryParaphrase>(); this.synsetID = new HashMap<Integer, Synset>(); this.lexUnitID = new HashMap<Integer, LexUnit>(); this.wordCategoryMap = new EnumMap<WordCategory, HashMap<String, ArrayList<LexUnit>>>(WordCategory.class); this.wordCategoryMapAllOrthForms = new EnumMap<WordCategory, HashMap<String, ArrayList<LexUnit>>>( WordCategory.class); if (!dir.isDirectory() && isZipFile(dir)) { ZipFile zipFile = new ZipFile(dir); Enumeration entries = zipFile.entries(); List<InputStream> inputStreamList = new ArrayList<InputStream>(); List<String> nameList = new ArrayList<String>(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entryName = entry.getName(); if (entryName.split(File.separator).length > 1) { entryName = entryName.split(File.separator)[entryName.split(File.separator).length - 1]; } nameList.add(entryName); InputStream stream = zipFile.getInputStream(entry); inputStreamList.add(stream); } inputStreams = inputStreamList; xmlNames = nameList; zipFile.close(); } else { this.dir = dir; } load(); }