Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:org.LexGrid.LexBIG.caCore.utils.LexEVSCaCoreUtils.java

public static <T> T recurseReflect(final T obj, final DoInReflectionCallback callback) {
    if (obj == null) {
        return null;
    }/* ww  w .ja v  a2 s .c  o  m*/
    ReflectionUtils.doWithFields(obj.getClass(), new FieldCallback() {

        public void doWith(Field arg0) throws IllegalArgumentException, IllegalAccessException {

            if (!ClassUtils.isPrimitiveOrWrapper(arg0.getType()) && !ClassUtils.isPrimitiveArray(arg0.getType())
                    && !ClassUtils.isPrimitiveWrapperArray(arg0.getType()) && !arg0.getType().isEnum()
                    && (isLexBigClass(arg0.getType()) || Collection.class.isAssignableFrom(arg0.getType())
                            || Map.class.isAssignableFrom(arg0.getType()))) {

                arg0.setAccessible(true);
                Object recurse = arg0.get(obj);

                if (recurse != null) {

                    if (CycleDetectingCallback.class.isAssignableFrom(recurse.getClass())) {
                        System.out.println("ere");
                    }

                    if (Collection.class.isAssignableFrom(recurse.getClass())) {
                        Collection collection = (Collection) recurse;
                        for (Object o : collection) {
                            if (callback.actionRequired(o)) {
                                collection.remove(o);
                                collection.add(recurseReflect(o, callback));
                            } else {
                                recurseReflect(o, callback);
                            }
                        }
                    } else if (Map.class.isAssignableFrom(recurse.getClass())) {
                        Map map = (Map) recurse;
                        for (Object key : map.keySet()) {
                            Object value = map.get(key);
                            if (callback.actionRequired(key) || callback.actionRequired(value)) {
                                map.remove(key);
                                map.put(recurseReflect(key, callback), recurseReflect(value, callback));
                            } else {
                                recurseReflect(key, callback);
                                recurseReflect(value, callback);
                            }
                        }
                    } else {
                        if (callback.actionRequired(recurse)) {
                            Object newObject = recurseReflect(recurse, callback);
                            arg0.set(obj, newObject);
                        } else {
                            recurseReflect(recurse, callback);
                        }
                    }
                }
            }
        }
    });

    return callback.doInReflection(obj);
}

From source file:com.comcast.oscar.utilities.JSONTools.java

/**
 * //from   w  ww  . ja  v  a 2 s  .  com
 * @param object
        
        
 * @return Object
 * @throws JSONException */
@SuppressWarnings("rawtypes")
public static Object toJSON(Object object) throws JSONException {

    if (object instanceof Map) {

        JSONObject json = new JSONObject();

        Map map = (Map) object;

        for (Object key : map.keySet()) {
            json.put(key.toString(), toJSON(map.get(key)));
        }

        return json;

    } else if (object instanceof Iterable) {

        JSONArray ja = new JSONArray();

        for (Object value : ((Iterable) object)) {
            ja.put(value);
        }

        return ja;

    } else {
        return object;
    }
}

From source file:microsoft.aspnet.signalr.client.http.android.AndroidHttpConnection.java

/**
 * Creates a request that can be accepted by the AndroidHttpClient
 * /*from   ww  w  .  ja  va 2  s.  c  o m*/
 * @param request
 *            The request information
 * @throws java.io.UnsupportedEncodingException
 */
private static BasicHttpEntityEnclosingRequest createRealRequest(Request request)
        throws UnsupportedEncodingException {
    BasicHttpEntityEnclosingRequest realRequest = new BasicHttpEntityEnclosingRequest(request.getVerb(),
            request.getUrl());

    if (request.getContent() != null) {
        realRequest.setEntity(new StringEntity(request.getContent()));
    }

    Map<String, String> headers = request.getHeaders();

    for (String key : headers.keySet()) {
        realRequest.addHeader(key, headers.get(key));
    }

    return realRequest;
}

From source file:com.cloud.test.utils.UtilsForTest.java

public static boolean verifyTags(Map<String, String> params) {
    boolean result = true;
    for (String value : params.keySet()) {
        if (params.get(value) == null) {
            result = false;/*w w  w .  ja  va2  s .com*/
        }
    }
    return result;
}

From source file:com.github.gaoyangthu.core.hbase.HbaseSynchronizationManager.java

/**
 * Returns the bound tables (by name)./*from w w w  . ja va  2s  . c o  m*/
 * 
 * @return names of bound tables
 */
public static Set<String> getTableNames() {
    Map<String, HTableInterface> map = resources.get();
    if (map != null && !map.isEmpty()) {
        return Collections.unmodifiableSet(map.keySet());
    }
    return Collections.emptySet();
}

From source file:net.cit.tetrad.utility.QueryUtils.java

public static void getUpdate(Update update, Map<String, Object> values) {
    Set<String> keys = values.keySet();
    Iterator<String> it = keys.iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        Object value = values.get(key);

        update.set(key, value);//from w  w w .  j  av  a2s. com
    }

}

From source file:edu.umn.msi.tropix.common.test.BeanTest.java

public static void testBeanProperties(final Object testBean, final HashMultimap<Class<?>, Object> typeObjects) {
    try {//from   w  w w  .j a  v  a2s . c om
        @SuppressWarnings("unchecked")
        final Map<String, ?> propertyMap = PropertyUtils.describe(testBean);
        for (final String propertyName : propertyMap.keySet()) {
            if (propertyName.equals("class") || !PropertyUtils.isWriteable(testBean, propertyName)) {
                continue;
            }
            final Class<?> type = PropertyUtils.getPropertyType(testBean, propertyName);
            Collection<?> objects = null;
            for (final Class<?> typeQuery : typeObjects.keySet()) {
                if (typeQuery.isAssignableFrom(type)) {
                    objects = typeObjects.get(typeQuery);
                }
            }
            boolean useEquals = true;
            if (objects == null) {
                useEquals = false;
                try {
                    objects = Lists.<Object>newArrayList(EasyMock.createMock(type));
                } catch (final Exception e) {
                    // Cannot instantiate mock of this type
                    continue;
                }
            }
            for (final Object expectedObject : objects) {
                PropertyUtils.setProperty(testBean, propertyName, expectedObject);
                final Object object = PropertyUtils.getProperty(testBean, propertyName);
                if (useEquals) {
                    assert object.equals(expectedObject) : "Expected " + expectedObject + " obtained " + object;
                } else {
                    assert object == expectedObject : "Expected " + expectedObject + " obtained " + object;
                }
            }
        }
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:de.saly.elasticsearch.importer.imap.IMAPImporterCl.java

public static void start(Map<String, Object> settings, boolean embeddedMode) throws Exception {

    Settings.Builder builder = Settings.settingsBuilder();

    for (String key : settings.keySet()) {
        builder.put(key, String.valueOf(settings.get(key)));
    }/*from   ww w.j  a  v  a2s.  c om*/

    if (embeddedMode) {
        try {
            FileUtils.forceDelete(new File("./data"));
        } catch (Exception e) {
            //ignore
        }
        builder.put("path.home", ".");
        builder.put("node.local", true);
        builder.put("http.cors.enabled", true);
        builder.put("http.cors.allow-origin", "*");
        builder.put("cluster.name", "imap-embedded-" + System.currentTimeMillis());
        node = new PluginAwareNode(builder.build(),
                (Collection) Lists.newArrayList(MapperAttachmentsPlugin.class));
        node.start();
        client = node.client();
    } else {
        Settings eSettings = builder.build();
        client = new TransportClient.Builder().settings(eSettings).build();
        String[] hosts = eSettings.get("elasticsearch.hosts").split(",");

        for (int i = 0; i < hosts.length; i++) {
            String host = hosts[i];
            String hostOnly = host.split(":")[0];
            String portOnly = host.split(":")[1];
            System.out.println("Adding " + hostOnly + ":" + portOnly);
            ((TransportClient) client).addTransportAddress(new InetSocketTransportAddress(
                    InetAddress.getByName(hostOnly), Integer.parseInt(portOnly)));
        }
    }
    imap = new IMAPImporter(settings, client);
    imap.start();
}

From source file:Main.java

public static boolean setProperty(String filePath, String fileName, Map<String, String> propertyMap) {
    try {//from   w  ww .  j  a v a 2  s.c om
        Properties p = loadPropertyInstance(filePath, fileName);
        for (String name : propertyMap.keySet()) {
            p.setProperty(name, propertyMap.get(name));
        }
        String comment = "Update '" + propertyMap.keySet().toString() + "' value";
        return storePropertyInstance(filePath, fileName, p, comment);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

/**
 * Returns <tt>true</tt> iff the given {@link Collection}s contain exactly
 * the same elements with exactly the same cardinality.
 * <p>//from  w ww . j  a  v  a  2 s. c  o m
 * That is, iff the cardinality of <i>e</i> in <i>a</i> is equal to the
 * cardinality of <i>e</i> in <i>b</i>, for each element <i>e</i> in
 * <i>a</i> or <i>b</i>.
 */
public static boolean isEqualCollection(final Collection a, final Collection b) {
    if (a.size() != b.size()) {
        return false;
    } else {
        Map mapa = getCardinalityMap(a);
        Map mapb = getCardinalityMap(b);
        if (mapa.size() != mapb.size()) {
            return false;
        } else {
            Iterator it = mapa.keySet().iterator();
            while (it.hasNext()) {
                Object obj = it.next();
                if (getFreq(obj, mapa) != getFreq(obj, mapb)) {
                    return false;
                }
            }
            return true;
        }
    }
}