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:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java

/** Writes the class information to a file in SOMLib format. */
public static void writeAsSOMLib(HashMap<String, String> classInfo, HashSet<String> classNames, String fileName)
        throws IOException, SOMLibFileFormatException {
    ArrayList<String> classNamesList = new ArrayList<String>(classNames);
    Collections.sort(classNamesList);

    PrintWriter writer = FileUtils.openFileForWriting("SOMLib class info", fileName);
    writer.println("$TYPE class_information");

    writer.println("$NUM_CLASSES " + classNames.size());
    writer.println("$CLASS_NAMES " + StringUtils.toString(classNamesList, "", "", " "));
    writer.println("$XDIM 2");
    writer.println("$YDIM " + classInfo.size());
    for (String key : classInfo.keySet()) {
        writer.println(key + " " + classNamesList.indexOf(classInfo.get(key)));
    }//  ww w  . ja  v a2s  . c o  m

    writer.flush();
    writer.close();
}

From source file:be.ibridge.kettle.core.XMLHandler.java

public static String[] getNodeElements(Node node) {
    ArrayList elements = new ArrayList(); // List of String 

    NodeList nodeList = node.getChildNodes();
    if (nodeList == null)
        return null;

    for (int i = 0; i < nodeList.getLength(); i++) {
        String nodeName = nodeList.item(i).getNodeName();
        if (elements.indexOf(nodeName) < 0)
            elements.add(nodeName);/*w  w  w .ja  v a  2  s  . com*/
    }

    if (elements.size() == 0)
        return null;

    return (String[]) elements.toArray(new String[elements.size()]);
}

From source file:io.github.agentsoz.abmjadex.super_central.ABMSimStarter.java

private static void parsingArguments(String[] args, Options options) {
    //flags/*from   w  w  w  .ja  va 2 s .c o m*/
    boolean isRunningCO = true;
    boolean isForced = false; //Overwrite any existing CO xml file
    boolean isRunningSC = true;
    boolean isLogToConsole = false;
    Level logLevel = Level.INFO;

    Properties prop = null;
    CommandLine line = null;
    BasicParser parser = new BasicParser();
    ArrayList<String> argsList = new ArrayList<String>();

    //Initialize argsList with args
    for (int i = 0; i < args.length; i++) {
        argsList.add(args[i]);
    }

    //Update 04/17/2013
    String[] specificArgs = packageOptionSpecific(args);

    try {
        // parse the command line arguments
        //line = parser.parse(options, args );
        //Update 04/17/2013
        line = parser.parse(options, specificArgs);

        //Commandline required -prop argument to be filled with valid properties file location
        if (line.hasOption(HELP)) {
            //Remove app specific arguments from total arguments
            int helpIndex = argsList.indexOf("-" + HELP);
            if (helpIndex == -1)
                helpIndex = argsList.indexOf("-" + HELP_LONG);
            argsList.remove(helpIndex);

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Jadex-ABMS", options);
        }

        if (line.hasOption(PROP)) {
            //Remove app specific arguments from total arguments
            int propIndex = argsList.indexOf("-" + PROP);
            if (propIndex == -1)
                propIndex = argsList.indexOf("-" + PROP_LONG);
            argsList.remove(propIndex + 1);
            argsList.remove(propIndex);

            String propertiesLoc = line.getOptionValue(PROP).replace("\\", "/").replace("\\\\", "/");
            prop = new Properties();

            try {
                prop.load(new FileInputStream(propertiesLoc));
                //Parsing options value into local flags------------------------
                if (line.hasOption(MODE)) {
                    String mode = line.getOptionValue(MODE);
                    if (mode.equalsIgnoreCase(CO_ONLY)) {
                        isRunningSC = false;
                    } else if (mode.equalsIgnoreCase(SC_CO)) {
                        //Default value is to run an SC and a CO
                    } else if (mode.equalsIgnoreCase(SC_ONLY)) {
                        isRunningCO = false;
                    } else {
                        throw new ParseException("Wrong argument for -mode.");
                    }

                    //Remove app specific arguments from total arguments
                    int modeIndex = argsList.indexOf("-" + MODE);
                    argsList.remove(modeIndex + 1);
                    argsList.remove(modeIndex);
                }

                if (line.hasOption(FORCED)) {
                    isForced = true;
                    //Remove app specific arguments from total arguments
                    int modeIndex = argsList.indexOf("-" + FORCED);
                    if (modeIndex == -1)
                        modeIndex = argsList.indexOf("-" + FORCED_LONG);
                    argsList.remove(modeIndex);
                }

                if (line.hasOption(GUI)) {
                    String guiMode = line.getOptionValue(GUI);
                    if (!guiMode.equalsIgnoreCase("true") && !guiMode.equalsIgnoreCase("false"))
                        throw new ParseException("Wrong argument for -gui.");
                } else {
                    argsList.add("-" + GUI);
                    int guiIndex = argsList.indexOf("-" + GUI);
                    argsList.add(guiIndex + 1, "false");
                }

                if (line.hasOption(LOG_CONSOLE)) {
                    isLogToConsole = true;
                    //Remove app specific arguments from total arguments
                    int logCIndex = argsList.indexOf("-" + LOG_CONSOLE);
                    argsList.remove(logCIndex);
                }

                if (line.hasOption(LOG_LVL)) {
                    String level = line.getOptionValue(LOG_LVL);
                    if (level.equalsIgnoreCase("INFO")) {
                        logLevel = Level.INFO;
                    } else if (level.equalsIgnoreCase("ALL")) {
                        logLevel = Level.ALL;
                    } else if (level.equalsIgnoreCase("CONFIG")) {
                        logLevel = Level.CONFIG;
                    } else if (level.equalsIgnoreCase("FINE")) {
                        logLevel = Level.FINE;
                    } else if (level.equalsIgnoreCase("FINER")) {
                        logLevel = Level.FINER;
                    } else if (level.equalsIgnoreCase("FINEST")) {
                        logLevel = Level.FINEST;
                    } else if (level.equalsIgnoreCase("OFF")) {
                        logLevel = Level.OFF;
                    } else if (level.equalsIgnoreCase("SEVERE")) {
                        logLevel = Level.SEVERE;
                    } else if (level.equalsIgnoreCase("WARNING")) {
                        logLevel = Level.WARNING;
                    } else {
                        throw new ParseException("argument for loglvl unknown");
                    }
                    //Remove app specific arguments from total arguments
                    int logLvlIndex = argsList.indexOf("-" + LOG_LVL);
                    argsList.remove(logLvlIndex + 1);
                    argsList.remove(logLvlIndex);
                }

                //Setup logger
                try {
                    ABMBDILoggerSetter.initialized(prop, isLogToConsole, logLevel);
                    ABMBDILoggerSetter.setup(LOGGER);
                } catch (IOException e) {
                    e.printStackTrace();
                    LOGGER.severe(e.getMessage());
                    throw new RuntimeException("Problems with creating logfile");
                }

                //Translate argsList into array------------------------------
                String[] newargs = new String[argsList.size()];
                for (int i = 0; i < argsList.size(); i++) {
                    newargs[i] = argsList.get(i);
                }

                //Running the system----------------------------------------
                if (isRunningSC == true) {
                    runSC(prop);
                }

                if (isRunningCO == true) {
                    runCO(prop, newargs, isForced);
                }

            } catch (IOException e) {
                e.printStackTrace();
                LOGGER.severe(e.getMessage());
            }
        } else {
            throw new ParseException("-prop <properties_location> is a required option");
        }

    } catch (ParseException exp) {
        LOGGER.severe("Unexpected exception:" + exp.getMessage());

        //If its not working print out help info
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Jadex-ABMS", options);
    }
}

From source file:org.erdc.cobie.shared.COBieUtility.java

public static int cobieStringRankingFromStringMap(Map<String, String> valMap,
        ArrayList<String> prioritizedPropertyNames) {
    int rank = -1;

    String cString = "";
    String tmpVal = "";
    for (String prioritizedPropertyName : prioritizedPropertyNames) {
        if (valMap.keySet().contains(prioritizedPropertyName)) {
            tmpVal = valMap.get(prioritizedPropertyName);
            if ((tmpVal.length() > 0) && (cString.length() == 0)) {
                rank = prioritizedPropertyNames.size()
                        - prioritizedPropertyNames.indexOf(prioritizedPropertyName);
            }/*from w ww.j  a v a2s. c  o  m*/
        }
    }
    return rank;
}

From source file:org.openossad.util.core.xml.XMLHandler.java

public static String[] getNodeElements(Node node) {
    ArrayList<String> elements = new ArrayList<String>(); // List of String 

    NodeList nodeList = node.getChildNodes();
    if (nodeList == null)
        return null;

    for (int i = 0; i < nodeList.getLength(); i++) {
        String nodeName = nodeList.item(i).getNodeName();
        if (elements.indexOf(nodeName) < 0)
            elements.add(nodeName);/*from   w w w. ja va 2 s .  c o m*/
    }

    if (elements.isEmpty())
        return null;

    return elements.toArray(new String[elements.size()]);
}

From source file:de.hybris.platform.subscriptionservices.interceptor.impl.AbstractOrderLoadInterceptorTest.java

private void verifyChildCartSequence(final CartModel masterCart) {
    assertTrue("", CollectionUtils.isNotEmpty(masterCart.getChildren()));
    assertEquals("", 3, masterCart.getChildren().size());

    final ArrayList<AbstractOrderModel> childCarts = new ArrayList<AbstractOrderModel>(
            masterCart.getChildren());// www.  j a  va  2 s.  c  om
    assertEquals("", 0, childCarts.indexOf(childCartMonthly));
    assertEquals("", 1, childCarts.indexOf(childCartQuarterly));
    assertEquals("", 2, childCarts.indexOf(childCartYearly));
}

From source file:org.openadaptor.auxil.convertor.fixedwidth.AbstractFixedWidthStringConvertor.java

/**
 * @return false if the field name supplied is null or an empty string
 * /*from   w  w  w. j a  v a2  s.c o  m*/
 * @throws ValidationException
 *           if there are multiple fields defined with the same name
 */
public boolean isValidFieldName(String name) {
    ArrayList names = getFieldNames();
    int a = names.indexOf(name);
    int b = names.lastIndexOf(name);
    if (a != b)
        throw new ValidationException("Multiple field names defined", this);

    return (name != null && !name.equals(""));
}

From source file:com.android.pchelper.http.RequestParams.java

@Override
public String toString() {
    StringBuilder result = new StringBuilder();
    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        if (result.length() > 0)
            result.append("&");

        result.append(entry.getKey());//  w w w .  jav a  2s.  c om
        result.append("=");
        result.append(entry.getValue());
    }

    for (ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) {
        if (result.length() > 0)
            result.append("&");

        ArrayList<String> values = entry.getValue();
        for (String value : values) {
            if (values.indexOf(value) != 0)
                result.append("&");
            result.append(entry.getKey());
            result.append("=");
            result.append(value);
        }
    }

    return result.toString();
}

From source file:org.mda.bcb.tcgagsdata.create.Metadata.java

public void writePatientDataFile(String theIdColumn, String theDataColumn, String theOutputFile,
        File[] theDiseaseSamplesFiles) throws IOException {
    // TODO: theDiseaseSampleFile - disease in first column, rest of row is SAMPLE barcode
    TcgaGSData.printWithFlag("Metadata::writePatientDataFile - start " + theOutputFile);
    TreeMap<String, String> patientDisease = new TreeMap<>();
    try (BufferedReader br = Files.newBufferedReader(Paths.get(mMetadataFile),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        // read header/write header
        int indexId = -1;
        int indexData = -1;
        {/*ww w . j a  v  a  2 s.co m*/
            String line = br.readLine();
            ArrayList<String> headerArray = new ArrayList<>();
            headerArray.addAll(Arrays.asList(line.split("\t", -1)));
            indexId = headerArray.indexOf(theIdColumn);
            indexData = headerArray.indexOf(theDataColumn);
        }
        //
        for (String line = br.readLine(); null != line; line = br.readLine()) {
            String[] splitted = line.split("\t", -1);
            patientDisease.put(trimToPatientId(splitted[indexId]), splitted[indexData]);
        }
        for (File file : theDiseaseSamplesFiles) {
            TreeSet<String> barcodes = getDiseaseSampleData(file, true);
            for (String barcode : barcodes) {
                String patientId = trimToPatientId(barcode);
                if (false == patientDisease.keySet().contains(patientId)) {
                    patientDisease.put(patientId, MetadataTcgaNames.M_UNKNOWN);
                }
            }
        }
    }
    try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(theOutputFile),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        bw.write("ID\tDATA");
        bw.newLine();
        for (String key : patientDisease.keySet()) {
            bw.write(key + "\t" + patientDisease.get(key));
            bw.newLine();
        }
    }
    TcgaGSData.printWithFlag("Metadata::writePatientDataFile - finished " + theOutputFile);
}

From source file:org.mda.bcb.tcgagsdata.create.Metadata.java

public void writeBarcodeDataFile(String theIdColumn, String theDataColumn, String theOutputFile,
        File[] theDiseaseSamplesFiles) throws IOException {
    // TODO: theDiseaseSampleFile - disease in first column, rest of row is SAMPLE barcode
    TcgaGSData.printWithFlag("Metadata::writeBarcodeDataFile - start " + theOutputFile);
    TreeSet<String> processedBarcode = new TreeSet<>();
    try (BufferedReader br = Files.newBufferedReader(Paths.get(mMetadataFile),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(theOutputFile),
                Charset.availableCharsets().get("ISO-8859-1"))) {
            // read header/write header
            int indexId = -1;
            int indexData = -1;
            {/*from  www . j  a v a  2 s .c  o  m*/
                String line = br.readLine();
                ArrayList<String> headerArray = new ArrayList<>();
                headerArray.addAll(Arrays.asList(line.split("\t", -1)));
                indexId = headerArray.indexOf(theIdColumn);
                indexData = headerArray.indexOf(theDataColumn);
            }
            bw.write("ID\tDATA");
            bw.newLine();
            //
            for (String line = br.readLine(); null != line; line = br.readLine()) {
                String[] splitted = line.split("\t", -1);
                bw.write(splitted[indexId] + "\t" + splitted[indexData]);
                processedBarcode.add(splitted[indexId]);
                bw.newLine();
            }
            TcgaGSData.printWithFlag("Metadata::writeBarcodeDataFile - processed file " + theOutputFile);
            for (File file : theDiseaseSamplesFiles) {
                TreeSet<String> barcodes = getDiseaseSampleData(file, true);
                for (String barcode : barcodes) {
                    if (false == processedBarcode.contains(barcode)) {
                        bw.write(barcode + "\t" + MetadataTcgaNames.M_UNKNOWN);
                        processedBarcode.add(barcode);
                        bw.newLine();
                    }
                }
            }
        }
    }
    TcgaGSData.printWithFlag("Metadata::writeBarcodeDataFile - finished");
}