List of usage examples for java.util TreeMap containsKey
public boolean containsKey(Object key)
From source file:org.apache.hadoop.hbase.index.mapreduce.IndexLoadIncrementalHFile.java
private void createTable(String tableName, String dirPath) throws Exception { Path hfofDir = new Path(dirPath); FileSystem fs = hfofDir.getFileSystem(getConf()); if (!fs.exists(hfofDir)) { throw new FileNotFoundException("HFileOutputFormat dir " + hfofDir + " not found"); }//from ww w. ja v a 2 s .c o m FileStatus[] familyDirStatuses = fs.listStatus(hfofDir); if (familyDirStatuses == null) { throw new FileNotFoundException("No families found in " + hfofDir); } HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd = null; // Add column families // Build a set of keys byte[][] keys = null; TreeMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR); for (FileStatus stat : familyDirStatuses) { if (!stat.isDir()) { LOG.warn("Skipping non-directory " + stat.getPath()); continue; } Path familyDir = stat.getPath(); // Skip _logs & .index etc if (familyDir.getName().startsWith("_")) continue; if (familyDir.getName().startsWith(IndexMapReduceUtil.INDEX_DATA_DIR)) { LOG.warn("Ignoring all the HFile specific to " + tableName + " indexed data."); continue; } byte[] family = Bytes.toBytes(familyDir.getName()); hcd = new HColumnDescriptor(family); htd.addFamily(hcd); Path[] hfiles = FileUtil.stat2Paths(fs.listStatus(familyDir)); for (Path hfile : hfiles) { if (hfile.getName().startsWith("_")) continue; HFile.Reader reader = HFile.createReader(fs, hfile, new CacheConfig(getConf())); final byte[] first, last; try { if (hcd.getCompressionType() != reader.getCompressionAlgorithm()) { hcd.setCompressionType(reader.getCompressionAlgorithm()); LOG.info("Setting compression " + hcd.getCompressionType().name() + " for family " + hcd.toString()); } reader.loadFileInfo(); first = reader.getFirstRowKey(); last = reader.getLastRowKey(); LOG.info("Trying to figure out region boundaries hfile=" + hfile + " first=" + Bytes.toStringBinary(first) + " last=" + Bytes.toStringBinary(last)); // To eventually infer start key-end key boundaries Integer value = map.containsKey(first) ? (Integer) map.get(first) : 0; map.put(first, value + 1); value = map.containsKey(last) ? (Integer) map.get(last) : 0; map.put(last, value - 1); } finally { reader.close(); } } } keys = IndexLoadIncrementalHFile.inferBoundaries(map); this.hbAdmin.createTable(htd, keys); LOG.info("Table " + tableName + " is available!!"); }
From source file:org.wso2.carbon.event.simulator.core.internal.generator.csv.util.CSVReader.java
/** * createEventsMap() methods creates a treeMap of events using the data in the CSV file. * The key of the treeMap will be the event timestamp and the value will be an array list of events belonging to * the timestamp.//from w w w.j av a 2 s . c o m * * @param csvConfig configuration of csv simulation * @param streamAttributes list of attributes of the stream to which events are produced * @param startTimestamp start timestamp of event simulation * @param endTimestamp end timestamp of event simulation * @return a treeMap of events */ private TreeMap<Long, ArrayList<Event>> createEventsMap(CSVSimulationDTO csvConfig, List<Attribute> streamAttributes, long startTimestamp, long endTimestamp) { TreeMap<Long, ArrayList<Event>> eventsMap = new TreeMap<>(); int timestampPosition = Integer.parseInt(csvConfig.getTimestampAttribute()); long lineNumber; long timestamp; List<Integer> indices = csvConfig.getIndices(); Event event; if (csvParser != null) { for (CSVRecord record : csvParser) { lineNumber = csvParser.getCurrentLineNumber(); ArrayList<String> attributes = new ArrayList<>(); for (String attribute : record) { attributes.add(attribute); } /* * retrieve the value at the position specified by timestamp attribute as the timestamp * if the timestamp is within the range specified by the startTimestamp and endTimestamp, proceed to * creating an event, else ignore record and proceed to next record * retrieve the data elements required for event using record using the indices specified * */ try { timestamp = Long.parseLong(attributes.get(timestampPosition)); if (timestamp >= startTimestamp) { if (endTimestamp == -1 || timestamp <= endTimestamp) { List<String> eventData = new ArrayList<>(); indices.forEach(index -> eventData.add(attributes.get(index))); try { event = EventConverter.eventConverter(streamAttributes, eventData.toArray(), timestamp); } catch (EventGenerationException e) { log.error( "Error occurred when generating event using CSV event generator to simulate" + " stream '" + csvConfig.getStreamName() + "' using source configuration : " + csvConfig.toString() + "Drop event and create next event.", e); continue; } if (!eventsMap.containsKey(timestamp)) { eventsMap.put(timestamp, new ArrayList<>(Collections.singletonList(event))); } else { eventsMap.get(timestamp).add(event); } } } } catch (NumberFormatException e) { log.warn("Invalid data '" + attributes.get(timestampPosition) + "' provided for timestamp" + "attribute in line " + lineNumber + ". Line content : " + attributes + ". " + "Ignore line and read next line. Source configuration : " + csvConfig.toString()); } catch (IndexOutOfBoundsException e) { log.warn("Cannot retrieve data elements from line " + lineNumber + " for all indices " + indices + ". Line content : " + attributes + ". Ignore line and read next line." + " Source configuration : " + csvConfig.toString()); } } } if (log.isDebugEnabled()) { log.debug("Create an ordered events map from CSV file '" + csvConfig.getFileName() + "' to simulate " + "stream '" + csvConfig.getStreamName() + "'."); } return eventsMap; }
From source file:org.jahia.admin.sites.ManageSites.java
/** * Display page to let user choose a set of templates. * * @param request Servlet request./*from w ww . j ava 2 s.c o m*/ * @param response Servlet response. * @param session HttpSession object. */ private void displayTemplateSetChoice(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException, ServletException { try { logger.debug("Display template set choice started "); // retrieve previous form values... String jahiaDisplayMessage = (String) request.getAttribute(CLASS_NAME + "jahiaDisplayMessage"); // set default values... if (jahiaDisplayMessage == null) { jahiaDisplayMessage = Jahia.COPYRIGHT; } String selectedTmplSet = (String) request.getAttribute("selectedTmplSet"); TreeMap<String, JCRNodeWrapper> orderedTemplateSets = getTemplatesSets(); // try to select the default set if not selected if (selectedTmplSet == null) { selectedTmplSet = SettingsBean.getInstance().getPropertiesFile() .getProperty("default_templates_set", orderedTemplateSets.firstKey()); } JCRNodeWrapper selectedPackage = selectedTmplSet != null && orderedTemplateSets.containsKey(selectedTmplSet) ? orderedTemplateSets.get(selectedTmplSet) : orderedTemplateSets.get(orderedTemplateSets.firstKey()); request.setAttribute("selectedTmplSet", selectedTmplSet); request.setAttribute("tmplSets", orderedTemplateSets.values()); request.setAttribute("modules", getModulesOfType(JahiaTemplateManagerService.MODULE_TYPE_MODULE).values()); request.setAttribute("jahiApps", getModulesOfType(JahiaTemplateManagerService.MODULE_TYPE_JAHIAPP).values()); request.setAttribute("selectedModules", jParams.getParameterValues("selectedModules")); request.setAttribute("selectedPackage", selectedPackage); Locale currentLocale = (Locale) session.getAttribute(ProcessingContext.SESSION_LOCALE); if (currentLocale == null) { currentLocale = request.getLocale(); } Locale selectedLocale = (Locale) session.getAttribute(CLASS_NAME + "selectedLocale"); if (selectedLocale == null) { selectedLocale = LanguageCodeConverters .languageCodeToLocale(Jahia.getSettings().getDefaultLanguageCode()); } session.setAttribute(CLASS_NAME + "selectedLocale", selectedLocale); request.setAttribute("selectedLocale", selectedLocale); request.setAttribute("currentLocale", currentLocale); logger.debug("Nb template set found " + orderedTemplateSets.size()); // redirect... JahiaAdministration.doRedirect(request, response, session, JSP_PATH + "site_choose_template_set.jsp"); // set default values... session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", Jahia.COPYRIGHT); } catch (RepositoryException e) { throw new ServletException(e); } }
From source file:org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles.java
private void createTable(TableName tableName, String dirPath) throws Exception { Path hfofDir = new Path(dirPath); FileSystem fs = hfofDir.getFileSystem(getConf()); if (!fs.exists(hfofDir)) { throw new FileNotFoundException("HFileOutputFormat dir " + hfofDir + " not found"); }/*from w w w . ja v a2s . c o m*/ FileStatus[] familyDirStatuses = fs.listStatus(hfofDir); if (familyDirStatuses == null) { throw new FileNotFoundException("No families found in " + hfofDir); } HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd; // Add column families // Build a set of keys byte[][] keys; TreeMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR); for (FileStatus stat : familyDirStatuses) { if (!stat.isDirectory()) { LOG.warn("Skipping non-directory " + stat.getPath()); continue; } Path familyDir = stat.getPath(); // Skip _logs, etc if (familyDir.getName().startsWith("_")) continue; byte[] family = familyDir.getName().getBytes(); hcd = new HColumnDescriptor(family); htd.addFamily(hcd); Path[] hfiles = FileUtil.stat2Paths(fs.listStatus(familyDir)); for (Path hfile : hfiles) { String fileName = hfile.getName(); if (fileName.startsWith("_") || StoreFileInfo.isReference(fileName) || HFileLink.isHFileLink(fileName)) continue; HFile.Reader reader = HFile.createReader(fs, hfile, new CacheConfig(getConf()), getConf()); final byte[] first, last; try { if (hcd.getCompressionType() != reader.getFileContext().getCompression()) { hcd.setCompressionType(reader.getFileContext().getCompression()); LOG.info("Setting compression " + hcd.getCompressionType().name() + " for family " + hcd.toString()); } reader.loadFileInfo(); first = reader.getFirstRowKey(); last = reader.getLastRowKey(); LOG.info("Trying to figure out region boundaries hfile=" + hfile + " first=" + Bytes.toStringBinary(first) + " last=" + Bytes.toStringBinary(last)); // To eventually infer start key-end key boundaries Integer value = map.containsKey(first) ? map.get(first) : 0; map.put(first, value + 1); value = map.containsKey(last) ? map.get(last) : 0; map.put(last, value - 1); } finally { reader.close(); } } } keys = LoadIncrementalHFiles.inferBoundaries(map); this.hbAdmin.createTable(htd, keys); LOG.info("Table " + tableName + " is available!!"); }
From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java
/** * Load a list of people this person has supervised in the past. * * @param guid the guid/*ww w .j a v a 2 s. co m*/ * @param allRotations the all rotations * @return the collection */ private HashMap<String, ArrayList<PersonBean>> loadSupervisedPeople(final int guid, final boolean allRotations) { HashMap<String, ArrayList<PersonBean>> supervisedPeople = new HashMap<String, ArrayList<PersonBean>>(); // Create new SearchBean of with default values SearchBean searchRotations = this.getSearchDAO().initiate("rotation", null); searchRotations.setLimit(0); RotationBean rotationParam = (RotationBean) searchRotations.getSearchCriteria(); SupervisorBean supervisor = new SupervisorBean(); supervisor.setPersonGUID(guid); rotationParam.addSupervisor(supervisor); BuilderBean loadDetails = new BuilderBean(); loadDetails.setParameter("ASSESSMENTS", true); loadDetails.setParameter("SUPERVISORS", true); searchRotations.setSearchCriteria(rotationParam); searchRotations.setOrderColumn("rotation.StartDate"); searchRotations.setOrderColumn2("people.LastName"); searchRotations.setOrderAscending(false); SearchResultsBean studentsSupervised = new SearchResultsBean(); try { studentsSupervised = this.getSearchDAO().search(searchRotations, loadDetails); } catch (Exception e) { dataLogger.error("Error searching for supervised people: " + e.getMessage()); } final Calendar currentDate = Calendar.getInstance(); final TreeMap<String, ArrayList<RotationBean>> currentlySupervising = new TreeMap<String, ArrayList<RotationBean>>(); final TreeMap<String, ArrayList<RotationBean>> previouslySupervised = new TreeMap<String, ArrayList<RotationBean>>(); final HashMap<String, PersonBean> personMap = new HashMap<String, PersonBean>(); for (Object rotationObj : studentsSupervised.getSearchResults()) { final RotationBean rotation = (RotationBean) rotationObj; boolean currentlyTakingPlace = false; if (rotation.getStartDate().before(currentDate.getTime()) && rotation.getEndDate().after(currentDate.getTime())) { currentlyTakingPlace = true; } if (rotation.getPerson() != null) { final PersonBean person = rotation.getPerson(); final String index = person.getLastName() + " " + person.getPreferredName() + " " + person.getPersonIdentifier(); boolean processed = false; if (currentlySupervising.containsKey(index)) { // The person exists in the currently supervising list. ArrayList<RotationBean> tneRots = currentlySupervising.get(index); if (allRotations || currentlyTakingPlace) { tneRots.add(rotation); } currentlySupervising.put(index, tneRots); processed = true; } if (previouslySupervised.containsKey(index)) { // The person exists in the previously supervised list ArrayList<RotationBean> tneRots = previouslySupervised.get(index); if (allRotations || currentlyTakingPlace) { tneRots.add(rotation); } if (currentlyTakingPlace) { // This is a current rotation, remove from the previously // supervised list and add to currently supervising. previouslySupervised.remove(index); currentlySupervising.put(index, tneRots); } else { previouslySupervised.put(index, tneRots); } processed = true; } if (!processed) { // This person has not been encountered yet. personMap.put(index, person); ArrayList<RotationBean> tneRots = new ArrayList<RotationBean>(); if (allRotations || currentlyTakingPlace) { tneRots.add(rotation); } if (currentlyTakingPlace) { currentlySupervising.put(index, tneRots); } else { previouslySupervised.put(index, tneRots); } } } } final ArrayList<PersonBean> currentPeople = new ArrayList<PersonBean>(); final ArrayList<PersonBean> previousPeople = new ArrayList<PersonBean>(); for (String index : currentlySupervising.keySet()) { final PersonBean person = personMap.get(index); final ArrayList<RotationBean> tneRots = currentlySupervising.get(index); person.setRotations(tneRots); currentPeople.add(person); } for (String index : previouslySupervised.keySet()) { final PersonBean person = personMap.get(index); final ArrayList<RotationBean> tneRots = previouslySupervised.get(index); person.setRotations(tneRots); previousPeople.add(person); } supervisedPeople.put("current", currentPeople); supervisedPeople.put("previous", previousPeople); return supervisedPeople; }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void initObstaclesAndPreLoad(int[] resources, int stride, TreeMap<Integer, Bitmap> map, ArrayList<Integer> list) { initObstacles(resources, stride, list); // Load the bitmaps for the first 20 obstacles. for (int i = 0; i < 20; i++) { int obstacle = list.get(i); for (int j = (obstacle * stride); j < ((obstacle + 1) * stride); j++) { // Check just in case something is wonky if (j < resources.length) { int id = resources[j]; if (id != -1) { // Only need to load it once... if (!map.containsKey(id)) { Bitmap bmp = BitmapFactory.decodeResource(getResources(), id); if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) { Bitmap tmp = Bitmap.createScaledBitmap(bmp, (int) ((float) bmp.getWidth() * mScaleX), (int) ((float) bmp.getHeight() * mScaleY), false); if (tmp != bmp) { bmp.recycle(); }/*from www .j ava2 s. com*/ map.put(id, tmp); } else { map.put(id, bmp); } } } } } } }
From source file:org.apache.hadoop.chukwa.extraction.engine.datasource.database.DatabaseDS.java
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE", justification = "Dynamic based upon tables in the database") public SearchResult search(SearchResult result, String cluster, String dataSource, long t0, long t1, String filter, Token token) throws DataSourceException { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); String timeField = null;//from ww w.j ava2 s.c om TreeMap<Long, List<Record>> records = result.getRecords(); if (cluster == null) { cluster = "demo"; } if (dataSource.equalsIgnoreCase("MRJob")) { timeField = "LAUNCH_TIME"; } else if (dataSource.equalsIgnoreCase("HodJob")) { timeField = "StartTime"; } else { timeField = "timestamp"; } String startS = formatter.format(t0); String endS = formatter.format(t1); Statement stmt = null; ResultSet rs = null; try { String dateclause = timeField + " >= '" + startS + "' and " + timeField + " <= '" + endS + "'"; // ClusterConfig cc = new ClusterConfig(); String jdbc = ""; // cc.getURL(cluster); Connection conn = org.apache.hadoop.chukwa.util.DriverManagerUtil.getConnection(jdbc); stmt = conn.createStatement(); String query = ""; query = "select * from " + dataSource + " where " + dateclause + ";"; rs = stmt.executeQuery(query); if (stmt.execute(query)) { rs = stmt.getResultSet(); ResultSetMetaData rmeta = rs.getMetaData(); int col = rmeta.getColumnCount(); while (rs.next()) { ChukwaRecord event = new ChukwaRecord(); StringBuilder cell = new StringBuilder(); ; long timestamp = 0; for (int i = 1; i < col; i++) { String value = rs.getString(i); if (value != null) { cell.append(" "); cell.append(rmeta.getColumnName(i)); cell.append(":"); cell.append(value); } if (rmeta.getColumnName(i).equals(timeField)) { timestamp = rs.getLong(i); event.setTime(timestamp); } } boolean isValid = false; if (filter == null || filter.equals("")) { isValid = true; } else if (cell.indexOf(filter) > 0) { isValid = true; } if (!isValid) { continue; } event.add(Record.bodyField, cell.toString()); event.add(Record.sourceField, cluster + "." + dataSource); if (records.containsKey(timestamp)) { records.get(timestamp).add(event); } else { List<Record> list = new LinkedList<Record>(); list.add(event); records.put(event.getTime(), list); } } } } catch (SQLException e) { e.printStackTrace(); throw new DataSourceException(e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { log.debug(ExceptionUtil.getStackTrace(sqlEx)); } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { log.debug(ExceptionUtil.getStackTrace(sqlEx)); } stmt = null; } } return result; }
From source file:com.nextgis.ngm_clink_monitoring.fragments.MapFragment.java
@Override public void onSingleTapUp(MotionEvent event) { double dMinX = event.getX() - mTolerancePX; double dMaxX = event.getX() + mTolerancePX; double dMinY = event.getY() - mTolerancePX; double dMaxY = event.getY() + mTolerancePX; GeoEnvelope mapEnv = mMapView.screenToMap(new GeoEnvelope(dMinX, dMaxX, dMinY, dMaxY)); if (null == mapEnv) { return;/* ww w . j a v a 2 s.c o m*/ } //show actions dialog List<ILayer> layers = mMapView.getVectorLayersByType(GeoConstants.GTAnyCheck); TreeMap<Integer, Integer> priorityMap = new TreeMap<>(); List<FoclVectorLayer> foclVectorLayers = new ArrayList<>(); for (ILayer layer : layers) { if (!layer.isValid()) { continue; } ILayerView layerView = (ILayerView) layer; if (!layerView.isVisible()) { continue; } FoclVectorLayer foclVectorLayer = (FoclVectorLayer) layer; List<Long> items = foclVectorLayer.query(mapEnv); if (!items.isEmpty()) { foclVectorLayers.add(foclVectorLayer); int type = foclVectorLayer.getFoclLayerType(); int priority; switch (type) { case FoclConstants.LAYERTYPE_FOCL_UNKNOWN: default: priority = 0; break; case FoclConstants.LAYERTYPE_FOCL_OPTICAL_CABLE: priority = 1; break; case FoclConstants.LAYERTYPE_FOCL_SPECIAL_TRANSITION: priority = 2; break; case FoclConstants.LAYERTYPE_FOCL_FOSC: priority = 3; break; case FoclConstants.LAYERTYPE_FOCL_OPTICAL_CROSS: priority = 4; break; case FoclConstants.LAYERTYPE_FOCL_ACCESS_POINT: priority = 5; break; case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT: priority = 6; break; case FoclConstants.LAYERTYPE_FOCL_REAL_FOSC: priority = 7; break; case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CROSS: priority = 8; break; case FoclConstants.LAYERTYPE_FOCL_REAL_ACCESS_POINT: priority = 9; break; case FoclConstants.LAYERTYPE_FOCL_REAL_SPECIAL_TRANSITION_POINT: priority = 10; break; } if (!priorityMap.containsKey(priority)) { priorityMap.put(priority, type); } } } Integer type = null; if (!priorityMap.isEmpty()) { Integer key = priorityMap.lastKey(); type = priorityMap.get(key); } if (null != type) { for (FoclVectorLayer layer : foclVectorLayers) { if (type == layer.getFoclLayerType()) { List<Long> items = layer.query(mapEnv); AttributesDialog attributesDialog = new AttributesDialog(); attributesDialog.setKeepInstance(true); attributesDialog.setParams(layer, items.get(0)); attributesDialog.show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_ATTRIBUTES); break; } } } }
From source file:de.tudarmstadt.ukp.uby.integration.alignment.xml.transform.sensealignments.VnFnSenseAlignmentXml.java
/** * @param metadata//from w w w.j ava2 s.c om * @throws IOException */ @Override public void toAlignmentXml(XmlMeta metadata) throws IOException { Lexicon vn = uby.getLexiconByName(lexiconName); TreeMap<String, Source> sourceMap = new TreeMap<>(); int noSource = 0; int lines = 0; int count = 0; ArrayList<String> output = new ArrayList<String>(); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new File(alignmentFile)); doc.getDocumentElement().normalize(); NodeList entries = doc.getElementsByTagName("vncls"); for (int i = 0; i < entries.getLength(); i++) { Node alignment = entries.item(i); NamedNodeMap atts = alignment.getAttributes(); String vnClass = atts.getNamedItem("class").getTextContent(); String vnLemma = atts.getNamedItem("vnmember").getTextContent(); String luId = atts.getNamedItem("fnlexent").getTextContent(); // there are mappings with empty (fn) target: if (luId.equals("")) { noSource++; } else { // add output here output.add(luId + "\t" + vnLemma + "\t" + vnClass + "\n"); List<LexicalEntry> vnentries = uby.getLexicalEntries(vnLemma, EPartOfSpeech.verb, vn); if (vnentries.size() > 0) { for (LexicalEntry e : vnentries) { List<Sense> vnSenses = e.getSenses(); for (Sense vns : vnSenses) { String senseId = vns.getId(); // filter by VN-class List<SemanticLabel> labels = uby.getSemanticLabelsbySenseIdbyType(senseId, ELabelTypeSemantics.verbnetClass.toString()); for (SemanticLabel l : labels) { String[] labelItems = l.getLabel().split("-"); StringBuffer parsedLabel = new StringBuffer(); parsedLabel.append(labelItems[1]); for (int ji = 2; ji < labelItems.length; ji++) { parsedLabel.append("-" + labelItems[ji]); } if (parsedLabel.toString().equals(vnClass)) { // get sourceMa Source source = null; if (sourceMap.containsKey(luId)) { source = sourceMap.get(luId); } else { source = new Source(); source.ref = luId; } Target target = new Target(); target.ref = vns.getMonolingualExternalRefs().iterator().next() .getExternalReference(); target.decision = new Decision(); target.decision.value = true; target.decision.confidence = DEFAULTCONFIDENCE; // add target to source if (source.targets.size() > 0) { source.targets.add(target); } else { source.targets.add(target); } count++; sourceMap.put(source.ref, source); } } } } } } lines++; } } catch (IOException | ParserConfigurationException | SAXException e) { throw new IOException(e); } logString.append("Converted " + alignmentFile + ", statistics:" + LF); logString.append("\tInput Lines: " + lines + LF); logString.append("\tOutput: " + output.size() + LF); logString.append("\tNo alignment target: " + noSource + LF); logString.append("\tControl: output + no alignment = input lines: " + (output.size() + noSource) + LF); logString.append("\tNumber of alignment pairs in output:" + count); logger.info(logString.toString()); writer.writeMetaData(metadata); Alignments alignments = new Alignments(); alignments.source = new LinkedList<>(); alignments.source.addAll(sourceMap.values()); writer.writeAlignments(alignments); writer.close(); }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void preZips() { Date timestamp = getLzhDao().getZipInfo().getTimestamp(); LinkedList<Pref> prefs = getPrefs(); LinkedList<City> cities = getCities(); try {//from w w w.j av a 2 s . c om for (Pref pref : prefs) { TreeMap<String, TreeSet<String>> zips = new TreeMap<String, TreeSet<String>>(); for (City city : cities) { if (!city.getCode().startsWith(pref.getCode())) { continue; } ParentChild data = getParentChildDao().get(city.getCode()); if (data != null) { for (String json : data.getChildren()) { String zip = new JSONObject(json).optString("code", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(city.getCode()); } } data = getParentChildDao().get(city.getCode() + "c"); if (data != null) { for (String json : data.getChildren()) { String zip = new JSONObject(json).optString("code", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(city.getCode() + "c"); } } } StringBuilder rec = new StringBuilder("["); LinkedList<String> list = new LinkedList<String>(); for (String zip : zips.keySet()) { for (String key : zips.get(zip)) { rec.append(new JSONStringer().object().key("zip").value(zip).key("key").value(key) .endObject().toString()); if (rec.length() > 400) { rec.append("]"); list.add(rec.toString()); rec = new StringBuilder("["); } else { rec.append(","); } } } if (rec.length() > 1) { rec.append("]"); list.add(rec.toString()); } getParentChildDao() .store(new ParentChild("pre" + pref.getCode(), timestamp, new LinkedList<String>(), list)); log.info(pref.getCode() + ":" + list.size()); } } catch (JSONException e) { log.log(Level.WARNING, "", e); } return; }