Example usage for java.util ArrayList indexOf

List of usage examples for java.util ArrayList indexOf

Introduction

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

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:de.ks.idnadrev.expimp.xls.XlsxExporterTest.java

@Test
public void testExportThoughts() throws Exception {
    File tempFile = File.createTempFile("thoughtExport", ".xlsx");
    EntityExportSource<Thought> source = new EntityExportSource<>(getAllIds(), Thought.class);
    XlsxExporter exporter = new XlsxExporter();
    exporter.export(tempFile, source);/*from w  ww.  j ava  2s.com*/

    Workbook wb = WorkbookFactory.create(tempFile);
    Sheet sheet = wb.getSheetAt(0);
    assertEquals(Thought.class.getName(), sheet.getSheetName());
    int lastRowNum = sheet.getLastRowNum();
    assertEquals(COUNT, lastRowNum);
    Row firstRow = sheet.getRow(0);

    ArrayList<String> titles = new ArrayList<>();
    firstRow.cellIterator().forEachRemaining(col -> titles.add(col.getStringCellValue()));
    assertThat(titles.size(), greaterThanOrEqualTo(3));
    log.info("Found titles {}", titles);

    String creationTime = PropertyPath.property(Thought.class, t -> t.getCreationTime());
    String name = PropertyPath.property(Thought.class, t -> t.getName());
    String description = PropertyPath.property(Thought.class, t -> t.getDescription());

    assertTrue(titles.contains(creationTime));
    assertTrue(titles.contains(name));
    assertTrue(titles.contains(description));

    int nameColumn = titles.indexOf(name);
    ArrayList<String> names = new ArrayList<String>(COUNT);
    for (int i = 1; i <= COUNT; i++) {
        Row row = sheet.getRow(i);
        names.add(row.getCell(nameColumn).getStringCellValue());
    }
    Collections.sort(names);
    assertEquals("Thought000", names.get(0));
    assertEquals("Thought141", names.get(COUNT - 1));

    Date excelDate = sheet.getRow(1).getCell(titles.indexOf(creationTime)).getDateCellValue();

    Thought thought = PersistentWork.forName(Thought.class, "Thought000");

    Timestamp timestamp = java.sql.Timestamp.valueOf(thought.getCreationTime());
    Date creationDate = new Date(timestamp.getTime());
    assertEquals(creationDate, excelDate);
}

From source file:com.arman.efficientqhalgoforch.SuperAwesomeCardFragment.java

public void updateChart(CopyOnWriteArrayList<DataHolder> holdder) {

    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < 25; i++) {
        xVals.add(i + "");
    }//from   w  w  w .  j  av a2 s  . c o m
    ArrayList<Entry> yValspoint = new ArrayList<Entry>();
    for (int i = 0; i < holdder.size(); i++) {

        yVals1.add(new Entry((holdder.get(i).getTime()),
                Integer.valueOf(xVals.get(xVals.indexOf(String.valueOf(holdder.get(i).getThread()))))));

    }

    ArrayList<ScatterDataSet> dataSets = new ArrayList<ScatterDataSet>();

    // create a dataset and give it a type
    ScatterDataSet set1 = new ScatterDataSet(yVals1, "Result");
    set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
    set1.setScatterShapeSize(8f);

    dataSets.add(set1); // add the datasets

    // create a data object with the datasets
    ScatterData data = new ScatterData(xVals, dataSets);
    data.setValueTypeface(tf);

    mChart.setData(data);
    mChart.invalidate();

}

From source file:com.ayaseya.padnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;//from   w  w  w.ja v a2  s.c om
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}

From source file:com.ayaseya.nolnotification.GcmIntentService.java

@Override
public void onCreate() {
    super.onCreate();

    ringerMode = false;/*from  ww  w  .  ja  va 2  s  .  c o  m*/
    silentMode = false;
    vibrateMode = false;

    isPlugged = false;

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    checkbox_sound = sharedPreferences.getBoolean("checkbox_sound_key", true);
    checkbox_vibration = sharedPreferences.getBoolean("checkbox_vibration_key", false);

    Set<String> multiValues = sharedPreferences.getStringSet("list_preference", null);
    ArrayList<String> timeZone = new ArrayList<String>();

    if (multiValues != null) {

        timeZone.addAll(multiValues);
        Collections.sort(timeZone);
        for (int i = 0; i < timeZone.size(); i++) {
            //            Log.v(TAG, "TimeZone=" + timeZone.get(i));
        }

        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);

        if (timeZone.indexOf(String.valueOf(hour)) == -1) {
            notificationPermission = false;
            //            Log.v(TAG, "?????????");
        } else {
            notificationPermission = true;
            //            Log.v(TAG, "??????");
        }
    }

    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    ringerModeStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_NORMAL) {
                    // 
                    ringerMode = true;
                } else {
                    ringerMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE,
                        -1) == AudioManager.RINGER_MODE_VIBRATE) {
                    // 
                    vibrateMode = true;

                } else {

                    vibrateMode = false;

                }

                if (intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1) == AudioManager.RINGER_MODE_SILENT) {
                    // 
                    silentMode = true;

                } else {

                    silentMode = false;

                }
            }
        }
    };

    plugStateChangeReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // ?
            if (intent.getIntExtra("state", 0) > 0) {
                isPlugged = true;
                //               Log.v(TAG, "IN");
            } else {
                isPlugged = false;
                //               Log.v(TAG, "OUT");
            }
        }
    };

    // Broadcast Receiver???
    registerReceiver(plugStateChangeReceiver, plugIntentFilter);
    registerReceiver(ringerModeStateChangeReceiver, ringerModeIntentFilter);
}

From source file:dr.app.bss.Utils.java

public static int isIdenticalWith(PartitionData data, ArrayList<PartitionData> partitionList,
        int elementIndex) {

    int index = -Integer.MAX_VALUE;

    switch (elementIndex) {

    case DEMOGRAPHIC_MODEL_ELEMENT:

        for (PartitionData data2 : partitionList) {
            if (demographicModelToString(data).equalsIgnoreCase(demographicModelToString(data2))) {
                index = partitionList.indexOf(data2);
                break;
            }/*from  w  w w . j  av a2  s  .c  om*/
        }

        break;

    case BRANCH_RATE_MODEL_ELEMENT:

        for (PartitionData data2 : partitionList) {
            if (clockRateModelToString(data).equalsIgnoreCase(clockRateModelToString(data2))) {
                index = partitionList.indexOf(data2);
                break;
            }
        }

        break;

    case FREQUENCY_MODEL_ELEMENT:

        for (PartitionData data2 : partitionList) {
            if (frequencyModelToString(data).equalsIgnoreCase(frequencyModelToString(data2))) {
                index = partitionList.indexOf(data2);
                break;
            }
        }

        break;

    case BRANCH_MODEL_ELEMENT:

        for (PartitionData data2 : partitionList) {
            if (branchSubstitutionModelToString(data)
                    .equalsIgnoreCase(branchSubstitutionModelToString(data2))) {
                index = partitionList.indexOf(data2);
                break;
            }
        }

        break;

    case SITE_RATE_MODEL_ELEMENT:

        for (PartitionData data2 : partitionList) {
            if (siteRateModelToString(data).equalsIgnoreCase(siteRateModelToString(data2))) {
                index = partitionList.indexOf(data2);
                break;
            }
        }

        break;

    default:

        throw new RuntimeException("Unknown element");

    }// END: switch

    return index;
}

From source file:com.appnexus.opensdk.AdRequest.java

private AdRequest(AdRequester adRequester, int httpRetriesLeft, int blankRetriesLeft) {
    owner = adRequester.getOwner();//from   w  w  w .ja v a2  s  .  c  o m
    this.requester = adRequester;
    this.httpRetriesLeft = httpRetriesLeft;
    this.blankRetriesLeft = blankRetriesLeft;
    this.placementId = owner.getPlacementID();
    context = owner.getContext();
    String aid = android.provider.Settings.Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    // Do we have access to location?
    if (context.checkCallingOrSelfPermission(
            "android.permission.ACCESS_FINE_LOCATION") == PackageManager.PERMISSION_GRANTED
            || context.checkCallingOrSelfPermission(
                    "android.permission.ACCESS_COARSE_LOCATION") == PackageManager.PERMISSION_GRANTED) {
        // Get lat, long from any GPS information that might be currently
        // available
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Location lastLocation = lm.getLastKnownLocation(lm.getBestProvider(new Criteria(), false));
        if (lastLocation != null) {
            lat = "" + lastLocation.getLatitude();
            lon = "" + lastLocation.getLongitude();
            locDataAge = "" + (System.currentTimeMillis() - lastLocation.getTime());
            locDataPrecision = "" + lastLocation.getAccuracy();
        }
    } else {
        Clog.w(Clog.baseLogTag, Clog.getString(R.string.permissions_missing_location));
    }

    // Do we have permission ACCESS_NETWORK_STATE?
    if (context.checkCallingOrSelfPermission(
            "android.permission.ACCESS_NETWORK_STATE") != PackageManager.PERMISSION_GRANTED) {
        Clog.e(Clog.baseLogTag, Clog.getString(R.string.permissions_missing_network_state));
        fail();
        this.cancel(true);
        return;
    }

    // Get orientation, the current rotation of the device
    orientation = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? "h"
            : "v";
    // Get hidmd5, hidsha1, the device ID hashed
    if (Settings.getSettings().hidmd5 == null) {
        Settings.getSettings().hidmd5 = HashingFunctions.md5(aid);
    }
    hidmd5 = Settings.getSettings().hidmd5;
    if (Settings.getSettings().hidsha1 == null) {
        Settings.getSettings().hidsha1 = HashingFunctions.sha1(aid);
    }
    hidsha1 = Settings.getSettings().hidsha1;
    // Get devMake, devModel, the Make and Model of the current device
    devMake = Settings.getSettings().deviceMake;
    devModel = Settings.getSettings().deviceModel;
    // Get carrier
    if (Settings.getSettings().carrierName == null) {
        Settings.getSettings().carrierName = ((TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE)).getNetworkOperatorName();
    }
    carrier = Settings.getSettings().carrierName;
    // Get firstlaunch and convert it to a string
    firstlaunch = Settings.getSettings().first_launch;
    // Get ua, the user agent...
    ua = Settings.getSettings().ua;
    // Get wxh

    if (owner.isBanner()) {
        this.width = ((BannerAdView) owner).getAdWidth();
        this.height = ((BannerAdView) owner).getAdHeight();
    }

    maxHeight = owner.getContainerHeight();
    maxWidth = owner.getContainerWidth();

    if (Settings.getSettings().mcc == null || Settings.getSettings().mnc == null) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String networkOperator = tm.getNetworkOperator();
        if (networkOperator != null && networkOperator.length() >= 6) {
            Settings.getSettings().mcc = networkOperator.substring(0, 3);
            Settings.getSettings().mnc = networkOperator.substring(3);
        }
    }
    mcc = Settings.getSettings().mcc;
    mnc = Settings.getSettings().mnc;

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    connection_type = wifi.isConnected() ? "wifi" : "wan";
    dev_time = "" + System.currentTimeMillis();

    if (owner instanceof InterstitialAdView) {
        // Make string for allowed_sizes
        allowedSizes = "";
        ArrayList<Size> sizes = ((InterstitialAdView) owner).getAllowedSizes();
        for (Size s : sizes) {
            allowedSizes += "" + s.width() + "x" + s.height();
            // If not last size, add a comma
            if (sizes.indexOf(s) != sizes.size() - 1)
                allowedSizes += ",";
        }
    }

    nativeBrowser = owner.getOpensNativeBrowser() ? "1" : "0";

    //Reserve price
    reserve = owner.getReserve();
    if (reserve <= 0) {
        this.psa = owner.shouldServePSAs ? "1" : "0";
    } else {
        this.psa = "0";
    }

    age = owner.getAge();
    if (owner.getGender() != null) {
        if (owner.getGender() == AdView.GENDER.MALE) {
            gender = "m";
        } else if (owner.getGender() == AdView.GENDER.FEMALE) {
            gender = "f";
        } else {
            gender = null;
        }
    }
    customKeywords = owner.getCustomKeywords();

    mcc = Settings.getSettings().mcc;
    mnc = Settings.getSettings().mnc;
    language = Settings.getSettings().language;
}

From source file:mp.teardrop.SongTimeline.java

/**
 * Set how to shuffle. Will shuffle the current set of songs when enabling
 * shuffling if random mode is not enabled.
 *
 * @param mode One of SongTimeline.MODE_*
 *//* w  ww . j a v a  2 s  . c  o m*/
public void setShuffleMode(int mode) {
    if (mode == mShuffleMode)
        return;

    synchronized (this) {
        saveActiveSongs();
        mShuffledSongs = null;
        mShuffleMode = mode;
        if (mode != SHUFFLE_NONE && mFinishAction != FINISH_RANDOM && !mSongs.isEmpty()) {
            shuffleAll();
            ArrayList<Song> songs = mShuffledSongs;
            mShuffledSongs = null;
            mCurrentPos = songs.indexOf(mSavedCurrent);
            mSongs = songs;
        }
        broadcastChangedSongs();
    }

    changed();
}

From source file:info.jtrac.hibernate.HibernateJtracDao.java

private void doInMemorySort(List<Item> list, ItemSearch itemSearch) {
    // we should never come here if search is across multiple spaces
    final Field field = itemSearch.getSpace().getMetadata().getField(itemSearch.getSortFieldName());
    final ArrayList<String> valueList = new ArrayList<String>(field.getOptions().keySet());
    Comparator<Item> comp = new Comparator<Item>() {
        public int compare(Item left, Item right) {
            Object leftVal = left.getValue(field.getName());
            String leftValString = leftVal == null ? null : leftVal.toString();
            int leftInd = valueList.indexOf(leftValString);
            Object rightVal = right.getValue(field.getName());
            String rightValString = rightVal == null ? null : rightVal.toString();
            int rightInd = valueList.indexOf(rightValString);
            return leftInd - rightInd;
        }// w  w  w.j a v a 2 s .  c o m
    };
    Collections.sort(list, itemSearch.isSortDescending() ? ComparatorUtils.reversedComparator(comp) : comp);
}

From source file:com.hiqes.andele.Andele.java

private static void checkAndExecute(RequestOwner owner, ProtectedAction[] actions) {
    ArrayList<ProtectedAction> reqActions = null;
    int status;/*from   w  ww .java  2 s.c  o  m*/
    int firstEduIndex = -1;

    //  Walk through the actions, check the permissions.  If the app
    //  already has them then call back the app.  Otherwise, we'll need
    //  to interface with the user on this.
    for (int i = 0; i < actions.length; i++) {
        ProtectedAction curAction = actions[i];

        status = owner.checkSelfPermission(curAction.mPermDetails.mPermission);
        if (status == PackageManager.PERMISSION_GRANTED) {
            //  Boom!  We got it already!  Call back the action immediately
            //  as we are already in the same context.
            curAction.mListener.onPermissionGranted(curAction.mPermDetails);
            curAction.mActionCb.doAction(curAction);
        } else {
            //  We don't have this one, so we need to ask for it or
            //  possibly educate the user.
            if (reqActions == null) {
                reqActions = new ArrayList<>();
            }

            reqActions.add(curAction);

            if (curAction.hasUserEdu() && (firstEduIndex == -1)) {
                firstEduIndex = reqActions.indexOf(curAction);
                Log.d(TAG, "Action with perm '" + curAction.mPermDetails.mPermission + "' has edu, index: "
                        + firstEduIndex);
            }
        }
    }

    //  If reqActions is not empty, we need to ask for the permission(s)
    //  and possibly educate te user.
    if ((reqActions != null) && (reqActions.size() > 0)) {
        ProtectedAction[] needyActions = new ProtectedAction[reqActions.size()];
        needyActions = reqActions.toArray(needyActions);

        //  First things first, queue the request with the needy actions
        //  which contains just the subset of stuff that needs edu/req.
        int reqCode = sReqMgr.queueRequest(owner, needyActions, getReqHandler());
        if (reqCode >= 0) {
            //  If firstEduIndex is not -1, somebody needs an explanation.
            if (firstEduIndex != -1) {
                Log.d(TAG, "Show edu for req " + reqCode);
                showEducateUi(reqCode, firstEduIndex);
            } else {
                doRequest(reqCode);
            }
        } else {
            Log.d(TAG, "checkAndExecute: req already queued and being processed");
        }
    }
}

From source file:org.wikimedia.analytics.kraken.funnel.Funnel.java

/**
 * Construct graph.//ww  w.  j  a  va  2 s .c  om
 *
 * @param funnelDefinition the edges
 * @return the directed graph
 * @throws MalformedFunnelException
 * @throws PatternSyntaxException
 */
public final DirectedGraph<FunnelNode, DefaultEdge> constructFunnelGraph(String funnelDefinition)
        throws PatternSyntaxException, MalformedFunnelException {
    String[] edgeList = funnelDefinition.split(";");
    DirectedGraph<FunnelNode, DefaultEdge> dg = new DefaultDirectedGraph<FunnelNode, DefaultEdge>(
            DefaultEdge.class);
    //TODO: probably faster to replace ArrayList with HashMap<String, Node>
    ArrayList<FunnelNode> nodes = new ArrayList<FunnelNode>();
    FunnelNode source;
    FunnelNode target;
    for (String edgeData : edgeList) {
        String[] edge = edgeData.split(",");
        source = new FunnelNode(edge[0]);
        target = new FunnelNode(edge[1]);

        //Curiously enough, there don't seem to be a method in jGraphT to get
        //a vertex from a graph, hence I keep an ArrayList of nodes that
        //already exist.
        if (!nodes.contains(source)) {
            dg.addVertex(source);
            nodes.add(source);
        } else {
            source = nodes.get(nodes.indexOf(source));
        }

        if (!nodes.contains(target)) {
            dg.addVertex(target);
            nodes.add(target);
        } else {
            target = nodes.get(nodes.indexOf(target));
        }

        if (!dg.containsEdge(source, target)) {
            dg.addEdge(source, target);
        }
    }
    System.out.println("Graph Summary: " + dg.toString());

    return dg;
}