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.metamx.druid.utils.ExposeS3DataSource.java

private static void updateWithS3Object(String zkBasePath, RestS3Service s3Client, ZkClient zkClient,
        S3Object partitionObject) throws ServiceException, IOException {
    log.info("Looking for object[%s]", partitionObject);

    String descriptor;/*  w  w  w  .j a  va2 s .  c  om*/
    try {
        descriptor = S3Utils.getContentAsString(s3Client, partitionObject);
    } catch (S3ServiceException e) {
        log.info(e, "Problem loading descriptor for partitionObject[%s]: %s", partitionObject, e.getMessage());
        return;
    }
    Map<String, Object> map = jsonMapper.readValue(descriptor, new TypeReference<Map<String, Object>>() {
    });
    DataSegment segment;
    if (map.containsKey("partitionNum") && "single".equals(MapUtils.getMap(map, "shardSpec").get("type"))) {
        MapUtils.getMap(map, "shardSpec").put("partitionNum", map.get("partitionNum"));
        segment = jsonMapper.convertValue(map, DataSegment.class);
    } else {
        segment = jsonMapper.readValue(descriptor, DataSegment.class);
    }

    final String dataSourceBasePath = JOINER.join(zkBasePath, segment.getDataSource());
    if (!zkClient.exists(dataSourceBasePath)) {
        zkClient.createPersistent(dataSourceBasePath,
                jsonMapper.writeValueAsString(ImmutableMap.of("created", new DateTime().toString())));
    }

    String zkPath = JOINER.join(zkBasePath, segment.getDataSource(), segment.getIdentifier());
    if (!zkClient.exists(zkPath)) {
        log.info("Adding descriptor to zkPath[%s]: %s", zkPath, descriptor);
        zkClient.createPersistent(zkPath, descriptor);
    }
}

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

public static boolean hasPermission(String permission) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth instanceof KeycloakAuthenticationToken) {
        log.debug("OIDC permission lookup");
        // Keycloak authentication
        KeycloakAuthenticationToken kat = (KeycloakAuthenticationToken) auth;
        KeycloakSecurityContext ksc = (KeycloakSecurityContext) kat.getCredentials();
        Map<String, Object> otherClaims = ksc.getToken().getOtherClaims();
        if (otherClaims.containsKey(AccessControlUtil.PERMISSIONS_PROPERTY_NAME)) {
            String usersPermissions = (String) otherClaims.get(AccessControlUtil.PERMISSIONS_PROPERTY_NAME);
            String[] permissionList = usersPermissions.split(",");
            for (String per : permissionList) {
                if (per.equalsIgnoreCase(permission)) {
                    return true;
                }//from  w w  w  .  j av a2s .co m
            }
        }
    } else if (auth instanceof PreAuthenticatedAuthenticationToken) {
        log.debug("Certificate permission lookup");
        // Certificate authentication
        PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) auth;
        // Check that the permission is granted to this user
        InetOrgPerson person = ((InetOrgPerson) token.getPrincipal());
        Collection<GrantedAuthority> authorities = person.getAuthorities();
        for (GrantedAuthority authority : authorities) {
            String usersPermissions = authority.getAuthority();
            String[] permissionList = usersPermissions.split(",");
            for (String per : permissionList) {
                if (per.equalsIgnoreCase(permission)) {
                    return true;
                }
            }
        }
    } else {
        if (auth != null) {
            log.debug("Unknown authentication method: " + auth.getClass());
        }
    }
    return false;
}

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

private static Map<String, Object> loadExtras(Map<String, Object> masterExtras) {
    Map<String, String> e = System.getenv();
    if (e.containsKey(LuaFields.KITTEN_EXTRA_LUA_VALUES)) {
        Map<String, Object> extras = Maps
                .newHashMap(LocalDataHelper.deserialize(e.get(LuaFields.KITTEN_EXTRA_LUA_VALUES)));
        extras.putAll(masterExtras);//from w ww .  j  av a 2 s  .c o m
        return extras;
    }
    return masterExtras;
}

From source file:com.morty.podcast.writer.PodCastUtils.java

/**
 * Gets a value from a hashmap, and if it doesnt exist, returns the default.
 * @param customValues// w ww. j a  v a 2 s .  c  o m
 * @param key
 * @param defaultValue
 * @return
 */
public static String getMapValue(Map customValues, String key, String defaultValue) {
    if (customValues.containsKey(key))
        return customValues.get(key).toString();
    else
        return defaultValue;
}

From source file:Main.java

public static List<String> findMatchingColumnsAfterSafeningNames(String[] columnNames) {
    // key is the safe, value is the unsafe
    Map<String, String> map = new HashMap<String, String>();
    for (String columnName : columnNames) {
        if (columnName.trim().length() > 0) {
            String safeColumn = toSafeColumnName(columnName);
            if (!map.containsKey(safeColumn)) {
                map.put(safeColumn, columnName);
            } else {
                return Arrays.asList(map.get(safeColumn), columnName);
            }/*from   w ww.j a va2  s  .  c o  m*/
        }
    }
    return null;
}

From source file:Main.java

public static String[] mapToStringArray(Map<String, Object> map, String... keys) {
    String[] array = new String[keys.length];
    for (int i = 0; i < keys.length; i++) {
        String key = keys[i];/*from ww w  .  j  a v  a  2 s . co m*/
        Object value = map.get(key);
        String strValue = null;
        if (!map.containsKey(key)) {
            strValue = key;
        } else if (value == null) {
            strValue = "";
        } else if (value instanceof BigDecimal) {
            BigDecimal conv = (BigDecimal) value;
            strValue = conv.toPlainString();
        } else {
            strValue = value.toString();
        }
        array[i] = strValue;
    }
    return array;
}

From source file:com.qualogy.qafe.web.ContextLoaderHelper.java

public static List<String> getLoadOnStartupWindowsFromParams(SessionContainer sessionContainer) {
    List<String> loadOnStartupWindowList = new ArrayList<String>();
    Map<String, String> parameters = sessionContainer.getParameters();
    if ((parameters != null) && parameters.containsKey(Configuration.LOAD_ON_STARTUP)) {
        String[] paramStartupWindows = StringUtils.split(parameters.get(Configuration.LOAD_ON_STARTUP), ",");
        if (paramStartupWindows != null) {
            for (int i = 0; i < paramStartupWindows.length; i++) {
                String paramStartupWindow = paramStartupWindows[i];
                if (!paramStartupWindow.contains(".")) {
                    ApplicationContext appContext = ApplicationCluster.getInstance()
                            .getApplicationContext(paramStartupWindow);
                    if (appContext != null) {
                        if ((appContext.getApplicationMapping() != null)
                                && (appContext.getApplicationMapping().getPresentationTier() != null)
                                && (appContext.getApplicationMapping().getPresentationTier().getView() != null)
                                && (appContext.getApplicationMapping().getPresentationTier().getView()
                                        .getWindows() != null)) {
                            List<Window> windowList = appContext.getApplicationMapping().getPresentationTier()
                                    .getView().getWindows();
                            // The first window is always the authentication window,
                            // so the size must be greater than 1
                            if (windowList.size() > 1) {
                                Window window = windowList.get(1);
                                paramStartupWindow = paramStartupWindow + "." + window.getId();
                                loadOnStartupWindowList.add(paramStartupWindow);
                            }//from w w w . ja v a  2  s . c  o  m
                        }
                    }
                } else {
                    loadOnStartupWindowList.add(paramStartupWindow);
                }
            }
        }
    }
    return loadOnStartupWindowList;
}

From source file:com.idega.hibernate.HibernateUtil.java

public static synchronized SessionFactory getSessionFactory(String cfgPath) {

    String confPath = StringUtil.isEmpty(cfgPath) ? "default" : cfgPath;

    Map<String, SessionFactory> sessionFactories = getInitializedSessionFactories();

    if (sessionFactories.containsKey(confPath))
        return sessionFactories.get(confPath);

    SessionFactory sf = StringUtil.isEmpty(cfgPath) ? configure() : configure(cfgPath);

    sessionFactories.put(confPath, sf);/*from   w ww .  ja va2  s. co  m*/
    return sf;
}

From source file:org.zalando.problem.ProblemModule.java

@SafeVarargs
private static <E extends Enum & StatusType> Map<Integer, StatusType> buildIndex(
        final Class<? extends E>... types) {
    final Map<Integer, StatusType> index = new HashMap<>();

    for (Class<? extends E> type : types) {
        for (final E status : type.getEnumConstants()) {
            if (index.containsKey(status.getStatusCode())) {
                throw new IllegalArgumentException("Duplicate status codes are not allowed");
            }/*from w w  w .  j  a v  a 2 s.  c  om*/
            index.put(status.getStatusCode(), status);
        }
    }

    return index;
}

From source file:com.adito.activedirectory.ActiveDirectoryPropertyManager.java

private static String getRealValue(Map<String, String> alternativeValues, String key, String value) {
    return alternativeValues.containsKey(key) ? alternativeValues.get(key) : value;
}