List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:net.sf.jasperreports.engine.util.JRFontUtil.java
/** * Returns a java.awt.Font instance by converting a JRFont instance. * Mostly used in combination with third-party visualization packages such as JFreeChart (for chart themes). * Unless the font parameter is null, this method always returns a non-null AWT font, regardless whether it was * found in the font extensions or not. This is because we do need a font to draw with and there is no point * in raising a font missing exception here, as it is not JasperReports who does the drawing. *///from w ww. ja va2s. c o m public static Font getAwtFont(JRFont font, Locale locale) { if (font == null) { return null; } // ignoring missing font as explained in the Javadoc Font awtFont = getAwtFontFromBundles(font.getFontName(), ((font.isBold() ? Font.BOLD : Font.PLAIN) | (font.isItalic() ? Font.ITALIC : Font.PLAIN)), font.getFontSize(), locale, true); if (awtFont == null) { awtFont = new Font(getAttributesWithoutAwtFont(new HashMap<Attribute, Object>(), font)); } else { // add underline and strikethrough attributes since these are set at // style/font level Map<Attribute, Object> attributes = new HashMap<Attribute, Object>(); if (font.isUnderline()) { attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } if (font.isStrikeThrough()) { attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); } if (!attributes.isEmpty()) { awtFont = awtFont.deriveFont(attributes); } } return awtFont; }
From source file:fr.ribesg.bukkit.api.chat.Chat.java
private static void appendItemTag(final StringBuilder builder, final ItemStack is) { boolean hasTag = false; final StringBuilder tagBuilder = new StringBuilder(); // Enchantments final Map<Enchantment, Integer> enchantments = is.getEnchantments(); if (enchantments != null && !enchantments.isEmpty()) { tagBuilder.append("ench:["); final Iterator<Entry<Enchantment, Integer>> it = enchantments.entrySet().iterator(); while (it.hasNext()) { final Entry<Enchantment, Integer> entry = it.next(); tagBuilder.append("{id:").append(entry.getKey().getId()).append(",lvl:").append(entry.getValue()); if (it.hasNext()) { tagBuilder.append(','); }/*from www . ja v a 2 s .c o m*/ } tagBuilder.append("],"); hasTag = true; } // Meta if (is.hasItemMeta()) { final ItemMeta meta = is.getItemMeta(); if (meta.hasDisplayName() || meta.hasLore() || Chat.isLeatherArmor(is)) { Chat.appendItemDisplay(tagBuilder, meta); } if (is.getType() == Material.POTION) { Chat.appendItemPotion(tagBuilder, (PotionMeta) meta); } if (is.getType() == Material.WRITTEN_BOOK) { Chat.appendItemBook(tagBuilder, (BookMeta) meta); } if (is.getType() == Material.SKULL_ITEM) { Chat.appendItemSkull(tagBuilder, (SkullMeta) meta); } if (is.getType() == Material.FIREWORK) { // Firework Rocket Chat.appendItemFirework(tagBuilder, (FireworkMeta) meta); } if (is.getType() == Material.FIREWORK_CHARGE) { // Firework Star Chat.appendItemFireworkEffect(tagBuilder, (FireworkEffectMeta) meta); } } if (hasTag && tagBuilder.charAt(builder.length() - 1) == ',') { tagBuilder.deleteCharAt(builder.length() - 1); } // Append to main builder if (hasTag) { builder.append(',').append("tag:{").append(tagBuilder).append('}'); } }
From source file:com.espertech.esper.event.util.XMLRendererImpl.java
private static void recursiveRender(EventBean theEvent, StringBuilder buf, int level, RendererMeta meta, RendererMetaOptions rendererMetaOptions) { GetterPair[] simpleProps = meta.getSimpleProperties(); for (GetterPair simpleProp : simpleProps) { Object value = simpleProp.getGetter().get(theEvent); if (value == null) { continue; }// w ww .j a v a 2s. co m ident(buf, level); buf.append('<'); buf.append(simpleProp.getName()); buf.append('>'); if (rendererMetaOptions.getRenderer() == null) { simpleProp.getOutput().render(value, buf); } else { EventPropertyRendererContext context = rendererMetaOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(simpleProp.getName()); context.setPropertyValue(value); context.setDefaultRenderer(simpleProp.getOutput()); rendererMetaOptions.getRenderer().render(context); } buf.append("</"); buf.append(simpleProp.getName()); buf.append('>'); buf.append(NEWLINE); } GetterPair[] indexProps = meta.getIndexProperties(); for (GetterPair indexProp : indexProps) { Object value = indexProp.getGetter().get(theEvent); if (value == null) { continue; } if (!value.getClass().isArray()) { log.warn("Property '" + indexProp.getName() + "' returned a non-array object"); continue; } for (int i = 0; i < Array.getLength(value); i++) { Object arrayItem = Array.get(value, i); if (arrayItem == null) { continue; } ident(buf, level); buf.append('<'); buf.append(indexProp.getName()); buf.append('>'); if (rendererMetaOptions.getRenderer() == null) { indexProp.getOutput().render(arrayItem, buf); } else { EventPropertyRendererContext context = rendererMetaOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(indexProp.getName()); context.setPropertyValue(arrayItem); context.setIndexedPropertyIndex(i); context.setDefaultRenderer(indexProp.getOutput()); rendererMetaOptions.getRenderer().render(context); } buf.append("</"); buf.append(indexProp.getName()); buf.append('>'); buf.append(NEWLINE); } } GetterPair[] mappedProps = meta.getMappedProperties(); for (GetterPair mappedProp : mappedProps) { Object value = mappedProp.getGetter().get(theEvent); if ((value != null) && (!(value instanceof Map))) { log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead"); continue; } ident(buf, level); buf.append('<'); buf.append(mappedProp.getName()); buf.append('>'); buf.append(NEWLINE); if (value != null) { Map<String, Object> map = (Map<String, Object>) value; if (!map.isEmpty()) { String localDelimiter = ""; Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); for (; it.hasNext();) { Map.Entry<String, Object> entry = it.next(); if (entry.getKey() == null) { continue; } buf.append(localDelimiter); ident(buf, level + 1); buf.append('<'); buf.append(entry.getKey()); buf.append('>'); if (entry.getValue() != null) { OutputValueRenderer outputValueRenderer = OutputValueRendererFactory .getOutputValueRenderer(entry.getValue().getClass(), rendererMetaOptions); if (rendererMetaOptions.getRenderer() == null) { outputValueRenderer.render(entry.getValue(), buf); } else { EventPropertyRendererContext context = rendererMetaOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(mappedProp.getName()); context.setPropertyValue(entry.getValue()); context.setMappedPropertyKey(entry.getKey()); context.setDefaultRenderer(outputValueRenderer); rendererMetaOptions.getRenderer().render(context); } } buf.append('<'); buf.append(entry.getKey()); buf.append('>'); localDelimiter = NEWLINE; } } } buf.append(NEWLINE); ident(buf, level); buf.append("</"); buf.append(mappedProp.getName()); buf.append('>'); buf.append(NEWLINE); } NestedGetterPair[] nestedProps = meta.getNestedProperties(); for (NestedGetterPair nestedProp : nestedProps) { Object value = nestedProp.getGetter().getFragment(theEvent); if (value == null) { continue; } if (!nestedProp.isArray()) { if (!(value instanceof EventBean)) { log.warn("Property '" + nestedProp.getName() + "' expected to return EventBean and returned " + value.getClass() + " instead"); buf.append("null"); continue; } renderElementFragment((EventBean) value, buf, level, nestedProp, rendererMetaOptions); } else { if (!(value instanceof EventBean[])) { log.warn("Property '" + nestedProp.getName() + "' expected to return EventBean[] and returned " + value.getClass() + " instead"); buf.append("null"); continue; } EventBean[] nestedEventArray = (EventBean[]) value; for (int i = 0; i < nestedEventArray.length; i++) { EventBean arrayItem = nestedEventArray[i]; if (arrayItem == null) { continue; } renderElementFragment(arrayItem, buf, level, nestedProp, rendererMetaOptions); } } } }
From source file:cz.vse.esper.XMLRenderer.java
private static void recursiveRender(EventBean theEvent, StringBuilder buf, int level, RendererMeta meta, RendererMetaOptions rendererMetaOptions) { GetterPair[] simpleProps = meta.getSimpleProperties(); for (GetterPair simpleProp : simpleProps) { Object value = simpleProp.getGetter().get(theEvent); if (value == null) { continue; }/* w w w . j a v a2 s .co m*/ ident(buf, level); buf.append('<'); buf.append(simpleProp.getName()); buf.append('>'); if (rendererMetaOptions.getRenderer() == null) { simpleProp.getOutput().render(value, buf); } else { EventPropertyRendererContext context = rendererMetaOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(simpleProp.getName()); context.setPropertyValue(value); context.setDefaultRenderer(simpleProp.getOutput()); rendererMetaOptions.getRenderer().render(context); } buf.append("</"); buf.append(simpleProp.getName()); buf.append('>'); buf.append(NEWLINE); } GetterPair[] indexProps = meta.getIndexProperties(); for (GetterPair indexProp : indexProps) { Object value = indexProp.getGetter().get(theEvent); if (value == null) { continue; } if (!value.getClass().isArray()) { log.warn("Property '" + indexProp.getName() + "' returned a non-array object"); continue; } for (int i = 0; i < Array.getLength(value); i++) { Object arrayItem = Array.get(value, i); if (arrayItem == null) { continue; } ident(buf, level); buf.append('<'); buf.append(indexProp.getName()); buf.append('>'); if (rendererMetaOptions.getRenderer() == null) { indexProp.getOutput().render(arrayItem, buf); } else { EventPropertyRendererContext context = rendererMetaOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(indexProp.getName()); context.setPropertyValue(arrayItem); context.setIndexedPropertyIndex(i); context.setDefaultRenderer(indexProp.getOutput()); rendererMetaOptions.getRenderer().render(context); } buf.append("</"); buf.append(indexProp.getName()); buf.append('>'); buf.append(NEWLINE); } } GetterPair[] mappedProps = meta.getMappedProperties(); for (GetterPair mappedProp : mappedProps) { Object value = mappedProp.getGetter().get(theEvent); if ((value != null) && (!(value instanceof Map))) { log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead"); continue; } ident(buf, level); buf.append('<'); buf.append(mappedProp.getName()); buf.append('>'); buf.append(NEWLINE); if (value != null) { Map<String, Object> map = (Map<String, Object>) value; if (!map.isEmpty()) { String localDelimiter = ""; Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); for (; it.hasNext();) { Map.Entry<String, Object> entry = it.next(); if (entry.getKey() == null) { continue; } buf.append(localDelimiter); ident(buf, level + 1); buf.append('<'); buf.append(entry.getKey()); buf.append('>'); if (entry.getValue() != null) { OutputValueRenderer outputValueRenderer = new OutputValueRendererXMLString(); if (rendererMetaOptions.getRenderer() == null) { outputValueRenderer.render(entry.getValue(), buf); } else { EventPropertyRendererContext context = rendererMetaOptions.getRendererContext(); context.setStringBuilderAndReset(buf); context.setPropertyName(mappedProp.getName()); context.setPropertyValue(entry.getValue()); context.setMappedPropertyKey(entry.getKey()); context.setDefaultRenderer(outputValueRenderer); rendererMetaOptions.getRenderer().render(context); } } buf.append('<'); buf.append(entry.getKey()); buf.append('>'); localDelimiter = NEWLINE; } } } buf.append(NEWLINE); ident(buf, level); buf.append("</"); buf.append(mappedProp.getName()); buf.append('>'); buf.append(NEWLINE); } NestedGetterPair[] nestedProps = meta.getNestedProperties(); for (NestedGetterPair nestedProp : nestedProps) { Object value = nestedProp.getGetter().getFragment(theEvent); if (value == null) { continue; } if (!nestedProp.isArray()) { if (!(value instanceof EventBean)) { log.warn("Property '" + nestedProp.getName() + "' expected to return EventBean and returned " + value.getClass() + " instead"); buf.append("null"); continue; } renderElementFragment((EventBean) value, buf, level, nestedProp, rendererMetaOptions); } else { if (!(value instanceof EventBean[])) { log.warn("Property '" + nestedProp.getName() + "' expected to return EventBean[] and returned " + value.getClass() + " instead"); buf.append("null"); continue; } EventBean[] nestedEventArray = (EventBean[]) value; for (int i = 0; i < nestedEventArray.length; i++) { EventBean arrayItem = nestedEventArray[i]; if (arrayItem == null) { continue; } renderElementFragment(arrayItem, buf, level, nestedProp, rendererMetaOptions); } } } }
From source file:com.screenslicer.common.CommonUtil.java
public static boolean isEmpty(Map<? extends Object, ? extends Object> map) { return map == null || map.isEmpty(); }
From source file:com.ctrip.infosec.rule.resource.DataProxy.java
/** * ??//from w w w . j av a 2 s . co m * * @param serviceName * @param operationName * @param params * @return */ public static Map queryForMap(String serviceName, String operationName, Map<String, Object> params) { check(); beforeInvoke("DataProxy.queryForMap"); beforeInvoke("DataProxy." + serviceName + "." + operationName); try { String cacheKey = buildCacheKey(serviceName, operationName, params); Map newResult = (Map) ThreadLocalCache.get(cacheKey); if (newResult == null) { boolean _isAsync = Contexts.isAsync(); DataProxyQueryCommand command = new DataProxyQueryCommand(serviceName, operationName, params, _isAsync); newResult = command.execute(); if (serviceName.equals("UserProfileService")) { newResult = parseProfileResult(newResult); } if (newResult != null && !newResult.isEmpty()) { ThreadLocalCache.set(cacheKey, newResult); } } else { logger.info("hit cache, key = " + cacheKey); } return newResult; } catch (Exception ex) { fault("DataProxy.queryForMap"); fault("DataProxy." + serviceName + "." + operationName); logger.error(Contexts.getLogPrefix() + "DataProxy.", ex); TraceLogger.traceLog("DataProxy, EXCEPTION: " + (ex.getCause() == null ? ex.toString() : ex.getCause().toString())); } finally { afterInvoke("DataProxy.queryForMap"); afterInvoke("DataProxy." + serviceName + "." + operationName); } return Collections.EMPTY_MAP; }
From source file:com.glaf.core.util.http.HttpClientUtils.java
/** * ??POST//from www .j a v a2s.c om * * @param url * ?? * @param encoding * * @param dataMap * ? * * @return */ public static String doPost(String url, String encoding, Map<String, String> dataMap) { StringBuffer buffer = new StringBuffer(); HttpPost post = null; InputStreamReader is = null; BufferedReader reader = null; BasicCookieStore cookieStore = new BasicCookieStore(); HttpClientBuilder builder = HttpClientBuilder.create(); CloseableHttpClient client = builder.setDefaultCookieStore(cookieStore).build(); try { post = new HttpPost(url); if (dataMap != null && !dataMap.isEmpty()) { List<org.apache.http.NameValuePair> nameValues = new ArrayList<org.apache.http.NameValuePair>(); for (Map.Entry<String, String> entry : dataMap.entrySet()) { String name = entry.getKey().toString(); String value = entry.getValue(); nameValues.add(new BasicNameValuePair(name, value)); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValues, encoding); post.setEntity(entity); } HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); is = new InputStreamReader(entity.getContent(), encoding); reader = new BufferedReader(is); String tmp = reader.readLine(); while (tmp != null) { buffer.append(tmp); tmp = reader.readLine(); } } catch (IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { IOUtils.closeStream(reader); IOUtils.closeStream(is); if (post != null) { post.releaseConnection(); } try { client.close(); } catch (IOException ex) { } } return buffer.toString(); }
From source file:com.github.NearestNeighbors.java
/** * Chooses the k best predictions to make from all evaluated distances. * Evaluations is a hash of the form {watcher_id => {repo1_id => distance1, repo2_id => distance2}} * * @param knn/*from w ww . j ava 2 s . co m*/ * @param evaluations * @param k * @return */ public static Set<Watcher> predict(final NearestNeighbors knn, final Map<String, Map<String, Collection<Float>>> evaluations, final int k, final Map<String, Watcher> test_data) { final Set<Watcher> ret = new HashSet<Watcher>(); for (final Map.Entry<String, Map<String, Collection<Float>>> evaluation : evaluations.entrySet()) { final String user_id = evaluation.getKey(); final Watcher w = new Watcher(user_id); final Map<String, Collection<Float>> distances = evaluation.getValue(); if (!distances.isEmpty()) { final Watcher training_watcher = knn.training_watchers.get(user_id); final List<Map.Entry<String, Collection<Float>>> sorted = MyUtils.sortMapByValues(distances, new FloatMeanComparator()); int upperBound = distances.size() < k ? distances.size() : k; for (int i = 0; i < upperBound; i++) { // TODO (KJM 8/10/09) Only add repo if distance is below some threshold. final String repo_id = sorted.get(i).getKey(); final Repository repo = knn.training_repositories.get(repo_id); w.associate(repo); // Make sure the predicted watcher follows the same distribution as the training watcher. //final float normalize_factor = ((float) k) / training_watcher.repositories.size(); //if ((w.owner_counts.get(repo.owner).floatValue() / training_watcher.repositories.size()) / normalize_factor < training_watcher.owner_distribution(repo.owner)) //{ // w.repositories.remove(repo); // } } } ret.add(w); } return ret; }
From source file:com.egt.core.db.util.Reporter.java
private static Map getReportParametersMap(File file, String format, Long userid, String usercode, String username, Map parametros) { Map parameters = getReportParametersMap(file, format, userid, usercode, username); if (parametros != null && !parametros.isEmpty()) { parameters.putAll(parametros);/*w ww. j a v a 2s . c o m*/ } return parameters; }
From source file:ddf.util.XSLTUtil.java
/** * Performs an xsl transformation against an XML document * * @param template/*from w w w .ja v a2 s. co m*/ * The compiled XSL template to be run * @param xmlDoc * xml document to be transformed * @param xslProperties * default classification * @return the transformed document. * @throws TransformerException */ public static Document transform(Templates template, Document xmlDoc, Map<String, Object> parameters) throws TransformerException { ByteArrayOutputStream baos; ByteArrayInputStream bais = null; Document resultDoc; try { Transformer transformer = template.newTransformer(); DBF.setNamespaceAware(true); DocumentBuilder builder = DBF.newDocumentBuilder(); StreamResult resultOutput = null; Source source = new DOMSource(xmlDoc); baos = new ByteArrayOutputStream(); try { resultOutput = new StreamResult(baos); if (parameters != null && !parameters.isEmpty()) { for (Map.Entry<String, Object> entry : parameters.entrySet()) { LOGGER.debug("Adding parameter key: {} value: {}", entry.getKey(), entry.getValue()); String key = entry.getKey(); Object value = entry.getValue(); if (key != null && !key.isEmpty() && value != null) { transformer.setParameter(key, value); } else { LOGGER.debug("Null or empty value for parameter: {}", entry.getKey()); } } } else { LOGGER.warn("All properties were null. Using \"last-resort\" defaults: U, USA, MTS"); } transformer.transform(source, resultOutput); bais = new ByteArrayInputStream(baos.toByteArray()); resultDoc = builder.parse(bais); } finally { IOUtils.closeQuietly(bais); IOUtils.closeQuietly(baos); } return resultDoc; } catch (TransformerException e) { LOGGER.warn(e.getMessage(), e); throw e; } catch (Exception e) { LOGGER.warn(e.getMessage(), e); throw new TransformerException("Error while transforming document: " + e.getMessage(), e); } }