List of usage examples for java.util Map clear
void clear();
From source file:edu.utah.further.ds.impl.service.query.logic.ResultTranslatorXQueryImpl.java
@Override public Object translate(final Object result, final Map<String, Object> attributes) { Validate.notNull(result, "Result object returned from execution cannot be null."); // Create a chain request for our result translation sub-chain final ChainRequest subRequest = new ChainRequestImpl(new AttributeContainerImpl(attributes)); // Set the validation schema in the request for the marshalling processor to // perform W3C Schema validation if (subRequest.getAttribute(RESULT_SCHEMA) != null) { setValidationSchema(subRequest); }/*from w w w .jav a 2 s. c o m*/ // Build & invoke the chain final RequestHandler requestHandler = buildSubChain(result, subRequest); requestHandler.handle(subRequest); attributes.clear(); attributes.putAll(subRequest.getAttributes()); // Return the result of the conversion return subRequest.getAttribute(unmarshallRp.getResultAttr()); }
From source file:cn.com.inhand.devicenetworks.ap.websocket.WSDNAccessPoint.java
/** * * @param type 1:login,2:heatbeat,3:logout,others:undefined * @param wsdnsn ,Websocket DN?//from ww w.j a v a 2 s .c o m * @return */ private int updateStatus(int action, WSDNSession wsdnsn) { Map map = new HashMap(); String id = wsdnsn.getId(); String key = wsdnsn.getKey(); String token = wsdnsn.getToken(); if (id == null || key == null) { return 23007; } map.put("key", key); map.put("action", 1); String result = restTemplate.postForObject( "http://" + server_addr + "/api/asset_status/" + id + "?access_token=" + token, null, String.class, map); System.out.println("----Debug in WSDNAccessPoint.auth()[ln:209]:result:" + result); map.clear(); if (!result.contains("error_code")) { //?? //?_id,asset_id return 0; } else { try { Error error = mapper.readValue(result, Error.class); System.out.println("----Debug in WSDNAccessPoint.auth()[ln:218]:Error=" + error.toString()); return error.getErrorCode(); } catch (IOException ex) { Logger.getLogger(WSDNAccessPoint.class.getName()).log(Level.SEVERE, null, ex); return -1; } } }
From source file:com.twinsoft.convertigo.engine.Context.java
@Override public void setResponseStatus(Integer code, String text) { if (httpServletRequest != null) { Map<Integer, String> status = RequestAttribute.responseStatus.get(httpServletRequest); if (status == null) { RequestAttribute.responseStatus.set(httpServletRequest, status = new HashMap<Integer, String>()); }/*w ww . ja v a 2 s . c om*/ status.clear(); status.put(code, text); } }
From source file:io.apiman.manager.test.es.ESMetricsAccessorTest.java
/** * Test method for {@link io.apiman.manager.api.es.ESMetricsAccessor#getUsagePerPlan(java.lang.String, java.lang.String, java.lang.String, java.util.Date, java.util.Date)}. *///from w w w .j a va2 s.c o m @Test public void testGetUsagePerPlan() throws Exception { ESMetricsAccessor metrics = new ESMetricsAccessor(); metrics.setEsClient(client); // data exists - all data for JBossOverlord/s-ramp-api:1.0 UsagePerPlanBean usagePerPlan = metrics.getUsagePerPlan("JBossOverlord", "s-ramp-api", "1.0", parseDate("2015-01-01"), new DateTime().withZone(DateTimeZone.UTC)); Assert.assertNotNull(usagePerPlan); Map<String, Long> expectedData = new HashMap<>(); expectedData.put("Platinum", 17L); expectedData.put("Silver", 16L); expectedData.put("Gold", 12L); Assert.assertEquals(expectedData, usagePerPlan.getData()); // data exists - all data for Test/echo:1.0 usagePerPlan = metrics.getUsagePerPlan("Test", "echo", "1.0", parseDate("2015-01-01"), new DateTime().withZone(DateTimeZone.UTC)); Assert.assertNotNull(usagePerPlan); expectedData.clear(); expectedData.put("Platinum", 31L); expectedData.put("Silver", 73L); expectedData.put("Gold", 67L); expectedData.put("Bronze", 43L); Assert.assertEquals(expectedData, usagePerPlan.getData()); // Test/echo:1.0 bounded by a different date range usagePerPlan = metrics.getUsagePerPlan("Test", "echo", "1.0", parseDate("2015-06-18"), new DateTime().withZone(DateTimeZone.UTC)); Assert.assertNotNull(usagePerPlan); expectedData.clear(); Assert.assertEquals(expectedData, usagePerPlan.getData()); // data exists - all data for Test/echo:1.0 (alt timeframe) usagePerPlan = metrics.getUsagePerPlan("Test", "echo", "1.0", parseDate("2015-06-01"), parseDate("2015-06-17")); Assert.assertNotNull(usagePerPlan); expectedData.clear(); expectedData.put("Platinum", 31L); expectedData.put("Silver", 73L); expectedData.put("Gold", 67L); expectedData.put("Bronze", 43L); Assert.assertEquals(expectedData, usagePerPlan.getData()); }
From source file:com.bmwcarit.barefoot.markov.StateTest.java
@Test public void TestStateJSON() throws JSONException { Map<Integer, MockElem> elements = new HashMap<>(); StateMemory<MockElem, StateTransition, Sample> state = new StateMemory<>(); {// w w w. j a v a 2s . co m JSONObject json = state.toJSON(); state = new StateMemory<>(json, new MockFactory()); } elements.put(0, new MockElem(0, Math.log10(0.3), 0.3, null)); elements.put(1, new MockElem(1, Math.log10(0.2), 0.2, null)); elements.put(2, new MockElem(2, Math.log10(0.5), 0.5, null)); state.update(new HashSet<>(Arrays.asList(elements.get(0), elements.get(1), elements.get(2))), new Sample(0)); { JSONObject json = state.toJSON(); state = new StateMemory<>(json, new MockFactory()); elements.clear(); for (MockElem element : state.vector()) { elements.put(element.numid(), element); } } elements.put(3, new MockElem(3, Math.log10(0.3), 0.3, elements.get(1))); elements.put(4, new MockElem(4, Math.log10(0.2), 0.2, elements.get(1))); elements.put(5, new MockElem(5, Math.log10(0.4), 0.4, elements.get(2))); elements.put(6, new MockElem(6, Math.log10(0.1), 0.1, elements.get(2))); state.update( new HashSet<>(Arrays.asList(elements.get(3), elements.get(4), elements.get(5), elements.get(6))), new Sample(1)); { JSONObject json = state.toJSON(); state = new StateMemory<>(json, new MockFactory()); elements.clear(); for (MockElem element : state.vector()) { elements.put(element.numid(), element); } } elements.put(7, new MockElem(7, Math.log10(0.3), 0.3, elements.get(5))); elements.put(8, new MockElem(8, Math.log10(0.2), 0.2, elements.get(5))); elements.put(9, new MockElem(9, Math.log10(0.4), 0.4, elements.get(6))); elements.put(10, new MockElem(10, Math.log10(0.1), 0.1, elements.get(6))); state.update( new HashSet<>(Arrays.asList(elements.get(7), elements.get(8), elements.get(9), elements.get(10))), new Sample(2)); { JSONObject json = state.toJSON(); state = new StateMemory<>(json, new MockFactory()); elements.clear(); for (MockElem element : state.vector()) { elements.put(element.numid(), element); } } elements.put(11, new MockElem(11, Math.log10(0.3), 0.3, null)); elements.put(12, new MockElem(12, Math.log10(0.2), 0.2, null)); elements.put(13, new MockElem(13, Math.log10(0.4), 0.4, null)); elements.put(14, new MockElem(14, Math.log10(0.1), 0.1, null)); state.update( new HashSet<>( Arrays.asList(elements.get(11), elements.get(12), elements.get(13), elements.get(14))), new Sample(3)); state.update(new HashSet<MockElem>(), new Sample(4)); { JSONObject json = state.toJSON(); StateMemory<MockElem, StateTransition, Sample> state2 = new StateMemory<>(json, new MockFactory()); assertEquals(state.size(), state2.size()); assertEquals(4, state2.size()); assertEquals(state.estimate().numid(), state2.estimate().numid()); assertEquals(13, state2.estimate().numid()); } }
From source file:com.esd.ps.AdministratorController.java
/** * ?// ww w . j a v a 2 s. c o m * * @param userId * @param userType * @return */ @RequestMapping(value = "/userDetail", method = RequestMethod.POST) @ResponseBody public Map<String, Object> userDetail(int userId, int userType) { Map<String, Object> map = new HashMap<>(); if (userType == 1) { manager manager = managerService.getManagerByUserId(userId); map.clear(); map.put("name", manager.getManagerName()); map.put("userId", manager.getUserId()); map.put(Constants.USER_DETAIL, manager); } if (userType == 2) { employer employer = employerService.getEmployerByUserId(userId); map.clear(); map.put("name", employer.getEmployerName()); map.put("userId", employer.getUserId()); map.put(Constants.USER_DETAIL, employer); } if (userType == 3) { inspector inspector = inspectorService.getinspectorByUserId(userId); map.clear(); map.put("name", inspector.getInspectorName()); map.put("userId", inspector.getUserId()); map.put(Constants.USER_DETAIL, inspector); } if (userType == 4) { worker worker = workerService.getWorkerByUserId(userId); map.clear(); map.put("name", worker.getWorkerRealName()); map.put("userId", worker.getUserId()); map.put("bankCard", worker.getWorkerBankCard()); map.put("disabilityCard", worker.getWorkerDisabilityCard()); map.put("paypal", worker.getWorkerPaypal()); map.put("phone", worker.getWorkerPhone()); map.put(Constants.USER_DETAIL, worker); } return map; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration.java
private Map<String, String> copy(Map<String, String> source, Map<String, String> dest) { if (source == null) return null; dest.clear(); for (String key : source.keySet()) { dest.put(key, source.get(key));/* w w w . j a v a2s .c o m*/ } return dest; }
From source file:ai.grakn.test.graql.analytics.AnalyticsTest.java
@Ignore //TODO: Stabalise this test. It fails way too often. @Test/*from w w w. j a va 2s . c o m*/ public void testDegreesAndPersist() throws Exception { // TODO: Fix on TinkerGraphComputer assumeFalse(usingTinker()); // create instances EntityType thing = graph.putEntityType("thing"); EntityType anotherThing = graph.putEntityType("another"); String entity1 = thing.addEntity().getId(); String entity2 = thing.addEntity().getId(); String entity3 = thing.addEntity().getId(); String entity4 = anotherThing.addEntity().getId(); RoleType role1 = graph.putRoleType("role1"); RoleType role2 = graph.putRoleType("role2"); thing.playsRole(role1).playsRole(role2); anotherThing.playsRole(role1).playsRole(role2); RelationType related = graph.putRelationType("related").hasRole(role1).hasRole(role2); // relate them String id1 = related.addRelation().putRolePlayer(role1, graph.getConcept(entity1)) .putRolePlayer(role2, graph.getConcept(entity2)).getId(); String id2 = related.addRelation().putRolePlayer(role1, graph.getConcept(entity2)) .putRolePlayer(role2, graph.getConcept(entity3)).getId(); String id3 = related.addRelation().putRolePlayer(role1, graph.getConcept(entity2)) .putRolePlayer(role2, graph.getConcept(entity4)).getId(); graph.commit(); // compute degrees on subgraph Analytics computer = new Analytics(graph.getKeyspace(), Sets.newHashSet("thing", "related"), new HashSet<>()); computer.degreesAndPersist(); Map<String, Long> correctDegrees = new HashMap<>(); correctDegrees.clear(); correctDegrees.put(entity1, 1L); correctDegrees.put(entity2, 3L); correctDegrees.put(entity3, 1L); correctDegrees.put(id1, 2L); correctDegrees.put(id2, 2L); correctDegrees.put(id3, 1L); // assert persisted degrees are correct checkDegrees(correctDegrees); // compute again and again ... long numVertices = 0; for (int i = 0; i < 2; i++) { computer.degreesAndPersist(); graph = factory.getGraph(); checkDegrees(correctDegrees); // assert the number of vertices remain the same if (i == 0) { numVertices = computer.count(); } else { assertEquals(numVertices, computer.count()); } } computer = new Analytics(graph.getKeyspace(), new HashSet<>(), new HashSet<>()); // compute degrees on all types, again and again ... correctDegrees.put(entity4, 1L); correctDegrees.put(id3, 2L); for (int i = 0; i < 2; i++) { computer.degreesAndPersist(); graph = factory.getGraph(); checkDegrees(correctDegrees); // assert the number of vertices remain the same if (i == 0) { assertEquals(1, computer.count() - numVertices); numVertices = computer.count(); } else { assertEquals(numVertices, computer.count()); } } }
From source file:com.microsoft.office.plugin.MetadataMojo.java
@Override public void execute() throws MojoExecutionException { if (new File(outputDirectory + File.separator + TOOL_DIR).exists()) { getLog().info("Nothing to do because " + TOOL_DIR + " directory already exists. Clean to update."); return;/*from w ww. j a va2 s.c om*/ } try { Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); generateInterfaces = generateTargets.contains("interfaces"); generateClasses = generateTargets.contains("classes"); ODataV4Client client = ODataClientFactory.getV4(); final ODataMetadataRequest<EdmV4Metadata, ?, ?, ?, ?, ?, ?, ?> req = client.getRetrieveRequestFactory() .getMetadataRequest(serviceRootURL); final String authHeader = "Basic " + Base64.encodeBase64String((serviceUsername + ":" + servicePassword).getBytes()); req.addCustomHeader("Authorization", authHeader); final ODataRetrieveResponse<EdmV4Metadata> res = req.execute(); final EdmV4Metadata metadata = res.getBody(); if (metadata == null) { throw new IllegalStateException("Metadata not found"); } // first namespace is base; other will be subpackages of first // so "System" becomes "Microsoft.Exchange.Services.OData.Model.System" List<Schema> schemas = metadata.getSchemas(); if (schemas.size() > 0) { String base = schemas.get(0).getNamespace(); for (int i = 1; i < schemas.size(); ++i) { schemas.get(i).setNamespace(base + "." + schemas.get(i).getNamespace()); } } for (Schema schema : metadata.getSchemas()) { namespaces.add(schema.getNamespace().toLowerCase()); } final Set<String> complexTypeNames = new HashSet<String>(); final File services = mkdir("META-INF/services"); for (Schema schema : metadata.getSchemas()) { utility = new Utility(metadata, schema, basePackage); // write package-info for the base package final String schemaPath = utility.getNamespace().toLowerCase().replace('.', File.separatorChar); final File base = mkPkgDir(schemaPath); final String pkg = basePackage + "." + utility.getNamespace().toLowerCase(); parseObj(base, pkg, "package-info", "package-info.java"); // write package-info for types package final File typesBaseDir = mkPkgDir(schemaPath + "/types"); final String typesPkg = pkg + ".types"; parseObj(typesBaseDir, typesPkg, "package-info", "package-info.java"); final Map<String, Object> objs = new HashMap<String, Object>(); if (generateInterfaces) { // write types into types package for (ComplexType complex : schema.getComplexTypes()) { final String className = utility.capitalize(complex.getName()); complexTypeNames.add(typesPkg + "." + className); objs.clear(); objs.put("complexType", complex); parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); } for (EnumType enumType : schema.getEnumTypes()) { final String className = utility.capitalize(enumType.getName()); complexTypeNames.add(typesPkg + "." + className); objs.clear(); objs.put("enumType", enumType); parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); } } for (EntityType entity : schema.getEntityTypes()) { try { objs.clear(); objs.put("entityType", entity); final Map<String, String> keys; EntityType baseType = null; if (entity.getBaseType() == null) { keys = utility.getEntityKeyType(entity); } else { baseType = schema.getEntityType(utility.getNameFromNS(entity.getBaseType())); objs.put("baseType", utility.getJavaType(entity.getBaseType())); while (baseType.getBaseType() != null) { baseType = schema.getEntityType(utility.getNameFromNS(baseType.getBaseType())); } keys = utility.getEntityKeyType(baseType); } if (keys.size() > 1) { // create compound key class final String keyClassName = utility .capitalize(baseType == null ? entity.getName() : baseType.getName()) + "Key"; objs.put("keyRef", keyClassName); if (entity.getBaseType() == null) { objs.put("keys", keys); parseObj(typesBaseDir, typesPkg, "entityTypeKey", keyClassName + ".java", objs); } } if (generateInterfaces) { parseObj(typesBaseDir, typesPkg, "entityType", "I" + utility.capitalize(entity.getName()) + ".java", objs); parseObj(typesBaseDir, typesPkg, "entityCollection", "I" + utility.capitalize(entity.getName()) + "Collection.java", objs); } if (generateClasses) { parseObj(typesBaseDir, typesPkg, "entityTypeImpl", utility.capitalize(entity.getName()) + ".java", objs); parseObj(typesBaseDir, typesPkg, "entityCollectionImpl", utility.capitalize(entity.getName()) + "Collection.java", objs); } } catch (Exception e) { getLog().error(e.getMessage()); if (e instanceof NullPointerException) { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); getLog().error(stringWriter.toString()); } continue; } } List<EntitySet> additionalSets = new ArrayList<EntitySet>(); // generate non-top level entity sets that accessible via other entity sets or singletons for (EntityContainer container : schema.getEntityContainers()) { Map<String, String> paths = new HashMap<String, String>(); Map<String, Boolean> generatedEntitySets = new HashMap<String, Boolean>(); Map<String, String> entitySetNames = new HashMap<String, String>(); Collection<String> containerEntitySets = getEntitySetTypes(container); for (EntityType type : schema.getEntityTypes()) { generatedEntitySets.put(type.getName(), containerEntitySets.contains(type.getName())); } for (Singleton singleton : container.getSingletons()) { String type = singleton.getType(); if (!paths.containsKey(utility.getNameFromNS(type))) { paths.put(utility.getNameFromNS(type), ""); } entitySetNames.put(utility.getNameFromNS(type), singleton.getName()); generateEntitySet(schema, base, pkg, objs, generatedEntitySets, entitySetNames, type, paths, additionalSets); } for (EntitySet set : container.getEntitySets()) { String type = set.getEntityType(); if (!paths.containsKey(utility.getNameFromNS(type))) { paths.put(utility.getNameFromNS(type), ""); } entitySetNames.put(utility.getNameFromNS(type), set.getName()); generateEntitySet(schema, base, pkg, objs, generatedEntitySets, entitySetNames, type, paths, additionalSets); } } // write container and top entity sets into the base package for (EntityContainer container : schema.getEntityContainers()) { for (EntitySet entitySet : container.getEntitySets()) { objs.clear(); objs.put("entitySet", entitySet); if (generateInterfaces) { parseObj(base, pkg, "entitySet", "I" + utility.capitalize(entitySet.getName()) + ".java", objs); } if (generateClasses) { parseObj(base, pkg, "entitySetImpl", utility.capitalize(entitySet.getName()) + ".java", objs); } } for (EntitySet set : additionalSets) { container.getEntitySets().add(set); } if (generateClasses) { for (Singleton singleton : container.getSingletons()) { objs.clear(); objs.put("singleton", singleton); parseObj(base, pkg, "singleton", utility.capitalize(singleton.getName()) + ".java", objs); } } if (generateInterfaces) { objs.clear(); objs.put("container", container); parseObj(base, pkg, "container", utility.capitalize(container.getName()) + ".java", objs); } } // default folders enumeration if (!pkg.endsWith("system") && generateInterfaces) { objs.clear(); objs.put("userType", schema.getEntityType("User")); parseObj(base, pkg, "defaultFolder", "DefaultFolder.java", objs); } parseObj(services, true, null, "services", "com.msopentech.odatajclient.proxy.api.AbstractComplexType", Collections.singletonMap("services", (Object) complexTypeNames)); } } catch (Throwable t) { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); t.printStackTrace(printWriter); getLog().error(stringWriter.toString()); throw (t instanceof MojoExecutionException) ? (MojoExecutionException) t : new MojoExecutionException("While executin mojo", t); } }
From source file:com.alibaba.otter.node.etl.common.datasource.impl.DBDataSourceService.java
public void destroy(Long pipelineId) { Map<DbMediaSource, DataSource> sources = dataSources.remove(pipelineId); if (sources != null) { for (DataSource source : sources.values()) { try { // for filter to destroy custom datasource if (letHandlerDestroyIfSupport(pipelineId, source)) { continue; }//from w ww. j a v a 2 s .co m // fallback for regular destroy // TODO need to integrate to handler BasicDataSource basicDataSource = (BasicDataSource) source; basicDataSource.close(); } catch (SQLException e) { logger.error("ERROR ## close the datasource has an error", e); } } sources.clear(); } }