List of usage examples for java.util Map containsKey
boolean containsKey(Object key);
From source file:gate.termraider.util.Utilities.java
/** This is a little dodgy because it forces the new value * to be Integer; to be used carefully.//from ww w .j a v a 2 s .c o m * @param map * @param key * @param increment * @return */ public static int incrementMap(Map<Term, Number> map, Term key, int increment) { int count = 0; if (map.containsKey(key)) { count = map.get(key).intValue(); } count += increment; map.put(key, Integer.valueOf(count)); return count; }
From source file:net.maritimecloud.identityregistry.utils.AccessControlUtil.java
public static boolean hasAccessToOrg(String orgMrn) { if (orgMrn == null || orgMrn.trim().isEmpty()) { log.debug("The orgMrn was empty!"); return false; }/*from w w w . java 2s. co m*/ Authentication auth = SecurityContextHolder.getContext().getAuthentication(); // First check if the user is a SITE_ADMIN, in which case he gets access. for (GrantedAuthority authority : auth.getAuthorities()) { String role = authority.getAuthority(); log.debug("User has role: " + role); if ("ROLE_SITE_ADMIN".equals(role)) { return true; } } log.debug("User not a SITE_ADMIN"); // Check if the user is part of the organization if (auth instanceof KeycloakAuthenticationToken) { log.debug("OIDC authentication in process"); // Keycloak authentication KeycloakAuthenticationToken kat = (KeycloakAuthenticationToken) auth; KeycloakSecurityContext ksc = (KeycloakSecurityContext) kat.getCredentials(); Map<String, Object> otherClaims = ksc.getToken().getOtherClaims(); if (otherClaims.containsKey(AccessControlUtil.ORG_PROPERTY_NAME) && ((String) otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME)).toLowerCase() .equals(orgMrn.toLowerCase())) { log.debug("Entity from org: " + otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME) + " is in " + orgMrn); return true; } log.debug("Entity from org: " + otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME) + " is not in " + orgMrn); } else if (auth instanceof PreAuthenticatedAuthenticationToken) { log.debug("Certificate authentication in process"); // Certificate authentication PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) auth; // Check that the Organization name of the accessed organization and the organization in the certificate is equal InetOrgPerson person = ((InetOrgPerson) token.getPrincipal()); // The O(rganization) value in the certificate is an MRN String certOrgMrn = person.getO(); if (orgMrn.equals(certOrgMrn)) { log.debug("Entity with O=" + certOrgMrn + " is in " + orgMrn); return true; } log.debug("Entity with O=" + certOrgMrn + " is not in " + orgMrn); } else { log.debug("Unknown authentication method: " + auth.getClass()); } return false; }
From source file:com.log4ic.compressor.utils.template.JavascriptTemplateEngine.java
protected static String run(URI uri, String source, RunIt runIt) { Map<String, String> params = HttpUtils.getParameterMap(uri); String name;/* w w w .j ava 2 s. co m*/ Mode m = null; if (params.containsKey("amd")) { name = params.get("amd"); m = Mode.AMD; } else { name = params.get("name"); String mode = params.get("mode"); if (StringUtils.isBlank(name)) { name = uri.getPath(); int lastI = name.lastIndexOf("."); name = name.substring(name.lastIndexOf("/") + 1, lastI); } if (StringUtils.isNotBlank(mode)) { try { m = Mode.valueOf(mode.toUpperCase()); } catch (Exception e) { //fuck ide } } if (m == null) { m = Mode.COMMON; } } return runIt.run(name, source, m); }
From source file:Main.java
public static <V> void get(final Map<?, ? extends V> map, final Collection<? extends Object> keys, final Collection<? super V> values) { for (final Object key : keys) { if (!map.containsKey(key)) { continue; }//from ww w .j a v a 2 s .c o m final V value = map.get(key); values.add(value); } }
From source file:com.formkiq.core.form.bean.FormFieldMapper.java
/** * Maps {@link FormJSONField} field values. * @param source {@link FormJSON}/*from w ww. ja v a2s.co m*/ * @param dest {@link FormJSON} * @param mapping {@link Map} */ public static void map(final FormJSON source, final FormJSON dest, final Map<String, String> mapping) { Map<String, FormJSONField> sourceMap = transformToIdMap(source); Map<String, FormJSONField> destMap = transformToIdMap(dest); mapping.entrySet().forEach(m -> { if (sourceMap.containsKey(m.getKey()) && destMap.containsKey(m.getValue())) { destMap.get(m.getValue()).setValue(sourceMap.get(m.getKey()).getValue()); } }); }
From source file:org.openspaces.security.ldap.GroupMapperAuthorityFactory.java
public static ArrayList<Authority> create(Collection<? extends GrantedAuthority> grantedAuthorities, Map authorityMap) { ArrayList<Authority> authoritiesList = new ArrayList<Authority>(); for (GrantedAuthority grantedAuthority : grantedAuthorities) { String memberOf = grantedAuthority.getAuthority().trim(); if (authorityMap.containsKey(memberOf)) { String gsAuthorityRules = (String) authorityMap.get(memberOf); String[] split = gsAuthorityRules.split(AUTHORITY_MAP_DELIM); for (String authority : split) { Authority gsAuthority = AuthorityFactory.create(authority); authoritiesList.add(gsAuthority); }//from w ww. jav a 2 s. c o m } } return authoritiesList; }
From source file:gate.termraider.util.Utilities.java
public static void addToMapSet(Map<Term, Set<String>> map, Term key, String value) { Set<String> valueSet; if (map.containsKey(key)) { valueSet = map.get(key);/*from w w w . ja va 2 s .c o m*/ } else { valueSet = new HashSet<String>(); } valueSet.add(value); map.put(key, valueSet); }
From source file:Maps.java
public static <K, V> Map<K, V> remove(Map<K, V> map, K key) { switch (map.size()) { case 0:/*from w w w . j ava 2 s. c om*/ // Empty return map; case 1: // Singleton -> Empty if (map.containsKey(key)) { return create(); } return map; case 2: // HashMap -> Singleton if (map.containsKey(key)) { map.remove(key); key = map.keySet().iterator().next(); return create(key, map.get(key)); } return map; default: // IdentityHashMap map.remove(key); return map; } }
From source file:com.nimbits.MainClass.java
private static Value buildValue(final Map<String, String> argsMap) { final double d = argsMap.containsKey(Parameters.value.getText()) ? Double.valueOf(argsMap.get(Parameters.value.getText())) : 0.0;/*from w ww .j a va2 s.c o m*/ final String note = argsMap.containsKey(Parameters.note.getText()) ? argsMap.get(Parameters.note.getText()) : null; final double lat = argsMap.containsKey(Parameters.lat.getText()) ? Double.valueOf(argsMap.get(Parameters.lat.getText())) : 0.0; final double lng = argsMap.containsKey(Parameters.lng.getText()) ? Double.valueOf(argsMap.get(Parameters.lng.getText())) : 0.0; Location location = LocationFactory.createLocation(lat, lng); return null;//ValueFactory.createValueModel(location, d, new Date(), note, ValueFactory.createValueData(""), AlertType.OK); }
From source file:com.ibm.rpe.web.service.docgen.impl.GenerateBaseTemplate.java
private static void writeContextInfo(List<BaseTemplateInput> inputDataList, String contextFilePath) throws FileNotFoundException { StringBuffer contextBuf = new StringBuffer(); if (inputDataList != null) { for (BaseTemplateInput data : inputDataList) { Map<String, String> params = data.getReplaceMap(); if (params != null && params.containsKey(TemplateConstants.QUERY_CONTEXT)) { String context = params.get(TemplateConstants.QUERY_CONTEXT); if (context != null && context.length() > 0) { contextBuf.append(data.getReplacement() == null ? TemplateConstants.DOCUMENT_TITLE : data.getReplacement()).append("=").append(context).append(";"); }/* ww w . j av a 2 s . c om*/ } } if (contextBuf.length() > 0) { FileUtils.writeFile(contextFilePath, contextBuf.toString()); } } }