List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:net.triptech.buildulator.model.Person.java
/** * Gets the user role.//from w ww . ja v a2s . c om * * @param value the value * @param context the context * @return the user role */ public static UserRole getUserRole(final String value, final ApplicationContext context) { UserRole pUserRole = UserRole.ROLE_USER; HashMap<String, UserRole> roles = new HashMap<String, UserRole>(); for (UserRole role : UserRole.values()) { roles.put(getMessage(role.getMessageKey(), context), role); } if (roles.containsKey(value)) { pUserRole = roles.get(value); } return pUserRole; }
From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java
public static void write(Resource resource, OutputStream os, Map<String, Object> saveOptions) throws IOException { ExtendedMetaData modelMetaData;/* w w w.j a v a 2 s . co m*/ if (resource.getResourceSet() != null) { modelMetaData = new BasicExtendedMetaData(resource.getResourceSet().getPackageRegistry()); } else { modelMetaData = new BasicExtendedMetaData(Registry.INSTANCE); } HashMap<String, Object> options = new HashMap<String, Object>(); options.put(XMIResource.OPTION_ENCODING, "UTF-8"); if (!options.containsKey(XMIResource.OPTION_KEEP_DEFAULT_CONTENT)) { options.put(XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE); } options.put(XMIResource.OPTION_EXTENDED_META_DATA, modelMetaData); options.put(XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware()); options.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.FALSE); if (saveOptions != null) { options.putAll(saveOptions); } if (os != null) { resource.save(os, options); } else { resource.save(options); } }
From source file:com.nec.nsgui.action.cifs.CommonUtil.java
/** * set the corresponding message for the specified Property of all the object in List * @param objList - the list of object/*w w w .j a v a 2 s .co m*/ * @param protertyName - the target Property * @param value_msgKey - the value and the corresponding message's key in the Resource file * @param msgResources - MessageResources * @param request - http servlet request */ static public void setMsgInObj(List objList, String protertyName, HashMap value_msgKey, MessageResources msgResources, HttpServletRequest request) throws Exception { int objNumbers = objList.size(); Object object; Object objValue; for (int i = 0; i < objNumbers; i++) { object = objList.get(i); try { objValue = PropertyUtils.getProperty(object, protertyName); } catch (Exception e) { throw e; } if (value_msgKey.containsKey(objValue)) { //need change the value to the corresponding message PropertyUtils.setProperty(object, protertyName, msgResources.getMessage(request.getLocale(), (String) value_msgKey.get(objValue.toString()))); } } }
From source file:com.zimbra.cs.util.yauth.TokenAuthenticateV1.java
private static void parseResponseBody(String responseBody, HashMap<String, String> map) { String[] lines = responseBody.split("\n"); for (String line : lines) { int eqIdx = line.indexOf('='); if (eqIdx > 0) { String[] cols = new String[2]; line = line.trim();//www . j a v a 2s .c o m cols[0] = line.substring(0, eqIdx); cols[1] = ""; if (eqIdx < line.length() - 1) { cols[1] = line.substring(eqIdx + 1); if (map.containsKey(cols[0]) && map.get(cols[0]) == null) // only pay attention to the first instance of a value map.put(cols[0], cols[1]); } } } }
From source file:frequencyanalysis.FrequencyAnalysis.java
public static List<Item> findAlphabetFreq(String input) { HashMap alphabetCount = new HashMap<Character, Integer>(); for (char c : input.toCharArray()) { if (!alphabetCount.containsKey(c)) { alphabetCount.put(c, 1);/*from w w w .j a v a2 s. c o m*/ } else { int tempCount = (int) alphabetCount.get(c); tempCount++; alphabetCount.put(c, tempCount); } } return sortByValue(alphabetCount); }
From source file:net.triptech.buildulator.model.Person.java
/** * Gets the user status./*ww w .j a v a 2s.c om*/ * * @param value the value * @param context the context * @return the user status */ public static UserStatus getUserStatus(final String value, final ApplicationContext context) { UserStatus pUserStatus = UserStatus.ACTIVE; HashMap<String, UserStatus> statuses = new HashMap<String, UserStatus>(); for (UserStatus status : UserStatus.values()) { statuses.put(getMessage(status.getMessageKey(), context), status); } if (statuses.containsKey(value)) { pUserStatus = statuses.get(value); } return pUserStatus; }
From source file:com.ciphertool.sentencebuilder.dao.IndexedWordMapDao.java
/** * @param allWords//from w w w. ja v a2 s . c o m * the List of all Words pulled in from the constructor * @return a Map of all Words keyed by their PartOfSpeech */ protected static Map<PartOfSpeechType, ArrayList<Word>> mapByPartOfSpeech(List<Word> allWords) { if (allWords == null || allWords.isEmpty()) { throw new IllegalArgumentException( "Error mapping Words by PartOfSpeech. The supplied List of Words cannot be null or empty."); } HashMap<PartOfSpeechType, ArrayList<Word>> byPartOfSpeech = new HashMap<PartOfSpeechType, ArrayList<Word>>(); for (Word word : allWords) { PartOfSpeechType pos = word.getId().getPartOfSpeech(); // Add the part of speech to the map if it doesn't exist if (!byPartOfSpeech.containsKey(pos)) { byPartOfSpeech.put(pos, new ArrayList<Word>()); } byPartOfSpeech.get(pos).add(word); } return byPartOfSpeech; }
From source file:it.acubelab.smaph.SmaphUtils.java
/** * Turns a list of pairs <b,r>, where b is a bold and r is the position in * which the bold occurred, to the list of bolds and the hashmap between a * position and the list of bolds occurring in that position. * //from ww w .j a va 2 s . c o m * @param boldAndRanks * a list of pairs <b,r>, where b is a bold and r is the position * in which the bold occurred. * @param positions * where to store the mapping between a position (rank) and all * bolds that appear in that position. * @param bolds * where to store the bolds. */ public static void mapRankToBoldsLC(List<Pair<String, Integer>> boldAndRanks, HashMap<Integer, HashSet<String>> positions, HashSet<String> bolds) { for (Pair<String, Integer> boldAndRank : boldAndRanks) { String spot = boldAndRank.first.toLowerCase(); int rank = boldAndRank.second; if (bolds != null) bolds.add(spot); if (positions != null) { if (!positions.containsKey(rank)) positions.put(rank, new HashSet<String>()); positions.get(rank).add(spot); } } }
From source file:net.itransformers.idiscover.discoveryhelpers.xml.SnmpForXslt.java
public static void resolveIPAddresses(DiscoveryResourceManager resourceManager, String connectionType) { for (String ipAddress : discoveredIPs.keySet()) { HashMap<String, String> deviceNameMap = discoveredIPs.get(ipAddress); if (!deviceNameMap.containsKey("snmp")) { deviceNameMap = new HashMap<String, String>(); } else {/* w w w . j ava 2s. c o m*/ //DeviceMap already filled in. continue; } if (!ipAddressValidator.isValidInet4Address(ipAddress)) continue; Map<String, String> resourceParameters = new HashMap<String, String>(); resourceParameters.put("ipAddress", ipAddress); ResourceType resourceType = resourceManager.returnResourceByParam(resourceParameters); List<ResourceType> snmpResources = resourceManager.returnResourcesByConnectionType("snmp"); Map<String, String> connParams = new HashMap<String, String>(); List<ConnectionParamsType> connectionParams = resourceType.getConnectionParams(); for (ConnectionParamsType connectionParam : connectionParams) { if (connectionParam.getConnectionType().equals(connectionType)) { for (ParamType param : connectionParam.getParam()) { connParams.put(param.getName(), param.getValue()); } break; } } connParams.put("ipAddress", ipAddress); String deviceNameFromSNMP = null; String deviceTypeFromSNMP = null; try { SnmpManager snmpManager = createSnmpManager(connParams); // snmpManager.setParameters(connParams); snmpManager.init(); deviceNameFromSNMP = snmpManager.snmpGet("1.3.6.1.2.1.1.5.0"); if (deviceNameFromSNMP == null) { snmpManager.closeSnmp(); for (ResourceType snmpResource : snmpResources) { connParams = resourceManager.getParamMap(snmpResource, "snmp"); connParams.put("ipAddress", ipAddress); if (!resourceType.getName().equals(snmpResource.getName())) { logger.info("Trying ipAddress " + ipAddress + " with " + connParams); snmpManager = createSnmpManager(connParams); snmpManager.init(); deviceNameFromSNMP = snmpManager.snmpGet("1.3.6.1.2.1.1.5.0"); if (deviceNameFromSNMP == null) { snmpManager.closeSnmp(); } else { final String sysDescr = snmpManager.snmpGet("1.3.6.1.2.1.1.1.0"); deviceTypeFromSNMP = getDeviceType(sysDescr); snmpManager.closeSnmp(); } } } } deviceNameMap.put("snmp", deviceNameFromSNMP); deviceNameMap.put("deviceType", deviceTypeFromSNMP); discoveredIPs.put(ipAddress, deviceNameMap); // NeighborDiscoveryResult neighborDiscoveryResult = new NeighborDiscoveryResult(); // neighborDiscoveryResult.setDiscoveredIpAddress(ipAddress); // neighborDiscoveryResult.setNeighborType(deviceTypeFromSNMP); // neighborDiscoveryResult.setNodeId(deviceNameFromSNMP); // neighborDiscoveryResult.setConnParams(connParams); // // if (neighborDiscoveryListeners != null) { // //Fire neighbourDiscoveredEvent // for (NeighborDiscoveryListener neighbourDiscoveryListerner : neighborDiscoveryListeners) { // // neighbourDiscoveryListerner.neighborDiscovered(neighborDiscoveryResult); // // } // } } catch (IOException e) { e.printStackTrace(); } } }
From source file:jp.mamesoft.mailsocketchat.Mail.java
static String logprint(String str) { for (int i = Mailsocketchat.logs.size() - 1; i >= 0; i--) { HashMap<String, String> log = Mailsocketchat.logs.get(i); if (Mailsocketchat.subjectname || !Mailsocketchat.push) { str = str + log.get("name") + "> "; }//from w w w. j a v a 2 s .c o m str = str + log.get("comment"); if (log.containsKey("channel")) { str = str + log.get("channel"); } if (Mailsocketchat.logformat.equals("all")) { str = str + " (" + log.get("ip") + "; " + log.get("time") + ")"; } if (Mailsocketchat.logformat.equals("normal")) { str = str + " (" + log.get("ip"); if (!Mailsocketchat.push) { str = str + "; " + log.get("simpletime"); } str = str + ")"; } if (Mailsocketchat.logformat.equals("simple") && !Mailsocketchat.push) { str = str + " (" + log.get("simpletime") + ")"; } str = str + "\n"; if (!Mailsocketchat.push) { str = str + "\n"; } } Mailsocketchat.logs.clear(); return str; }