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:ch.digitalfondue.npjt.QueryType.java

@SuppressWarnings("unchecked")
private static <T> AffectedRowCountAndKey<T> executeUpdateAndKeepKeys(String template, Method method,
        NamedParameterJdbcTemplate jdbc, SqlParameterSource parameters) {

    Class<T> keyClass = (Class<T>) ((ParameterizedType) method.getGenericReturnType())
            .getActualTypeArguments()[0];

    KeyHolder keyHolder = new GeneratedKeyHolder();

    int result = jdbc.update(template, parameters, keyHolder);
    Map<String, Object> keys = keyHolder.getKeys();
    Object key;/*w  w  w .  ja v a  2  s.  c  om*/
    if (keys.size() > 1) {
        AutoGeneratedKey spec = Objects.requireNonNull(method.getDeclaredAnnotation(AutoGeneratedKey.class),
                "more than one key for query " + template + ": annotation @AutoGeneratedKey required");
        key = Objects.requireNonNull(keys.get(spec.value()), "the key with name " + spec.value()
                + " has returned null for query " + template + ": required a non null key");
    } else if (Number.class.isAssignableFrom(keyClass)) {
        Class<? extends Number> c = (Class<? extends Number>) keyClass;
        return new AffectedRowCountAndKey<>(result,
                (T) NumberUtils.convertNumberToTargetClass(keyHolder.getKey(), c));
    } else {
        key = keys.values().iterator().next();
    }
    return new AffectedRowCountAndKey<>(result, keyClass.cast(key));
}

From source file:elaborate.publication.solr.SearchService.java

@SuppressWarnings("unchecked")
static Map<String, FacetInfo> toMap(Object object) {
    Map<String, Map<String, String>> inMap = (Map<String, Map<String, String>>) object;
    Map<String, FacetInfo> outMap = Maps.newHashMapWithExpectedSize(inMap.size());
    for (Entry<String, Map<String, String>> entry : inMap.entrySet()) {
        String key = entry.getKey();
        Map<String, String> value = entry.getValue();
        outMap.put(key, new FacetInfo().setName(value.get("name")).setTitle(value.get("title"))
                .setType(FacetType.valueOf(value.get("type"))));
    }/*w  w  w .ja v a2  s  .  c o m*/
    return outMap;
}

From source file:com.frank.search.solr.server.support.SolrClientUtils.java

private static LBHttpSolrClient cloneSolr4LBHttpServer(SolrClient solrClient, String core)
        throws MalformedURLException, InstantiationException, IllegalAccessException, IllegalArgumentException,
        InvocationTargetException {
    Map<String, ?> map = readField(solrClient, "aliveServers");

    String[] servers = new String[map.size()];
    int i = 0;/*from  w  ww .j ava2s. c  om*/
    for (String key : map.keySet()) {
        servers[i] = appendCoreToBaseUrl(key, core);
        i++;
    }

    Boolean isInternalCient = readField(solrClient, "clientIsInternal");

    if (isInternalCient != null && !isInternalCient) {
        HttpClient clientToUse = readAndCloneHttpClient(solrClient);
        return new LBHttpSolrClient(clientToUse, servers);
    }
    return new LBHttpSolrClient(servers);
}

From source file:org.calrissian.restdoclet.writer.swagger.SwaggerWriter.java

private static void writeApi(String resource, Collection<Endpoint> endpoints, Configuration config)
        throws IOException {
    Map<String, Collection<Endpoint>> pathGroups = groupPaths(endpoints);

    File apiFile = new File("./" + API_DOC_DIR, resource);
    apiFile.getParentFile().mkdirs();/* ww  w .  ja v a2  s  .  co  m*/

    Collection<Api> apis = new ArrayList<Api>(pathGroups.size());
    for (Entry<String, Collection<Endpoint>> entry : pathGroups.entrySet())
        apis.add(new Api(entry.getKey(), "", getOperations(entry.getValue())));

    mapper.writerWithDefaultPrettyPrinter().writeValue(new FileOutputStream(apiFile),
            new ApiListing(SWAGGER_VERSION, config.getUrl(), resource, config.getApiVersion(), apis));
}

From source file:com.greenline.guahao.biz.manager.payment.util.AlipayCore.java

/**
 * ???/*from  ww  w.j  av  a  2 s. c  o m*/
 * 
 * @param sArray ???
 * @return ???????
 */
public static Map<String, String> paraFilter(Map<String, String> sArray) {
    Map<String, String> result = new HashMap<String, String>();
    if (sArray == null || sArray.size() <= 0) {
        return result;
    }
    for (String key : sArray.keySet()) {
        String value = sArray.get(key);
        if (StringUtils.isBlank(value) || "sign".equalsIgnoreCase(key) || "sign_type".equalsIgnoreCase(key)) {
            continue;
        }
        result.put(key, value);
    }
    return result;
}

From source file:com.pactera.edg.am.metamanager.extractor.control.impl.ExtractorServiceImpl.java

private static void deleteAmData(String rootId, Map<String, List<Map<String, String>>> deleteMapDatas) {
    if (deleteMapDatas.size() > 0) {
        IMetadataLoaderService loader = (IMetadataLoaderService) ExtractorContextLoader
                .getBean(IMetadataLoaderService.SPRING_NAME);

        if (!AdapterExtractorContext.getInstance().isNeedAudit()) {
            // ?/*from w w  w .j a  va2  s.c  om*/
            loader.deleteData(rootId, deleteMapDatas);
        }
    }

}

From source file:edu.valelab.GaussianFit.CoordinateMapper.java

/**
* Creates an AffineTransform object that maps a source planar coordinate system to
* a destination planar coordinate system. At least three point pairs are needed.
* 
* @pointPairs is a Map of points measured in the two coordinates systems (srcPt->destPt)
*///from w  w w . j  a v  a2 s  . c  o m
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;
    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:dao.UserDAO.java

public static String updateUserSettings(Map<String, String[]> settings, String user) {
    String message = "Internal error";
    if (settings == null || settings.size() == 0) {
        return "Empty post body";
    }//from w w  w . ja v a 2 s . co m

    String defaultView = "";
    if (settings.containsKey("detail_default_view")) {
        String[] defaultViewArray = settings.get("detail_default_view");
        if (defaultViewArray != null && defaultViewArray.length > 0) {
            defaultView = defaultViewArray[0];
        }
    }
    String defaultWatch = "";
    if (settings.containsKey("default_watch")) {
        String[] defaultWatchArray = settings.get("default_watch");
        if (defaultWatchArray != null && defaultWatchArray.length > 0) {
            defaultWatch = defaultWatchArray[0];
        }
    }
    Integer userId = 0;
    if (StringUtils.isNotBlank(user)) {
        try {
            userId = (Integer) getJdbcTemplate().queryForObject(GET_USER_ID, Integer.class, user);
        } catch (EmptyResultDataAccessException e) {
            Logger.error("UserDAO updateUserSettings get user id failed, username = " + user);
            Logger.error("Exception = " + e.getMessage());
        }
    }
    if (userId != null && userId > 0) {
        if (StringUtils.isBlank(defaultView)) {
            defaultView = DEFAULT_DETAIL_VIEW;
        }

        if (StringUtils.isBlank(defaultWatch)) {
            defaultWatch = DEFAULT_WATCH;
        }

        int row = getJdbcTemplate().update(UPDATE_USER_SETTINGS, userId, defaultView, defaultWatch, defaultView,
                defaultWatch);
        if (row > 0) {
            message = "";
        }
    } else {
        message = "User not found";
    }
    return message;
}

From source file:com.bigdata.dastor.dht.BootStrapper.java

static InetAddress getBootstrapSource(final TokenMetadata metadata, final Map<InetAddress, Double> load) {
    // sort first by number of nodes already bootstrapping into a source node's range, then by load.
    List<InetAddress> endpoints = new ArrayList<InetAddress>(load.size());
    for (InetAddress endpoint : load.keySet()) {
        if (!metadata.isMember(endpoint))
            continue;
        endpoints.add(endpoint);/* w  ww. j ava 2  s .  c  om*/
    }

    if (endpoints.isEmpty())
        throw new RuntimeException("No other nodes seen!  Unable to bootstrap");
    Collections.sort(endpoints, new Comparator<InetAddress>() {
        public int compare(InetAddress ia1, InetAddress ia2) {
            int n1 = metadata.pendingRangeChanges(ia1);
            int n2 = metadata.pendingRangeChanges(ia2);
            if (n1 != n2)
                return -(n1 - n2); // more targets = _less_ priority!

            double load1 = load.get(ia1);
            double load2 = load.get(ia2);
            if (load1 == load2)
                return 0;
            return load1 < load2 ? -1 : 1;
        }
    });

    InetAddress maxEndpoint = endpoints.get(endpoints.size() - 1);
    assert !maxEndpoint.equals(FBUtilities.getLocalAddress());
    return maxEndpoint;
}

From source file:org.echocat.jomon.net.http.HttpUtils.java

@Nonnull
public static HttpPost postFor(@Nonnull URI uri, @Nonnull Charset charset,
        @Nullable Map<String, String> parameters) throws UnsupportedEncodingException {
    final HttpPost httpPost = new HttpPost(uri);
    final List<NameValuePair> pairs = new ArrayList<>(parameters != null ? parameters.size() : 0);
    if (parameters != null) {
        for (final Entry<String, String> keyToValue : parameters.entrySet()) {
            pairs.add(new BasicNameValuePair(keyToValue.getKey(), keyToValue.getValue()));
        }/*w ww .  ja  va 2s. c om*/
    }
    httpPost.setEntity(new UrlEncodedFormEntity(pairs, charset));
    return httpPost;
}