Example usage for java.util ArrayList contains

List of usage examples for java.util ArrayList contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:alpine.notification.NotificationService.java

/**
 * {@inheritDoc}//  w  w  w .  j  a  v a2s.c o m
 * @since 1.3.0
 */
public void subscribe(Class<? extends Notification> notificationClass, Subscription subscription) {
    if (!SUBSCRIPTION_MAP.containsKey(notificationClass)) {
        SUBSCRIPTION_MAP.put(notificationClass, new ArrayList<>());
    }
    final ArrayList<Subscription> subscriptions = SUBSCRIPTION_MAP.get(notificationClass);
    if (!subscriptions.contains(subscription)) {
        subscriptions.add(subscription);
    }
}

From source file:androidGLUESigner.helpers.SettingsHelper.java

/**
 * adds a new file to the signed document list
 * @param path to the file//  w ww . j a  va 2s  . c  om
 */
public void addSignedDocumentToList(String path) {

    ArrayList<String> values = getSignedDocList();
    if (!values.contains(path)) {
        values.add(path);
    }
    saveNewDocList(values, sharedPref.edit());

}

From source file:com.stefensharkey.entityedit.command.CommandEnchant.java

@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    ArrayList<String> enchantments = new ArrayList<>();
    ArrayList<String> argsList = new ArrayList<>(Arrays.asList(args));

    if (argsList.contains("-h") || argsList.contains("-c") || argsList.contains("-l")
            || argsList.contains("-b")) {
        for (Enchantment enchantment : Enchantment.values()) {
            enchantments.add(enchantment.toString());
        }//from w  ww. j ava 2 s  .com

        Collections.sort(enchantments);
        return enchantments;
    }

    return null;
}

From source file:nl.wur.plantbreeding.logic.jfreechart.PieChart.java

/**
 * Returns a PieDataset from a List of String.
 * @param list List of String containg all the values
 * @return a PieDataset/*from w ww  .  j av  a  2 s .c  o m*/
 */
public final PieDataset createDataset(final List<String> list) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    ArrayList<String> done = new ArrayList<String>();
    for (String key : list) {
        if (!done.contains(key)) {
            dataset.setValue(key, this.count(key, list));
        }

    }
    return dataset;
}

From source file:edu.umass.cs.gigapaxos.testing.TESTPaxosConfig.java

/**
 * @param myID/*w  w  w .java2 s  . c o  m*/
 * @return True if found my IP.
 * @throws SocketException
 */
public static boolean findMyIP(Integer myID) throws SocketException {
    if (myID == null)
        return false;
    Enumeration<NetworkInterface> netfaces = NetworkInterface.getNetworkInterfaces();
    ArrayList<InetAddress> myIPs = new ArrayList<InetAddress>();
    while (netfaces.hasMoreElements()) {
        NetworkInterface iface = netfaces.nextElement();
        Enumeration<InetAddress> allIPs = iface.getInetAddresses();
        while (allIPs.hasMoreElements()) {
            InetAddress addr = allIPs.nextElement();
            if ((addr instanceof Inet4Address))
                myIPs.add((InetAddress) addr);
        }
    }
    System.out.println(myIPs);
    boolean found = false;
    if (myIPs.contains(getNodeConfig().getNodeAddress(myID))) {
        found = true;
    }
    if (found)
        System.out.println("Found my IP");
    else {
        System.out.println("\n\n****Could not locally find the IP " + getNodeConfig().getNodeAddress(myID)
                + "; should change all addresses to localhost instead.****\n\n.");
    }
    return found;
}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.MovieListAdapter.java

private String getGenre(String movie) throws JSONException {
    Set<String> keySet = model.keySet();
    Iterator<String> iter = keySet.iterator();
    while (iter.hasNext()) {
        String gen = iter.next();
        ArrayList<String> list = model.get(gen);
        if (list.contains(movie)) {
            return gen;
        }//from w w w. j  a v a2  s.  co m
    }
    return "";
}

From source file:fr.gouv.vitam.mdbes.MongoDbAccess.java

/**
 * Add a one way relation (n) from Obj1 to Obj2, with no Save
 *
 * @param obj1//from  www . j a  va2  s .co m
 * @param obj1ToObj2
 * @param obj2
 * @return true if the link is updated
 */
protected static final boolean addAsymmetricLinksetNoSave(final VitamType obj1, final String obj1ToObj2,
        final VitamType obj2) {
    @SuppressWarnings("unchecked")
    ArrayList<String> relation12 = (ArrayList<String>) obj1.get(obj1ToObj2);
    final String oid2 = (String) obj2.get(VitamType.ID);
    if (relation12 == null) {
        relation12 = new ArrayList<String>();
    }
    if (relation12.contains(oid2)) {
        return false;
    }
    relation12.add(oid2);
    obj1.put(obj1ToObj2, relation12);
    return true;
}

From source file:gov.nih.nci.cabig.caaers.validation.annotation.UniqueObjectInCollectionValidator.java

/**
 * Will return true if there is no duplicate
 * Will return false if there is a duplicate
 *//*from  w  ww . ja v  a 2 s . c  o m*/
//BJ : Changed the orginal HashSet based implementation as some of the objects' hashCode and equals are not in sync.
public boolean validate(final Object value) {
    logger.info("in the validate method of" + this.getClass().getName());
    if (value instanceof Collection) {
        Collection c = (Collection) value;
        ArrayList<Object> list = new ArrayList<Object>(c.size());
        for (Object o : c) {

            if ((o instanceof Retireable) && ((Retireable) o).isRetired())
                continue;

            if (list.contains(o))
                return false;
            list.add(o);
        }
    }
    return true;
}

From source file:eionet.cr.util.Util.java

/**
 *
 * @param acceptLanguageHeader//from  w  w  w.  j a v a  2s .c o m
 * @return
 */
public static List<String> getAcceptedLanguages(String acceptLanguageHeader) {

    final HashMap<String, Double> languageMap = new LinkedHashMap<String, Double>();
    if (!StringUtils.isBlank(acceptLanguageHeader)) {

        String[] languageStrings = StringUtils.split(acceptLanguageHeader, ',');
        for (int i = 0; i < languageStrings.length; i++) {

            String languageString = languageStrings[i].trim();
            String languageCode = StringUtils.substringBefore(languageString, ";").trim();
            if (!StringUtils.isEmpty(languageCode)) {

                String languageCodeUnrefined = StringUtils.split(languageCode, "-_")[0];
                String qualityString = StringUtils.substringAfter(languageString, ";").trim();
                double qualityValue = NumberUtils.toDouble(StringUtils.substringAfter(qualityString, "="),
                        1.0d);

                Double existingQualityValue = languageMap.get(languageCodeUnrefined);
                if (existingQualityValue == null || qualityValue > existingQualityValue) {
                    languageMap.put(languageCodeUnrefined, Double.valueOf(qualityValue));
                }
            }
        }
    }

    ArrayList<String> result = new ArrayList<String>(languageMap.keySet());
    Collections.sort(result, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            return (-1) * languageMap.get(o1).compareTo(languageMap.get(o2));
        }
    });

    if (!result.contains("en")) {
        result.add("en");
    }
    result.add("");
    return result;
}

From source file:de.fhg.iais.asc.commons.exceptions.AscReportableErrorException.java

private String getAllErrorMessages(Throwable e, ArrayList<String> list) {
    if (e != null) {

        if (!Strings.isNullOrEmpty(e.getLocalizedMessage())) {
            String message = e.getLocalizedMessage().trim();
            if (!list.contains(message)) {
                list.add(message);/*from  ww  w  .j  a v a 2  s .c  o  m*/
            }
        }
        return getAllErrorMessages(e.getCause(), list);
    } else {
        return list.toString();
    }
}