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:TweetAttributes.java

private static Map<Integer, List<TweetAttributes>> getTweetCLusterMapping(List<TweetAttributes> tweets) {
    Map<Integer, List<TweetAttributes>> clusterMap = new LinkedHashMap<Integer, List<TweetAttributes>>();

    for (TweetAttributes te : tweets) {
        if (clusterMap.containsKey(te.getClusterId())) {
            List<TweetAttributes> clusterPoints = clusterMap.get(te.getClusterId());
            clusterPoints.add(te);//  w w  w . ja  v a2 s .c om
            clusterMap.put(te.getClusterId(), clusterPoints);
        } else {
            List<TweetAttributes> newClusterPoint = new ArrayList<>();
            newClusterPoint.add(te);
            clusterMap.put(te.getClusterId(), newClusterPoint);
        }
    }
    return clusterMap;
}

From source file:TweetAttributes.java

private static void writeOutputToFile(List<TweetAttributes> tweets, String outputFile) throws IOException {
    try {//  ww  w  .  j  a va  2  s  .  c o  m

        File file = new File(outputFile); //Your file

        FileOutputStream fos = new FileOutputStream(file);

        PrintStream ps = new PrintStream(fos);

        System.setOut(ps);

    } catch (FileNotFoundException e) {

        e.printStackTrace();

    }

    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
    //    List<Long> output=new ArrayList<>();
    //  int count=1;
    Map<Integer, ArrayList> opmap = new HashMap<Integer, ArrayList>();

    for (TweetAttributes user : tweets) {
        if (opmap.containsKey(user.getClusterId())) {
            opmap.get(user.getClusterId()).add(user.getId());
        } else {
            ArrayList<Long> ids = new ArrayList<Long>();
            ids.add(user.getId());
            opmap.put(user.getClusterId(), ids);
        }
        //  count++;
    }

    /*   for(TweetAttributes model : tweets) {
            
          System.out.println(model.getClusterId()+" "+model.getId());
            
       }*/
    //   System.out.println(outputFile+"  "+out);
    for (Entry<Integer, ArrayList> entry : opmap.entrySet()) {
        System.out.print(entry.getKey() + "   ");
        for (Object fruitNo : entry.getValue()) {
            System.out.print(fruitNo);
            System.out.print(", ");
        }
        System.out.println();
    }

}

From source file:org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil.java

private static void addAppDomainContext(Map<String, Map<String, ?>> appDomainContexts, String domain,
        String subDomain, AppDomainContext appCtxt) {

    Map<String, AppDomainContext> map;

    if (appDomainContexts.containsKey(domain)) {
        map = (Map<String, AppDomainContext>) appDomainContexts.get(domain);
    } else {/*from  w w w  .ja v a 2s . c  o  m*/
        map = new HashMap<String, AppDomainContext>();
    }
    // put this appDomainContext
    map.put(subDomain, appCtxt);

    // update the parent map
    appDomainContexts.put(domain, map);

}

From source file:com.edmunds.autotest.ClassUtil.java

public static Map<String, Field> getAllDeclaredFieldsMap(Class originalCls, boolean lowercase,
        AutoTestConfig config) {//from   www  .  j  av a2s. c  o m
    Map<String, Field> fields = new HashMap<String, Field>();

    Class cls = originalCls;

    do {
        for (Field field : cls.getDeclaredFields()) {
            String fieldName = field.getName();

            if (lowercase) {
                fieldName = fieldName.toLowerCase();
            }

            if (fields.containsKey(fieldName)) {

                if (isDeclaredUnderRootPackage(config, field)
                        && !config.getFieldOverrideExceptions().contains(field.getName())) {

                    String msg = "Instance variable (" + field.getName() + ") has been overridden: "
                            + originalCls.getName();
                    log.warn(msg);

                    if (config.isFailOnFieldOverride()) {
                        fail(msg);
                    }
                }
            } else {
                fields.put(fieldName, field);
            }
        }
        cls = cls.getSuperclass();
    } while (cls != null);
    return fields;
}

From source file:com.userhook.UserHook.java

/**
 * Checks a push notification to see if it came from User Hook or another service
 *
 * @param data//from  www .  j  a v  a  2 s. c o m
 * @return boolean if push message originated from User Hook
 */
public static boolean isPushFromUserHook(Map<String, String> data) {
    return data != null && data.containsKey(PUSH_SOURCE_PARAM)
            && data.get(PUSH_SOURCE_PARAM).equals(PUSH_SOURCE_VALUE);
}

From source file:azkaban.reportal.util.ReportalHelper.java

public static boolean isSubscribeProject(Project project, User user) {
    @SuppressWarnings("unchecked")
    Map<String, String> subscription = (Map<String, String>) project.getMetadata().get("subscription");
    if (subscription == null) {
        return false;
    }/*from ww w  .  ja  va 2  s. c  o m*/
    return subscription.containsKey(user.getUserId());
}

From source file:Main.java

public static Object setFieldValue(Map<String, String> map, Class<?> cls) throws Exception {
    Field[] fields = cls.getDeclaredFields();
    Object obj = cls.newInstance();
    for (Field field : fields) {
        Class<?> clsType = field.getType();
        String name = field.getName();
        String strSet = "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
        Method methodSet = cls.getDeclaredMethod(strSet, clsType);
        if (map.containsKey(name)) {
            Object objValue = typeConversion(clsType, map.get(name));
            methodSet.invoke(obj, objValue);
        }//from   w ww  .  j  a v a  2s .c  om
    }
    return obj;
}

From source file:com.diversityarrays.kdxplore.curate.TypedSampleMeasurement.java

/**
 * Return null if all the DeviceNames are unique else
 * the shortFormat if it is sufficient to uniquely identify the TypedSampleMeasurements
 * @param coll/*from w  ww. java 2 s. co  m*/
 * @param shortFormat
 * @param longFormat
 * @return
 */
static public DateFormat getDateFormatForUniqueIdent(Collection<TypedSampleMeasurement> coll,
        DateFormat shortFormat, DateFormat longFormat) {
    Map<String, Bag<String>> datesByDeviceName = new HashMap<>();

    boolean foundDuplicateDeviceName = false;
    for (TypedSampleMeasurement tsm : coll) {
        if (DeviceType.KDSMART == tsm.deviceIdentifier.getDeviceType()) {
            String deviceName = tsm.deviceIdentifier.getDeviceName();
            if (datesByDeviceName.containsKey(deviceName)) {
                foundDuplicateDeviceName = true;
            } else {
                datesByDeviceName.put(deviceName, new HashBag<>());
            }
        }
    }
    if (!foundDuplicateDeviceName) {
        return null;
    }

    for (TypedSampleMeasurement tsm : coll) {
        if (DeviceType.KDSMART == tsm.deviceIdentifier.getDeviceType()) {
            String deviceName = tsm.deviceIdentifier.getDeviceName();

            Bag<String> bag = datesByDeviceName.get(deviceName);
            if (tsm.sampleGroupDate != null) {
                String s = longFormat.format(tsm.sampleGroupDate);
                bag.add(s);
            }
        }
    }

    for (Bag<String> bag : datesByDeviceName.values()) {
        for (String key : bag.uniqueSet()) {
            if (bag.getCount(key) > 1) {
                return longFormat;
            }
        }
    }

    return shortFormat;
}

From source file:de.qaware.chronix.solr.type.metric.SolrDocumentBuilder.java

/**
 * Merges to sets of time series attributes.
 * The result is set for each key holding the values.
 * If the other value is a collection, than all values
 * of the collection are added instead of the collection object.
 *
 * @param merged     the merged attributes
 * @param attributes the attributes of the other time series
 */// ww  w . jav  a  2s . c o m
private static void merge(Map<String, Object> merged, Map<String, Object> attributes) {

    for (HashMap.Entry<String, Object> newEntry : attributes.entrySet()) {

        String key = newEntry.getKey();

        //we ignore the version in the result
        if (key.equals("_version_")) {
            continue;
        }

        if (!merged.containsKey(key)) {
            merged.put(key, new LinkedHashSet());
        }

        LinkedHashSet values = (LinkedHashSet) merged.get(key);
        Object value = newEntry.getValue();

        //Check if the value is a collection.
        //If it is a collection we add all values instead of adding a collection object
        if (value instanceof Collection && !values.contains(value)) {
            values.addAll((Collection) value);
        } else if (!values.contains(value)) {
            //Otherwise we have a single value or an array.
            values.add(value);
        }
        //otherwise we ignore the value
    }
}

From source file:exm.stc.ic.ICUtil.java

/**
 * If oa is a variable with a name in the renames map, replace
 * @param renames/*  w  w w.ja  va  2s  .  c  o m*/
 * @param oa
 * @param nullsOk set to true if oa may be null, otherwise exception
 *    will be thrown
 * @return null if oa is null. If oa is variable and
 *      is in renames, return the replacements.  If it isn't,
 *      return the argument
 */
public static Arg replaceArg(Map<Var, Arg> renames, Arg oa, boolean nullsOk) {
    assert (nullsOk || oa != null);
    if (oa != null && oa.isVar()) {
        Var var = oa.getVar();
        if (renames.containsKey(var)) {
            Arg res = renames.get(var);
            assert (res != null);
            return res;
        }
    }
    return oa;
}