List of usage examples for java.util Map size
int size();
From source file:com.salesmanager.core.util.LocaleUtil.java
public static void setLocaleForRequest(HttpServletRequest request, HttpServletResponse response, ActionContext ctx, MerchantStore store) throws Exception { /**/* ww w . ja v a2s . c om*/ * LOCALE */ Map sessions = ctx.getSession(); if (ctx == null) { throw new Exception("This request was not made inside Struts request, ActionContext is null"); } Locale locale = null; // check in http request String req_locale = (String) request.getParameter("request_locale"); if (!StringUtils.isBlank(req_locale)) { String l = null; String c = null; if (req_locale.length() == 2) {//assume it is the language l = req_locale; c = CountryUtil.getCountryIsoCodeById(store.getCountry()); } if (req_locale.length() == 5) { try { l = req_locale.substring(0, 2); c = req_locale.substring(3); } catch (Exception e) { log.warn("Invalid locale format " + req_locale); l = null; c = null; } } if (l != null && c != null) { String storeLang = null; Map languages = store.getGetSupportedLanguages(); if (languages != null && languages.size() > 0) { Iterator i = languages.keySet().iterator(); while (i.hasNext()) { Integer langKey = (Integer) i.next(); Language lang = (Language) languages.get(langKey); if (lang.getCode().equals(l)) { storeLang = l; break; } } } if (storeLang == null) { l = store.getDefaultLang(); if (StringUtils.isBlank(l)) { l = LanguageUtil.getDefaultLanguage(); } } locale = new Locale(l, c); if (StringUtils.isBlank(locale.getLanguage()) || StringUtils.isBlank(locale.getCountry())) { log.error("Language or Country is not set in the new locale " + req_locale); return; } sessions.put("WW_TRANS_I18N_LOCALE", locale); } } locale = (Locale) sessions.get("WW_TRANS_I18N_LOCALE"); request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", locale); if (locale == null) { String c = CountryUtil.getCountryIsoCodeById(store.getCountry()); String lang = store.getDefaultLang(); if (!StringUtils.isBlank(c) && !StringUtils.isBlank(lang)) { locale = new Locale(lang, c); } else { locale = LocaleUtil.getDefaultLocale(); String langs = store.getSupportedlanguages(); if (!StringUtils.isBlank(langs)) { Map languages = store.getGetSupportedLanguages(); String defaultLang = locale.getLanguage(); if (languages != null && languages.size() > 0) { Iterator i = languages.keySet().iterator(); String storeLang = ""; while (i.hasNext()) { Integer langKey = (Integer) i.next(); Language l = (Language) languages.get(langKey); if (l.getCode().equals(defaultLang)) { storeLang = defaultLang; break; } } if (!storeLang.equals(defaultLang)) { defaultLang = storeLang; } } if (!StringUtils.isBlank(defaultLang) && !StringUtils.isBlank(c)) { locale = new Locale(defaultLang, c); } } } sessions.put("WW_TRANS_I18N_LOCALE", locale); } if (locale != null) { LabelUtil label = LabelUtil.getInstance(); label.setLocale(locale); String lang = label.getText("label.language." + locale.getLanguage()); request.setAttribute("LANGUAGE", lang); } if (store.getLanguages() == null || store.getLanguages().size() == 0) { // languages if (!StringUtils.isBlank(store.getSupportedlanguages())) { List languages = new ArrayList(); List langs = LanguageUtil.parseLanguages(store.getSupportedlanguages()); for (Object o : langs) { String lang = (String) o; Language l = LanguageUtil.getLanguageByCode(lang); if (l != null) { l.setLocale(locale, store.getCurrency()); languages.add(l); } } store.setLanguages(languages); } } request.setAttribute("LOCALE", locale); Cookie c = new Cookie("LOCALE", locale.getLanguage() + "_" + locale.getCountry()); c.setPath("/"); c.setMaxAge(2 * 24 * 24); response.addCookie(c); }
From source file:com.netsteadfast.greenstep.base.model.SqlGenerateUtil.java
public static Map<String, Object> getInsert(Object entityObject) throws Exception { String tableName = getTableName(entityObject); Map<String, Object> queryMap = new HashMap<String, Object>(); Map<String, Object> fieldMap = getField(entityObject); if ("".equals(tableName.trim()) || fieldMap == null || fieldMap.size() < 1) { throw new java.lang.IllegalArgumentException(NOT_ENTITY_BEAN); }/* ww w . j a v a 2s .com*/ int field = 0; StringBuilder sql = new StringBuilder(); Object params[] = new Object[fieldMap.size()]; sql.append(" insert into ").append(tableName).append(" ( "); for (Map.Entry<String, Object> entry : fieldMap.entrySet()) { params[field] = entry.getValue(); field++; sql.append(" ").append(entry.getKey()); if (field < fieldMap.size()) { sql.append(", "); } } sql.append(" ) "); sql.append(" values ( "); for (int ix = 1; ix <= params.length; ix++) { sql.append(" ").append("?"); if (ix < fieldMap.size()) { sql.append(", "); } } sql.append(" ) "); queryMap.put(RETURN_SQL, sql.toString()); queryMap.put(RETURN_PARAMS, params); return queryMap; }
From source file:io.mycat.server.packet.util.CharsetUtil.java
/** * ? ? charset collation(? mycat.xml dataHosts mysqld? charset collation ) * @param charsetConfigMap mycat.xml charset-config collationIndex charsetName *//*w w w .j a v a2 s .c o m*/ public static void load(Map<String, PhysicalDBPool> dataHosts, Map<String, Object> charsetConfigMap) { try { if (dataHosts != null && dataHosts.size() > 0) CharsetUtil.initCharsetAndCollation(dataHosts); // mysqld? charset collation else logger.debug("param dataHosts is null"); // ? collationIndex --> charsetName for (String index : charsetConfigMap.keySet()) { int collationIndex = Integer.parseInt(index); String charsetName = INDEX_TO_CHARSET.get(collationIndex); if (StringUtils.isNotBlank(charsetName)) { INDEX_TO_CHARSET.put(collationIndex, charsetName); CHARSET_TO_INDEX.put(charsetName, collationIndex); } logger.debug("load charset and collation from mycat.xml."); } } catch (Exception e) { logger.error(e.getMessage()); } }
From source file:com.concursive.connect.web.modules.calendar.utils.DimDimUtils.java
private static String buildDimdimUrl(Map<String, String> param) { if (param.size() < 1) { return ""; }/*from ww w. ja va2s . c o m*/ //query string start char String queryString = "?"; //append name value pair prefixed with amp symbol for (String name : param.keySet()) { //discard the 'response' param from query string if (!"response".equalsIgnoreCase(name)) { queryString += "&" + name + "=" + param.get(name); } } return queryString; }
From source file:com.googlecode.blaisemath.app.MenuConfig.java
/** Convert a map with a single entry to the entry */ static <X> Entry<String, X> singletonMapEntry(Map<String, X> map) { checkArgument(map != null);//from w ww . j a v a2 s .co m checkArgument(map.size() == 1); return map.entrySet().iterator().next(); }
From source file:com.feilong.commons.core.io.CSVUtil.java
/** * .<br>//from w ww . j a v a 2s.c o m * {@link com.feilong.commons.core.bean.BeanUtil#describe(Object)} ? * * @param <T> * the generic type * @param fileName * the file name * @param collection * the iterable * @param excludePropertyNames * ?? * @throws UncheckedIOException * the unchecked io exception * @throws IllegalArgumentException * the illegal argument exception * @see #write(String, String[], List, CSVParams) * @see com.feilong.commons.core.bean.BeanUtil#describe(Object) * @see org.apache.commons.beanutils.ConvertUtils#convert(Object) * @since 1.0.9 */ public static final <T> void write(String fileName, Collection<T> collection, String[] excludePropertyNames) throws UncheckedIOException, IllegalArgumentException { if (Validator.isNullOrEmpty(fileName)) { throw new NullPointerException("fileName can't be null/empty!"); } if (Validator.isNullOrEmpty(collection)) { throw new NullPointerException("iterable can't be null/empty!"); } String[] columnTitles = null; List<Object[]> dataList = new ArrayList<Object[]>(collection.size()); for (T t : collection) { // Map<String, Object> fieldValueMap = FieldUtil.getFieldValueMap(t, excludeFields); Map<String, Object> propertyValueMap = PropertyUtil.describe(t); propertyValueMap = MapUtil.getSubMapExcludeKeys(propertyValueMap, excludePropertyNames); int size = propertyValueMap.size(); Object[] rowData = new Object[size]; //?? if (null == columnTitles) { columnTitles = new String[size]; } int i = 0; for (Map.Entry<String, Object> entry : propertyValueMap.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (Validator.isNullOrEmpty(value)) { rowData[i] = StringUtils.EMPTY; } else { //rowData[i] = ConvertUtils.convert(value); rowData[i] = ConvertUtils.convert(value, String.class); } columnTitles[i] = key; i++; } dataList.add(rowData); } write(fileName, columnTitles, dataList, new CSVParams()); }
From source file:com.geewhiz.pacify.utils.ArchiveUtils.java
public static File extractFile(File archive, String archiveType, String file) { Map<String, File> result = extractFiles(archive, archiveType, file, false); if (result.size() == 0) return null; if (result.size() > 1) throw new DefectRuntimeException( "We got more than one File for [" + file + "] in archive [" + archive.getName() + "]."); return result.get(file); }
From source file:Main.java
/** * Converts <code>params</code> into an application/x-www-form-urlencoded encoded string. *///from w w w . j a va 2s .c om public static String encodeParamsToStr(Map<String, String> params, String paramsEncoding) { StringBuilder encodedParams = new StringBuilder(); try { int i = 0; for (Map.Entry<String, String> entry : params.entrySet()) { encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding)); encodedParams.append('='); encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding)); if (i != params.size() - 1) { encodedParams.append('&'); } i++; } return encodedParams.toString(); } catch (UnsupportedEncodingException uee) { throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee); } }
From source file:com.datumbox.framework.core.common.dataobjects.DataframeMatrix.java
/** * Parses a single Record and converts it to RealVector by using an already * existing mapping between feature names and column ids. * //from w w w . ja v a 2 s .c o m * @param r * @param featureIdsReference * @return */ public static RealVector parseRecord(Record r, Map<Object, Integer> featureIdsReference) { if (featureIdsReference.isEmpty()) { throw new IllegalArgumentException("The featureIdsReference map should not be empty."); } int d = featureIdsReference.size(); //create an Map-backed vector only if we have available info about configuration. RealVector v = (storageEngine != null) ? new MapRealVector(d) : new OpenMapRealVector(d); boolean addConstantColumn = featureIdsReference.containsKey(Dataframe.COLUMN_NAME_CONSTANT); if (addConstantColumn) { v.setEntry(0, 1.0); //add the constant column } for (Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Double value = TypeInference.toDouble(entry.getValue()); if (value != null) { Integer featureId = featureIdsReference.get(feature); if (featureId != null) {//if the feature exists v.setEntry(featureId, value); } } else { //else the X matrix maintains the 0.0 default value } } return v; }
From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java
/** * Return oracle style argument to java list * // www .ja v a2 s. c o m * @param mapIndex * @param strArgument * @return * @throws RESTFulArgumentNotMatchException * @throws UnsupportedEncodingException */ public static List<Object> makeArgumentToOracleList(Map<Integer, String> mapIndex, String strArgument) throws RESTFulArgumentNotMatchException, RESTFULUnsupportedEncodingException { List<Object> listParam = new ArrayList<Object>(); Map<String, String> params = maekArgumentTOMap(strArgument); for (int i = 1; i <= mapIndex.size(); i++) { String strKey = mapIndex.get(i); if (!params.containsKey(strKey)) { throw new RESTFulArgumentNotMatchException( "SQL Parameter not found. Must have to key name is " + strKey); } else { listParam.add(params.get(strKey)); } } return listParam; }