List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.AuditReportPPTData.java
/** * Create and add the array of results for the application in a slide * //w ww .j a v a 2 s. co m * @param slideToSet slide to set * @param where place to add results * @param factorsMap information about cells * @throws IOException if error * @throws PPTGeneratorException */ private void createApplicationResultsTable(Slide slideToSet, Rectangle where, TreeMap factorsMap) throws IOException, PPTGeneratorException { StringBuffer html = new StringBuffer("<html><body><table border='1'>"); StringBuffer title = new StringBuffer("<tr bgcolor=\"#00FFFF\">"); List resultsBuffers = new ArrayList(); // title of first column title.append("<td><b>" + WebMessages.getString(request, "component.project") + "</b></td>"); for (Iterator it = factorsMap.keySet().iterator(); it.hasNext();) { String factorName = (String) it.next(); // factor title title.append("<td><b>" + factorName + "</b></td>"); Map results = (TreeMap) factorsMap.get(factorName); int rowProj = 1; for (Iterator projIt = results.keySet().iterator(); projIt.hasNext(); rowProj++) { String projName = (String) projIt.next(); StringBuffer projectResults = null; if (rowProj > resultsBuffers.size()) { projectResults = new StringBuffer("<td>" + projName + "</td>"); resultsBuffers.add(projectResults); } else { projectResults = (StringBuffer) resultsBuffers.get(rowProj - 1); } // project title // fill factor column appendFactorResultToProjectRow(projectResults, (Float[]) results.get(projName)); projectResults.append("</td>"); } } html.append(title + "</tr>"); for (int i = 0; i < resultsBuffers.size(); i++) { html.append("<tr>"); html.append((StringBuffer) resultsBuffers.get(i)); html.append("</tr>"); } html.append("</table></body></html>"); addHtmlPicture(slideToSet, html.toString(), where.x, where.y); }
From source file:edu.isi.wings.portal.controllers.PlanController.java
private ArrayList<TreeMap<String, Binding>> getParameterBindings(ArrayList<Template> cts) { ArrayList<TreeMap<String, Binding>> bindings_b = new ArrayList<TreeMap<String, Binding>>(); for (Template bt : cts) { TreeMap<String, Binding> binding_b = new TreeMap<String, Binding>(); for (Variable v : bt.getInputVariables()) { if (v.isParameterVariable() && v.getBinding() != null) { binding_b.put(v.getName(), v.getBinding()); }/* ww w.j a v a 2 s.co m*/ } bindings_b.add(binding_b); } // Expanding collections into multiple configurations // FIXME: Cannot handle parameter collections right now ArrayList<TreeMap<String, Binding>> bindings = new ArrayList<TreeMap<String, Binding>>(); HashMap<String, Boolean> bstrs = new HashMap<String, Boolean>(); while (!bindings_b.isEmpty()) { boolean hasSets = false; TreeMap<String, Binding> binding_b = bindings_b.remove(0); TreeMap<String, Binding> binding = new TreeMap<String, Binding>(); for (String v : binding_b.keySet()) { Binding b = binding_b.get(v); if (b.isSet() && b.size() > 1) { for (WingsSet cb : b) { TreeMap<String, Binding> binding_x = new TreeMap<String, Binding>(); for (String v1 : binding_b.keySet()) { Binding b1 = binding_b.get(v1); binding_x.put(v1, b1); } binding_x.put(v, (Binding) cb); bindings_b.add(binding_x); } hasSets = true; } else if (b.isSet() && b.size() == 1) { Binding tmpb = (Binding) b.get(0); while (tmpb.isSet() && tmpb.size() == 1) { tmpb = (Binding) tmpb.get(0); } ValueBinding vb = (ValueBinding) tmpb; binding.put(v, new ValueBinding(vb.getValue(), vb.getDatatype())); } else if (!b.isSet()) { ValueBinding vb = (ValueBinding) b; binding.put(v, new ValueBinding(vb.getValue(), vb.getDatatype())); } } if (!hasSets) { String bstr = ""; for (String v : binding.keySet()) { bstr += binding.get(v).toString() + ","; } if (!bstrs.containsKey(bstr)) { bstrs.put(bstr, true); bindings.add(binding); } } } return bindings; }
From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java
@NonNull @Override/* w w w .j a v a 2s . c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { SessionInfo sessionInfo = getSessionInfo(); List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags(); if (tags != null && tags.size() > 0) { TreeMap<String, Long> map = new TreeMap<>(); for (Object o : tags) { if (o instanceof Map) { Map<?, ?> mapTag = (Map<?, ?>) o; long uid = MapUtils.getMapLong(mapTag, "uid", 0); String name = MapUtils.getMapString(mapTag, "name", "??"); int type = MapUtils.getMapInt(mapTag, "type", 0); if (type == 3) { // type-name will be "Manual" :( name = "Tag: " + name; } else { String typeName = MapUtils.getMapString(mapTag, "type-name", null); if (typeName != null) { name = typeName + ": " + name; } } map.put(name, uid); } } long[] vals = new long[map.size()]; String[] strings = map.keySet().toArray(new String[map.keySet().size()]); for (int i = 0; i < vals.length; i++) { vals[i] = map.get(strings[i]); } filterByList = new ValueStringArray(vals, strings); } if (filterByList == null) { filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list); } AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(), R.layout.dialog_filter_by); View view = alertDialogBuilder.view; AlertDialog.Builder builder = alertDialogBuilder.builder; // get our tabHost from the xml TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost); tabHost.setup(); // create tab 1 TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1"); spec1.setIndicator("States"); spec1.setContent(R.id.filterby_sv_state); tabHost.addTab(spec1); //create tab2 TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2"); spec2.setIndicator("Tags"); spec2.setContent(R.id.filterby_tv_tags); tabHost.addTab(spec2); int height = AndroidUtilsUI.dpToPx(32); tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height; tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height; TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state); tvState.setMovementMethod(LinkMovementMethod.getInstance()); final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags); tvTags.setMovementMethod(LinkMovementMethod.getInstance()); // for API <= 10 (maybe 11?), otherwise tags will display on one line tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if (!tabId.equals("tab2")) { return; } tvTags.post(new Runnable() { @Override public void run() { spanTags.updateTags(); } }); } }); builder.setTitle(R.string.filterby_title); // Add action buttons builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (mapSelectedTag == null) { return; } long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1); String name = MapUtils.getMapString(mapSelectedTag, "name", "??"); mListener.filterBy(uidSelected, name, true); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { DialogFragmentFilterByTags.this.getDialog().cancel(); } }); List<Map<?, ?>> manualTags = new ArrayList<>(); List<Map<?, ?>> stateTags = new ArrayList<>(); if (sessionInfo != null) { // Dialog never gets called wehn getTags has no tags List<Map<?, ?>> allTags = sessionInfo.getTags(); if (allTags != null) { for (Map<?, ?> mapTag : allTags) { int type = MapUtils.getMapInt(mapTag, "type", 0); switch (type) { case 0: case 1: case 2: stateTags.add(mapTag); break; case 3: // manual manualTags.add(mapTag); break; } } } } SpanTagsListener l = new SpanTagsListener() { @Override public void tagClicked(Map mapTag, String name) { mapSelectedTag = mapTag; // todo: long click, don't exit long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1); mListener.filterBy(uidSelected, name, true); DialogFragmentFilterByTags.this.getDialog().dismiss(); } @Override public int getTagState(Map mapTag, String name) { if (mapSelectedTag == null) { return SpanTags.TAG_STATE_UNSELECTED; } long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1); if (uidSelected == -1) { return SpanTags.TAG_STATE_UNSELECTED; } long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1); return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED; } }; spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l); spanTags.setTagMaps(manualTags); spanTags.setShowIcon(false); spanTags.updateTags(); SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l); spanState.setTagMaps(stateTags); spanState.setShowIcon(false); spanState.updateTags(); return builder.create(); }
From source file:com.eucalyptus.ws.handlers.WalrusAuthenticationHandler.java
private String getCanonicalizedAmzHeaders(MappingHttpRequest httpRequest) { String result = ""; Set<String> headerNames = httpRequest.getHeaderNames(); TreeMap amzHeaders = new TreeMap<String, String>(); for (String headerName : headerNames) { String headerNameString = headerName.toLowerCase().trim(); if (headerNameString.startsWith("x-amz-")) { String value = httpRequest.getHeader(headerName).trim(); String[] parts = value.split("\n"); value = ""; for (String part : parts) { part = part.trim();/*from w ww . j av a2 s . co m*/ value += part + " "; } value = value.trim(); if (amzHeaders.containsKey(headerNameString)) { String oldValue = (String) amzHeaders.remove(headerNameString); oldValue += "," + value; amzHeaders.put(headerNameString, oldValue); } else { amzHeaders.put(headerNameString, value); } } } Iterator<String> iterator = amzHeaders.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); String value = (String) amzHeaders.get(key); result += key + ":" + value + "\n"; } return result; }
From source file:com.stgmastek.core.logic.ExecutionOrder.java
/** * Static method to setup the execution order. * This method essentially looks up in to the setup table BATCH_COLUMN_MAP to * get the details.Using the details it would setup the execution order for the batch * Once the execution order is set, it sets the order into the {@link BatchInfo#setOrderedMap(TreeMap)} * for all other objects to derive knowledge from. * Note: The batch could be run for - // ww w .j a v a 2 s. c o m * <OL> * <LI> For a date i.e. all entities and all values for those entities. * <LI> For an entity i.e. batch for only policy records and all its values * i.e. P1, P2 ... Pn * <LI> For a single object identified as GENERAL type of job with a * sequence number i.e. JOB_SCHEDULE.job_seq * <LI> For only Meta events like ALL PRE and ALL POST * <LI> For any combination of above, a few given - * <UL> * <LI> Policy P1 and ALL PRE * <LI> ALL Agency records and Policy P1 * <LI> Policy P1 and Agency A1 * </UL> * </OL> * * Every step has inline comments associated with it. * * @param batchContext * The context for the batch * @return true * If the setup is done successfully * @throws BatchException * Any database I/O exception */ public synchronized static Boolean setExecutionOrder(BatchContext batchContext) throws BatchException { //Get request parameters HashMap<String, Object> params = batchContext.getRequestParams().getProcessRequestParams(); //Check whether it is a date batch run or specific batch run if (params.size() < 1) { batchContext.getBatchInfo().setDateRun(true); } Connection con = batchContext.getBATCHConnection(); IBatchDao bDao = DaoFactory.getBatchDao(); try { //Query the setup table to get the setup values LookupTable lookupTable = bDao.getLookupTable(con); Map<String, String> orderByLookupTable = bDao.getOrderByLookupTable(con); TreeMap<Integer, EntityParams> orderedMap = new TreeMap<Integer, EntityParams>(); //If it is date batch run, then for all entities, populate "ALL" if (batchContext.getBatchInfo().isDateRun()) { Iterator<String> lTableIter = lookupTable.keySet().iterator(); while (lTableIter.hasNext()) { String entity = lTableIter.next(); params.put(entity + "_1", "ALL"); } } //Iterate over each parameters set for (Entry<String, Object> entry : params.entrySet()) { String paramName = entry.getKey(); Object paramValue = entry.getValue(); if (logger.isDebugEnabled()) { logger.debug("In ExecutionOrder >>>> paramName ==>" + paramName); } String entity = null; //Strip the last occurrence of _ and get the entity name entity = paramName.substring(0, paramName.lastIndexOf("_")); if (logger.isDebugEnabled()) { logger.debug("In ExecutionOrder >>>> Entity ==>" + entity); } //Validate whether the entity is setup appropriately in //the BATCH_COLUMN_MAP table if (!lookupTable.containsKey(entity)) { //If the entity is not set, raise an exception and exit throw new BatchException("The entity " + entity + " is not set up in the COLUMN_MAP table."); } else { //Get the lookup record //Once found, get the details and set it against the entity List<ColumnLookup> lookupColumns = lookupTable.get(entity); Integer order = lookupColumns.get(0).getPrecedenceOrder(); if (!orderedMap.containsKey(order)) { EntityParams entityParams = new EntityParams(entity); orderedMap.put(order, entityParams); } EntityParams entityParams = orderedMap.get(order); entityParams.setLookupColumns(lookupColumns); entityParams.setOrderByMap(orderByLookupTable);//Added on 01-OCT-2013 - Mandar //Check 'ALL' or for specific entity values. //Note: Batch could be run for a date i.e. all entities (and all values) // or for any combination of entity and values if (!paramValue.equals("ALL")) { List<GroupInfo> list = entityParams.getValues(); //check if all exists. If exists do not write the new value if (list.size() == 0 || !list.get(0).getEntityValue().equals("ALL")) entityParams.getValues().add(new GroupInfo((String) paramValue)); } else { entityParams.setAll(new GroupInfo((String) paramValue)); } } } batchContext.getBatchInfo().setOrderedMap(orderedMap); } finally { bDao.releaseResources(null, null, con); } return true; }
From source file:com.redhat.rhn.taskomatic.task.DailySummary.java
/** * DO NOT CALL FROM OUTSIDE THIS CLASS. Renders the actions email message * @param actions list of recent actions * @return the actions email message//from w ww. j a va 2 s.c om */ public String renderActionsMessage(List<ActionMessage> actions) { int longestActionLength = HEADER_SPACER; int longestStatusLength = 0; StringBuilder hdr = new StringBuilder(); StringBuilder body = new StringBuilder(); StringBuilder legend = new StringBuilder(); StringBuilder msg = new StringBuilder(); LinkedHashSet<String> statusSet = new LinkedHashSet(); TreeMap<String, Map<String, Integer>> nonErrataActions = new TreeMap(); TreeMap<String, Map<String, Integer>> errataActions = new TreeMap(); TreeMap<String, String> errataSynopsis = new TreeMap(); legend.append(LocalizationService.getInstance().getMessage("taskomatic.daily.errata")); legend.append("\n\n"); for (ActionMessage am : actions) { if (!statusSet.contains(am.getStatus())) { statusSet.add(am.getStatus()); if (am.getStatus().length() > longestStatusLength) { longestStatusLength = am.getStatus().length(); } } if (am.getType().equals(ERRATA_UPDATE)) { String advisoryKey = ERRATA_INDENTION + am.getAdvisory(); if (!errataActions.containsKey(advisoryKey)) { errataActions.put(advisoryKey, new HashMap()); if (advisoryKey.length() + HEADER_SPACER > longestActionLength) { longestActionLength = advisoryKey.length() + HEADER_SPACER; } } Map<String, Integer> counts = errataActions.get(advisoryKey); counts.put(am.getStatus(), am.getCount()); if (am.getAdvisory() != null && !errataSynopsis.containsKey(am.getAdvisory())) { errataSynopsis.put(am.getAdvisory(), am.getSynopsis()); } } else { if (!nonErrataActions.containsKey(am.getType())) { nonErrataActions.put(am.getType(), new HashMap()); if (am.getType().length() + HEADER_SPACER > longestActionLength) { longestActionLength = am.getType().length() + HEADER_SPACER; } } Map<String, Integer> counts = nonErrataActions.get(am.getType()); counts.put(am.getStatus(), am.getCount()); } } hdr.append(StringUtils.repeat(" ", longestActionLength)); for (String status : statusSet) { hdr.append(status + StringUtils.repeat(" ", (longestStatusLength + ERRATA_SPACER) - status.length())); } if (!errataActions.isEmpty()) { body.append(ERRATA_UPDATE + ":" + "\n"); } StringBuffer formattedErrataActions = renderActionTree(longestActionLength, longestStatusLength, statusSet, errataActions); body.append(formattedErrataActions); for (String advisory : errataSynopsis.keySet()) { legend.append(ERRATA_INDENTION + advisory + ERRATA_INDENTION + errataSynopsis.get(advisory) + "\n"); } StringBuffer formattedNonErrataActions = renderActionTree(longestActionLength, longestStatusLength, statusSet, nonErrataActions); body.append(formattedNonErrataActions); // finally put all this together msg.append(hdr.toString()); msg.append("\n"); msg.append(body.toString()); msg.append("\n\n"); if (!errataSynopsis.isEmpty()) { msg.append(legend.toString()); } return msg.toString(); }
From source file:com.sfs.whichdoctor.dao.MembershipDAOImpl.java
/** * Test if the person is applicable for a membership upgrade. * * @param person the person//from w ww.ja v a 2 s. com * @return true, if successful */ private boolean testIfMembershipUpgradeApplicable(final PersonBean person) { boolean membershipUpgradeApplicable = false; dataLogger.info("Automated training check: person is a basic trainee"); boolean passedWritten = false; boolean passedClinical = false; int totalTraining = 0; if (person.getExams() != null) { for (ExamBean exam : person.getExams()) { if (StringUtils.equalsIgnoreCase(exam.getStatus(), "Passed")) { if (StringUtils.equalsIgnoreCase(exam.getType(), "Written Exam")) { passedWritten = true; } if (StringUtils.equalsIgnoreCase(exam.getType(), "Clinical Exam")) { passedClinical = true; } } } } final TreeMap<String, AccreditationBean[]> summary = person.getTrainingSummary("Basic Training"); if (summary != null) { for (String key : summary.keySet()) { AccreditationBean[] details = summary.get(key); AccreditationBean core = details[0]; AccreditationBean nonCore = details[1]; totalTraining += core.getWeeksCertified(); totalTraining += nonCore.getWeeksCertified(); } } final int basicTrainingLimit = this.getTrainingLimit("Basic Training"); if (totalTraining >= basicTrainingLimit && passedWritten && passedClinical) { membershipUpgradeApplicable = true; } return membershipUpgradeApplicable; }
From source file:eoss.problem.EOSSProblem.java
private void aggregate_performance_score_facts(EOSSArchitecture arch) { ArrayList subobj_scores = new ArrayList(); ArrayList obj_scores = new ArrayList(); ArrayList panel_scores = new ArrayList(); double science = 0.0; FuzzyValue fuzzy_science = null;/*from w w w .j a v a2 s . c o m*/ Explanation explanations = new Explanation(); TreeMap<String, Double> tm = new TreeMap<String, Double>(); try { ArrayList<Fact> vals = qb.makeQuery("AGGREGATION::VALUE"); Fact val = vals.get(0); science = val.getSlotValue("satisfaction").floatValue(r.getGlobalContext()); if (Params.req_mode.equalsIgnoreCase("FUZZY-ATTRIBUTES")) { fuzzy_science = (FuzzyValue) val.getSlotValue("fuzzy-value").javaObjectValue(r.getGlobalContext()); } panel_scores = jessList2ArrayList(val.getSlotValue("sh-scores").listValue(r.getGlobalContext())); ArrayList<Fact> subobj_facts = qb.makeQuery("AGGREGATION::SUBOBJECTIVE"); for (int n = 0; n < subobj_facts.size(); n++) { Fact f = subobj_facts.get(n); String subobj = f.getSlotValue("id").stringValue(r.getGlobalContext()); Double subobj_score = f.getSlotValue("satisfaction").floatValue(r.getGlobalContext()); Double current_subobj_score = tm.get(subobj); if (current_subobj_score != null && subobj_score > current_subobj_score || current_subobj_score == null) { tm.put(subobj, subobj_score); } explanations.put(subobj, qb.makeQuery("AGGREGATION::SUBOBJECTIVE (id " + subobj + ")")); } for (Iterator<String> name = tm.keySet().iterator(); name.hasNext();) { subobj_scores.add(tm.get(name.next())); } //TO DO: obj_score and subobj_scores. } catch (JessException ex) { Logger.getLogger(EOSSProblem.class.getName()).log(Level.SEVERE, null, ex); } if (Params.req_mode.equalsIgnoreCase("FUZZY-ATTRIBUTES")) { arch.setFuzzyObjective(0, fuzzy_science); } if (explanation) { arch.setExplanation(0, explanations); arch.setCapabilities(qb.makeQuery("REQUIREMENTS::Measurement")); } }
From source file:org.apache.hadoop.tools.HadoopArchives.java
/** * this method writes all the valid top level directories * into the srcWriter for indexing. This method is a little * tricky. example- //from w w w . j a v a 2 s . c o m * for an input with parent path /home/user/ and sources * as /home/user/source/dir1, /home/user/source/dir2 - this * will output <source, dir, dir1, dir2> (dir means that source is a dir * with dir1 and dir2 as children) and <source/dir1, file, null> * and <source/dir2, file, null> * @param srcWriter the sequence file writer to write the * directories to * @param paths the source paths provided by the user. They * are glob free and have full path (not relative paths) * @param parentPath the parent path that you wnat the archives * to be relative to. example - /home/user/dir1 can be archived with * parent as /home or /home/user. * @throws IOException */ private void writeTopLevelDirs(SequenceFile.Writer srcWriter, List<Path> paths, Path parentPath) throws IOException { //add all the directories List<Path> justDirs = new ArrayList<Path>(); for (Path p : paths) { if (!p.getFileSystem(getConf()).isFile(p)) { justDirs.add(new Path(p.toUri().getPath())); } else { justDirs.add(new Path(p.getParent().toUri().getPath())); } } /* find all the common parents of paths that are valid archive * paths. The below is done so that we do not add a common path * twice and also we need to only add valid child of a path that * are specified the user. */ TreeMap<String, HashSet<String>> allpaths = new TreeMap<String, HashSet<String>>(); /* the largest depth of paths. the max number of times * we need to iterate */ Path deepest = largestDepth(paths); Path root = new Path(Path.SEPARATOR); for (int i = parentPath.depth(); i < deepest.depth(); i++) { List<Path> parents = new ArrayList<Path>(); for (Path p : justDirs) { if (p.compareTo(root) == 0) { //do nothing } else { Path parent = p.getParent(); if (null != parent) { if (allpaths.containsKey(parent.toString())) { HashSet<String> children = allpaths.get(parent.toString()); children.add(p.getName()); } else { HashSet<String> children = new HashSet<String>(); children.add(p.getName()); allpaths.put(parent.toString(), children); } parents.add(parent); } } } justDirs = parents; } Set<Map.Entry<String, HashSet<String>>> keyVals = allpaths.entrySet(); for (Map.Entry<String, HashSet<String>> entry : keyVals) { final Path relPath = relPathToRoot(new Path(entry.getKey()), parentPath); if (relPath != null) { final String[] children = new String[entry.getValue().size()]; int i = 0; for (String child : entry.getValue()) { children[i++] = child; } append(srcWriter, 0L, relPath.toString(), children); } } }
From source file:org.commoncrawl.service.crawler.CrawlLog.java
private static CrawlSegmentDetail loadCrawlSegment(String fileName) throws IOException { TreeMap<String, CrawlSegmentHost> hosts = new TreeMap<String, CrawlSegmentHost>(); URL resourceURL = CrawlEnvironment.getHadoopConfig().getResource(fileName); if (resourceURL == null) { throw new FileNotFoundException(); }//ww w.j a v a 2 s.c om InputStream stream = resourceURL.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(stream))); String line = null; do { line = reader.readLine(); if (line != null) { if (Environment.detailLogEnabled()) LOG.info(line); try { URL theURL = new URL(line); CrawlSegmentHost host = hosts.get(theURL.getHost()); if (host == null) { host = createHost(theURL.getHost()); hosts.put(theURL.getHost(), host); } CrawlSegmentURL segmentURL = createSegmentURL(theURL); host.getUrlTargets().add(segmentURL); } catch (MalformedURLException e) { LOG.error("SKIPPING Malformed URL::" + line); } } } while (line != null); CrawlSegmentDetail crawlSegmentDetail = new CrawlSegmentDetail(); int urlCount = 0; crawlSegmentDetail.setSegmentId(1); for (CrawlSegmentHost host : hosts.values()) { crawlSegmentDetail.getHosts().add(host); urlCount += host.getUrlTargets().size(); } crawlSegmentDetail.setUrlCount(urlCount); // finally, sort by host (as will be the case in a proper map reduce // produced segment ... Collections.sort(crawlSegmentDetail.getHosts()); return crawlSegmentDetail; }