List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:com.buildria.mocking.stub.Call.java
public static Call fromRequest(HttpRequest req) { Objects.requireNonNull(req);//from w w w . j av a 2 s .com Call call = new Call(); call.method = req.getMethod().name(); QueryStringDecoder decoder = new QueryStringDecoder(req.getUri()); call.path = QueryStringDecoder.decodeComponent(decoder.path()); Map<String, List<String>> params = decoder.parameters(); for (String name : params.keySet()) { List<String> values = params.get(name); for (String value : values) { call.parameters.add(new Pair(name, value)); } } HttpHeaders headers = req.headers(); for (String name : headers.names()) { List<String> values = headers.getAll(name); for (String value : values) { call.headers.add(new Pair(name, value)); } if (CONTENT_TYPE.equalsIgnoreCase(name)) { call.contentType = MediaType.parse(headers.get(CONTENT_TYPE)); } } if (req instanceof ByteBufHolder) { ByteBuf buf = ((ByteBufHolder) req).content(); if (buf != null) { call.body = new byte[buf.readableBytes()]; buf.readBytes(call.body); } } return call; }
From source file:com.cubeia.backoffice.report.RequestBean.java
@SuppressWarnings("rawtypes") private static Map<String, String> checkParameters(Map p) { Map<String, String> m = new HashMap<String, String>(p.size()); for (Object o : p.keySet()) { String key = o.toString(); if (key.startsWith("param:")) { key = key.substring(6);//www . ja va 2 s.c o m Object v = p.get(o); m.put(key, v.toString()); } } return m; }
From source file:com.metadave.stow.Stow.java
public static void generateObjects(String groupFile, String classPackage, String classPrefix, String dest) { if (classPrefix == null) { classPrefix = ""; }//from w w w. j a va2s .c o m Set<String> templateNames = new HashSet<String>(); StowSTGroupFile stg = new StowSTGroupFile(groupFile); STGroup outputGroup = new STGroupFile("Stow.stg"); Map<String, CompiledST> ts = stg.getTemplates(); int i = 1; for (String s : ts.keySet()) { CompiledST t = ts.get(s); if (t.isAnonSubtemplate) { continue; } String templateId; if (!templateNames.contains(t.name.toUpperCase())) { templateNames.add(t.name.toUpperCase()); templateId = t.name; } else { System.out.println("Adding a unique id to " + t.name); templateId = t.name + i; } STOWSTBean bean = new STOWSTBean(outputGroup); bean.addPackage(classPackage); bean.addTemplateName(t.name); String className = classPrefix + templateId; bean.addBeanClass(className); if (t.hasFormalArgs) { Map<String, FormalArgument> fas = t.formalArguments; if (fas != null) { for (String fa : fas.keySet()) { FormalArgument f = fas.get(fa); STOWSTAccessor acc = new STOWSTAccessor(outputGroup); acc.addBeanClass(className); acc.addMethodName(getNiceName(f.name)); acc.addParamName(f.name); bean.addAccessor(acc); } } } String outputFileName = dest + File.separator + className + ".java"; System.out.println("Generating " + outputFileName); File f = new File(outputFileName); try { FileUtils.writeStringToFile(f, bean.getST().render()); } catch (Exception e) { e.printStackTrace(); } } System.out.println("Finished!"); }
From source file:Main.java
public static String httpGet(String url, Map<String, String> params) { List<NameValuePair> lst = new ArrayList<NameValuePair>(); if (params != null) { Iterator<String> keyItors = params.keySet().iterator(); while (keyItors.hasNext()) { String key = keyItors.next(); String val = params.get(key); lst.add(new BasicNameValuePair(key, val)); }/*from ww w .jav a2 s . c om*/ } return httpGet(url, lst); }
From source file:net.ontopia.topicmaps.cmdlineutils.rdbms.RDBMSIndexTool.java
protected static void print(String prefix, Map m) { Iterator iter = m.keySet().iterator(); while (iter.hasNext()) { Object k = iter.next();/* w w w . ja v a2 s .c o m*/ System.out.println(prefix + k + " " + m.get(k)); } }
From source file:com.hoccer.http.AsyncHttpRequestWithBody.java
public static String urlEncodeValues(Map<String, String> pData) { StringBuffer tmp = new StringBuffer(); Set keys = pData.keySet(); int idx = 0;/*from w ww .ja va 2 s.co m*/ for (Object key : keys) { tmp.append(String.valueOf(key)); tmp.append("="); tmp.append(URLEncoder.encode(String.valueOf(pData.get(key)))); idx += 1; if (idx < keys.size()) { tmp.append("&"); } } return tmp.toString(); }
From source file:jp.co.tis.gsp.tools.dba.dialect.DialectFactory.java
public static void registerOptionalDialects(Map<String, String> optionalDialectClassNames) { if (optionalDialectClassNames == null) { return;//w w w.j a v a 2 s .c om } try { for (String urlPrefix : optionalDialectClassNames.keySet()) { Class<?> dialectClass = Class.forName(optionalDialectClassNames.get(urlPrefix)); classMap.put(urlPrefix, dialectClass); } } catch (Exception e) { throw new IllegalArgumentException("Can't create dialect:" + optionalDialectClassNames, e); } }
From source file:Main.java
public static void applyProperties(Object o, Element root) { Map<String, Object> map = getProperties(root); Iterator<String> it = map.keySet().iterator(); Field[] fields = o.getClass().getFields(); Method[] methods = o.getClass().getMethods(); while (it.hasNext()) { String name = (String) it.next(); Object value = map.get(name); try {// w w w.j a v a 2 s . com for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equalsIgnoreCase(name) && isTypeMatch(fields[i].getType(), value.getClass())) { fields[i].set(o, value); System.err.println("Set field " + fields [i].getName() + "=" + value); break; } } for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equalsIgnoreCase("set" + name) && methods[i].getParameterTypes ().length == 1 && isTypeMatch(methods [i].getParameterTypes()[0], value.getClass())) { methods[i].invoke(o, new Object[] { value }); System.err.println("Set method " + methods [i].getName() + "=" + value); break; } } } catch (Exception e) { System.err.println("Unable to apply property '" + name + "': " + e.toString()); } } }
From source file:Main.java
public static Intent mapToIntent(Context context, Class<?> clazz, Map<String, Object> map) { Intent intent = new Intent(context, clazz); Bundle bundle = new Bundle(); if (map != null && map.size() > 0) { for (String key : map.keySet()) { if (map.get(key) instanceof String) { bundle.putString(key, (String) map.get(key)); } else if (map.get(key) instanceof Integer) { bundle.putInt(key, (Integer) map.get(key)); } else if (map.get(key) instanceof Boolean) { bundle.putBoolean(key, (Boolean) map.get(key)); } else if (map.get(key) instanceof Double) { bundle.putDouble(key, (Double) map.get(key)); } else if (map.get(key) instanceof Long) { bundle.putLong(key, (Long) map.get(key)); } else if (map.get(key) instanceof Float) { bundle.putFloat(key, (Float) map.get(key)); } else if (map.get(key) instanceof Double) { bundle.putDouble(key, (Double) map.get(key)); } else if (map.get(key) instanceof Serializable) { bundle.putSerializable(key, (Serializable) map.get(key)); } else if (map.get(key) instanceof Parcelable) { bundle.putParcelable(key, (Parcelable) map.get(key)); }/*from w w w . j a va2 s. com*/ } } return intent.putExtras(bundle); }
From source file:Main.java
public static String toString(Map<?, ?> m, String prefix) { if (m == null) { return "null"; }/* w w w. j a v a 2 s . c o m*/ StringBuilder sb = new StringBuilder(); String sep = ""; for (Object object : m.keySet()) { Object value = m.get(object); sb.append(sep).append(prefix).append(object.toString()).append(arrow).append(value.toString()); sep = separator; } return sb.toString(); }