List of usage examples for java.util Map containsValue
boolean containsValue(Object value);
From source file:com.company.project.service.dao.RedisDaoTest.java
@Test public void testMultiSetGetDeleteHash() { System.out.println("get"); String objectKey = "objectKeyHash"; Map map = new HashMap<>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); map.put("key4", "value4"); redisDao.multiSetHash(objectKey, map); List values = redisDao.multiGetHash(objectKey, map.keySet()); assertEquals(map.values().size(), values.size()); for (Object object : values) { assertTrue(map.containsValue(object)); }/*from w w w .j a v a2s . c om*/ boolean hasKey = redisDao.hasKeyHash(objectKey, "key1"); assertTrue(hasKey); hasKey = redisDao.hasKeyHash(objectKey, "key2"); assertTrue(hasKey); hasKey = redisDao.hasKeyHash(objectKey, "key3"); assertTrue(hasKey); hasKey = redisDao.hasKeyHash(objectKey, "key4"); assertTrue(hasKey); Map entries = redisDao.entriesHash(objectKey); assertNotNull(entries); for (Object object : entries.keySet()) { assertTrue(map.containsKey(object)); } for (Object object : entries.values()) { assertTrue(map.containsValue(object)); } Set entriesKey = redisDao.keysHash(objectKey); assertNotNull(entriesKey); assertEquals(4, entriesKey.size()); assertTrue(entriesKey.contains("key1")); assertTrue(entriesKey.contains("key2")); assertTrue(entriesKey.contains("key3")); assertTrue(entriesKey.contains("key4")); Object object = redisDao.getHash(objectKey, "key1"); assertNotNull(object); assertEquals("value1", "" + object); object = redisDao.getHash(objectKey, "key2"); assertNotNull(object); assertEquals("value2", "" + object); object = redisDao.getHash(objectKey, "key3"); assertNotNull(object); assertEquals("value3", "" + object); object = redisDao.getHash(objectKey, "key4"); assertNotNull(object); assertEquals("value4", "" + object); redisDao.deleteHash(objectKey, "key1", "key2", "key3", "key4"); object = redisDao.getHash(objectKey, "key1"); assertNull(object); object = redisDao.getHash(objectKey, "key2"); assertNull(object); object = redisDao.getHash(objectKey, "key3"); assertNull(object); object = redisDao.getHash(objectKey, "key4"); assertNull(object); }
From source file:org.eclipse.mylyn.koji.client.api.AbstractKojiHubBaseClient.java
/** * Gets a map represent the source rpm by a build ID. For use with description * retrieving by package ID, which is contained by the map returned here. * @param buildId The build ID.//from w w w . ja v a 2s. com * @return A map representing the source rpm. * @throws KojiClientException */ @SuppressWarnings("unchecked") public Map<String, Object> getSourceRPMFromBuildIdAsMap(int buildId) throws KojiClientException { if (this.userID == null) this.userID = KojiSessionInfoParsingUtility.getUserID(this.getSessionInfoAsMap()); ArrayList<Object> params = new ArrayList<Object>(); params.add(new Integer(buildId)); Object[] webMethodResult = null; try { webMethodResult = (Object[]) xmlRpcClient.execute("listBuildRPMs", params); } catch (XmlRpcException e) { throw new KojiClientException(e); } if ((webMethodResult != null) && (webMethodResult.length > 0)) { //Select only the source rpm for (Object o : webMethodResult) { Map<String, Object> tempMap = (Map<String, Object>) o; if (tempMap.containsValue("src")) return tempMap; } //should not happen as the srpm is not found... return null; } else return null; }
From source file:com.haulmont.cuba.web.App.java
protected Locale resolveLocale(@Nullable Locale requestLocale) { Map<String, Locale> locales = globalConfig.getAvailableLocales(); if (globalConfig.getLocaleSelectVisible()) { String lastLocale = getCookieValue(COOKIE_LOCALE); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; }/* w w w . j a va 2 s . c om*/ } } } if (requestLocale != null) { Locale requestTrimmedLocale = messageTools.trimLocale(requestLocale); if (locales.containsValue(requestTrimmedLocale)) { return requestTrimmedLocale; } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(requestLocale.getCountry())) { Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } } // return default locale return messageTools.getDefaultLocale(); }
From source file:com.haulmont.cuba.web.sys.CubaApplicationServlet.java
protected Locale resolveLocale(HttpServletRequest req, Messages messages, GlobalConfig globalConfig) { Map<String, Locale> locales = globalConfig.getAvailableLocales(); if (globalConfig.getLocaleSelectVisible()) { String lastLocale = getCookieValue(req, "LAST_LOCALE"); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; }/*from w ww .ja v a2s . c om*/ } } } Locale requestLocale = req.getLocale(); if (requestLocale != null) { Locale requestTrimmedLocale = messages.getTools().trimLocale(requestLocale); if (locales.containsValue(requestTrimmedLocale)) { return requestTrimmedLocale; } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(requestLocale.getCountry())) { Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } } return messages.getTools().getDefaultLocale(); }
From source file:org.jamocha.dn.NetworkToDot.java
public NetworkToDot(final SideEffectFunctionToNetwork network, final String... rules) { super();/*from w w w .ja va 2 s.co m*/ Arrays.sort(rules); for (final TerminalNode terminalNode : network.getTerminalNodes()) { final String ruleName = terminalNode.getRule().getParent().getName(); if (rules.length != 0 && Arrays.binarySearch(rules, ruleName) < 0) { continue; } this.terminalNodes.put(terminalNode, ruleName); final Node sourceNode = terminalNode.getEdge().getSourceNode(); final Map<Template, String> template2Name = new HashMap<>(); final Map<Template, Integer> template2Occurences = new HashMap<>(); final List<Template> templates = Arrays.asList(sourceNode.getMemory().getTemplate()); final List<FactAddress> addresses = new ArrayList<>(Collections.nCopies(templates.size(), null)); final List<String> names = new ArrayList<>(Collections.nCopies(templates.size(), null)); for (int i = 0; i < templates.size(); i++) { final Template template = templates.get(i); String name = template2Name.get(template); if (null == name) { int length = 1; while (null == name || template2Name.containsValue(name)) { name = template.getName().substring(0, length++); } template2Name.put(template, name); } final Integer occurencesI = template2Occurences.get(template); int occurences = 0; if (null != occurencesI) { occurences = occurencesI; } occurences++; template2Occurences.put(template, occurences); name = name + StringUtils.repeat("'", occurences - 1); names.set(i, name); } final String sourceNodeName = getNodeName(sourceNode); sourceNode.accept(new GraphConstructingNodeVisitor(names, templates, addresses)); generateEdge(sourceNodeName, ruleName, "(" + String.join(", ", names) + ")"); } }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.aop.ListLikeMapAdapterInterceptor.java
/** * {@inheritDoc}//from w w w . j a v a2 s. c o m */ @Override public Object invoke(final MethodInvocation invocation) throws Throwable { final Object result; final Method method = invocation.getMethod(); final Class<?> declaringClass = method.getDeclaringClass(); final Object this1 = invocation.getThis(); if ((List.class.equals(declaringClass) || Collection.class.equals(declaringClass)) && !(this1 instanceof List<?>)) { if (invocation instanceof ProxyMethodInvocation && ((ProxyMethodInvocation) invocation).getProxy() instanceof Map<?, ?>) { final Map<?, ?> map = (Map<?, ?>) ((ProxyMethodInvocation) invocation).getProxy(); final String methodName = method.getName(); boolean proceedInvocation = false; Object adaptedResult = null; final Object[] arguments = invocation.getArguments(); final Class<?>[] parameterTypes = method.getParameterTypes(); // String-switch not supported in Java < 8 switch (ListMethodName.methodLiteralOf(methodName)) { case SIZE: adaptedResult = Integer.valueOf(map.size()); break; case ISEMPTY: adaptedResult = Boolean.valueOf(map.isEmpty()); break; case CONTAINS: adaptedResult = Boolean.valueOf(map.containsValue(arguments[0])); break; case ITERATOR: adaptedResult = map.values().iterator(); break; case TOARRAY: adaptedResult = arguments.length == 1 ? map.values().toArray((Object[]) arguments[0]) : map.values().toArray(); break; case CONTAINSALL: adaptedResult = Boolean.valueOf(map.values().containsAll((Collection<?>) arguments[0])); break; case REMOVEALL: adaptedResult = Boolean.valueOf(map.values().removeAll((Collection<?>) arguments[0])); break; case INDEXOF: { int idx = 0; int foundIdx = -1; final Iterator<?> valueIterator = map.values().iterator(); while (valueIterator.hasNext()) { final Object el = valueIterator.next(); if (el == arguments[0] || (arguments[0] != null && arguments[0].equals(el))) { foundIdx = idx; break; } idx++; } adaptedResult = Integer.valueOf(foundIdx); } break; case LASTINDEXOF: { int idx = 0; int foundIdx = -1; final Iterator<?> valueIterator = map.values().iterator(); while (valueIterator.hasNext()) { final Object el = valueIterator.next(); if (el == arguments[0] || (arguments[0] != null && arguments[0].equals(el))) { foundIdx = idx; } idx++; } adaptedResult = Integer.valueOf(foundIdx); } break; case GET: { final int targetIdx = ((Integer) arguments[0]).intValue(); if (targetIdx < 0 || targetIdx >= map.size()) { throw new IndexOutOfBoundsException(); } int idx = 0; Object found = null; final Iterator<?> valueIterator = map.values().iterator(); while (valueIterator.hasNext()) { final Object el = valueIterator.next(); if (idx == targetIdx) { found = el; break; } idx++; } adaptedResult = found; } break; case REMOVE: { if (arguments[0] instanceof Integer && int.class.equals(parameterTypes[0])) { final int targetIdx = ((Integer) arguments[0]).intValue(); if (targetIdx < 0 || targetIdx >= map.size()) { throw new IndexOutOfBoundsException(); } int idx = 0; final Iterator<?> keyIterator = map.keySet().iterator(); Object keyToRemove = null; while (keyIterator.hasNext()) { final Object el = keyIterator.next(); if (idx == targetIdx) { keyToRemove = el; break; } idx++; } adaptedResult = keyToRemove != null ? map.remove(keyToRemove) : null; } else { adaptedResult = Boolean.valueOf(map.values().remove(arguments[0])); } } break; case RETAINALL: adaptedResult = Boolean.valueOf(map.values().retainAll((Collection<?>) arguments[0])); break; case CLEAR: map.clear(); break; case LISTITERATOR: // fallthrough case SUBLIST: // fallthrough case SET:// fallthrough case ADD:// fallthrough case ADDALL: // not supported throw new UnsupportedOperationException(); default: proceedInvocation = true; } if (proceedInvocation) { // may fail (if we have forgotten to map a specific operation or a new operation may have been introduced) result = invocation.proceed(); } else { result = adaptedResult; } } else { // may fail when other interceptors / target do not support List result = invocation.proceed(); } } else { // may fail when List was declaring class but type of "this" does not support this interceptor result = invocation.proceed(); } return result; }
From source file:net.dv8tion.jda.managers.RoleManager.java
/** * Moves this Role up or down in the list of Roles (changing position attribute) * This change takes effect immediately! * * @param newPosition/*from w w w .ja v a2 s . c om*/ * the amount of positions to move up (offset < 0) or down (offset > 0) * @return * this */ public RoleManager move(int newPosition) { checkPermission(Permission.MANAGE_ROLES); checkPosition(); int maxRolePosition = role.getGuild().getRolesForUser(role.getJDA().getSelfInfo()).get(0).getPosition(); if (newPosition >= maxRolePosition) throw new PermissionException( "Cannot move to a position equal to or higher than the highest role that you have access to."); if (newPosition < 0 || newPosition == role.getPosition()) return this; Map<Integer, Role> newPositions = new HashMap<>(); Map<Integer, Role> currentPositions = role.getGuild().getRoles().stream() .collect(Collectors.toMap(role -> role.getPosition(), role -> role)); //Remove the @everyone role from our working set. currentPositions.remove(-1); int searchIndex = newPosition > role.getPosition() ? newPosition : newPosition; int index = 0; for (Role r : currentPositions.values()) { if (r == role) continue; if (index == searchIndex) { newPositions.put(index, role); index++; } newPositions.put(index, r); index++; } //If the role was moved to the very top, this will make sure it is properly handled. if (!newPositions.containsValue(role)) newPositions.put(newPosition, role); for (int i = 0; i < newPositions.size(); i++) { if (currentPositions.get(i) == newPositions.get(i)) newPositions.remove(i); } JSONArray rolePositions = new JSONArray(); newPositions.forEach((pos, r) -> { rolePositions.put(new JSONObject().put("id", r.getId()).put("position", pos + 1)); }); ((JDAImpl) role.getJDA()).getRequester().patch( Requester.DISCORD_API_PREFIX + "guilds/" + role.getGuild().getId() + "/roles", rolePositions); return this; }
From source file:pt.webdetails.cpk.sitemap.LinkGenerator.java
private void generateLinks(Map<String, IElement> elementsMap) { dashboardLinks = new ArrayList<Link>(); Map<String, File> directories = getTopLevelDirectories(elementsMap.values()); Link l = null;//from w w w . j av a 2 s .c om for (File directory : directories.values()) { if (!directory.getName().equals(ADMIN_DIR) && !directory.getName().equals(KETTLE_DIR)) { for (File file : getFiles(directory)) { int index = file.getName().indexOf("."); String filename = file.getName().substring(0, index).toLowerCase(); if (elementsMap.containsKey(filename)) { IElement element = elementsMap.get(filename); if (isDashboard(element)) { l = new Link(elementsMap.get(filename), pluginUtils); if (!linkExists(dashboardLinks, l)) { dashboardLinks.add(l); } } } for (File dir : getDirectories(directory)) { if (!dir.getName().equals(ADMIN_DIR) && !directories.containsValue(dir)) { l = new Link(dir, elementsMap, pluginUtils); if (!linkExists(dashboardLinks, l)) { dashboardLinks.add(l); } } } } } } }
From source file:io.cloudslang.content.amazon.factory.helpers.InstanceUtils.java
private void setOptionalQueryParamEntry(Map<String, String> queryParamsMap, String[] inputArray, String customKey, int index, boolean condition) { if (condition && ENCRYPTED.equalsIgnoreCase(customKey) && valueOf(ONE).equalsIgnoreCase(inputArray[index])) { queryParamsMap.put(getQueryParamsSpecificString(EBS, index) + customKey, inputArray[index]); } else if (condition && VOLUME_TYPE.equalsIgnoreCase(customKey)) { queryParamsMap.put(getQueryParamsSpecificString(EBS, index) + customKey, VolumeType.getValue(inputArray[index])); } else if (condition && IOPS.equalsIgnoreCase(customKey) && queryParamsMap.containsValue(VolumeType.IO1.toString())) { queryParamsMap.put(getQueryParamsSpecificString(EBS, index) + customKey, inputArray[index]); } else if (condition && VOLUME_SIZE.equalsIgnoreCase(customKey) && queryParamsMap.keySet().toString().contains(BLOCK_DEVICE_MAPPING)) { String currentVolumeType = getCurrentVolumeType(queryParamsMap, index); String currentValidSize = isBlank(currentVolumeType) ? getValidEbsSize(inputArray[index], STANDARD) : getValidEbsSize(inputArray[index], currentVolumeType); setOptionalMapEntry(queryParamsMap, getQueryParamsSpecificString(EBS, index) + customKey, currentValidSize, !NOT_RELEVANT.equalsIgnoreCase(currentValidSize)); } else if (condition && DELETE_ON_TERMINATION.equalsIgnoreCase(customKey) && getEnforcedBooleanCondition(inputArray[index], true) == Boolean.FALSE) { queryParamsMap.put(getQueryParamsSpecificString(EBS, index) + customKey, inputArray[index]); } else if (condition && SNAPSHOT_ID.equalsIgnoreCase(customKey)) { queryParamsMap.put(getQueryParamsSpecificString(EBS, index) + customKey, inputArray[index]); }/*from w w w . j av a 2s . co m*/ }
From source file:io.cloudslang.content.amazon.factory.helpers.NetworkUtils.java
private void setPrivateIpAddressesQueryParams(Map<String, String> queryParamsMap, InputsWrapper wrapper, String specificArea, String delimiter) { if (isNotBlank(wrapper.getElasticIpInputs().getPrivateIpAddressesString())) { String[] privateIpAddressesArray = getArrayWithoutDuplicateEntries( wrapper.getElasticIpInputs().getPrivateIpAddressesString(), PRIVATE_IP_ADDRESSES_STRING, delimiter);/*from w w w . j a v a 2 s . c o m*/ if (isNotEmpty(privateIpAddressesArray)) { for (int index = START_INDEX; index < privateIpAddressesArray.length; index++) { privateIpAddressesArray[index] = getValidIPv4Address(privateIpAddressesArray[index]); if (index == START_INDEX && !queryParamsMap .containsKey(getQueryParamsSpecificString(specificArea, START_INDEX) + PRIMARY) && !queryParamsMap.containsValue(Boolean.TRUE.toString().toLowerCase())) { queryParamsMap.put(getQueryParamsSpecificString(specificArea, index) + PRIMARY, Boolean.TRUE.toString().toLowerCase()); queryParamsMap.put(getQueryParamsSpecificString(specificArea, index) + PRIVATE_IP_ADDRESS, privateIpAddressesArray[index]); } else { int startIndex = NETWORK_INTERFACE.equalsIgnoreCase(specificArea) ? index : index + ONE; queryParamsMap.put(getQueryParamsSpecificString(specificArea, startIndex) + PRIMARY, Boolean.FALSE.toString().toLowerCase()); queryParamsMap.put( getQueryParamsSpecificString(specificArea, startIndex) + PRIVATE_IP_ADDRESS, privateIpAddressesArray[index]); } if (NETWORK_INTERFACE.equalsIgnoreCase(specificArea)) { setNetworkInterfaceSpecificQueryParams(queryParamsMap, wrapper, privateIpAddressesArray, index); } } } } }