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:com.parse.ParseAddUniqueOperation.java

@Override
public Object apply(Object oldValue, String key) {
    if (oldValue == null) {
        return new ArrayList<>(objects);
    } else if (oldValue instanceof JSONArray) {
        ArrayList<Object> old = ParseFieldOperations.jsonArrayAsArrayList((JSONArray) oldValue);
        @SuppressWarnings("unchecked")
        ArrayList<Object> newValue = (ArrayList<Object>) this.apply(old, key);
        return new JSONArray(newValue);
    } else if (oldValue instanceof List) {
        ArrayList<Object> result = new ArrayList<>((List<?>) oldValue);

        // Build up a Map of objectIds of the existing ParseObjects in this field.
        HashMap<String, Integer> existingObjectIds = new HashMap<>();
        for (int i = 0; i < result.size(); i++) {
            if (result.get(i) instanceof ParseObject) {
                existingObjectIds.put(((ParseObject) result.get(i)).getObjectId(), i);
            }/*  w  w w.ja  v  a2  s .  c om*/
        }

        // Iterate over the objects to add. If it already exists in the field,
        // remove the old one and add the new one. Otherwise, just add normally.
        for (Object obj : objects) {
            if (obj instanceof ParseObject) {
                String objectId = ((ParseObject) obj).getObjectId();
                if (objectId != null && existingObjectIds.containsKey(objectId)) {
                    result.set(existingObjectIds.get(objectId), obj);
                } else if (!result.contains(obj)) {
                    result.add(obj);
                }
            } else {
                if (!result.contains(obj)) {
                    result.add(obj);
                }
            }
        }
        return result;
    } else {
        throw new IllegalArgumentException("Operation is invalid after previous operation.");
    }
}

From source file:com.google.dart.engine.internal.element.ClassElementImpl.java

private void collectAllSupertypes(ArrayList<InterfaceType> supertypes) {
    ArrayList<InterfaceType> typesToVisit = new ArrayList<InterfaceType>();
    ArrayList<ClassElement> visitedClasses = new ArrayList<ClassElement>();
    typesToVisit.add(this.getType());
    while (!typesToVisit.isEmpty()) {
        InterfaceType currentType = typesToVisit.remove(0);
        ClassElement currentElement = currentType.getElement();
        if (!visitedClasses.contains(currentElement)) {
            visitedClasses.add(currentElement);
            if (currentType != this.getType()) {
                supertypes.add(currentType);
            }/*from   ww w  .  j  a va  2s  .co m*/
            InterfaceType supertype = currentType.getSuperclass();
            if (supertype != null) {
                typesToVisit.add(supertype);
            }
            for (InterfaceType type : currentElement.getInterfaces()) {
                typesToVisit.add(type);
            }
            for (InterfaceType type : currentElement.getMixins()) {
                ClassElement element = type.getElement();
                if (!visitedClasses.contains(element)) {
                    supertypes.add(type);
                }
            }
        }
    }
}

From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java

public void save() {
    String selectedPackages = "";
    ArrayList<String> tmpArray = new ArrayList<String>();
    if (lvPackages == null || lvPackages.getAdapter() == null) {
        return;/* w w  w .j  ava  2s. c  o  m*/
    }
    for (String strPackage : ((packageAdapter) lvPackages.getAdapter()).selected) {
        if (!strPackage.isEmpty()) {
            if (!tmpArray.contains(strPackage)) {
                tmpArray.add(strPackage);
                selectedPackages += strPackage + ",";
            }
        }
    }
    tmpArray.clear();
    tmpArray = null;
    if (!selectedPackages.isEmpty()) {
        selectedPackages = selectedPackages.substring(0, selectedPackages.length() - 1);
    }
    if (Constants.IS_LOGGABLE) {
        switch (mMode) {
        case OFF:
            Log.i(Constants.LOG_TAG, "Mode is: off");
            break;
        case EXCLUDE:
            Log.i(Constants.LOG_TAG, "Mode is: exclude");
            break;
        case INCLUDE:
            Log.i(Constants.LOG_TAG, "Mode is: include");
            break;
        }

        Log.i(Constants.LOG_TAG, "Package list is: " + selectedPackages);
    }

    if (mode == Mode.STANDARD) {

        Editor editor = sharedPreferences.edit();
        editor.putInt(Constants.PREFERENCE_MODE, mMode.ordinal());
        editor.putString(Constants.PREFERENCE_PACKAGE_LIST, selectedPackages);
        editor.putString(Constants.PREFERENCE_PKG_RENAMES, arrayRenames.toString());

        // we saved via the application, reset the variable if it exists
        editor.remove(Constants.PREFERENCE_TASKER_SET);

        // clear out legacy preference, if it exists
        editor.remove(Constants.PREFERENCE_EXCLUDE_MODE);

        // save!
        editor.commit();

        // notify service via file that it needs to reload the preferences
        File watchFile = new File(getFilesDir() + "PrefsChanged.none");
        if (!watchFile.exists()) {
            try {
                watchFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        watchFile.setLastModified(System.currentTimeMillis());
    } else if (mode == Mode.LOCALE) {
        if (!isCanceled()) {
            final Intent resultIntent = new Intent();
            final Bundle resultBundle = new Bundle();

            // set the version, title and body
            resultBundle.putInt(Constants.BUNDLE_EXTRA_INT_VERSION_CODE,
                    Constants.getVersionCode(getApplicationContext()));
            resultBundle.putInt(Constants.BUNDLE_EXTRA_INT_TYPE, Constants.Type.SETTINGS.ordinal());
            resultBundle.putInt(Constants.BUNDLE_EXTRA_INT_MODE, mMode.ordinal());
            resultBundle.putString(Constants.BUNDLE_EXTRA_STRING_PACKAGE_LIST, selectedPackages);
            resultBundle.putString(Constants.BUNDLE_EXTRA_STRING_PKG_RENAMES, arrayRenames.toString());
            String blurb = "";
            switch (mMode) {
            case OFF:
                blurb = getResources().getStringArray(R.array.mode_choices)[0];
                break;
            case INCLUDE:
                blurb = getResources().getStringArray(R.array.mode_choices)[2];
                break;
            case EXCLUDE:
                blurb = getResources().getStringArray(R.array.mode_choices)[1];
            }
            Log.i(Constants.LOG_TAG, resultBundle.toString());

            resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE, resultBundle);
            resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB, blurb);
            setResult(RESULT_OK, resultIntent);
        }
    }

}

From source file:com.gamethrive.TrackGooglePurchase.java

private void QueryBoughtItems() {
    if (isWaitingForPurchasesRequest)
        return;//from  w ww .  j a v  a 2 s.co m

    new Thread(new Runnable() {
        public void run() {
            isWaitingForPurchasesRequest = true;
            try {
                if (getPurchasesMethod == null)
                    getPurchasesMethod = IInAppBillingServiceClass.getMethod("getPurchases", int.class,
                            String.class, String.class, String.class);

                Bundle ownedItems = (Bundle) getPurchasesMethod.invoke(mIInAppBillingService, 3,
                        appContext.getPackageName(), "inapp", null);
                if (ownedItems.getInt("RESPONSE_CODE") == 0) {
                    ArrayList<String> skusToAdd = new ArrayList<String>();
                    ArrayList<String> newPurchaseTokens = new ArrayList<String>();

                    ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                    ArrayList<String> purchaseDataList = ownedItems
                            .getStringArrayList("INAPP_PURCHASE_DATA_LIST");

                    for (int i = 0; i < purchaseDataList.size(); i++) {
                        String purchaseData = purchaseDataList.get(i);
                        String sku = ownedSkus.get(i);
                        JSONObject itemPurchased = new JSONObject(purchaseData);
                        String purchaseToken = itemPurchased.getString("purchaseToken");

                        if (!purchaseTokens.contains(purchaseToken)
                                && !newPurchaseTokens.contains(purchaseToken)) {
                            newPurchaseTokens.add(purchaseToken);
                            skusToAdd.add(sku);
                        }
                    }

                    if (skusToAdd.size() > 0)
                        sendPurchases(skusToAdd, newPurchaseTokens);
                    else if (purchaseDataList.size() == 0) {
                        newAsExisting = false;
                        prefsEditor.putBoolean("ExistingPurchases", false);
                        prefsEditor.commit();
                    }

                    // TODO: Handle very large list. Test for continuationToken != null then call getPurchases again
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
            isWaitingForPurchasesRequest = false;
        }
    }).start();
}

From source file:io.siddhi.extension.io.file.FileSinkTestCase.java

@Test
public void fileSinkTest8() throws InterruptedException {
    log.info("test SiddhiIoFile Sink 8");

    String streams = "" + "@App:name('TestSiddhiApp')"
            + "define stream FooStream (symbol string, price float, volume long); "
            + "@sink(type='file', @map(type='text'), append='false', " + "file.uri='" + sinkUri
            + "/{{symbol}}.txt') " + "define stream BarStream (symbol string, price float, volume long); ";

    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";

    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");

    siddhiAppRuntime.start();/*from   w  ww  .j a  v  a  2 s  .c om*/

    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 57.678f, 100L });
    stockStream.send(new Object[] { "GOOGLE", 50f, 100L });
    stockStream.send(new Object[] { "REDHAT", 50f, 100L });
    Thread.sleep(100);

    ArrayList<String> symbolNames = new ArrayList<>();
    symbolNames.add("WSO2.txt");
    symbolNames.add("IBM.txt");
    symbolNames.add("GOOGLE.txt");
    symbolNames.add("REDHAT.txt");

    File sink = new File(sinkUri);
    if (sink.isDirectory()) {
        for (File file : sink.listFiles()) {
            if (symbolNames.contains(file.getName())) {
                count.incrementAndGet();
            }
        }
        AssertJUnit.assertEquals(4, count.intValue());
    } else {
        AssertJUnit.fail(sinkUri + " is not a directory.");
    }

    Thread.sleep(1000);
    siddhiAppRuntime.shutdown();
}

From source file:io.siddhi.extension.io.file.FileSinkTestCase.java

@Test
public void fileSinkTest9() throws InterruptedException {
    log.info("test SiddhiIoFile Sink 9");

    String streams = "" + "@App:name('TestSiddhiApp')"
            + "define stream FooStream (symbol string, price float, volume long); "
            + "@sink(type='file', @map(type='xml'), append='false', " + "file.uri='" + sinkUri
            + "/{{symbol}}.xml') " + "define stream BarStream (symbol string, price float, volume long); ";

    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";

    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");

    siddhiAppRuntime.start();/*from  ww w .  j a v  a2  s  .  c om*/

    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 57.678f, 100L });
    stockStream.send(new Object[] { "GOOGLE", 50f, 100L });
    stockStream.send(new Object[] { "REDHAT", 50f, 100L });
    Thread.sleep(100);

    ArrayList<String> symbolNames = new ArrayList<>();
    symbolNames.add("WSO2.xml");
    symbolNames.add("IBM.xml");
    symbolNames.add("GOOGLE.xml");
    symbolNames.add("REDHAT.xml");

    File sink = new File(sinkUri);
    if (sink.isDirectory()) {
        for (File file : sink.listFiles()) {
            if (symbolNames.contains(file.getName())) {
                count.incrementAndGet();
            }
        }
        AssertJUnit.assertEquals(4, count.intValue());
    } else {
        AssertJUnit.fail(sinkUri + " is not a directory.");
    }

    Thread.sleep(1000);
    siddhiAppRuntime.shutdown();
}

From source file:io.siddhi.extension.io.file.FileSinkTestCase.java

@Test
public void fileSinkTest1() throws InterruptedException {
    log.info("test SiddhiIoFile Sink 1");

    String streams = "" + "@App:name('TestSiddhiApp')"
            + "define stream FooStream (symbol string, price float, volume long); "
            + "@sink(type='file', @map(type='json'), append='false', " + "file.uri='" + sinkUri
            + "/{{symbol}}.json') " + "define stream BarStream (symbol string, price float, volume long); ";

    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";

    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");

    siddhiAppRuntime.start();//from   w  w w  .  java2  s  .co m

    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 57.678f, 100L });
    stockStream.send(new Object[] { "GOOGLE", 50f, 100L });
    stockStream.send(new Object[] { "REDHAT", 50f, 100L });
    Thread.sleep(100);

    ArrayList<String> symbolNames = new ArrayList<>();
    symbolNames.add("WSO2.json");
    symbolNames.add("IBM.json");
    symbolNames.add("GOOGLE.json");
    symbolNames.add("REDHAT.json");

    File sink = new File(sinkUri);
    if (sink.isDirectory()) {
        for (File file : sink.listFiles()) {
            if (symbolNames.contains(file.getName())) {
                count.incrementAndGet();
            }
        }
        AssertJUnit.assertEquals(4, count.intValue());
    } else {
        AssertJUnit.fail(sinkUri + " is not a directory.");
    }

    Thread.sleep(1000);
    siddhiAppRuntime.shutdown();
}

From source file:es.bsc.servicess.ide.editors.deployers.GridDeployer.java

private String[] getWorkerZips(final String packageFolder, final ProjectMetadata prMetadata) {
    ArrayList<String> list = new ArrayList<String>();
    String[] packs = prMetadata.getPackagesWithCores();
    for (int i = 0; i < packs.length; i++) {
        list.add(packageFolder + File.separator + packs[i] + "_deps.zip");
        for (Dependency d : prMetadata.getDependencies(prMetadata.getElementsInPackage(packs[i]))) {
            if (d.getType().equalsIgnoreCase(ProjectMetadata.ZIP_DEP_TYPE)) {
                if (!list.contains(d.getLocation())) {
                    list.add(d.getLocation());
                }//www .j  av a  2s . co  m
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:gsn.webservice.standard.GSNWebServiceSkeleton.java

private void updateSelection(HashMap<String, ArrayList<String>> source, String key, String value) {
    if (source == null || key == null || value == null)
        return;/*from w ww . j a v a 2 s .  c om*/
    ArrayList<String> sv = source.get(key);
    if (sv == null) {
        ArrayList<String> values = new ArrayList<String>();
        values.add(value);
        source.put(key, values);
    } else {
        if (!sv.contains(value))
            sv.add(value);
    }
}

From source file:io.siddhi.extension.io.file.FileSinkTestCase.java

@Test
public void fileSinkTest10() throws InterruptedException, CannotRestoreSiddhiAppStateException {
    log.info("test SiddhiIoFile Sink 10");

    String streams = "" + "@App:name('TestSiddhiApp')"
            + "define stream FooStream (symbol string, price float, volume long); "
            + "@sink(type='file', @map(type='xml'), append='false', " + "file.uri='" + sinkUri
            + "/{{symbol}}.xml') " + "define stream BarStream (symbol string, price float, volume long); ";

    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";

    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    SiddhiAppRuntime siddhiAppRuntime2 = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
    InputHandler stockStream2 = siddhiAppRuntime2.getInputHandler("FooStream");

    siddhiAppRuntime.start();// ww  w  . j  a v a 2 s. c o  m

    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 57.678f, 100L });
    byte[] snapshot = siddhiAppRuntime.snapshot();
    siddhiAppRuntime.shutdown();
    Thread.sleep(1000);

    siddhiAppRuntime2.restore(snapshot);
    siddhiAppRuntime2.start();

    stockStream2.send(new Object[] { "GOOGLE", 50f, 100L });
    stockStream2.send(new Object[] { "REDHAT", 50f, 100L });
    Thread.sleep(100);

    ArrayList<String> symbolNames = new ArrayList<>();
    symbolNames.add("WSO2.xml");
    symbolNames.add("IBM.xml");
    symbolNames.add("GOOGLE.xml");
    symbolNames.add("REDHAT.xml");

    File sink = new File(sinkUri);
    if (sink.isDirectory()) {
        for (File file : sink.listFiles()) {
            if (symbolNames.contains(file.getName())) {
                count.incrementAndGet();
            }
        }
        AssertJUnit.assertEquals(4, count.intValue());
    } else {
        AssertJUnit.fail(sinkUri + " is not a directory.");
    }

    Thread.sleep(1000);
    siddhiAppRuntime.shutdown();
}