Example usage for java.util Map containsKey

List of usage examples for java.util Map containsKey

Introduction

In this page you can find the example usage for java.util Map containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

private static boolean isCached(File imgRef, File img) {
    if (cache.containsKey(imgRef)) {
        Map<File, Boolean> comparisons = cache.get(imgRef);
        if (comparisons.containsKey(img)) {
            return true;
        }//from  w w w.  jav  a  2  s  .  co  m
    }
    return false;
}

From source file:Main.java

public static Map<String, String> compareMap(Map<String, String> map, Object obj) {
    Map<String, String> mapValue = new HashMap<String, String>();
    Field[] fields = obj.getClass().getDeclaredFields();
    for (Field field : fields) {
        String name = field.getName();
        if (map.containsKey(name)) {
            mapValue.put(name, map.get(name));
        }/*from w w  w. j av a 2s .co m*/
    }
    return mapValue;
}

From source file:de.iritgo.simplelife.bean.BeanTools.java

/**
 * Copy all attributes from the given bean to the given map
 * /*ww w .j  a  v a 2  s . c  om*/
 * @param object The bean
 * @param map The map
 * @param overwrite If true existing attributes in the map will be
 *            overwritten
 */
static public void copyBean2Map(Object object, Map<String, Object> map, boolean overwrite) {
    for (PropertyDescriptor pd : PropertyUtils.getPropertyDescriptors(object)) {
        String name = pd.getName();

        if (!overwrite && map.containsKey(name)) {
            continue;
        }

        try {
            map.put(name, PropertyUtils.getProperty(object, name));
        } catch (Exception ignore) {
        }
    }
}

From source file:com.oplay.nohelper.volley.toolbox.HttpHeaderParser.java

/**
 * Extracts a {@link Cache.Entry} from a {@link NetworkResponse}.
 *
 * @param response The network response to parse headers from
 * @return a cache entry for the given response, or null if the response is not cacheable.
 *///from   w  w  w  .  j a v a 2 s .  co m
public static Cache.Entry parseCacheHeaders(NetworkResponse response) {
    long now = System.currentTimeMillis();

    Map<String, String> headers = response.headers;

    long serverDate = 0;

    String serverEtag = null;
    String headerValue;

    if (headers.containsKey("Data")) {
        headerValue = headers.get("Date");
        if (headerValue != null) {
            serverDate = parseDateAsEpoch(headerValue);
        }
    }

    if (headers.containsKey("ETag")) {
        serverEtag = headers.get("ETag");
        VolleyLog.d("Cache-Control", serverEtag.toString());
    }

    Cache.Entry entry = new Cache.Entry();
    entry.setKey(key);
    entry.data = response.data;
    entry.mEtag = serverEtag;
    entry.mServerDate = serverDate;
    entry.responseHeaders = headers;
    return entry;
}

From source file:net.maritimecloud.endorsement.utils.AccessControlUtil.java

public static boolean hasAccessToOrg(String orgMrn) {
    if (orgMrn == null || orgMrn.trim().isEmpty()) {
        logger.debug("The orgMrn was empty!");
        return false;
    }//from   www  .  j  av  a  2s  .c o 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();
    logger.debug("User has role: " + role);
    if ("ROLE_SITE_ADMIN".equals(role)) {
        return true;
    }
    }
    logger.debug("User not a SITE_ADMIN");*/
    // Check if the user is part of the organization
    if (auth instanceof KeycloakAuthenticationToken) {
        logger.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())) {
            logger.debug("Entity from org: " + otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME) + " is in "
                    + orgMrn);
            return true;
        }
        logger.debug("Entity from org: " + otherClaims.get(AccessControlUtil.ORG_PROPERTY_NAME) + " is not in "
                + orgMrn);
        /*} else if (auth instanceof PreAuthenticatedAuthenticationToken) {
            logger.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)) {
        logger.debug("Entity with O=" + certOrgMrn + " is in " + orgMrn);
        return true;
            }
            logger.debug("Entity with O=" + certOrgMrn + " is not in " + orgMrn);*/
    } else {
        if (auth != null) {
            logger.debug("Unknown authentication method: " + auth.getClass());
        }
    }
    return false;
}

From source file:net.doubledoordev.backend.webserver_old.methods.Post.java

/**
 * Handle post requests from the register page
 *//*  ww  w . ja  v  a 2 s. c  o m*/
private static void handleRegister(HashMap<String, Object> dataObject, NanoHTTPD.HTTPSession session,
        Map<String, String> map) {
    if (map.containsKey("username") && map.containsKey("password") && map.containsKey("areyouhuman")) {
        boolean admin = false;
        if ((Main.adminKey != null && map.get("areyouhuman").equals(Main.adminKey)))
            admin = true;
        else if (!map.get("areyouhuman").trim().equals("4")) // only do human test if not admin key
        {
            dataObject.put("message", "You failed the human test...");
            return;
        }

        User user = Settings.getUserByName(map.get("username"));
        if (!Constants.USERNAME_PATTERN.matcher(map.get("username")).matches()) {
            dataObject.put("message", "Username contains invalid chars.<br>Only a-Z, 0-9, _ and - please.");
        } else if (user == null) {
            try {
                user = new User(map.get("username"), PasswordHash.createHash(map.get("password")));
                if (admin) {
                    user.setGroup(Group.ADMIN);
                    Main.adminKey = null;
                }
                Settings.SETTINGS.users.put(user.getUsername().toLowerCase(), user);
                session.getCookies().set(COOKIE_KEY, user.getUsername() + "|" + user.getPasshash(), 30);
                dataObject.put("user", user);
                Settings.save();
            } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
                // Hash algorithm doesn't work.
                throw new RuntimeException(e);
            }
        } else
            dataObject.put("message", "Username taken.");
    } else
        dataObject.put("message", "Form error.");
}

From source file:Main.java

public static <TKey extends TKeyT, TKeyT> Map<? super TKey, Integer> mergeMapWithAdd(Map<TKeyT, Integer> target,
        Map<? extends TKey, ? extends Integer> source) {
    for (Entry<? extends TKey, ? extends Integer> entry2 : source.entrySet()) {
        TKey key2 = entry2.getKey();//ww w.  j  a va 2 s  .  co m
        int val2 = entry2.getValue();
        if (target.containsKey(key2)) {
            int val1 = target.get(key2);
            target.put(key2, val1 + val2);
        } else {
            target.put(key2, val2);
        }
    }
    return target;
}

From source file:com.netflix.spinnaker.clouddriver.google.controllers.GoogleNamedImageLookupController.java

private static boolean matchesTagFilters(NamedImage namedImage, Map<String, String> tagFilters) {
    Map<String, String> tags = namedImage.tags;
    return tagFilters.keySet().stream().allMatch(tag -> tags.containsKey(tag.toLowerCase())
            && tags.get(tag.toLowerCase()).equalsIgnoreCase(tagFilters.get(tag)));
}

From source file:ai.susi.tools.JsonSignature.java

public static boolean verify(Map<String, byte[]> obj, PublicKey key)
        throws SignatureException, InvalidKeyException {

    if (!obj.containsKey(signatureString))
        throw new SignatureException("No signature supplied");

    Signature signature;//from w  w  w  .  j  a va2  s .c om
    try {
        signature = Signature.getInstance("SHA256withRSA");
    } catch (NoSuchAlgorithmException e) {
        return false; //does not happen
    }

    byte[] sigString = obj.get(signatureString);
    byte[] sig = Base64.getDecoder().decode(sigString);
    obj.remove(signatureString);

    signature.initVerify(key);
    signature.update(obj.toString().getBytes(StandardCharsets.UTF_8));
    boolean res = signature.verify(sig);

    obj.put(signatureString, sigString);

    return res;
}

From source file:com.cloudera.kitten.appmaster.params.lua.WorkflowParameters.java

private static Map<String, URI> loadLocalToUris() {
    Map<String, String> e = System.getenv();
    if (e.containsKey(LuaFields.KITTEN_LOCAL_FILE_TO_URI)) {
        return LocalDataHelper.deserialize(e.get(LuaFields.KITTEN_LOCAL_FILE_TO_URI));
    }/*  w  w w. j  a  v a 2 s  .  c  om*/
    return ImmutableMap.of();
}