Example usage for java.util Map size

List of usage examples for java.util Map size

Introduction

In this page you can find the example usage for java.util Map size.

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:ViewImageTest.java

/**
 * Display detailed results. All parametrers required not to be null.
 * // ww w  .  ja v a 2 s .  co  m
 * @param inFiles
 *            input image files
 * @param failures
 *            map input file url which failed with eventual cause exception
 */
private static void displayResults(File[] inFiles, Map<String, Exception> failures) {
    if (failures.size() > 0) {
        if (failures.size() == inFiles.length) {
            System.out.println("No input files could be processed :");
        } else {
            System.out.println("Some input files could not be processed :");
        }
        for (Entry<String, Exception> entry : failures.entrySet()) {
            System.out.println(entry.getKey());
            if (entry.getValue() != null) {
                System.out.println("cause : " + entry.getValue());
            }
        }
    } else {
        System.out.println("All input files were successfully processed.");
    }
}

From source file:info.archinnov.achilles.internal.validation.Validator.java

public static void validateSize(Map<?, ?> arg, int size, String message, Object... args) {
    validateNotEmpty(arg, "The map '%s' should not be empty", args);
    if (arg.size() != size) {
        throw new AchillesException(format(message, args));
    }/*from  w  w w. ja va2s .c om*/
}

From source file:AIR.Common.Web.taglib.JsfHelpers.java

public static void setValueExpressions(UIComponent component, Map<String, String> valueExpressions,
        FacesContext context) {//from  w  ww.  j a  v  a 2  s . com
    if (valueExpressions == null || valueExpressions.size() == 0)
        return;
    if (context == null) {
        context = FacesContext.getCurrentInstance();
    }

    Application application = context.getApplication();
    // http://stackoverflow.com/a/16058002/1961102
    if (valueExpressions != null && !valueExpressions.isEmpty()) {
        ExpressionFactory factory = application.getExpressionFactory();
        ELContext ctx = context.getELContext();
        for (Map.Entry<String, String> entry : valueExpressions.entrySet()) {
            ValueExpression expr = factory.createValueExpression(ctx, entry.getValue(), Object.class);
            component.setValueExpression(entry.getKey(), expr);
        }
    }
}

From source file:com.cyou.hithere.center.util.JsonMapper.java

/**
 * ??/*from ww  w.  j  a  va  2  s.  c om*/
 * 
 * @param map
 * @return
 */
public static String getJsonFromMap(Map<String, Object> map) {
    if (map == null || map.size() == 0) {
        return null;
    }
    String json = null;
    try {
        json = JSONObject.fromObject(map).toString();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return json;
}

From source file:com.exxonmobile.ace.hybris.storefront.servlets.util.FilterSpringUtil.java

/**
 * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first
 * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is.
 *///from w ww . ja  v  a2s  .c  o m
public static <T> T getSpringBean(final ServletContext servletContext, final String beanName,
        final Class<T> beanClass) {
    T ret = null;
    final WebApplicationContext appContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    if (StringUtils.isNotBlank(beanName)) {
        try {
            ret = (T) appContext.getBean(beanName);
        } catch (final NoSuchBeanDefinitionException ex) {
            LOG.warn("No bean found with the specified name. Trying to resolve bean using type...");
        }
    }
    if (ret == null) {
        if (beanClass == null) {
            LOG.warn("No bean could be resolved. Reason: No type specified.");
        } else {
            final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass);
            if (beansOfType != null && !beansOfType.isEmpty()) {
                if (beansOfType.size() > 1) {
                    LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName()
                            + ". Returning the first one found.");
                }
                ret = beansOfType.values().iterator().next();
            }
        }
    }
    return ret;
}

From source file:MathFunctions.java

public static AffineTransform generateAffineTransformFromPointPairs(
        Map<Point2D.Double, Point2D.Double> pointPairs) {
    RealMatrix u = new Array2DRowRealMatrix(pointPairs.size(), 3);
    RealMatrix v = new Array2DRowRealMatrix(pointPairs.size(), 3);

    // Create u (source) and v (dest) matrices whose row vectors
    // are [x,y,1] for each Point2D.Double:

    int i = 0;/*from  ww w . ja  v  a  2  s .c  om*/
    for (Map.Entry pair : pointPairs.entrySet()) {
        Point2D.Double uPt = (Point2D.Double) pair.getKey();
        Point2D.Double vPt = (Point2D.Double) pair.getValue();

        insertPoint2DInMatrix(u, uPt, i);
        insertPoint2DInMatrix(v, vPt, i);

        i++;
    }
    // Find the 3x3 linear least squares solution to u*m'=v
    // (the last row should be [0,0,1]):
    DecompositionSolver solver = (new QRDecompositionImpl(u)).getSolver();
    double[][] m = solver.solve(v).transpose().getData();

    // Create an AffineTransform object from the elements of m
    // (the last row is omitted as specified in AffineTransform class):
    return new AffineTransform(m[0][0], m[1][0], m[0][1], m[1][1], m[0][2], m[1][2]);
}

From source file:com.kenshoo.freemarker.view.FreeMarkerOnlineView.java

private static List<SelectionOption> toSelectionOptions(Map<String, ?> settingValueMap) {
    ArrayList<SelectionOption> selectionOptions = new ArrayList<SelectionOption>(settingValueMap.size());
    for (String key : settingValueMap.keySet()) {
        selectionOptions.add(new SelectionOption(key, truncate(key, 25)));
    }//from w  w w . j a va  2 s . c  o m
    Collections.sort(selectionOptions);
    return selectionOptions;
}

From source file:de.vandermeer.skb.base.utils.Skb_TextUtils.java

/**
 * Returns a transformer that takes a map and returns a string representation of its contents.
 * @return map to string transformer/*from  w  ww  . j a v  a 2 s. c o  m*/
 */
public static final Skb_Transformer<Map<String, ?>, String> MAP_TO_TEXT() {
    return new Skb_Transformer<Map<String, ?>, String>() {
        @Override
        public String transform(Map<String, ?> map) {
            StrBuilder ret = new StrBuilder(map.size() * 20);
            TreeSet<String> keys = new TreeSet<String>(map.keySet());
            for (String leaf : keys) {
                //               int level=StringUtils.countMatches(leaf, builder.getSeparatorAsString());
                //               ret.append('-');
                //               for(int i=0;i<=level;i++){
                //                  ret.append("-");
                //               }
                //               ret.append("> ").append(leaf);
                ret.append("--> ").append(leaf);
                ret.append(" ::= ");
                ret.append(map.get(leaf));
                ret.append('\n');
            }
            return ret.toString();
        }
    };
}

From source file:com.acc.filter.FilterSpringUtil.java

/**
 * The same as {@link #getSpringBean(HttpServletRequest, String, Class)} but uses ServletContext as the first
 * parameter. It might be used in places, where HttpServletRequest is not available, but ServletContext is.
 *///www .  j  a  va2 s . c o  m
public static <T> T getSpringBean(final ServletContext servletContext, final String beanName,
        final Class<T> beanClass) {
    T ret = null;
    final WebApplicationContext appContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);

    if (StringUtils.isNotBlank(beanName)) {
        try {
            ret = (T) appContext.getBean(beanName);
        } catch (final NoSuchBeanDefinitionException nsbde) {
            LOG.warn("No bean found with the specified name. Trying to resolve bean using type...");
        }
    }
    if (ret == null) {
        if (beanClass == null) {
            LOG.warn("No bean could be resolved. Reason: No type specified.");
        } else {
            final Map<String, T> beansOfType = appContext.getBeansOfType(beanClass);
            if (beansOfType != null && !beansOfType.isEmpty()) {
                if (beansOfType.size() > 1) {
                    LOG.warn("More than one matching bean found of type " + beanClass.getSimpleName()
                            + ". Returning the first one found.");
                }
                ret = beansOfType.values().iterator().next();
            }
        }
    }
    return ret;
}

From source file:com.kenshoo.freemarker.view.FreeMarkerOnlineView.java

private static List<SelectionOption> toLocaleSelectionOptions(Map<String, Locale> localeMap) {
    ArrayList<SelectionOption> selectionOptions = new ArrayList<SelectionOption>(localeMap.size());
    for (Map.Entry<String, Locale> ent : localeMap.entrySet()) {
        Locale locale = ent.getValue();
        selectionOptions.add(new SelectionOption(ent.getKey(),
                truncate(locale.getDisplayName(Locale.US), 18) + "; " + locale.toString()));
    }//  w w w  .ja  v  a  2  s .co  m
    Collections.sort(selectionOptions);
    return selectionOptions;
}