List of usage examples for java.util Map size
int size();
From source file:com.reachlocal.grails.plugins.cassandra.utils.OrmHelper.java
public static Map<String, Object> sort(Map<String, Object> map) { Map<String, Object> sorted = new LinkedHashMap<String, Object>(); List<String> keys = new ArrayList<String>(map.size()); keys.addAll(map.keySet());/*ww w. ja va2s.co m*/ Collections.sort(keys); for (String key : keys) { sorted.put(key, map.get(key)); } return sorted; }
From source file:com.wso2telco.ids.utils.ClaimUtil.java
/** * Gets the claims from user store.//from ww w .j av a2 s . com * * @param tokenResponse the token response * @return the claims from user store * @throws Exception the exception */ public static Map<String, Object> getClaimsFromUserStore(OAuth2TokenValidationResponseDTO tokenResponse) throws Exception { String username = tokenResponse.getAuthorizedUser(); String tenantUser = MultitenantUtils.getTenantAwareUsername(username); String tenantDomain = MultitenantUtils.getTenantDomain(tokenResponse.getAuthorizedUser()); UserRealm realm; Claim claims[]; List<String> claimURIList = new ArrayList<String>(); Map<String, Object> mappedAppClaims = new HashMap<String, Object>(); try { realm = IdentityTenantUtil.getRealm(tenantDomain, username); if (realm == null) { log.warn("No valid tenant domain provider. Empty claim returned back"); return new HashMap<String, Object>(); } claims = realm.getUserStoreManager().getUserClaimValues(tenantUser, null); Map<String, String> spToLocalClaimMappings; UserStoreManager userstore = realm.getUserStoreManager(); // need to get all the requested claims Map<String, String> requestedLocalClaimMap = ClaimManagerHandler.getInstance() .getMappingsMapFromOtherDialectToCarbon(spDialect, null, tenantDomain, true); if (requestedLocalClaimMap != null && requestedLocalClaimMap.size() > 0) { for (Iterator<String> iterator = requestedLocalClaimMap.keySet().iterator(); iterator.hasNext();) { claimURIList.add(iterator.next()); } if (log.isDebugEnabled()) { log.debug("Requested number of local claims: " + claimURIList.size()); } spToLocalClaimMappings = ClaimManagerHandler.getInstance() .getMappingsMapFromOtherDialectToCarbon(spDialect, null, tenantDomain, false); Map<String, String> userClaims = userstore.getUserClaimValues( MultitenantUtils.getTenantAwareUsername(username), claimURIList.toArray(new String[claimURIList.size()]), null); if (log.isDebugEnabled()) { log.debug("User claims retrieved from user store: " + userClaims.size()); } if (userClaims == null || userClaims.size() == 0) { return new HashMap<String, Object>(); } for (Iterator<Map.Entry<String, String>> iterator = spToLocalClaimMappings.entrySet() .iterator(); iterator.hasNext();) { Map.Entry<String, String> entry = iterator.next(); String value = userClaims.get(entry.getValue()); if (value != null) { mappedAppClaims.put(entry.getKey(), value); if (log.isDebugEnabled()) { log.debug("Mapped claim: key - " + entry.getKey() + " value -" + value); } } } } } catch (Exception e) { throw new UserInfoEndpointException(e.getMessage()); } return mappedAppClaims; }
From source file:com.edgenius.test.TestUtil.java
/** * @param outAtt/*from ww w .j a va2s . c o m*/ * @param inAtt * @param dynamicAttMap */ private static boolean compareWajx(String outAtt, String inAtt, Map<String, String> dynamicAttMap) { //parse wajax Map<String, String> inWajxMap = RichTagUtil.parseWajaxAttribute(inAtt); Map<String, String> outWajxMap = RichTagUtil.parseWajaxAttribute(outAtt); if (inWajxMap.size() != outWajxMap.size()) return false; for (java.util.Map.Entry<String, String> entry : inWajxMap.entrySet()) { String outValue = outWajxMap.get(entry.getKey()); String inValue = entry.getValue(); //dynamic attribute value if (inValue.matches("\\$\\$DD\\d\\$\\$")) { if (checkDynamicAttribute(dynamicAttMap, outValue, inValue)) { continue; } else { return false; } } if (!StringUtils.equals(inValue, outValue)) { return false; } } return true; }
From source file:com.mingsoft.util.proxy.Proxy.java
/** * ?// w ww . j a va 2s.co m * * @param headers * Header??<br> * @return Header */ public static BasicHeader[] assemblyHeader(Map headers) { BasicHeader[] allHeader = new BasicHeader[headers.size()]; int i = 0; //log.info("?"); Iterator it = headers.keySet().iterator(); while (it.hasNext()) { String str = (String) it.next(); allHeader[i] = new BasicHeader(str, (String) headers.get(str)); i++; //log.info(str + ":" + headers.get(str)); } //log.info("??"); return allHeader; }
From source file:com.caibowen.gplume.misc.test.HttpClientUtil.java
public static HttpEntityEnclosingRequestBase setParam(HttpEntityEnclosingRequestBase request, Map<String, ? extends Serializable> params, Charset charset) { if (charset == null) charset = Consts.UTF_8;/*ww w . ja v a 2s .c o m*/ if (params != null && params.size() > 0) { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(getParamsList(params), charset); request.setEntity(formEntity); } return request; }
From source file:com.mongodb.hadoop.pig.BSONStorage.java
public static Object getTypeForBSON(Object o, ResourceSchema.ResourceFieldSchema field) throws IOException { byte dataType = field != null ? field.getType() : DataType.UNKNOWN; ResourceSchema s = null;/*from ww w .j ava 2 s . c o m*/ if (field == null) { if (o instanceof Map) { dataType = DataType.MAP; } else if (o instanceof List) { dataType = DataType.BAG; } else { dataType = DataType.UNKNOWN; } } else { s = field.getSchema(); if (dataType == DataType.UNKNOWN) { if (o instanceof Map) dataType = DataType.MAP; if (o instanceof List) dataType = DataType.BAG; } } if (dataType == DataType.BYTEARRAY && o instanceof Map) { dataType = DataType.MAP; } switch (dataType) { case DataType.NULL: return null; case DataType.INTEGER: case DataType.LONG: case DataType.FLOAT: case DataType.DOUBLE: return o; case DataType.BYTEARRAY: return o.toString(); case DataType.CHARARRAY: return (String) o; // Given a TUPLE, create a Map so BSONEncoder will eat it case DataType.TUPLE: if (s == null) { throw new IOException("Schemas must be fully specified to use " + "this storage function. No schema found for field " + field.getName()); } ResourceSchema.ResourceFieldSchema[] fs = s.getFields(); LinkedHashMap m = new java.util.LinkedHashMap(); for (int j = 0; j < fs.length; j++) { m.put(fs[j].getName(), getTypeForBSON(((Tuple) o).get(j), fs[j])); } return m; // Given a BAG, create an Array so BSONEnconder will eat it. case DataType.BAG: if (s == null) { throw new IOException("Schemas must be fully specified to use " + "this storage function. No schema found for field " + field.getName()); } fs = s.getFields(); if (fs.length != 1 || fs[0].getType() != DataType.TUPLE) { throw new IOException("Found a bag without a tuple " + "inside!"); } // Drill down the next level to the tuple's schema. s = fs[0].getSchema(); if (s == null) { throw new IOException("Schemas must be fully specified to use " + "this storage function. No schema found for field " + field.getName()); } fs = s.getFields(); ArrayList a = new ArrayList<Map>(); for (Tuple t : (DataBag) o) { LinkedHashMap ma = new java.util.LinkedHashMap(); for (int j = 0; j < fs.length; j++) { ma.put(fs[j].getName(), ((Tuple) t).get(j)); } a.add(ma); } return a; case DataType.MAP: Map map = (Map) o; Map<String, Object> out = new HashMap<String, Object>(map.size()); for (Object key : map.keySet()) { out.put(key.toString(), getTypeForBSON(map.get(key), null)); } return out; default: return o; } }
From source file:dm_p2.DBSCAN.java
public static double[][] distmat(Map<Integer, List<Double>> lhm) { System.out.println(lhm.size()); double[][] dmat = new double[lhm.size() + 1][lhm.size() + 1]; for (int i = 1; i <= lhm.size(); i++) { List<Double> curg = lhm.get(i); for (int j = 1; j <= lhm.size(); j++) { if (i != j) { List<Double> nxtg = lhm.get(j); double sum = 0; for (int k = 0; k < curg.size(); k++) { sum += Math.pow((curg.get(k) - nxtg.get(k)), 2); }//from ww w . j a v a 2 s .c om dmat[i][j] = Math.sqrt(sum); } else { dmat[i][j] = 0.0; } } } return dmat; }
From source file:org.elasticsearch.xpack.ml.integration.MlBasicMultiNodeIT.java
private static void assertFlushResponse(Response response, boolean expectedFlushed, long expectedLastFinalizedBucketEnd) throws IOException { Map<String, Object> asMap = responseEntityToMap(response); assertThat(asMap.size(), equalTo(2)); assertThat(asMap.get("flushed"), is(true)); assertThat(asMap.get("last_finalized_bucket_end"), equalTo(expectedLastFinalizedBucketEnd)); }
From source file:com.caibowen.gplume.misc.test.HttpClientUtil.java
/** * Get???,URL???, ?http://www.g.cn/*from w w w . j a va 2s . co m*/ * * @param url ??? * @param params ?, / * @return ?? */ public static String setParam(String url, Map<String, ? extends Serializable> params, Charset charset) { if (charset == null) charset = Consts.UTF_8; if (params != null && params.size() > 0) { List<NameValuePair> qparams = getParamsList(params); if (qparams != null && qparams.size() > 0) { String formatParams = URLEncodedUtils.format(qparams, charset); url = url + (url.indexOf("?") < 0 ? "?" : "&") + formatParams; } } return url; }
From source file:com.uber.hoodie.hadoop.realtime.AbstractRealtimeRecordReader.java
/** * Convert the projected read from delta record into an array writable *///from ww w . j a va 2 s . c om public static Writable avroToArrayWritable(Object value, Schema schema) { // if value is null, make a NullWritable if (value == null) { return NullWritable.get(); } switch (schema.getType()) { case STRING: return new Text(value.toString()); case BYTES: return new BytesWritable((byte[]) value); case INT: return new IntWritable((Integer) value); case LONG: return new LongWritable((Long) value); case FLOAT: return new FloatWritable((Float) value); case DOUBLE: return new DoubleWritable((Double) value); case BOOLEAN: return new BooleanWritable((Boolean) value); case NULL: return NullWritable.get(); case RECORD: GenericRecord record = (GenericRecord) value; Writable[] values1 = new Writable[schema.getFields().size()]; int index1 = 0; for (Schema.Field field : schema.getFields()) { values1[index1++] = avroToArrayWritable(record.get(field.name()), field.schema()); } return new ArrayWritable(Writable.class, values1); case ENUM: return new Text(value.toString()); case ARRAY: GenericArray arrayValue = (GenericArray) value; Writable[] values2 = new Writable[arrayValue.size()]; int index2 = 0; for (Object obj : arrayValue) { values2[index2++] = avroToArrayWritable(obj, schema.getElementType()); } return new ArrayWritable(Writable.class, values2); case MAP: Map mapValue = (Map) value; Writable[] values3 = new Writable[mapValue.size()]; int index3 = 0; for (Object entry : mapValue.entrySet()) { Map.Entry mapEntry = (Map.Entry) entry; Writable[] mapValues = new Writable[2]; mapValues[0] = new Text(mapEntry.getKey().toString()); mapValues[1] = avroToArrayWritable(mapEntry.getValue(), schema.getValueType()); values3[index3++] = new ArrayWritable(Writable.class, mapValues); } return new ArrayWritable(Writable.class, values3); case UNION: List<Schema> types = schema.getTypes(); if (types.size() != 2) { throw new IllegalArgumentException("Only support union with 2 fields"); } Schema s1 = types.get(0); Schema s2 = types.get(1); if (s1.getType() == Schema.Type.NULL) { return avroToArrayWritable(value, s2); } else if (s2.getType() == Schema.Type.NULL) { return avroToArrayWritable(value, s1); } else { throw new IllegalArgumentException("Only support union with null"); } case FIXED: return new BytesWritable(((GenericFixed) value).bytes()); default: return null; } }