List of usage examples for java.util Map values
Collection<V> values();
From source file:common.Utilities.java
public static double getMapCount(Map<Integer, Integer> map) { double sum = 0.0; if (map != null) { for (Integer val : map.values()) { sum += (double) val; }//from ww w . j a v a 2 s . com } return sum; }
From source file:common.Utilities.java
public static double getMapDenom(Map<Integer, Integer> map) { double sum = 0.0; if (map != null) { for (Integer val : map.values()) { sum += Math.exp((double) val); }/*from w w w. j a v a2 s. c o m*/ } return sum; }
From source file:ca.sfu.federation.utils.IContextUtils.java
public static ArrayList<INamed> getElementsInTopologicalOrder(Map<String, INamed> ElementMap) throws GraphCycleException { ArrayList<INamed> sorted = new ArrayList<INamed>(); Iterator iter = ElementMap.values().iterator(); while (iter.hasNext()) { INamed named = (INamed) iter.next(); if (named instanceof IGraphable) { IGraphable graphobject = (IGraphable) named; // get dependancies for the node LinkedHashMap deps = (LinkedHashMap) graphobject.getDependancies(); // for each dependancy, do a topological sort on its subgraph Iterator it = deps.values().iterator(); while (it.hasNext()) { INamed namedDep = (INamed) it.next(); getElementsInTopologicalOrder(namedDep, sorted); }/*from ww w . ja va 2 s . c o m*/ // insert self into list if (!sorted.contains(named)) { sorted.add(named); } } else { // what should we do with an object that does not have dependancies? } } // return result return sorted; }
From source file:com.astamuse.asta4d.web.dispatch.RedirectUtil.java
public static void redirectToUrlWithSavedFlashScopeData(HttpServletResponse response, int status, String url) { // regulate status if (status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_MOVED_TEMP) { ////from ww w .j a va2 s .c om } else { status = HttpURLConnection.HTTP_MOVED_TEMP; } // check illegal url if (url.indexOf('\n') >= 0 || url.indexOf('\r') >= 0) { throw new RuntimeException("illegal redirct url:" + url); } // before redirect task Map<String, RedirectInterceptor> interceptorMap = Context.getCurrentThreadContext() .getData(RedirectInterceptorMapKey); if (interceptorMap != null) { for (RedirectInterceptor interceptor : interceptorMap.values()) { interceptor.beforeRedirect(); } addFlashScopeData(RedirectInterceptorMapKey, interceptorMap); } // create flash data map Map<String, Object> dataMap = new HashMap<String, Object>(); WebApplicationContext context = Context.getCurrentThreadContext(); List<Map<String, Object>> dataList = context.getData(FlashScopeDataListKey); if (dataList != null) { for (Map<String, Object> map : dataList) { dataMap.putAll(map); } } // save flash data map if (!dataMap.isEmpty()) { String flashScopeId = SecureIdGenerator.createEncryptedURLSafeId(); WebApplicationConfiguration.getWebApplicationConfiguration().getExpirableDataManager().put(flashScopeId, dataMap, DATA_EXPIRE_TIME_MILLI_SECONDS); // create target url if (url.contains("?")) { url = url + '&' + KEY_FLASH_SCOPE_ID + '=' + flashScopeId; } else { url = url + '?' + KEY_FLASH_SCOPE_ID + '=' + flashScopeId; } } // do redirection response.setStatus(status); response.addHeader("Location", url); }
From source file:samples.jms.AbstractMessagingTests.java
/** * Shutdown gracefully at the end of the test to avoid an ugly exception. * Doing it explicitly avoids that. This method automatically runs after all * tests and must be static./*from w ww . j av a 2 s . com*/ */ @AfterClass public static void shutdown() { Map<String, DefaultMessageListenerContainer> ctrs = applicationContext .getBeansOfType(DefaultMessageListenerContainer.class); LoggerFactory.getLogger(AbstractMessagingTests.class) .info("Shutting down " + ctrs.size() + " message listener container(s)."); for (DefaultMessageListenerContainer ctr : ctrs.values()) ctr.shutdown(); }
From source file:com.astamuse.asta4d.web.dispatch.RedirectUtil.java
public static void restoreFlashScopeData(HttpServletRequest request) { String flashScopeId = request.getParameter(RedirectUtil.KEY_FLASH_SCOPE_ID); if (StringUtils.isEmpty(flashScopeId)) { return;// w w w .j a va2 s .c om } else { Map<String, Object> savedMap = WebApplicationConfiguration.getWebApplicationConfiguration() .getExpirableDataManager().get(flashScopeId, true); if (savedMap == null) { return; } else { WebApplicationContext context = WebApplicationContext.getCurrentThreadWebApplicationContext(); for (Entry<String, Object> entry : savedMap.entrySet()) { context.setData(WebApplicationContext.SCOPE_FLASH, entry.getKey(), entry.getValue()); } Map<String, RedirectInterceptor> interceptorMap = context.getData(WebApplicationContext.SCOPE_FLASH, RedirectInterceptorMapKey); if (interceptorMap != null) { for (RedirectInterceptor interceptor : interceptorMap.values()) { interceptor.afterRedirectDataRestore(); } } } } }
From source file:cn.quickj.utils.Assert.java
/** * Assert that a Map has entries; that is, it must not be <code>null</code> * and must have at least one entry.// w w w. ja v a 2 s. c o m * <pre class="code">Assert.notEmpty(map, "Map must have entries");</pre> * @param map the map to check * @param message the exception message to use if the assertion fails * @throws IllegalArgumentException if the map is <code>null</code> or has no entries */ public static void notEmpty(Map map, String message) { if (CollectionUtils.isEmpty(map.values())) { throw new IllegalArgumentException(message); } }
From source file:com.wrmsr.wava.TestWhatever.java
public static Node worst(Map<Name, Basic> basics, Set<Name> loops) { checkState(basics.values().stream().allMatch(basic -> basic.getIndex().isPresent())); checkState(basics.values().stream().flatMap(basic -> optionalToStream(basic.getIndex()).boxed()) .collect(toImmutableSet()).size() == basics.size()); List<Basic> basicList = new ArrayList<>(basics.values()); Collections.sort(basicList,//from w w w. j a v a2s . c o m (left, right) -> Integer.compare(left.getIndex().getAsInt(), right.getIndex().getAsInt())); checkState(!basicList.isEmpty()); Node ret = new Nop(); for (Basic basic : basicList) { Block body = new Block(ImmutableList.<Node>builder().add(ret).addAll(basic.getBody()) .addAll(optionalToList(Basics.simplifyBreakTable(basic.getBreakTable()))).build()); if (loops.contains(basic.getName())) { ret = new Loop(basic.getName(), body); } else { ret = new Label(basic.getName(), body); } } return ret; }
From source file:net.sf.jabref.exporter.ExportFormats.java
public static void initAllExports() { ExportFormats.EXPORT_FORMATS.clear(); // Initialize Build-In Export Formats ExportFormats.putFormat(new ExportFormat("HTML", "html", "html", null, ".html")); ExportFormats.putFormat(//from www. jav a2s .c om new ExportFormat(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, ".html")); ExportFormats.putFormat(new ExportFormat("DocBook 4.4", "docbook", "docbook", null, ".xml")); ExportFormats.putFormat(new ExportFormat("DIN 1505", "din1505", "din1505winword", "din1505", ".rtf")); ExportFormats.putFormat(new ExportFormat("BibTeXML", "bibtexml", "bibtexml", null, ".xml")); ExportFormats.putFormat(new ExportFormat("BibO RDF", "bibordf", "bibordf", null, ".rdf")); ExportFormats.putFormat(new ModsExportFormat()); ExportFormats.putFormat( new ExportFormat(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", ".html")); ExportFormats.putFormat( new ExportFormat(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", ".html")); ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", ".html")); ExportFormats.putFormat(new ExportFormat("Harvard RTF", "harvard", "harvard", "harvard", ".rtf")); ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690rtf", "iso690RTF", "iso690rtf", ".rtf")); ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690txt", "iso690", "iso690txt", ".txt")); ExportFormats.putFormat(new ExportFormat("Endnote", "endnote", "EndNote", "endnote", ".txt")); ExportFormats.putFormat( new ExportFormat("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", "openoffice", ".csv")); ExportFormat ef = new ExportFormat("RIS", "ris", "ris", "ris", ".ris"); ef.setEncoding(StandardCharsets.UTF_8); ExportFormats.putFormat(ef); ExportFormats.putFormat(new ExportFormat("MIS Quarterly", "misq", "misq", "misq", ".rtf")); ExportFormats.putFormat(new OpenOfficeDocumentCreator()); ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator()); ExportFormats.putFormat(new MSBibExportFormat()); ExportFormats.putFormat(new ModsExportFormat()); // Now add custom export formats Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(); for (IExportFormat format : customFormats.values()) { ExportFormats.putFormat(format); } }
From source file:com.liangc.hq.base.utils.MonitorUtils.java
public static Integer formatMetrics(Map metrics, Locale userLocale) { Integer resourceCount = null; try {//w w w . j av a 2 s . c om for (Iterator iter = metrics.values().iterator(); iter.hasNext();) { Collection metricList = (Collection) iter.next(); for (Iterator m = metricList.iterator(); m.hasNext();) { MetricDisplaySummary mds = (MetricDisplaySummary) m.next(); if (resourceCount == null) resourceCount = mds.getAvailUp(); // the formatting subsystem doesn't interpret // units set to empty strings as "no units" so // we'll explicity set it so if (mds.getUnits().length() < 1) { mds.setUnits(MeasurementConstants.UNITS_NONE); } FormattedNumber[] fs = new FormattedNumber[0]; if (msgs.containsKey(Constants.UNIT_FORMAT_PREFIX_KEY + mds.getUnits())) { // this means that there's a whole song and dance for formatting this type of thing // a certain way (hopefully in a way that some decendent of java.test.Format will // help with) String fmtString = msgs.get(Constants.UNIT_FORMAT_PREFIX_KEY + mds.getUnits()); if (mds.getUnits().equals(MeasurementConstants.UNITS_EPOCH_MILLIS)) { DateSpecifics specs = new DateSpecifics(); specs.setDateFormat(new SimpleDateFormat(fmtString, userLocale)); fs = UnitsConvert.convertSame(mds.getMetricValueDoubles(), mds.getUnits(), userLocale, specs); } else { fs = UnitsConvert.convertSame(mds.getMetricValueDoubles(), mds.getUnits(), userLocale); } } else { fs = UnitsConvert.convertSame(mds.getMetricValueDoubles(), mds.getUnits(), userLocale); } String[] keys = mds.getMetricKeys(); if (keys.length != fs.length) throw new IllegalStateException("Formatting metrics failed"); for (int i = 0; i < keys.length; i++) { mds.getMetric(keys[i]).setValueFmt(fs[i]); } } } } catch (IllegalArgumentException e) { // catch and rethrow for debug/logging only if (log.isDebugEnabled()) log.debug("formatting metrics failed due to IllegalArgumentException: ", e); throw e; } return resourceCount; }