Example usage for java.util List contains

List of usage examples for java.util List contains

Introduction

In this page you can find the example usage for java.util List contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:org.zht.framework.util.ZBeanUtil.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<?> removeDuplicateWithOrder(List list) {
    if (list == null || list.size() == 0) {
        return list;
    }//from   w w w .  j ava  2s  . c  o  m
    List newList = new ArrayList();
    for (Object object : list) {
        if (!newList.contains(object)) {
            newList.add(object);
        }
    }
    return newList;
}

From source file:de.knurt.fam.core.util.mvc.validator.JmValidationUtils.java

/**
 * Reject the given field if it's empty or is one of the given wrong values
 * /*from   ww w. j a v a2s  . com*/
 * @param errors
 *            the Errors instance to register errors on
 * @param field
 *            the field name to check
 * @param errorCode
 *            error code, interpretable as message key
 * @param errorArgs
 *            the error arguments, for argument binding via MessageFormat
 *            (can be null)
 * @param defaultMessage
 *            fallback default message
 * @param wrongValues
 *            list of values that are rejected
 */
public static void rejectIfEmptyOrOneOfValues(Errors errors, String field, String errorCode, Object[] errorArgs,
        String defaultMessage, List<String> wrongValues) {
    Object value = errors.getFieldValue(field);
    if (value == null || wrongValues.contains(value.toString())) {
        errors.rejectValue(field, errorCode, errorArgs, defaultMessage);
    }
}

From source file:org.zht.framework.util.ZBeanUtil.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object[] removeDuplicateWithOrder(Object[] array) {
    if (array == null || array.length == 0) {
        return array;
    }/*w  w  w  . j  a va  2 s.  c o  m*/
    List newList = new ArrayList();
    for (Object object : array) {
        if (!newList.contains(object)) {
            newList.add(object);
        }
    }
    Class elementType = array.getClass().getComponentType();
    Object[] newArray = (Object[]) java.lang.reflect.Array.newInstance(elementType, 0);
    array = newList.toArray(newArray);
    return array;
}

From source file:controllers.group.GroupMsgApp.java

/**
 * ???/*w w  w .  j av  a  2s .  c o m*/
 * @return
 * @throws IOException 
 */
@Transactional
public static Result agreeInvit() throws IOException {
    User currentUser = User.getFromSession(session());
    ObjectNodeResult result = new ObjectNodeResult();
    Long groupId = new Long(request().getQueryString("groupId"));
    Long messageId = new Long(request().getQueryString("messageId"));
    Group group = Group.queryGroupById(groupId);
    if (group == null)
        return ok(result.errorkey("group.error.nofound").getObjectNode());
    if (group.getType() != null && group.getType() == Group.Type.NORMAL) { // ??
        User recevierUser = User.findById(group.owner.userId);
        List<User> userList = Group.queryUserListOfGroup(groupId); // ?
        if (!userList.contains(currentUser)) { // ?
            ChatService.appendMemberToGroup(groupId, currentUser.id);
            MessageService.pushMsgInvitAgree(currentUser, recevierUser, group);
            MessageService.handlerMessage(messageId);
        } else {
            MessageService.handlerMessage(messageId);
            return ok(result.error("?.").getObjectNode());
        }

    }
    return ok(result.getObjectNode());
}

From source file:Main.java

public static Iterator getElementsByTagNames(Element element, String[] tags) {
    List<Element> children = new ArrayList<Element>();
    if (element != null && tags != null) {
        List tagList = Arrays.asList(tags);
        NodeList nodes = element.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node child = nodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && tagList.contains(((Element) child).getTagName())) {
                children.add((Element) child);
            }//from  w ww.  j a v a  2s .c  o m
        }
    }
    return children.iterator();
}

From source file:Main.java

/**
 * Add all given objects to given target list. No duplicates will be added. The contains() method of the given
 * target list will be used to determine whether or not an object is already in the list.
 * @param target the collection to which to objects will be added
 * @param objects the objects to add/*from w  w w .ja v a 2s.  co  m*/
 * @return whether or not the target collection changed
 */
public static <T> boolean addAllNoDuplicates(List<T> target, T... objects) {
    if (objects == null || objects.length == 0) {
        return false;
    } else {
        boolean changed = false;
        for (int i = 0; i < objects.length; i++) {
            if (!target.contains(objects[i])) {
                target.add(objects[i]);
                changed = true;
            }
        }
        return changed;
    }
}

From source file:com.tlabs.eve.api.EveRequest.java

protected static final long[] filter(long[] ids) {
    List<Long> l = new ArrayList<Long>(ids.length);
    for (Long id : ids) {
        if (!l.contains(id)) {
            l.add(id);//from w  w w .  ja  va  2  s  .c o m
        }
    }
    Long[] fck = l.toArray(new Long[l.size()]);
    long[] r = new long[fck.length];
    for (int i = 0; i < fck.length; i++) {
        r[i] = fck[i];
    }
    return r;
}

From source file:com.tlabs.eve.api.EveRequest.java

protected static final long[] filter(Long[] ids) {
    List<Long> l = new ArrayList<Long>(ids.length);
    for (Long id : ids) {
        if (!l.contains(id)) {
            l.add(id);//from ww w .j  a  v  a2s. c o  m
        }
    }
    Long[] fck = l.toArray(new Long[l.size()]);
    long[] r = new long[fck.length];
    for (int i = 0; i < fck.length; i++) {
        r[i] = fck[i].longValue();
    }
    return r;
}

From source file:Main.java

/**
 * Compares two lists. Caution: Lists can hold same values multiple times.
 * //from w  ww .j  ava 2 s  .  c  om
 * @param list1
 * @param list2
 * @return -1 if no common elements or any of lists are empty/null.
 *          0 if two lists have the same contents.
 *          x (x>0) if there are x elements in common. 
 */

public static int compareLists(List<? extends Object> list1, List<? extends Object> list2) {
    if (null == list1 || null == list2 || list1.isEmpty() || list2.isEmpty()) {
        return -1;
    }

    int count = 0;

    for (Object o : list1) {
        if (list2.contains(o))
            count++;
    }

    return count;

}

From source file:com.tlabs.eve.api.EveRequest.java

protected static final String[] filter(String[] names) {
    List<String> l = new ArrayList<String>(names.length);
    for (String s : names) {
        if (!l.contains(s)) {
            l.add(s);//from w  w w .j a  v a  2s. c  om
        }
    }
    return l.toArray(new String[l.size()]);
}