Example usage for java.util Map clear

List of usage examples for java.util Map clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the mappings from this map (optional operation).

Usage

From source file:com.cloudera.recordservice.tests.ClusterController.java

/**
 * This method allows the caller to add environment variables to the JVM.
 * There is no easy way to do this through a simple call, such as there is to
 * read env variables using System.getEnv(variableName). Much of the method
 * was written with guidance from stack overflow:
 * http://stackoverflow.com/questions/*w  w w .  ja v  a 2s .co m*/
 * /318239/how-do-i-set-environment-variables-from-java
 */
protected static void setEnv(Map<String, String> newenv) {
    try {
        Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
        Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
        theEnvironmentField.setAccessible(true);
        Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
        env.putAll(newenv);
        Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                .getDeclaredField("theCaseInsensitiveEnvironment");
        theCaseInsensitiveEnvironmentField.setAccessible(true);
        Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
        cienv.putAll(newenv);
    } catch (NoSuchFieldException e) {
        try {
            Class[] classes = Collections.class.getDeclaredClasses();
            Map<String, String> env = System.getenv();
            for (Class cl : classes) {
                if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                    Field field = cl.getDeclaredField("m");
                    field.setAccessible(true);
                    Object obj = field.get(env);
                    Map<String, String> map = (Map<String, String>) obj;
                    map.clear();
                    map.putAll(newenv);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:org.wte4j.ui.server.services.TemplateServiceImpl.java

private static void copyMappingData(Map<String, MappingDetail> target, List<MappingDto> source) {
    target.clear();
    for (MappingDto dto : source) {
        if (StringUtils.isNotBlank(dto.getModelKey()) || StringUtils.isNotBlank(dto.getFormatterDefinition())) {
            MappingDetail mappingDetail = new MappingDetail();
            mappingDetail.setModelKey(dto.getModelKey());
            mappingDetail.setFormatterDefinition(dto.getFormatterDefinition());
            target.put(dto.getConentControlKey(), mappingDetail);
        }//  ww w .j a  v a 2 s.c o m
    }

}

From source file:Main.java

public static void freeBitmapMap(Map map) {
    Iterator iterator = map.entrySet().iterator();
    do {/*www. j ava  2s . com*/
        if (!iterator.hasNext())
            break;
        Bitmap bitmap = (Bitmap) ((java.util.Map.Entry) iterator.next()).getValue();
        if (bitmap != null)
            bitmap.recycle();
    } while (true);
    map.clear();
}

From source file:com.liferay.portal.security.permission.PermissionCacheUtil.java

public static void clearLocalCache() {
    if (_localCacheAvailable) {
        Map<String, Object> localCache = _localCache.get();

        localCache.clear();
    }/*from  w  ww. j ava  2 s . co m*/
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.InterceptorsTest.java

private static void consume(Consumer<String, String> consumer) {
    boolean halt = false;
    int ei = 0;/*from w  w  w.  jav a 2  s. c o  m*/
    Map<String, Object> data = new HashMap<>(3);
    while (!halt) {
        try {
            ConsumerRecords<String, String> records = consumer.poll(Long.MAX_VALUE);
            for (ConsumerRecord<String, String> record : records) {
                data.clear();
                data.put("partition", record.partition()); // NON-NLS
                data.put("offset", record.offset()); // NON-NLS
                data.put("value", record.value()); // NON-NLS
                LOGGER.log(OpLevel.INFO, "Consuming Kafka message: seqNumber={2} msg={1}", consumer.hashCode(), // NON-NLS
                        data, ei++);

                try {
                    Thread.sleep((long) (200 * Math.random()));
                } catch (InterruptedException exc) {
                }
            }
        } catch (WakeupException exc) {
            halt = true;
        }
    }

    consumer.close();
}

From source file:com.codebase.foundation.classloader.xbean.ClassLoaderUtil.java

/**
 * Clears the caches maintained by the SunVM object stream implementation.  This method uses reflection and
 * setAccessable to obtain access to the Sun cache.  The cache is locked with a synchronize monitor and cleared.
 * This method completely clears the class loader cache which will impact performance of object serialization.
 * @param clazz the name of the class containing the cache field
 * @param fieldName the name of the cache field
 *//*from   ww w .j a  v a  2s.  co m*/
@SuppressWarnings("all")
public static void clearSunSoftCache(Class clazz, String fieldName) {
    Map cache = null;
    try {
        Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        cache = (Map) field.get(null);
    } catch (Throwable ignored) {
        // there is nothing a user could do about this anyway
    }

    if (cache != null) {
        synchronized (cache) {
            cache.clear();
        }
    }
}

From source file:edu.illinois.ncsa.springdata.SpringData.java

/**
 * Check each field in object to see if it is already seen. This will modify
 * collections, lists and arrays as well as the fields in an object.
 * //from  www .  ja  v  a 2s . c o  m
 * @param obj
 *            the object to be checked for duplicates.
 * @param seen
 *            objects that have already been checked.
 * @return the object with all duplicates removed
 */
private static <T> T removeDuplicate(T obj, Map<String, Object> seen) {
    if (obj == null) {
        return null;
    }
    if (obj instanceof AbstractBean) {
        String id = ((AbstractBean) obj).getId();
        if (seen.containsKey(id)) {
            return (T) seen.get(id);
        }
        seen.put(id, obj);

        // check all subfields
        for (Field field : obj.getClass().getDeclaredFields()) {
            if ((field.getModifiers() & Modifier.FINAL) == 0) {
                try {
                    field.setAccessible(true);
                    field.set(obj, removeDuplicate(field.get(obj), seen));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    } else if (obj instanceof Collection<?>) {
        Collection col = (Collection) obj;
        ArrayList arr = new ArrayList(col);
        col.clear();
        for (int i = 0; i < arr.size(); i++) {
            Object x = removeDuplicate(arr.get(i), seen);
            col.add(x);
        }
    } else if (obj instanceof Map<?, ?>) {
        Map map = (Map) obj;
        ArrayList<Entry> arr = new ArrayList(map.entrySet());
        map.clear();
        for (int i = 0; i < arr.size(); i++) {
            Object k = removeDuplicate(arr.get(i).getKey(), seen);
            Object v = removeDuplicate(arr.get(i).getValue(), seen);
            map.put(k, v);
        }
    } else if (obj.getClass().isArray()) {
        Object[] arr = (Object[]) obj;
        for (int i = 0; i < arr.length; i++) {
            arr[i] = removeDuplicate(arr[i], seen);
        }
    }

    return obj;
}

From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.collection.PhysicalWebCollection.java

/**
 * Given a list of PwPairs, return a filtered list such that only one PwPair from each group
 * is included./*from w w w .ja  v a  2 s . co m*/
 *
 * @param allPairs    Input PwPairs list.
 * @param outGroupMap Optional output map from discovered group IDs to UrlGroups, may be null.
 * @return Filtered PwPairs list.
 */
private static List<PwPair> removeDuplicateGroupIds(List<PwPair> allPairs, Map<String, UrlGroup> outGroupMap) {
    List<PwPair> filteredPairs = new ArrayList<>();
    Map<String, UrlGroup> groupMap = outGroupMap;
    if (groupMap == null) {
        groupMap = new HashMap<>();
    } else {
        groupMap.clear();
    }

    for (PwPair pwPair : allPairs) {
        PwsResult pwsResult = pwPair.getPwsResult();
        String groupId = pwsResult.getGroupId();
        if (groupId == null || groupId.equals("")) {
            // Pairs without a group are always included
            filteredPairs.add(pwPair);
        } else {
            // Create the group if it doesn't exist
            UrlGroup urlGroup = groupMap.get(groupId);
            if (urlGroup == null) {
                urlGroup = new UrlGroup(groupId);
                groupMap.put(groupId, urlGroup);
            }
            urlGroup.addPair(pwPair);
        }
    }

    for (UrlGroup urlGroup : groupMap.values()) {
        filteredPairs.add(urlGroup.getTopPair());
    }

    return filteredPairs;
}

From source file:com.netsteadfast.greenstep.bsc.util.HistoryItemScoreReportContentQueryUtils.java

private static List<VisionVO> getBasicDataList() throws ServiceException, Exception {
    List<VisionVO> visions = new LinkedList<VisionVO>();
    List<VisionVO> visionsTempList = new ArrayList<VisionVO>();
    Map<String, String> visionMap = visionService.findForMap(false);
    for (Map.Entry<String, String> visionEntry : visionMap.entrySet()) {
        DefaultResult<VisionVO> visionResult = visionService.findForSimple(visionEntry.getKey());
        if (visionResult.getValue() == null) {
            throw new ServiceException(visionResult.getSystemMessage().getValue());
        }/*from  ww w  .  j a  va 2  s.c o m*/
        VisionVO vision = visionResult.getValue();
        visionsTempList.add(vision);
    }
    Map<String, Object> paramMap = new HashMap<String, Object>();
    for (VisionVO vision : visionsTempList) {
        paramMap.clear();
        paramMap.put("visId", vision.getVisId());
        List<PerspectiveVO> perspectivesList = perspectiveService.findListVOByParams(paramMap);
        for (int p = 0; perspectivesList != null && p < perspectivesList.size(); p++) {
            PerspectiveVO perspective = perspectivesList.get(p);
            vision.getPerspectives().add(perspective);
            paramMap.clear();
            paramMap.put("perId", perspective.getPerId());
            List<ObjectiveVO> objectivesList = objectiveService.findListVOByParams(paramMap);
            for (int o = 0; objectivesList != null && o < objectivesList.size(); o++) {
                ObjectiveVO objective = objectivesList.get(o);
                perspective.getObjectives().add(objective);
                paramMap.clear();
                paramMap.put("objId", objective.getObjId());
                List<KpiVO> kpiList = kpiService.findListVOByParams(paramMap);
                if (kpiList != null && kpiList.size() > 0) {
                    objective.getKpis().addAll(kpiList);
                }
            }
        }
    }
    //  KPI ? visions
    for (int v = 0; v < visionsTempList.size(); v++) {
        boolean isFoundData = true;
        VisionVO vision = visionsTempList.get(v);
        for (int p = 0; p < vision.getPerspectives().size() && isFoundData; p++) {
            PerspectiveVO perspective = vision.getPerspectives().get(p);
            for (int o = 0; o < perspective.getObjectives().size() && isFoundData; o++) {
                ObjectiveVO objective = perspective.getObjectives().get(o);
                if (objective.getKpis() == null || objective.getKpis().size() < 1) {
                    isFoundData = false;
                }
            }
        }
        if (isFoundData) {
            visions.add(vision);
        }
    }
    return visions;
}

From source file:com.github.seqware.queryengine.system.exporters.JSONDumper.java

/**
 * <p>outputFeatureInVCF.</p>
 *
 * @param buffer a {@link java.lang.StringBuffer} object.
 * @param feature a {@link com.github.seqware.queryengine.model.Feature} object.
 * @return a boolean./*w  w w . jav  a 2 s  .c  o  m*/
 */

public static boolean outputFeatureInVCF(StringBuilder buffer, Feature feature, FeatureSet set) {
    boolean caughtNonVCF = false;
    Gson gson = new GsonBuilder().create();
    Map<String, Map<String, Object>> map = new HashMap<String, Map<String, Object>>();
    Map<String, Object> innerMap = new HashMap<String, Object>();
    innerMap.put("_index", "queryengine");
    innerMap.put("_type", "features");
    innerMap.put("_id", feature.getSGID().getRowKey());
    map.put("index", innerMap);

    buffer.append(gson.toJson(map));
    buffer.append("\n");

    Gson gson2 = new GsonBuilder().create();
    innerMap.clear();
    innerMap.put("id", feature.getSGID().getRowKey());
    String title = "chr" + feature.getSeqid() + ":" + feature.getStart() + "-" + feature.getStop() + ":"
            + feature.getTagByKey(VCF, ImportConstants.VCF_REFERENCE_BASE).getValue().toString() + "->"
            + feature.getTagByKey(VCF, ImportConstants.VCF_CALLED_BASE).getValue().toString();
    innerMap.put("title", title);

    String[] interestingTags = { "isCompleteGenomics", "isDbSNP", "isDGV", "isEvoFold",
            "isGenomicsSegmentalDups", "isGERP", "isGWASCatalog", "isLRT", "isMutationTaster", "isNHLBI",
            "isPhastConsElements", "isPhyloPConservationScore", "isPolyPhen", "isTargetScanS",
            "isTfbsConsSite" };

    // create clean tags
    Map<String, String> cleanTags = new HashMap<String, String>();
    for (String tag : interestingTags) {
        // take off the "is"
        String cleanName = tag.substring(2);
        cleanTags.put(tag, cleanName);
    }

    List<String> databases = new ArrayList<String>();

    for (String tag : interestingTags) {
        Tag tagByKey = feature.getTagByKey(VCF, tag);
        if (tagByKey != null) {
            databases.add(cleanTags.get(tag));
        }
    }
    innerMap.put("databases", databases);

    // we'll take consequence type from SNPEFF_EFFECT
    List<String> consequences = new ArrayList<String>();
    if (feature.getTagByKey(VCF, "SNPEFF_EFFECT") != null) {
        String value = feature.getTagByKey(VCF, "SNPEFF_EFFECT").getValue().toString();
        // clean up value
        value = value.toLowerCase();
        consequences.add(value);
    }
    if (consequences.isEmpty()) {
        consequences.add("none");
    }
    innerMap.put("consequences", consequences);

    innerMap.put("feature_set", set.getSGID().getRowKey().replaceAll("-", ""));
    innerMap.put("variant_type", feature.getTagByKey(VCF, "IndelType") != null ? "INDEL" : "SNV");

    buffer.append(gson2.toJson(innerMap));

    return caughtNonVCF;
}