Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

In this page you can find the example usage for java.util Set iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:com.glaf.core.util.HttpQueryUtils.java

public static BaseQuery prepareQuery(HttpServletRequest request, HttpServletResponse response,
        String serviceKey, Map<String, Object> paramMap) {
    BaseQuery query = new BaseQuery();
    Map<String, Object> params = new java.util.HashMap<String, Object>();
    List<QueryCondition> conditions = new java.util.ArrayList<QueryCondition>();
    JSONObject rootJson = new JSONObject();
    JSONObject paramJson = new JSONObject();
    JSONObject queryJson = new JSONObject();

    String qt = getStringValue(request, "qt");
    String qid = getStringValue(request, "qid");
    String field = getStringValue(request, "field");
    boolean removeLast = getBooleanValue(request, "removeLast");

    queryJson.put("removeLast", removeLast);

    if (serviceKey != null) {
        queryJson.put("serviceKey", serviceKey);
    }/*from  w w  w  . j a v a 2s .c om*/
    if (qt != null) {
        queryJson.put("qt", qt);
    }
    if (qid != null) {
        queryJson.put("qid", qid);
    }
    if (field != null) {
        queryJson.put("field", field);
    }

    /**
     * IP?Cookie
     */
    String ip = RequestUtils.getIPAddress(request);
    String cookieKey = ip + "_mx_query_" + serviceKey;
    cookieKey = Hex.bytesToHex(cookieKey.getBytes());

    String content = null;

    Cookie[] cookies = request.getCookies();
    if (cookies != null && cookies.length > 0) {
        for (Cookie cookie : cookies) {
            /**
             * Cookie???
             */
            if (StringUtils.equals(cookie.getName(), cookieKey)) {
                content = cookie.getValue();
            }
        }
    }

    JSONObject oldJson = null;

    if (StringUtils.isNotEmpty(content)) {
        String str = new String(Hex.hexToBytes(content));
        if (str != null) {
            oldJson = JSON.parseObject(str);
        }
    }

    Object value = null;
    String fieldValue = null;
    QueryCondition currentCondition = null;

    if (oldJson != null) {
        logger.debug("@@previous query json:\n" + oldJson.toJSONString());
        JSONObject paramJx = oldJson.getJSONObject("params");
        if (paramJx != null && !paramJx.isEmpty()) {
            Set<String> keySet = paramJx.keySet();
            Iterator<String> iterator = keySet.iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                if (paramJx.getString(key) != null) {
                    params.put(key, paramJx.getString(key));
                    paramJson.put(key, paramJx.getString(key));
                }
            }
        }

        JSONObject conjx = oldJson.getJSONObject("currentCondition");
        if (conjx != null && conjx.get("value") != null) {
            currentCondition = new QueryCondition();
            currentCondition.setAlias(conjx.getString("alias"));
            currentCondition.setName(conjx.getString("name"));
            currentCondition.setColumn(conjx.getString("column"));
            currentCondition.setType(conjx.getString("type"));
            currentCondition.setFilter(conjx.getString("filter"));
            currentCondition.setStringValue(conjx.getString("stringValue"));
            currentCondition.setValue(conjx.get("value"));
        }
    }

    Enumeration<?> enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) {
        String paramName = (String) enumeration.nextElement();
        String paramValue = getStringValue(request, paramName);
        if (paramName != null) {
            if (StringUtils.isNotEmpty(paramValue)) {
                params.put(paramName, paramValue);
                paramJson.put(paramName, paramValue);
            }
        }
    }

    if (paramMap != null && !paramMap.isEmpty()) {
        if (paramMap != null && paramMap.size() > 0) {
            Set<Entry<String, Object>> entrySet = paramMap.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                String name = entry.getKey();
                Object v = entry.getValue();
                if (name != null && v != null) {
                    params.put(name, v);
                    paramJson.put(name, v);
                }
            }
        }
    }

    if (qt == null) {
        qt = (String) params.get("qt");
    }
    if (qid == null) {
        qid = (String) params.get("qid");
    }
    if (field == null) {
        field = (String) params.get("field");
    }

    /**
     * ??
     */
    if (StringUtils.isNotEmpty(qid)) {
        EntityService entityService = ContextFactory.getBean("entityService");
        /**
         * ?????
         */
        List<Object> rows = entityService.getList(qid, params);
        if (rows != null && rows.size() > 0) {
            for (Object object : rows) {
                if (object instanceof ColumnDefinition) {
                    ColumnDefinition column = (ColumnDefinition) object;
                    query.addColumn(column.getName(), column.getColumnName());
                    if (StringUtils.isNotEmpty(field) && StringUtils.equals(field, column.getName())) {
                        fieldValue = request.getParameter(field);
                        if (StringUtils.isNotEmpty(fieldValue)) {
                            String alias = getStringValue(request, "alias");
                            String filter = getStringValue(request, "filter");
                            if (StringUtils.isEmpty(alias)) {
                                alias = getStringValue(request, field + "_alias");
                            }
                            if (StringUtils.isEmpty(filter)) {
                                filter = getStringValue(request, field + "_filter");
                            }
                            String type = column.getJavaType();
                            if (StringUtils.equalsIgnoreCase(type, "datetime")
                                    || StringUtils.equalsIgnoreCase(type, "Date")) {
                                type = "Date";
                                value = fieldValue;
                                if (StringUtils.isEmpty(filter)) {
                                    filter = SearchFilter.GREATER_THAN_OR_EQUAL;
                                }
                            } else if (StringUtils.equalsIgnoreCase(type, "i4")
                                    || StringUtils.equalsIgnoreCase(type, "Integer")) {
                                type = "Integer";
                                value = Integer.parseInt(fieldValue);
                                if (StringUtils.isEmpty(filter)) {
                                    filter = SearchFilter.GREATER_THAN_OR_EQUAL;
                                }
                            } else if (StringUtils.equalsIgnoreCase(type, "i8")
                                    || StringUtils.equalsIgnoreCase(type, "Long")) {
                                type = "Long";
                                value = Long.parseLong(fieldValue);
                                if (StringUtils.isEmpty(filter)) {
                                    filter = SearchFilter.GREATER_THAN_OR_EQUAL;
                                }
                            } else if (StringUtils.equalsIgnoreCase(type, "r8")
                                    || StringUtils.equalsIgnoreCase(type, "Double")) {
                                type = "Double";
                                value = Double.parseDouble(fieldValue);
                                if (StringUtils.isEmpty(filter)) {
                                    filter = SearchFilter.GREATER_THAN_OR_EQUAL;
                                }
                            } else if (StringUtils.equalsIgnoreCase(type, "String")) {
                                type = "String";
                                value = fieldValue;
                                if (StringUtils.isEmpty(filter)) {
                                    filter = SearchFilter.LIKE;
                                }
                                if (StringUtils.equals(filter, SearchFilter.LIKE)) {
                                    value = "%" + fieldValue + "%";
                                }
                            }
                            if (value != null && filter != null) {
                                currentCondition = new QueryCondition();
                                currentCondition.setType(type);
                                currentCondition.setAlias(alias);
                                currentCondition.setName(field);
                                currentCondition.setColumn(column.getColumnName());
                                currentCondition.setFilter(filter);
                                currentCondition.setStringValue(fieldValue);
                                currentCondition.setValue(value);
                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * CookieSession??Ta???
     */
    if (oldJson != null) {
        JSONArray array = oldJson.getJSONArray("conditions");
        if (array != null) {
            // logger.debug("previous conditions:" + array.toJSONString());
            int size = array.size();
            for (int i = 0; i < size; i++) {
                JSONObject json = array.getJSONObject(i);
                QueryCondition c = new QueryCondition();
                c.setAlias(json.getString("alias"));
                c.setName(json.getString("name"));
                c.setColumn(json.getString("column"));
                c.setType(json.getString("type"));
                c.setFilter(json.getString("filter"));
                String val = json.getString("stringValue");

                if (StringUtils.equals(c.getType(), "Date")) {
                    c.setValue(DateUtils.toDate(val));
                    c.setStringValue(val);
                } else if (StringUtils.equals(c.getType(), "Integer")) {
                    c.setValue(Integer.parseInt(val));
                    c.setStringValue(val);
                } else if (StringUtils.equals(c.getType(), "Long")) {
                    c.setValue(Long.parseLong(val));
                    c.setStringValue(val);
                } else if (StringUtils.equals(c.getType(), "Double")) {
                    c.setValue(Double.parseDouble(val));
                    c.setStringValue(val);
                } else if (StringUtils.equals(c.getType(), "Boolean")) {
                    c.setValue(Boolean.valueOf(val));
                    c.setStringValue(val);
                } else {
                    c.setValue(json.get("value"));
                    c.setStringValue(val);
                }

                if (!conditions.contains(c)) {
                    conditions.add(c);
                }
            }
        }
        /**
         * ?
         */
        if (removeLast && conditions.size() > 0) {
            conditions.remove(conditions.size() - 1);
        }
    }

    /**
     * ????
     */
    if (StringUtils.equals("R", qt)) {
        logger.debug("#### clear conditions");
        conditions.clear();
    }

    if (currentCondition != null && currentCondition.getValue() != null) {
        query.setCurrentQueryCondition(currentCondition);
        if (!conditions.contains(currentCondition)) {
            conditions.add(currentCondition);
        }
        JSONObject json = new JSONObject();
        if (currentCondition.getAlias() != null) {
            json.put("alias", currentCondition.getAlias());
        }
        json.put("name", currentCondition.getName());
        json.put("column", currentCondition.getColumn());
        json.put("type", currentCondition.getType());
        json.put("filter", currentCondition.getFilter());
        json.put("value", currentCondition.getValue());
        json.put("stringValue", currentCondition.getStringValue());
        json.put("index", 0);
        rootJson.put("currentCondition", json);
    }

    if (conditions.size() > 0) {
        JSONArray jsonArray = new JSONArray();
        int index = 0;
        for (QueryCondition c : conditions) {
            if (c.getValue() != null) {
                JSONObject json = new JSONObject();
                if (c.getAlias() != null) {
                    json.put("alias", c.getAlias());
                }
                json.put("name", c.getName());
                json.put("column", c.getColumn());
                json.put("type", c.getType());
                json.put("filter", c.getFilter());
                json.put("value", c.getValue());
                json.put("stringValue", c.getStringValue());
                json.put("index", index++);
                jsonArray.add(json);
            }
        }
        rootJson.put("conditions", jsonArray);
    }

    rootJson.put("query", queryJson);
    rootJson.put("params", paramJson);

    String jsonText = rootJson.toJSONString();
    logger.debug("prepare query json:\n" + jsonText);

    jsonText = Hex.bytesToHex(jsonText.getBytes());

    if (response != null) {
        Cookie cookie = new Cookie(cookieKey, jsonText);
        response.addCookie(cookie);
    }

    query.setParameter(params);
    query.getParameters().putAll(params);

    logger.debug("#conditions:" + conditions);

    for (QueryCondition condition : conditions) {
        query.addCondition(condition);
    }

    return query;
}

From source file:com.smart.utils.ReflectionUtils.java

/**
 * ?Class?(?),ListClass/*from   w  w  w  .j av  a 2s.  co  m*/
 * 
 * @param bean
 * @return
 */
public static List<Class> getAllInterfaceOfClazz(Class clz) {
    List allClass = getAllClassesOfClazz(clz);
    // ??
    Set s = new HashSet();
    for (int i = 0; i < allClass.size(); i++) {
        Class clazz = (Class) allClass.get(i);
        List temp = getInterfaceOfClass(clazz);
        s.addAll(temp);
    }
    List result = new LinkedList();
    Iterator itrt = s.iterator();
    while (itrt.hasNext()) {
        Class c = (Class) itrt.next();
        result.add(c);
    }
    return result;

}

From source file:com.stratio.deep.cassandra.util.CassandraUtils.java

/**
 * Returns an instance of the Cassandra validator that matches the provided object.
 *
 * @param obj the object to use to resolve the cassandra marshaller.
 * @param <T> the generic object type.
 * @return an instance of the Cassandra validator that matches the provided object.
 * @throws com.stratio.deep.commons.exception.DeepGenericException if no validator can be found for the specified object.
 *//*from  w w  w  . j  av  a 2  s . com*/
public static <T> AbstractType<?> marshallerInstance(T obj) {

    AbstractType<?> abstractType = null;

    if (obj != null) {
        abstractType = MAP_JAVA_TYPE_TO_ABSTRACT_TYPE.get(obj.getClass());

        if (obj instanceof UUID) {
            UUID uuid = (UUID) obj;

            if (uuid.version() == 1) {
                abstractType = TimeUUIDType.instance;

            } else {
                abstractType = UUIDType.instance;
            }
        }

        if (abstractType == null) {
            //LIST Case
            if (List.class.isAssignableFrom(obj.getClass())) {

                List list = (List) obj;
                if (!list.isEmpty()) {
                    abstractType = ListType.getInstance(marshallerInstance(list.get(0)));
                }

            }
            // SET Case
            else if (Set.class.isAssignableFrom(obj.getClass())) {
                Set set = (Set) obj;
                if (!set.isEmpty()) {
                    java.util.Iterator i = set.iterator();
                    Object o = i.next();
                    abstractType = SetType.getInstance(marshallerInstance(o));
                }
            }
            // MAP Case
            else if (Map.class.isAssignableFrom(obj.getClass())) {
                Set set = ((Map) obj).keySet();
                if (!set.isEmpty()) {
                    java.util.Iterator i = set.iterator();
                    Object o = i.next();
                    abstractType = MapType.getInstance(marshallerInstance(o),
                            marshallerInstance(((Map) obj).get(o)));

                }

            }
        }

    }

    if (abstractType == null) {
        throw new DeepGenericException("parameter class " + obj.getClass().getCanonicalName()
                + " does not have a" + " Cassandra marshaller");
    }

    return abstractType;
}

From source file:com.ery.hadoop.mrddx.hbase.HbaseInputFormat.java

/**
 * ??//from  w  w  w  . j  a  v a2 s  . c  o  m
 * 
 * @param dbConf ??
 * @param tableName ??
 * @return true ?
 * @throws TableNotFoundException ?
 * @throws IOException
 */
protected static boolean validateCondition(HbaseConfiguration dbConf, String tableName)
        throws TableNotFoundException, IOException {
    if (null == tableName) {
        return false;
    }

    HBaseAdmin admin = new HBaseAdmin(dbConf.getConf());
    HTableDescriptor tableDes = admin.getTableDescriptor(tableName.getBytes());
    // ???
    Set<byte[]> setByte = tableDes.getFamiliesKeys();
    Set<String> familySets = new HashSet<String>();
    Iterator<byte[]> iterator = setByte.iterator();
    while (iterator.hasNext()) {
        familySets.add(new String(iterator.next()));
    }

    // check column and family
    String familyColumns[] = dbConf.getInputHBaseQueryFamilyColumns();
    if (null != familyColumns) {
        for (int i = 0; i < familyColumns.length; i++) {
            if (null == familyColumns[i] || familyColumns[i].trim().length() <= 0) {
                String meg = "The parameter of columnfamily is null!";
                MRLog.error(LOG, meg);
                return false;
            }

            String fcolumn[] = familyColumns[i].split(HbaseConfiguration.sign_colon);
            if (fcolumn.length != 2) {
                String meg = "The parameter of columnfamily is format error !";
                MRLog.error(LOG, meg);
                return false;
            }

            // check column
            HColumnDescriptor hcDesc = tableDes.getFamily(fcolumn[0].getBytes());
            if (!(null != hcDesc && familySets.contains(fcolumn[0])
                    && fcolumn[0].equals(new String(hcDesc.getName())))) {
                String meg = "Column is not exist! column:" + fcolumn[0];
                MRLog.error(LOG, meg);
                return false;
            }
        }
    }

    // check family
    String familys[] = dbConf.getInputHBaseQueryFamilys();
    if (null != familys) {
        for (int i = 0; i < familys.length; i++) {
            if (!familySets.contains(familys[i])) {
                String meg = "Family is not exist! family:" + familys[i];
                MRLog.error(LOG, meg);
                return false;
            }
        }
    }

    return true;
}

From source file:com.glaf.base.utils.HibernateUtil.java

/**
 * /*from w  w  w  .j  a  v a2 s.  co  m*/
 * @param map
 * @param forClass
 * @return
 */
public static DetachedCriteria getCriteria(Map<String, String> map, Class<?> forClass) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(forClass);
    Set<String> params = map.keySet();
    // boolean createAliased = false;
    if (params != null) {
        Map<String, String> aliasMap = new java.util.HashMap<String, String>();// ??
        int aliasNum = 0;// ???
        Iterator<String> it = params.iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            String value = map.get(key) == null ? null : map.get(key).toString();
            value = value == null ? value : value.trim();
            if (key.startsWith(QUERY_PREFIX) && value != null && value.trim().length() > 0) {
                // ??
                String name = key.substring(QUERY_PREFIX.length());
                // ?? "="
                String op = "eq";
                if (name.indexOf("_") != -1) {
                    int pos = name.lastIndexOf("_");
                    op = name.substring(pos + 1);
                    name = name.substring(0, pos);
                }

                if ("me".equals(op)) { //  ?????
                    String maintAlias = detachedCriteria.getAlias();
                    // ? string 
                    detachedCriteria.add(Restrictions.sqlRestriction(maintAlias + "_." + name + "=" + value));

                } else if ("zns".equals(op)) { // 
                    // ? string 
                    detachedCriteria.add(Restrictions.sqlRestriction(" 1 = 2 "));

                } else if ("mn".equals(op)) { //  ?????
                    String maintAlias = detachedCriteria.getAlias();
                    // ? string 
                    detachedCriteria.add(Restrictions.sqlRestriction(maintAlias + "_." + name + " is NULL "));

                } else if ("mnn".equals(op)) { //  ?????
                    String maintAlias = detachedCriteria.getAlias();
                    // ? string 
                    detachedCriteria
                            .add(Restrictions.sqlRestriction(maintAlias + "_." + name + " is not NULL "));

                } else if ("md".equals(op)) { //  ?????
                    String maintAlias = detachedCriteria.getAlias();
                    // ? string 
                    detachedCriteria.add(Restrictions.sqlRestriction(maintAlias + "_." + name + "=?",
                            DateUtils.toDate(value), StandardBasicTypes.DATE));

                } else if ("mis".equals(op)) { // in( ?_select )
                    String maintAlias = detachedCriteria.getAlias();
                    // ? string 
                    detachedCriteria.add(
                            Restrictions.sqlRestriction(maintAlias + "_." + name + " in (" + value + ") "));
                } else if ("xd".equals(op)) { //  . date
                    // ? string 
                    int pos = name.lastIndexOf(".");
                    String alias = name.substring(0, pos);
                    name = name.substring(pos + 1);
                    if (aliasMap.get(alias) == null) {
                        detachedCriteria.createAlias(alias, alias);
                        aliasNum++;
                        aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                    }
                    detachedCriteria.add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + "=? ",
                            DateUtils.toDate(value), StandardBasicTypes.DATE));
                } else if ("xs".equals(op)) { //  . String
                    // ? string 
                    int pos = name.lastIndexOf(".");
                    String alias = name.substring(0, pos);
                    name = name.substring(pos + 1);
                    if (aliasMap.get(alias) == null) {
                        detachedCriteria.createAlias(alias, alias);
                        aliasNum++;
                        aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                    }
                    detachedCriteria
                            .add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + "='" + value + "' "));
                } else if ("xe".equals(op)) { //  .  
                    if (!value.equals("") && Integer.parseInt(value) > 0) {
                        int pos = name.lastIndexOf(".");
                        String alias = name.substring(0, pos);
                        name = name.substring(pos + 1);
                        if (aliasMap.get(alias) == null) {
                            detachedCriteria.createAlias(alias, alias);
                            aliasNum++;
                            aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                        }
                        detachedCriteria
                                .add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + "=" + value));
                    }
                } else if ("ixe".equals(op)) { //  .  
                    if (!value.equals("") && Integer.parseInt(value) >= 0) {
                        int pos = name.lastIndexOf(".");
                        String alias = name.substring(0, pos);
                        name = name.substring(pos + 1);
                        if (aliasMap.get(alias) == null) {
                            detachedCriteria.createAlias(alias, alias);
                            aliasNum++;
                            aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                        }
                        detachedCriteria
                                .add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + "=" + value));
                    }
                } else if ("xel".equals(op)) { //  .  
                    if (!value.equals("") && Long.parseLong(value) != -1) {
                        int pos = name.lastIndexOf(".");
                        String alias = name.substring(0, pos);
                        name = name.substring(pos + 1);
                        if (aliasMap.get(alias) == null) {
                            detachedCriteria.createAlias(alias, alias);
                            aliasNum++;
                            aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                        }
                        detachedCriteria
                                .add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + "=" + value));
                    }
                } else if ("xne".equals(op)) { //  .  
                    if (!value.equals("") && Integer.parseInt(value) != -1) {
                        int pos = name.lastIndexOf(".");
                        String alias = name.substring(0, pos);
                        name = name.substring(pos + 1);
                        if (aliasMap.get(alias) == null) {
                            detachedCriteria.createAlias(alias, alias);
                            aliasNum++;
                            aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                        }
                        detachedCriteria
                                .add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + "<>" + value));
                    }
                } else if ("xi".equals(op)) { //  . in () String
                    int pos = name.lastIndexOf(".");
                    String alias = name.substring(0, pos);
                    name = name.substring(pos + 1);
                    if (aliasMap.get(alias) == null) {
                        detachedCriteria.createAlias(alias, alias);
                        aliasNum++;
                        aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                    }
                    // ? string 
                    detachedCriteria.add(
                            Restrictions.sqlRestriction(aliasMap.get(alias) + name + " in (" + value + ") "));
                } else if ("xl".equals(op)) { //  like . String
                    int pos = name.lastIndexOf(".");
                    String alias = name.substring(0, pos);
                    name = name.substring(pos + 1);
                    if (aliasMap.get(alias) == null) {
                        detachedCriteria.createAlias(alias, alias);
                        aliasNum++;
                        aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                    }
                    detachedCriteria.add(Restrictions
                            .sqlRestriction(aliasMap.get(alias) + name + " like '%" + value + "%'"));
                } else if (op.startsWith("xdate")) { // Date
                    String dateOp = "=";
                    if ("xdatelt".equals(op)) {
                        dateOp = "<";
                    } else if ("xdategt".equals(op)) {
                        dateOp = ">";
                    } else if ("xdatele".equals(op)) {
                        dateOp = "<=";
                    } else if ("xdatege".equals(op)) {
                        dateOp = ">=";
                    }
                    int pos = name.lastIndexOf(".");
                    String alias = name.substring(0, pos);
                    name = name.substring(pos + 1);
                    if (aliasMap.get(alias) == null) {
                        detachedCriteria.createAlias(alias, alias);
                        aliasNum++;
                        aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                    }
                    detachedCriteria.add(Restrictions.sqlRestriction(aliasMap.get(alias) + name + dateOp + "?",
                            DateUtils.toDate(value), StandardBasicTypes.DATE));
                } else if (op.startsWith("date")) { // Date
                    String dateOp = "=";
                    if ("datelt".equals(op)) {
                        dateOp = "<";
                    } else if ("dategt".equals(op)) {
                        dateOp = ">";
                    } else if ("datele".equals(op)) {
                        dateOp = "<=";
                    } else if ("datege".equals(op)) {
                        dateOp = ">=";
                    }
                    detachedCriteria.add(Restrictions.sqlRestriction(name + dateOp + "?",
                            DateUtils.toDate(value), StandardBasicTypes.DATE));
                } /*
                  * else if(op.equals("double")){ //Double String doubleOp
                  * = "="; if("double".equals(op)){ } }
                  */else if ("like".equals(op)) { // like
                    detachedCriteria.add(Restrictions.like(name, "%" + value + "%"));
                } else if ("es".equals(op)) {
                    // if(Integer.parseInt(value) != -1){
                    detachedCriteria
                            .add(Restrictions.sqlRestriction(name + " = ? ", value, StandardBasicTypes.STRING));
                    // }
                } else if ("ex".equals(op)) { // =int
                    if (Integer.parseInt(value) != -1) {
                        detachedCriteria.add(Restrictions.eq(name, new Integer(value)));
                    }
                } else if ("el".equals(op)) { // =long
                    if (Long.parseLong(value) != -1) {
                        detachedCriteria.add(Restrictions.eq(name, new Long(value)));
                    }
                } else if ("ed".equals(op)) { // =double
                    if (Double.parseDouble(value) != -1) {
                        detachedCriteria.add(Restrictions.eq(name, new Double(value)));
                    }
                } else if ("nei".equals(op)) { // <>int
                    if (Integer.parseInt(value) != -1) {
                        detachedCriteria.add(Restrictions.ne(name, new Integer(value)));
                    }
                } else if ("nel".equals(op)) { // <>long
                    if (Long.parseLong(value) != -1) {
                        detachedCriteria.add(Restrictions.ne(name, new Long(value)));
                    }
                } else if ("in".equals(op)) { // in ()
                    if (!"".trim().equals(value)) {
                        String maintAlias = detachedCriteria.getAlias();
                        detachedCriteria.add(
                                Restrictions.sqlRestriction(maintAlias + "_." + name + " in (" + value + ") "));
                        // detachedCriteria.add(Restrictions
                        // .sqlRestriction(name + " in (" + value
                        // + ") "));
                    }
                } else if ("nin".equals(op)) { // not in ()
                    if (!"".trim().equals(value)) {
                        String maintAlias = detachedCriteria.getAlias();
                        detachedCriteria.add(Restrictions
                                .sqlRestriction(maintAlias + "_." + name + " not in (" + value + ") "));
                        // detachedCriteria.add(Restrictions
                        // .sqlRestriction(name + " not in (" + value
                        // + ") "));
                    }
                } else {
                    detachedCriteria.add(Restrictions.eq(name, value));
                }
            } else if (key.startsWith(ORDER_PREFIX)) {
                // ????? //order__asc(desc) ? hidden 
                String name = key.substring(ORDER_PREFIX.length());

                int pos = name.lastIndexOf(".");
                if (pos != -1) {
                    String alias = name.substring(0, pos);
                    if (aliasMap.get(alias) == null) {
                        detachedCriteria.createAlias(alias, alias);
                        aliasNum++;
                        aliasMap.put(alias, getNewAliasName(alias, aliasNum));
                    }
                }

                if (value.trim().equalsIgnoreCase("asc")) {
                    detachedCriteria.addOrder(Order.asc(name));
                } else {
                    detachedCriteria.addOrder(Order.desc(name));
                }
            }
        }
        map.putAll(aliasMap);
    }

    return detachedCriteria;
}

From source file:fr.inria.oak.paxquery.algebra.optimizer.rules.PushProjections.java

private static ColumnsMapping obtainMapping(Set<ProjectColumn> requiredFromBelow) {
    ColumnsMapping resultMapping = new ColumnsMapping();
    int here = 0;
    Iterator<ProjectColumn> it = requiredFromBelow.iterator();
    while (it.hasNext()) {
        ProjectColumn column = it.next();
        resultMapping.mappingColumns.put(column.pos, here++);
        if (!column.nestedColumns.isEmpty()) {
            ColumnsMapping nestedMapping = obtainMapping(column.nestedColumns);
            resultMapping.nestedMappingColumns.put(column.pos, nestedMapping);
        }/*  w w w . j a v  a2s .  com*/
    }
    return resultMapping;
}

From source file:com.krawler.workflow.module.dao.BaseBuilderDao.java

public static HashMap<String, String> getParamList(Map<String, String[]> list) {
    HashMap<String, String> resultList = new HashMap<String, String>();
    java.util.Set s1 = list.keySet();
    java.util.Iterator ite = s1.iterator();
    while (ite.hasNext()) {
        String key = (String) ite.next();
        String[] val = list.get(key);
        resultList.put(key, val[0]);

    }// ww  w.  ja  v a2s.c  o m
    return resultList;
}

From source file:io.starter.datamodel.Sys.java

/**
 * search and replace the strings in the input with delimiter %XX_SOMENAME%
 * with the map values://from  w w  w .  j av  a 2  s.c  o  m
 * 
 * "SOMENAME", "somevalue"
 * 
 * 
 * @param input
 * @param params
 * @return
 */
public static String stringRep(String input, Map<String, String> params) {

    if (params == null) {// unchanged
        Logger.warn("Sys.stringRep(): no parameters to replace. String unchanged.");
        return input;
    }

    Set<String> it = params.keySet();
    Iterator<String> its = it.iterator();

    // SEARCH AND REPLACE
    while (its.hasNext()) {
        String key = its.next();
        String o = String.valueOf(params.get(key));
        // transform to the replace string
        String find = "%" + key.toUpperCase() + "%";
        input = input.replace(find, o);

    }
    return input;
}

From source file:com.netscape.cms.servlet.csadmin.CertUtil.java

/**
 * reads from the admin cert profile caAdminCert.profile and determines the algorithm as follows:
 *
 * 1.  First gets list of allowed algorithms from profile (constraint.params.signingAlgsAllowed)
 *     If entry does not exist, uses entry "ca.profiles.defaultSigningAlgsAllowed" from CS.cfg
 *     If that entry does not exist, uses basic default
 *
 * 2.  Gets default.params.signingAlg from profile.
 *     If entry does not exist or equals "-", selects first algorithm in allowed algorithm list
 *     that matches CA signing key type//  w w w.ja  v a2 s .  c  om
 *     Otherwise returns entry if it matches signing CA key type.
 *
 * @throws EBaseException
 * @throws IOException
 * @throws FileNotFoundException
 */

public static String getAdminProfileAlgorithm(IConfigStore config)
        throws EBaseException, FileNotFoundException, IOException {
    String caSigningKeyType = config.getString("preop.cert.signing.keytype", "rsa");
    String pfile = config.getString("profile.caAdminCert.config");
    Properties props = new Properties();
    props.load(new FileInputStream(pfile));

    Set<String> keys = props.stringPropertyNames();
    Iterator<String> iter = keys.iterator();
    String defaultAlg = null;
    String[] algsAllowed = null;

    while (iter.hasNext()) {
        String key = iter.next();
        if (key.endsWith("default.params.signingAlg")) {
            defaultAlg = props.getProperty(key);
        }
        if (key.endsWith("constraint.params.signingAlgsAllowed")) {
            algsAllowed = StringUtils.split(props.getProperty(key), ",");
        }
    }

    if (algsAllowed == null) { //algsAllowed not defined in profile, use a global setting
        algsAllowed = StringUtils.split(config.getString("ca.profiles.defaultSigningAlgsAllowed",
                "SHA256withRSA,SHA256withEC,SHA1withDSA"), ",");
    }

    if (ArrayUtils.isEmpty(algsAllowed)) {
        throw new EBaseException("No allowed signing algorithms defined.");
    }

    if (StringUtils.isNotEmpty(defaultAlg) && !defaultAlg.equals("-")) {
        // check if the defined default algorithm is valid
        if (!isAlgorithmValid(caSigningKeyType, defaultAlg)) {
            throw new EBaseException("Administrator cert cannot be signed by specfied algorithm."
                    + "Algorithm incompatible with signing key");
        }

        for (String alg : algsAllowed) {
            if (defaultAlg.trim().equals(alg.trim())) {
                return defaultAlg;
            }
        }
        throw new EBaseException("Administrator Certificate cannot be signed by the specified algorithm "
                + "as it is not one of the allowed signing algorithms.  Check the admin cert profile.");
    }

    // no algorithm specified.  Pick the first allowed algorithm.
    for (String alg : algsAllowed) {
        if (isAlgorithmValid(caSigningKeyType, alg))
            return alg;
    }

    throw new EBaseException("Admin certificate cannot be signed by any of the specified possible algorithms."
            + "Algorithm is incompatible with the CA signing key type");
}

From source file:net.ontopia.topicmaps.utils.TopicMapSynchronizer.java

/**
 * PUBLIC: Updates the target topic map from the source topic map,
 * synchronizing the selected topics in the target (ttopicq) with
 * the selected topics in the source (stopicq) using the deciders to
 * filter topic characteristics to synchronize.
 * @param target the topic map to update
 * @param ttopicq tolog query selecting the target topics to update
 * @param tchard filter for the target characteristics to update
 * @param source the source topic map//from w ww  .  j a  va  2  s . c om
 * @param stopicq tolog query selecting the source topics to use
 * @param schard filter for the source characteristics to update
 */
public static void update(TopicMapIF target, String ttopicq, DeciderIF<TMObjectIF> tchard, TopicMapIF source,
        String stopicq, DeciderIF<TMObjectIF> schard) throws InvalidQueryException {
    // build sets of topics    
    Set<TopicIF> targetts = queryForSet(target, ttopicq);
    Set<TopicIF> sourcets = queryForSet(source, stopicq);

    // loop over source topics (we change targetts later, so we have to pass
    // a copy to the tracker)
    AssociationTracker tracker = new AssociationTracker(new CompactHashSet<TopicIF>(targetts), sourcets);
    Iterator<TopicIF> topicIterator = sourcets.iterator();
    while (topicIterator.hasNext()) {
        TopicIF stopic = topicIterator.next();
        TopicIF ttopic = getOrCreate(target, stopic);
        targetts.remove(ttopic);
        update(target, stopic, tchard, schard, tracker);
    }

    // remove extraneous associations
    Iterator<AssociationIF> associationIterator = tracker.getUnsupported().iterator();
    while (associationIterator.hasNext()) {
        AssociationIF assoc = associationIterator.next();
        log.debug("Tracker removing {}", assoc);
        assoc.remove();
    }

    // remove extraneous topics
    topicIterator = targetts.iterator();
    while (topicIterator.hasNext())
        topicIterator.next().remove();
}