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:Main.java

public static void revokePermission(String packageName, String permission, Context ctx) {
    String[] rPerms = getRevokedPerms(packageName, ctx);
    if (rPerms == null)
        rPerms = new String[0];
    ArrayList<String> revokedPerms = new ArrayList<String>();
    revokedPerms.addAll(Arrays.asList(rPerms));

    if (!revokedPerms.contains(permission)) {
        revokedPerms.add(permission);//from  w w w  .j  a v  a  2 s.c  om
        String[] permsToRevoke = new String[revokedPerms.size()];
        revokedPerms.toArray(permsToRevoke);
        setRevokedPermissions(packageName, permsToRevoke, ctx);
    }
}

From source file:Main.java

public static <T> List<T> merge(T[]... many) {
    ArrayList<T> ret = new ArrayList();
    for (T[] list : many) {
        if (list != null) {
            for (T val : list) {
                if (!ret.contains(val)) {
                    ret.add(val);
                }// w  w w .ja v a2s  .  com
            }
        }
    }
    ret.trimToSize();
    return ret;
}

From source file:Main.java

public static <T> List<T> merge(List<T>... many) {
    ArrayList<T> ret = new ArrayList();
    for (List<T> list : many) {
        if (list != null) {
            for (T val : list) {
                if (!ret.contains(val)) {
                    ret.add(val);
                }/*  w w w .  j  a va  2  s. co m*/
            }
        }
    }
    ret.trimToSize();
    return ret;
}

From source file:Main.java

public static int[] randNum(int num, int min, int max) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    Random rand = new Random();
    while (true) {
        int rm = (rand.nextInt(max - min) + min);
        if (!list.contains(rm)) {
            list.add(rm);/*from  www .ja  va2s  . co m*/
            if (list.size() >= num)
                break;
        }
    }
    int result[] = new int[num];
    for (int i = 0; i < list.size(); i++) {
        result[i] = list.get(i);
    }
    return result;
}

From source file:Main.java

public static ArrayList<String> sortDaysToTake(ArrayList<String> daysToTake) {
    ArrayList<String> daysToTakeSorted = new ArrayList<>();
    String[] days = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };

    for (String day : days) {
        if (daysToTake.contains(day)) {
            daysToTakeSorted.add(day);//from  ww w .j  a v  a 2s  .co m
        }
    }

    return daysToTakeSorted;
}

From source file:Main.java

private static void _addSuperTypes(Class<?> cls, Class<?> endBefore, ArrayList<Class<?>> result,
        boolean addClassItself) {
    if (cls == endBefore || cls == null || cls == Object.class) {
        return;//from  w ww. j  av  a2  s. c  o m
    }
    if (addClassItself) {
        if (result.contains(cls)) { // already added, no need to check supers
            return;
        }
        result.add(cls);
    }
    for (Class<?> intCls : cls.getInterfaces()) {
        _addSuperTypes(intCls, endBefore, result, true);
    }
    _addSuperTypes(cls.getSuperclass(), endBefore, result, true);
}

From source file:module.siadap.domain.wrappers.SiadapYearWrapper.java

public static SiadapYearWrapper getCurrentYearOrLatestAvailableWrapper() {
    SiadapYearWrapper siadapYearWrapper = null;
    ArrayList<Integer> yearsWithConfigs = SiadapYearsFromExistingSiadapConfigurations
            .getYearsWithExistingConfigs();
    if (yearsWithConfigs.contains(new Integer(new LocalDate().getYear()))) {
        int year = new LocalDate().getYear();
        siadapYearWrapper = new SiadapYearWrapper(year);
    } else {//from   w ww  .  j  ava 2s.c o  m
        siadapYearWrapper = new SiadapYearWrapper(yearsWithConfigs.get(yearsWithConfigs.size() - 1));
    }

    return siadapYearWrapper;

}

From source file:Main.java

public static boolean isAccessibilityServiceOn(Context context, String packageName, String className) {
    ArrayList<String> allAccessibilityServices = getAllAccessibilityServices(context);
    StringBuffer concat = new StringBuffer();
    concat.append(packageName);//www  . j a v  a2  s.  com
    concat.append('/');
    concat.append(className);

    return allAccessibilityServices.contains(concat.toString());
}

From source file:Main.java

public static ArrayList<String> getCountriesArray1() {
    Locale[] locales = Locale.getAvailableLocales();
    ArrayList<String> countries = new ArrayList<String>();
    for (Locale locale : locales) {
        String country = locale.getDisplayCountry();
        Currency currency = Currency.getInstance(locale);
        if (country.trim().length() > 0 && !countries.contains(country) && !country.trim().equals("World")) {
            countries.add(country + " (" + currency + ")");
        }/*from w ww.  j  a  v  a 2s .  c o m*/
    }
    Collections.sort(countries);
    setCountriesISOMap();
    return countries;
}

From source file:Main.java

/**
 * Returns map values summary list with unique elements only.
 *
 * @param map map to process// w w  w. j av a  2s  .c  om
 * @param <K> key object type
 * @param <V> value object type
 * @return map values summary list with unique elements only
 */
public static <K, V> ArrayList<V> valuesSummaryList(final Map<K, List<V>> map) {
    final ArrayList<V> summary = new ArrayList<V>(0);
    for (final Map.Entry<K, List<V>> entry : map.entrySet()) {
        final List<V> list = entry.getValue();
        summary.ensureCapacity(summary.size() + list.size());
        for (final V value : list) {
            if (!summary.contains(value)) {
                summary.add(value);
            }
        }
    }
    return summary;
}