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:cooccurrence.Omer_Levy.java

/**
 * Method to populate the apache matrix from cooccur hashmap
 * @param matrixR/*from  w  w  w .java2  s . c  o  m*/
 * @param cooccur
 * @param rowStrings
 * @param colStrings 
 */
private static void populateMatrixR(RealMatrix matrixR, HashMap<String, HashMap<String, Double>> cooccur,
        ArrayList<String> rowStrings, ArrayList<String> colStrings) {
    Iterator iter = cooccur.keySet().iterator();

    while (iter.hasNext()) {
        String row = iter.next().toString();
        int i = rowStrings.indexOf(row);
        HashMap<String, Double> inner = cooccur.get(row);
        for (String col : inner.keySet()) {
            int j = colStrings.indexOf(col);
            double val = inner.get(col);
            matrixR.setEntry(i, j, val);
        }
        iter.remove();
    }
}

From source file:org.jbpm.designer.server.diagram.DiagramBuilder.java

/**
 * Gives a new or already instantiated Shape (out of the shapes Array)
 * /*from   www  .  j av a 2  s  .  co  m*/
 * @param id
 * @param shapes
 */
private static Shape getShapeWithId(String id, ArrayList<Shape> shapes) {
    Shape result = new Shape(id);
    if (shapes.contains(result)) {
        return shapes.get(shapes.indexOf(result));
    }

    shapes.add(result);
    return result;
}

From source file:sample.ModelObject.java

public static ArrayList<ModelObject> modelObjectListFromIdString(String modelObjectIdString,
        ArrayList<ModelObject> fullModelObjectArrayList) {

    ArrayList<ModelObject> resultList = new ArrayList<ModelObject>();

    if (modelObjectIdString == null)
        return resultList;

    //  ??  ? Id ? 
    ArrayList<String> stringList = ModelObject.stringIdListFromModelObjectList(fullModelObjectArrayList);

    // ? ?      ? ?   ?? ? ,  ?    ??
    String[] stringArray = modelObjectIdString.split(",");
    for (String modelObjectId : stringArray) {
        int index = stringList.indexOf(modelObjectId);
        ModelObject ModelObject = fullModelObjectArrayList.get(index);
        resultList.add(ModelObject);/*from ww  w  .j a v  a2 s.  co  m*/
    }

    Log.v(Helper.TAG, "Number of ModelObjects in result list = " + resultList.size());

    return resultList;
}

From source file:org.eclim.command.Main.java

/**
 * Main method for executing the client.
 *
 * @param context The nailgun context./*from  w  w w .  j a v  a 2 s . co m*/
 */
public static final void nailMain(final NGContext context) {
    try {
        logger.debug("args: " + Arrays.toString(context.getArgs()));

        ArrayList<String> arguments = new ArrayList<String>();
        for (String arg : context.getArgs()) {
            if (arg.startsWith("-D")) {
                String[] prop = StringUtils.split(arg.substring(2), '=');
                System.setProperty(prop[0], prop[1]);
            } else {
                arguments.add(arg);
            }
        }

        if (arguments.isEmpty() || arguments.contains("-?")) {
            int index = arguments.indexOf("-?");
            String cmd = arguments.size() > index + 1 ? arguments.get(index + 1) : null;
            usage(cmd, context.out);
            System.exit(arguments.isEmpty() ? 1 : 0);
        }

        Options options = new Options();
        final CommandLine commandLine = options
                .parse((String[]) arguments.toArray(new String[arguments.size()]));

        String commandName = commandLine.getValue(Options.COMMAND_OPTION);
        logger.debug("Main - command: {}", commandName);

        final Command command = commandLine.getCommand();
        command.setContext(context);

        final Object[] results = new Object[1];
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                try {
                    results[0] = command.execute(commandLine);
                } catch (Exception e) {
                    results[0] = e;
                } finally {
                    command.cleanup(commandLine);
                }
            }
        });
        Object result = results[0];

        if (result != null) {
            if (result instanceof Throwable) {
                throw (Throwable) result;
            }
            GsonBuilder builder = new GsonBuilder();
            if (commandLine.hasOption(Options.PRETTY_OPTION)) {
                builder = builder.setPrettyPrinting();
            }
            if (commandLine.hasOption(Options.EDITOR_OPTION)
                    && commandLine.getValue(Options.EDITOR_OPTION).equals("vim")) {
                builder = builder.registerTypeAdapter(Boolean.TYPE, new BooleanSerializer())
                        .registerTypeAdapter(Boolean.class, new BooleanSerializer());
            }
            context.out.println(builder.create().toJson(result));
        }
    } catch (ParseException e) {
        context.out.println(Services.getMessage(e.getClass().getName(), e.getMessage()));
        logger.debug("Main - exit on error");
        System.exit(1);
    } catch (Throwable e) {
        logger.debug("Command triggered exception: " + Arrays.toString(context.getArgs()), e);
        e.printStackTrace(context.err);

        logger.debug("Main - exit on error");
        System.exit(1);
    }
}

From source file:android.support.animation.DynamicAnimation.java

/**
 * Remove an entry from the list by marking it {@code null} and clean up later.
 *//*w w  w  . j  av a 2 s . c  om*/
private static <T> void removeEntry(ArrayList<T> list, T entry) {
    int id = list.indexOf(entry);
    if (id >= 0) {
        list.set(id, null);
    }
}

From source file:com.sean.takeastand.util.Utils.java

public static void setScheduleTitle(String title, Context context, int UID) {
    if (title.equals("")) {
        ArrayList<FixedAlarmSchedule> fixedAlarmSchedules = new ScheduleDatabaseAdapter(context)
                .getFixedAlarmSchedules();
        int schedulePosition = 1;
        for (int i = 0; i < fixedAlarmSchedules.size(); i++) {
            if (UID == fixedAlarmSchedules.get(i).getUID()) {
                schedulePosition += fixedAlarmSchedules.indexOf(fixedAlarmSchedules.get(i));
            }/*from  w w  w . j av a  2s  .c  om*/
        }
        title = context.getString(R.string.schedule) + schedulePosition;
    }
    SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.EVENT_SHARED_PREFERENCES, 0);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(Constants.CURRENT_SCHEDULED_ALARM_TITLE, title);
    editor.commit();
}

From source file:eionet.cr.web.action.admin.harvestscripts.HarvestScriptParser.java

/**
 *
 * @param str//from  www  . jav a2 s . c o m
 * @param token
 * @return
 */
private static String substringBeforeToken(String str, String token) {

    if (str == null || str.trim().length() == 0 || token == null || token.trim().length() == 0) {
        return str;
    }

    StringTokenizer st = new StringTokenizer(str, " \t\n\r\f", true);
    ArrayList<String> originalTokens = new ArrayList<String>();
    ArrayList<String> upperCaseTokens = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String nextToken = st.nextToken();
        originalTokens.add(nextToken);
        upperCaseTokens.add(nextToken.toUpperCase());
    }

    int tokenIndex = upperCaseTokens.indexOf(token.toUpperCase());
    if (tokenIndex >= 0) {
        return tokensToString(originalTokens.subList(0, tokenIndex));
    } else {
        return str;
    }
}

From source file:eionet.cr.web.action.admin.harvestscripts.HarvestScriptParser.java

/**
 *
 * @param str/* w w w  .  ja  v  a2s . co m*/
 * @param token
 * @return
 */
private static String substringAfterToken(String str, String token) {

    if (str == null || str.trim().length() == 0 || token == null || token.trim().length() == 0) {
        return str;
    }

    StringTokenizer st = new StringTokenizer(str, " \t\n\r\f", true);
    ArrayList<String> originalTokens = new ArrayList<String>();
    ArrayList<String> upperCaseTokens = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String nextToken = st.nextToken();
        originalTokens.add(nextToken);
        upperCaseTokens.add(nextToken.toUpperCase());
    }

    int tokenIndex = upperCaseTokens.indexOf(token.toUpperCase());
    if (tokenIndex >= 0) {
        String afterToken = "";
        int tokensSize = originalTokens.size();
        if (tokenIndex < tokensSize - 1) {
            afterToken = tokensToString(originalTokens.subList(tokenIndex + 1, tokensSize));
        }

        return afterToken;
    } else {
        return str;
    }
}

From source file:com.draagon.meta.manager.ObjectManager.java

/**
 * Clips the specified objects by the provided range
 *//*from   ww  w  .jav a 2 s .  co m*/
public static Collection<Object> distinctObjects(Collection<?> objs) throws MetaException {
    // TODO:  Check this, as I don't think it works!

    ArrayList<Object> a = new ArrayList<Object>(objs);
    for (Iterator<Object> i = a.iterator(); i.hasNext();) {
        Object o = i.next();

        // Find the first index of the object
        int fi = a.indexOf(o);

        // Remove all objects of the same value
        int li = 0;
        while ((li = a.lastIndexOf(o)) != fi)
            a.remove(li);
    }

    return a;
}

From source file:org.apache.sysml.hops.codegen.opt.PlanSelectionFuseCostBased.java

private static boolean hasNoRefToMaterialization(MemoTableEntry me, ArrayList<Long> M, boolean[] plan) {
    boolean ret = true;
    for (int i = 0; ret && i < 3; i++)
        ret &= (!M.contains(me.input(i)) || !plan[M.indexOf(me.input(i))]);
    return ret;/*w  ww  .  j  a va 2s  .  c  o  m*/
}