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:org.jahia.modules.external.modules.osgi.ModulesSourceSpringInitializer.java

public void mountSourcesProvider(JahiaTemplatesPackage templatePackage) {
    if (context != null) {
        JCRStoreProvider provider = jcrStoreService.getSessionFactory().getProviders()
                .get("module-" + templatePackage.getId() + "-" + templatePackage.getVersion().toString());
        if (provider == null) {
            try {
                Object dataSource = SpringContextSingleton
                        .getBeanInModulesContext("ModulesDataSourcePrototype");
                logger.info("Mounting source for bundle {}", templatePackage.getName());
                Map<String, Object> properties = new LinkedHashMap<String, Object>();
                properties.put("root", templatePackage.getSourcesFolder().toURI().toString());
                properties.put("module", templatePackage);

                BeanUtils.populate(dataSource, properties);

                ExternalContentStoreProvider ex = (ExternalContentStoreProvider) SpringContextSingleton
                        .getBeanInModulesContext("ExternalStoreProviderPrototype");
                properties.clear();
                properties.put("key",
                        "module-" + templatePackage.getId() + "-" + templatePackage.getVersion().toString());
                properties.put("mountPoint", "/modules/" + templatePackage.getIdWithVersion() + "/sources");
                properties.put("dataSource", dataSource);
                properties.put("lockSupport", true);
                properties.put("slowConnection", false);

                BeanUtils.populate(ex, properties);

                ex.start();/*from w w w  .  j  a  v a  2  s.  c om*/
            } catch (IllegalAccessException e) {
                logger.error(e.getMessage(), e);
            } catch (InvocationTargetException e) {
                logger.error(e.getMessage(), e);
            } catch (JahiaInitializationException e) {
                logger.error(e.getMessage(), e);
            } catch (NoSuchBeanDefinitionException e) {
                logger.debug(e.getMessage(), e);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.SteeringTest.java

License:asdf

public String setupSteering(Map<String, String> domains, Map<String, Integer> weights, String resourcePath)
        throws IOException {
    domains.clear();
    weights.clear();/*ww w .  ja v a  2s  .co  m*/

    JsonNode steeringNode = getJsonForResourcePath(resourcePath);

    Iterator<JsonNode> steeredDeliveryServices = steeringNode.get("targets").iterator();
    while (steeredDeliveryServices.hasNext()) {
        JsonNode steeredDeliveryService = steeredDeliveryServices.next();
        String targetId = steeredDeliveryService.get("deliveryService").asText();
        Integer targetWeight = steeredDeliveryService.get("weight").asInt();
        weights.put(targetId, targetWeight);
        domains.put(targetId, "");
    }
    //System.out.println("steeringNode.get = "+ steeringNode.get("deliveryService").asText());
    return steeringNode.get("deliveryService").asText();
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap")
public void clear_whenEmpty(Map<Integer, Integer> map) {
    map.clear();
    assertThat(map, is(emptyMap()));/*from  w w w .j a v a2  s.c  o m*/
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "warmedMap")
public void clear_whenPopulated(Map<Integer, Integer> map) {
    map.clear();
    assertThat(map, is(emptyMap()));/*  www.j a  va2s . co  m*/
}

From source file:hoot.services.osm.OsmTestUtils.java

public static Set<Long> createTestRelations(final long changesetId, final Set<Long> nodeIds,
        final Set<Long> wayIds) throws Exception {
    Set<Long> relationIds = new LinkedHashSet<Long>();
    final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
    final Long[] wayIdsArr = wayIds.toArray(new Long[] {});
    Map<String, String> tags = new HashMap<String, String>();
    List<RelationMember> members = new ArrayList<RelationMember>();

    members.add(new RelationMember(nodeIdsArr[0], ElementType.Node, "role1"));
    members.add(new RelationMember(wayIdsArr[1], ElementType.Way, "role3"));
    members.add(new RelationMember(wayIdsArr[0], ElementType.Way, "role2"));
    members.add(new RelationMember(nodeIdsArr[2], ElementType.Node));
    tags.put("key 1", "val 1");
    final long firstRelationId = Relation.insertNew(changesetId, mapId, members, tags, conn);
    relationIds.add(firstRelationId);/*from   ww  w .java2 s  .c  o  m*/
    tags.clear();
    members.clear();

    tags.put("key 2", "val 2");
    tags.put("key 3", "val 3");
    members.add(new RelationMember(nodeIdsArr[4], ElementType.Node, "role1"));
    members.add(new RelationMember(firstRelationId, ElementType.Relation, "role1"));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

    tags.put("key 4", "val 4");
    members.add(new RelationMember(wayIdsArr[1], ElementType.Way));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, tags, conn));
    tags.clear();
    members.clear();

    members.add(new RelationMember(nodeIdsArr[2], ElementType.Node, "role1"));
    relationIds.add(Relation.insertNew(changesetId, mapId, members, null, conn));
    members.clear();

    return relationIds;
}

From source file:mhao.threewalnut.controller.LoginController.java

/**
 * // w w w. j  a  va2 s  . c  om
 * @param uid
 * @param position_uid
 * @param name
 * @param phone
 * @return
 */
@RequestMapping("/user/unbound")
@ResponseBody
public Result unbound(@RequestParam String uid, @RequestParam String phone) {
    try {
        Map<String, Object> inParams = new HashMap<String, Object>();
        String businessPhone = null;
        String disable_uid = "";
        inParams.put("i_phone", phone);
        try {
            Map<String, Object> rs = this.storedProcedureTemplate.call("p_get_user_by_phone", inParams);
            disable_uid = (String) rs.get("uid");
            businessPhone = (String) rs.get("businessPhone");
            inParams.clear();
            inParams.put("i_uid", uid);
            inParams.put("i_disable_uid", disable_uid);
        } catch (ProcedureException e) {
            logger.info(e.getMessage());
            return new Result(Result.RESULT_CODE_FAILE, "?");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(Result.RESULT_CODE_FAILE, "?");
        }
        if (StringUtils.isNotBlank(businessPhone)) {
            MhaoResult mhaoResult = BindMobile.unbindMobile(businessPhone, phone);
            if (mhaoResult.getResult() == 0) {
                logger.info("??");
            } else {
                logger.error("?vm:{},tm:{},{}",
                        new Object[] { businessPhone, phone, mhaoResult });
                return new Result(Result.RESULT_CODE_FAILE, "??(?)");
            }
        }
        boolean success = false;
        try {
            this.storedProcedureTemplate.call("p_disable_user", inParams);
            success = true;
        } catch (ProcedureException e) {
            logger.info(e.getMessage());
            return new Result(Result.RESULT_CODE_FAILE, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(Result.RESULT_CODE_FAILE);
        } finally {
            if (!success) {
                logger.info("?,?");
                MhaoResult rollback = BindMobile.bindMobile(disable_uid, phone, businessPhone, 0);
                logger.info("Mhao SDK bindMobile Result:{}", rollback);
                if (rollback.getResult() != 0) {
                    logger.error("?,{}", rollback);
                }
            }
        }
        return new Result(Result.RESULT_CODE_SUCCESS);
    } catch (Exception e) {
        e.printStackTrace();
        return new Result(Result.RESULT_CODE_FAILE);
    }
}

From source file:com.linkedin.pinot.controller.helix.core.realtime.PinotLLCRealtimeSegmentManager.java

private IdealState addLLCRealtimeSegmentsInIdealState(final IdealState idealState,
        Map<String, List<String>> idealStateEntries) {
    for (Map.Entry<String, List<String>> entry : idealStateEntries.entrySet()) {
        final String segmentId = entry.getKey();
        final Map<String, String> stateMap = idealState.getInstanceStateMap(segmentId);
        if (stateMap != null) {
            // Replace the segment if it already exists
            stateMap.clear();
        }//from w w w  .j a v a 2  s.  c o m
        for (String instanceName : entry.getValue()) {
            idealState.setPartitionState(segmentId, instanceName,
                    PinotHelixSegmentOnlineOfflineStateModelGenerator.CONSUMING_STATE);
        }
    }
    return idealState;
}

From source file:jmona.example.ipd.IPDEvolutionTester.java

/** Test method for an iterated prisoner's dilemma evolution. */
@SuppressWarnings("unchecked")
@Test/* ww  w .  j  a  v a  2s  .  co m*/
@DirtiesContext
public final void testIPDEvolution() {
    final Map<Class<S>, Integer> results = new HashMap<Class<S>, Integer>();

    try {
        while (!this.completionCondition.execute(this.context)) {
            this.context.stepGeneration();

            for (final S strategy : this.context.currentPopulation()) {
                if (results.containsKey(strategy.getClass())) {
                    results.put((Class<S>) strategy.getClass(), results.get(strategy.getClass()) + 1);
                } else {
                    results.put((Class<S>) strategy.getClass(), 1);
                }
            }

            LOG.debug(results);

            results.clear();
        }
    } catch (final CompletionException exception) {
        TestUtils.fail(exception);
    } catch (final EvolutionException exception) {
        TestUtils.fail(exception);
    }

}

From source file:com.google.gdt.eclipse.designer.hosted.tdt.HostedModeSupport.java

public void dispose() {
    if (moduleSpaceHost != null) {
        // clear static caches
        ClassLoader devClassLoader = getDevClassLoader();
        try {//w w w.j a  v  a 2s .  c  o  m
            Class<?> clazz = devClassLoader.loadClass("com.google.gwt.i18n.rebind.ClearStaticData");
            ReflectionUtils.invokeMethod2(clazz, "clear");
        } catch (Throwable e) {
        }
        try {
            Class<?> clazz = devClassLoader.loadClass("com.google.gwt.uibinder.rebind.model.OwnerFieldClass");
            Map<?, ?> map = (Map<?, ?>) ReflectionUtils.getFieldObject(clazz, "FIELD_CLASSES");
            map.clear();
        } catch (Throwable e) {
        }
        // remove parent of CompilingClassLoader
        if (parentClassLoader != null) {
            ClassLoader classLoader = getClassLoader();
            ReflectionUtils.setField(classLoader, "parent", null);
        }
        // clear "loadedModulesCaches" in com.google.gwt.dev.cfg.ModuleDefLoader
        try {
            Class<?> moduleDefLoader = devClassLoader.loadClass("com.google.gwt.dev.cfg.ModuleDefLoader");
            Map<?, ?> loadedModulesCaches = (Map<?, ?>) ReflectionUtils.getFieldObject(moduleDefLoader,
                    "loadedModulesCaches");
            loadedModulesCaches.clear();
        } catch (Throwable e) {
        }
        /*// clear "threadLocalLogger" in com.google.gwt.dev.shell.ModuleSpace
        try {
          Class<?> classModuleSpace =
              devClassLoader.loadClass("com.google.gwt.dev.shell.ModuleSpace");
          ThreadLocal<?> threadLocalLogger =
              (ThreadLocal<?>) ReflectionUtils.getFieldObject(classModuleSpace, "threadLocalLogger");
          threadLocalLogger.set(null);
        } catch (Throwable e) {
        }
        // shutdown com.google.gwt.dev.javac.PersistentUnitCache
        try {
          Class<?> classUnitCacheFactory =
              devClassLoader.loadClass("com.google.gwt.dev.javac.UnitCacheFactory");
          Object cacheInstance = ReflectionUtils.getFieldObject(classUnitCacheFactory, "instance");
          if (cacheInstance != null) {
            Method shutdownMethod =
                ReflectionUtils.getMethodBySignature(cacheInstance.getClass(), "shutdown()");
            if (shutdownMethod != null) {
              shutdownMethod.invoke(cacheInstance);
            }
          }
          ReflectionUtils.setField(classUnitCacheFactory, "instance", null);
        } catch (Throwable e) {
        }
        // Call and remove GWT related java.lang.ApplicationShutdownHooks
        try {
          Class<?> hooksClass =
              ClassLoader.getSystemClassLoader().loadClass("java.lang.ApplicationShutdownHooks");
          Field hooksField = ReflectionUtils.getFieldByName(hooksClass, "hooks");
          @SuppressWarnings("unchecked")
          Map<Thread, ?> hooks = (Map<Thread, ?>) hooksField.get(null);
          List<Thread> threads = ImmutableList.copyOf(hooks.keySet());
          for (Thread thread : threads) {
            ClassLoader contextClassLoader = thread.getContextClassLoader();
            if (contextClassLoader == devClassLoader) {
              thread.setContextClassLoader(ClassLoader.getSystemClassLoader());
              thread.run();
              hooks.remove(thread);
            }
          }
        } catch (Throwable e) {
          e.printStackTrace();
        }
        // close com.google.gwt.dev.util.DiskCache
        try {
          Class<?> classDiskCache = devClassLoader.loadClass("com.google.gwt.dev.util.DiskCache");
          Object cacheInstance = ReflectionUtils.getFieldObject(classDiskCache, "INSTANCE");
          ReflectionUtils.invokeMethod(cacheInstance, "close()");
        } catch (Throwable e) {
        }
        // find embedded Guava Finalizer and clear reference of our "dev" URLClassLoader
        try {
          Thread[] threads = getAllThreads();
          for (Thread thread : threads) {
            if (thread != null && thread.getContextClassLoader() == devClassLoader) {
              thread.setContextClassLoader(null);
            }
          }
        } catch (Throwable e) {
        }*/
    }
    //
    if (browserShell != null) {
        browserShell.dispose();
    }
    logSupport.dispose();
    moduleSpaceHost = null;
    impl = null;
    projectClassLoader = null;
    dispatchIdOracle = null;
}

From source file:com.linkedin.pinot.queries.QueryExceptionTest.java

@Test
public void testSingleQuery() throws RecognitionException, Exception {
    String query = "select count(*) from testTable where column1='24516187'";
    LOGGER.info("running  : " + query);
    final Map<ServerInstance, DataTable> instanceResponseMap = new HashMap<ServerInstance, DataTable>();
    final BrokerRequest brokerRequest = REQUEST_COMPILER.compileToBrokerRequest(query);
    InstanceRequest instanceRequest = new InstanceRequest(1, brokerRequest);
    instanceRequest.setSearchSegments(new ArrayList<String>());
    instanceRequest.getSearchSegments().add(segmentName);
    QueryRequest queryRequest = new QueryRequest(instanceRequest);
    final DataTable instanceResponse = QUERY_EXECUTOR.processQuery(queryRequest);
    instanceResponseMap.clear();
    instanceResponseMap.put(new ServerInstance("localhost:0000"), instanceResponse);
    final BrokerResponseNative brokerResponse = REDUCE_SERVICE.reduceOnDataTable(brokerRequest,
            instanceResponseMap);//from  w  ww  . j  av a  2s  . c  o m
    LOGGER.info("BrokerResponse is " + brokerResponse.getAggregationResults().get(0));
}