List of usage examples for java.util Map clear
void clear();
From source file:com.linkedin.pinot.queries.QueryExceptionTest.java
@Test public void testQueryParsingFailedQuery() throws RecognitionException, Exception { String query = "select sudm(blablaa) 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 ww w . java 2 s . c o m*/ LOGGER.info("BrokerResponse is {}", brokerResponse); Assert.assertTrue(brokerResponse.getExceptionsSize() > 0); }
From source file:com.linkedin.pinot.queries.QueryExceptionTest.java
@Test public void testQueryPlanFailedQuery() throws RecognitionException, Exception { String query = "select sum(blablaa) 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 a v a 2 s . c o m*/ LOGGER.info("BrokerResponse is {}", brokerResponse); Assert.assertTrue(brokerResponse.getExceptionsSize() > 0); }
From source file:com.linkedin.pinot.queries.QueryExceptionTest.java
@Test public void testQueryExecuteFailedQuery() throws RecognitionException, Exception { String query = "select count(*) from testTable where column1='24516187' group by bla"; 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);//w w w .j av a 2 s . com LOGGER.info("BrokerResponse is {}", brokerResponse); Assert.assertEquals(brokerResponse.getExceptionsSize(), 1); }
From source file:org.red5.server.net.rtmp.codec.RTMP.java
/** * Releases number of packets./*w w w .ja v a 2 s . c o m*/ * * @param packets Packets to release */ private void freePackets(Map<Integer, Packet> packets) { for (Packet packet : packets.values()) { if (packet != null && packet.getData() != null) { packet.getData().free(); packet.setData(null); } } packets.clear(); }
From source file:jp.co.conit.sss.sp.ex1.io.AbstSSSSPParser.java
/** * SamuraiParchace?WebAPI?????<br> * ???????Map????//from w ww. ja va 2s .c om * * @param str * @return */ private Map<String, String> parseStatus(String str) { Map<String, String> resultMap = new HashMap<String, String>(); if (str == null) { return resultMap; } try { JSONObject jsonObject = new JSONObject(str); if (!jsonObject.has("error_info")) { return resultMap; } JSONObject databaseObject = jsonObject.getJSONObject("error_info"); String statusCode = databaseObject.getString("code"); resultMap.put("code", statusCode); String message = databaseObject.getString("message"); resultMap.put("message", message); } catch (JSONException e) { resultMap.clear(); return resultMap; } return resultMap; }
From source file:es.logongas.ix3.web.json.impl.JsonReaderImplEntityJackson.java
private void populateEntity(Object entity, Object jsonObj, MetaData metaData, String path, BeanMapper beanMapper, DataSession dataSession) throws BusinessException { if (jsonObj == null) { return;/* ww w.ja v a 2 s . c o m*/ } if (metaData == null) { throw new IllegalArgumentException("El argumento 'metaData' no puede ser null"); } for (String propertyName : metaData.getPropertiesMetaData().keySet()) { MetaData propertyMetaData = metaData.getPropertiesMetaData().get(propertyName); String absolutePropertyName; if ((path == null) || (path.trim().length() == 0)) { absolutePropertyName = propertyName; } else { absolutePropertyName = path + "." + propertyName; } if (beanMapper.isDeleteInProperty(absolutePropertyName) == true) { //No se puede generar esa propiedad desde el "exterior" continue; } if (propertyMetaData.isCollection() == false) { switch (propertyMetaData.getMetaType()) { case Scalar: { Object rawValue = getValueFromBean(jsonObj, propertyName); setValueToBean(entity, rawValue, propertyName); break; } case Entity: { //Debemos leer la referencia de la base de datos Object rawValue = getValueFromBean(jsonObj, propertyName); Object value = readForeingEntity(rawValue, propertyMetaData, dataSession); setValueToBean(entity, value, propertyName); break; } case Component: { //Es un componente, as que hacemos la llamada recursiva Object rawValue = getValueFromBean(jsonObj, propertyName); Object component = getValueFromBean(entity, propertyName); if (component == null) { try { component = propertyMetaData.getType().newInstance(); setValueToBean(entity, component, propertyName); } catch (InstantiationException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } } populateEntity(component, rawValue, propertyMetaData, absolutePropertyName, beanMapper, dataSession); break; } default: throw new RuntimeException("El MetaTypo es desconocido:" + propertyMetaData.getMetaType()); } } else { switch (propertyMetaData.getCollectionType()) { case List: case Set: { if (beanMapper.isExpandInProperty(absolutePropertyName)) { Collection rawCollection = (Collection) getValueFromBean(jsonObj, propertyName); Collection currentCollection = (Collection) getValueFromBean(entity, propertyName); //Borramos todos los elementos para aadir despues los que vienen desde JSON if (currentCollection != null) { currentCollection.clear(); } else { //Si no hay coleccion hay que crearla aqui if (propertyMetaData.getCollectionType() == CollectionType.List) { currentCollection = new ArrayList(); } else if (propertyMetaData.getCollectionType() == CollectionType.Set) { currentCollection = new HashSet(); } else { throw new RuntimeException( "El tipo coneccion no es vlida:" + propertyMetaData.getCollectionType()); } setValueToBean(entity, currentCollection, propertyName); } //Aadimos los elementos que vienen desde JSON if (rawCollection != null) { for (Object rawValue : rawCollection) { Object value = readForeingEntity(rawValue, propertyMetaData, dataSession); currentCollection.add(value); } } } else { //NO cargamos la coleccion desde el JSON } break; } case Map: { if (beanMapper.isExpandInProperty(absolutePropertyName)) { //TODO:No cargamos nunca las coleccione pq aun no sabemos si hay que hacerlo o no Map rawMap = (Map) getValueFromBean(jsonObj, propertyName); Map currentMap = (Map) getValueFromBean(entity, propertyName); //Borramos todos los elementos para aadir despues los que vienen desde JSON if (currentMap != null) { currentMap.clear(); } else { //Si no hay coleccion hay que crearla qui currentMap = new HashMap(); setValueToBean(entity, currentMap, propertyName); } //Aadimos los elementos que vienen desde JSON if (rawMap != null) { for (Object key : rawMap.keySet()) { Object rawValue = rawMap.get(key); Object value = readEntity(rawValue, propertyMetaData, absolutePropertyName, beanMapper, dataSession); currentMap.put(key, value); } } } else { //NO cargamos la coleccion desde el JSON } break; } default: throw new RuntimeException( "El CollectionType es desconocido:" + propertyMetaData.getCollectionType()); } } } }
From source file:com.msopentech.odatajclient.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;/* w ww . j a va2 s . com*/ } try { Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); determineAndSetBasicAuthentication(); final ODataMetadataRequest req = ODataRetrieveRequestFactory.getMetadataRequest(serviceRootURL); final ODataRetrieveResponse<EdmMetadata> res = req.execute(); final EdmMetadata metadata = res.getBody(); if (metadata == null) { throw new IllegalStateException("Metadata not found"); } 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>(); // 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 (EntityType entity : schema.getEntityTypes()) { 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); } } parseObj(typesBaseDir, typesPkg, "entityType", utility.capitalize(entity.getName()) + ".java", objs); parseObj(typesBaseDir, typesPkg, "entityCollection", utility.capitalize(entity.getName()) + "Collection.java", objs); } // write container and top entity sets into the base package for (EntityContainer container : schema.getEntityContainers()) { objs.clear(); objs.put("container", container); parseObj(base, pkg, "container", utility.capitalize(container.getName()) + ".java", objs); for (EntitySet entitySet : container.getEntitySets()) { objs.clear(); objs.put("entitySet", entitySet); parseObj(base, pkg, "entitySet", utility.capitalize(entitySet.getName()) + ".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:hoot.services.controllers.osm.OSMTestUtils.java
static Set<Long> createTestWays(long changesetId, Set<Long> nodeIds) throws Exception { Long[] nodeIdsArr = nodeIds.toArray(new Long[nodeIds.size()]); Map<String, String> tags = new HashMap<>(); tags.put("key 1", "val 1"); tags.put("key 2", "val 2"); List<Long> wayNodeIds = new ArrayList<>(); wayNodeIds.add(nodeIdsArr[0]);/*from w w w.j a v a 2 s.c o m*/ wayNodeIds.add(nodeIdsArr[1]); wayNodeIds.add(nodeIdsArr[4]); Set<Long> wayIds = new LinkedHashSet<>(); wayIds.add(insertNewWay(changesetId, getMapId(), wayNodeIds, tags)); tags.clear(); wayNodeIds.clear(); wayNodeIds.add(nodeIdsArr[2]); wayNodeIds.add(nodeIdsArr[1]); wayIds.add(insertNewWay(changesetId, getMapId(), wayNodeIds, null)); wayNodeIds.clear(); tags.put("key 3", "val 3"); wayNodeIds.add(nodeIdsArr[0]); wayNodeIds.add(nodeIdsArr[1]); wayIds.add(insertNewWay(changesetId, getMapId(), wayNodeIds, tags)); tags.clear(); wayNodeIds.clear(); return wayIds; }
From source file:com.javaeeeee.dropbookmarks.resources.BookmarksResource.java
/** * A method to modify an existing bookmark data. * * @param id the id of the bookmark to be modified. * @param jsonData Modifications in JSON format. * @param user Authenticated user with whose bookmarks we work. * @return Bookmark with modified fields or throws an exception if bookmark * was not found.//ww w . j ava 2 s .co m */ @PUT @Path("/{id}") @UnitOfWork public Bookmark modifyBookmark(@PathParam("id") IntParam id, String jsonData, @Auth User user) { Bookmark bookmark = findBookmarkOrTrowException(id, user); // Update bookmark data ObjectMapper objectMapper = new ObjectMapper(); Map<String, String> changeMap = null; try { changeMap = objectMapper.readValue(jsonData, HashMap.class); purgeMap(changeMap); BeanUtils.populate(bookmark, changeMap); return bookmarkDAO.save(bookmark); } catch (IOException | IllegalAccessException | InvocationTargetException ex) { LOGGER.warn(WRONG_BODY_DATA_FORMAT, ex); throw new WebApplicationException(WRONG_BODY_DATA_FORMAT, ex, Response.Status.BAD_REQUEST); } finally { if (changeMap != null) { changeMap.clear(); } } }
From source file:com.glaf.base.modules.todo.TodoXlsReader.java
public List<Todo> readXls(java.io.InputStream inputStream) { List<Todo> todos = new java.util.ArrayList<Todo>(); HSSFWorkbook wb = null;//from w w w .j a v a2s. c o m try { wb = new HSSFWorkbook(inputStream); } catch (Exception ex) { throw new RuntimeException(ex); } HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(1); Map<Integer, String> keyMap = new java.util.HashMap<Integer, String>(); Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); int cells = row.getPhysicalNumberOfCells(); for (int colIndex = 0; colIndex < cells; colIndex++) { HSSFCell cell = row.getCell(colIndex); keyMap.put(colIndex, cell.getStringCellValue()); } Set<String> keys = new HashSet<String>(); for (int rowIndex = 2; rowIndex < sheet.getPhysicalNumberOfRows(); rowIndex++) { HSSFRow rowx = sheet.getRow(rowIndex); if (rowx == null) { continue; } // System.out.println(); dataMap.clear(); for (int colIndex = 0; colIndex < cells; colIndex++) { String fieldName = keyMap.get(colIndex); HSSFCell cell = rowx.getCell(colIndex); if (cell == null) { continue; } Object cellValue = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: break; case HSSFCell.CELL_TYPE_BOOLEAN: cellValue = cell.getBooleanCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: cellValue = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: if (StringUtils.isNotEmpty(cell.getRichStringCellValue().getString())) { cellValue = cell.getRichStringCellValue().getString(); } break; default: if (StringUtils.isNotEmpty(cell.getStringCellValue())) { cellValue = cell.getStringCellValue(); } break; } if (cellValue != null) { dataMap.put(fieldName, cellValue); if ("id".equals(fieldName)) { cellValue = cellValue.toString().substring(0, cellValue.toString().indexOf(".")); dataMap.put(fieldName, cellValue); } } } if (dataMap.get("code") != null) { String id = ParamUtils.getString(dataMap, "id"); if (!keys.contains(ParamUtils.getString(dataMap, "code"))) { if (id != null && StringUtils.isNotEmpty(id)) { Todo model = new Todo(); Tools.populate(model, dataMap); if (ParamUtils.getInt(dataMap, "limitDay") > 0) { model.setLimitDay(ParamUtils.getInt(dataMap, "limitDay")); } todos.add(model); keys.add(model.getCode()); } } } } return todos; }