Example usage for java.util Map getClass

List of usage examples for java.util Map getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.apache.cassandra.cql.jdbc.HandleObjects.java

private static final <K, V> ByteBuffer makeByteBuffer4Map(AbstractJdbcType<?> keyInstanceType,
        AbstractJdbcType<?> valueInstanceType, Map<K, V> value) {
    return MapMaker.getInstance(keyInstanceType, valueInstanceType).decompose(value.getClass().cast(value));
}

From source file:org.rhq.plugins.jbossas5.ManagedComponentComponent.java

private static String toString(ManagedComponent managedComponent) {
    Map<String, ManagedProperty> properties = managedComponent.getProperties();
    return managedComponent.getClass().getSimpleName() + "@" + System.identityHashCode(managedComponent) + "["
            + "type=" + managedComponent.getType() + ", name=" + managedComponent.getName() + ", properties="
            + properties.getClass().getSimpleName() + "@" + System.identityHashCode(properties) + "]";
}

From source file:org.openecomp.sdc.ci.tests.utils.rest.ResponseParser.java

@SuppressWarnings("unchecked")
public static ResourceRespJavaObject parseJsonListReturnResourceDetailsObj(RestResponse restResponse,
        String resourceType, String searchPattern, String expectedResult) throws Exception {

    // Gson gson = new Gson;

    JsonElement jElement = new JsonParser().parse(restResponse.getResponse());
    JsonObject jObject = jElement.getAsJsonObject();
    JsonArray arrayOfObjects = (JsonArray) jObject.get(resourceType);
    Gson gson = new Gson();
    Map<String, Object> map = new HashMap<String, Object>();
    ResourceRespJavaObject jsonToJavaObject = new ResourceRespJavaObject();

    for (int counter = 0; counter < arrayOfObjects.size(); counter++) {
        JsonObject jHitObject = (JsonObject) arrayOfObjects.get(counter);

        map = (Map<String, Object>) gson.fromJson(jHitObject.toString(), map.getClass());
        if (map.get(searchPattern).toString().contains(expectedResult)) {

            jsonToJavaObject = gson.fromJson(jObject, ResourceRespJavaObject.class);
            break;
        }//from ww w . j a v  a 2  s .c  om
    }
    return jsonToJavaObject;

}

From source file:br.msf.commons.util.CollectionUtils.java

public static Map<String, String> asStringMap(final Map<?, ?> map) {
    if (map == null) {
        return null;
    }//from  w w  w . j  a va 2 s  .  c  o m
    if (isNotEmpty(map)) {
        final Map<String, String> converted = new LinkedHashMap<>(map.size());
        if (Properties.class.isAssignableFrom(map.getClass())) {
            // Properties are a case apart, because it can have 'defaults'.
            final Properties p = (Properties) map;
            for (String key : p.stringPropertyNames()) {
                converted.put(key, p.getProperty(key));
            }
        } else {
            for (Entry<? extends Object, ? extends Object> entry : map.entrySet()) {
                converted.put(CharSequenceUtils.toNullSafeString(entry.getKey()),
                        CharSequenceUtils.toString(entry.getValue()));
            }
        }
        return converted;
    }
    return EMPTY_MAP;
}

From source file:br.ojimarcius.commons.util.CollectionUtils.java

public static Map<String, String> asStringMap(final Map<?, ?> map) {
    if (map == null) {
        return null;
    }// w w  w  . j a  va  2s. c  om
    if (isNotEmpty(map)) {
        final Map<String, String> converted = new LinkedHashMap<String, String>(map.size());
        if (Properties.class.isAssignableFrom(map.getClass())) {
            // Properties are a case apart, because it can have 'defaults'.
            final Properties p = (Properties) map;
            for (String key : p.stringPropertyNames()) {
                converted.put(key, p.getProperty(key));
            }
        } else {
            for (Entry<? extends Object, ? extends Object> entry : map.entrySet()) {
                converted.put(CharSequenceUtils.toNullSafeString(entry.getKey()),
                        CharSequenceUtils.toString(entry.getValue()));
            }
        }
        return converted;
    }
    return EMPTY_MAP;
}

From source file:io.dockstore.webservice.helpers.Helper.java

/**
 * Refreshes user's Bitbucket token.//from w  w  w  . j  a v a 2  s  .  c  om
 *
 * @param token
 * @param client
 * @param tokenDAO
 * @param bitbucketClientID
 * @param bitbucketClientSecret
 * @return the updated token
 */
public static Token refreshBitbucketToken(Token token, HttpClient client, TokenDAO tokenDAO,
        String bitbucketClientID, String bitbucketClientSecret) {

    String url = BITBUCKET_URL + "site/oauth2/access_token";

    try {
        Optional<String> asString = ResourceUtilities.bitbucketPost(url, null, client, bitbucketClientID,
                bitbucketClientSecret, "grant_type=refresh_token&refresh_token=" + token.getRefreshToken());

        if (asString.isPresent()) {
            String accessToken;
            String refreshToken;
            LOG.info(token.getUsername() + ": RESOURCE CALL: {}", url);
            String json = asString.get();

            Gson gson = new Gson();
            Map<String, String> map = new HashMap<>();
            map = (Map<String, String>) gson.fromJson(json, map.getClass());

            accessToken = map.get("access_token");
            refreshToken = map.get("refresh_token");

            token.setContent(accessToken);
            token.setRefreshToken(refreshToken);

            long create = tokenDAO.create(token);
            return tokenDAO.findById(create);
        } else {
            throw new CustomWebApplicationException("Could not retrieve bitbucket.org token based on code",
                    HttpStatus.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (UnsupportedEncodingException ex) {
        LOG.info(token.getUsername() + ": " + ex.toString());
        throw new CustomWebApplicationException(ex.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.xpfriend.fixture.cast.temp.MapFactory.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private Map toMap(Class<?> cls, DynaBean bean) throws IllegalAccessException, InvocationTargetException,
        NoSuchMethodException, InstantiationException {
    Map map = new DynaBeanMapDecorator(bean, false);
    if (cls.isAssignableFrom(map.getClass())) {
        return map;
    } else {//  w w w . jav  a  2s . c om
        Map obj = (Map) newInstance(cls);
        obj.putAll(map);
        return obj;
    }
}

From source file:jetbrains.buildServer.clouds.TestDeserialize.java

public void testDeserialize() throws IOException, DecoderException {

    String jsondata = "{\"data\":\"beta\"}";
    Gson gson = new Gson();
    Map<String, String> map = new HashMap<String, String>();
    map = gson.fromJson(jsondata, map.getClass());
    System.out.println();//from   www  . j a va  2  s.  co m

    final String data = "aa7214cd622cf7e6fa086bd0b4e7bb0fcc61b320901f97c17d77c9f7e0df30b0f60bbb19fe72e5a93fda4aa6288bc0f3b1ed2a4badf985ac6677edf0f58d31d415c70d46163c6843a245fd4c90ff65fb381c916d2476c0759ca0f87316bc6b95ec4be4054a114f86ab16297850c6665b9548057b770167aaebe71f0a916146a6";
    final String pw = "qwerty";
    final String s = RSACipher.decryptData(RSACipher.encryptData(pw));
    System.out.println(s);
    System.out.println(data);
    System.out.println(RSACipher.encryptData(pw));

    System.out.println(RSACipher.getHexEncodedPublicKey());
    System.out.println(RSACipher.encryptDataForWeb(pw));
}

From source file:com.synnex.saas.platform.core.jpa.MultiTenantJpaTransactionManager.java

/**
 * NOTE: Maybe it would be also possible to replace existing entityManager
 * in transaction with new but it isn't a good idea because of rollback and
 * other problems. So when new tenant is required always start new
 * transaction for it.//from  w  w w  . ja  v a 2  s . c  o m
 */

@Override
public Map<String, Object> getJpaPropertyMap() {
    Map<String, Object> superProperties = super.getJpaPropertyMap();
    System.out.println("##############Class ID:" + superProperties.getClass());
    Map<String, Object> tenantProperties = SessionManager.getEMFProperties();
    if (tenantProperties != null && !tenantProperties.isEmpty()) {
        superProperties.putAll(tenantProperties);
    }
    return superProperties;
}

From source file:com.frank.search.solr.core.convert.SolrJConverter.java

@SuppressWarnings("unchecked")
private <S> void initializeTypedConverter(Map<String, ?> source, Class<? extends S> rawType) {
    getConversionService().addConverter(source.getClass(), rawType,
            new SolrjConverters.SolrInputDocumentToObjectConverter<S>((Class<S>) rawType));
}