Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:com.clearspring.metriccatcher.MetricCatcher.java

/**
 * Create a Metric object from a JSONMetric
 *
 * @param jsonMetric A JSONMetric to make a Metric from
 * @return A Metric equivalent to the given JSONMetric
 *///from   ww w.  ja v  a  2 s. c om
protected Metric createMetric(JSONMetric jsonMetric) {
    // Split the name from the JSON on dots for the metric group/type/name
    MetricName metricName;
    ArrayList<String> parts = new ArrayList<String>(Arrays.asList(jsonMetric.getName().split("\\.")));
    if (parts.size() >= 3) {
        metricName = new MetricName(parts.remove(0), parts.remove(0), StringUtils.join(parts, "."));
    } else {
        metricName = new MetricName(jsonMetric.getName(), "", "");
    }

    Class<?> metricType = jsonMetric.getMetricClass();
    if (metricType == Gauge.class) {
        return Metrics.newGauge(metricName, new GaugeMetricImpl());
    } else if (metricType == Counter.class) {
        return Metrics.newCounter(metricName);
    } else if (metricType == Meter.class) {
        // TODO timeunit
        return Metrics.newMeter(metricName, jsonMetric.getName(), TimeUnit.MINUTES);
    } else if (metricType == Histogram.class) {
        if (jsonMetric.getType().equals("biased")) {
            return Metrics.newHistogram(metricName, true);
        } else {
            return Metrics.newHistogram(metricName, false);
        }
    } else if (metricType == Timer.class) {
        return Metrics.newTimer(metricName, TimeUnit.MILLISECONDS, TimeUnit.SECONDS);
    }

    // Uh-oh
    return null;
}

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

private static void parsingArguments(String[] args, Options options) {
    //flags/*from   w  w w.  j  a  va  2s .co 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:edu.usc.squash.Main.java

private static HashMap<String, Module> parseQASMHF(Library library) {
    HFQParser hfqParser = null;//from w  ww.ja  v  a  2 s  . c o  m
    /*
     * Pass 1: Getting module info
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> moduleMap = hfqParser.parse(library, true, null);

    /* 
     * In order traversal of modules
     */

    ArrayList<CalledModule> modulesList = new ArrayList<CalledModule>();
    modulesList.add(new CalledModule(moduleMap.get("main"), new ArrayList<String>()));
    while (!modulesList.isEmpty()) {
        Module module = modulesList.get(0).getModule();

        if (!module.isVisited()) {
            module.setVisited();

            ArrayList<CalledModule> calledModules = module.getChildModules();
            modulesList.addAll(calledModules);
            for (CalledModule calledModule : calledModules) {
                Module childModule = calledModule.getModule();
                for (int i = 0; i < calledModule.getOps().size(); i++) {
                    Operand operand = childModule.getOperand(i);
                    if (operand.isArray() && operand.getLength() == -1) {
                        operand.setLength(module.getOperandLength(calledModule.getOps().get(i)));
                    }
                }
            }
        }
        modulesList.remove(0);
    }

    /*
     * Pass 2: Making hierarchical QMDG
     */
    try {
        hfqParser = new HFQParser(new FileInputStream(hfqPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    HashMap<String, Module> modules = hfqParser.parse(library, false, moduleMap);

    return modules;
}

From source file:com.shanke.common.conf.StringHandle.java

/**
 * Split a string using the given separator, with no escaping performed.
 * /*  w ww.  jav a2s  .c  o  m*/
 * @param str
 *            a string to be split. Note that this may not be null.
 * @param separator
 *            a separator char
 * @return an array of strings
 */
public static String[] split(String str, char separator) {
    // String.split returns a single empty result for splitting the empty
    // string.
    if (str.isEmpty()) {
        return new String[] { "" };
    }
    ArrayList<String> strList = new ArrayList<String>();
    int startIndex = 0;
    int nextIndex = 0;
    while ((nextIndex = str.indexOf((int) separator, startIndex)) != -1) {
        strList.add(str.substring(startIndex, nextIndex));
        startIndex = nextIndex + 1;
    }
    strList.add(str.substring(startIndex));
    // remove trailing empty split(s)
    int last = strList.size(); // last split
    while (--last >= 0 && "".equals(strList.get(last))) {
        strList.remove(last);
    }
    return strList.toArray(new String[strList.size()]);
}

From source file:ai_coursework.HWState.java

/**
 * Takes the Person Objects that are on the raft away from one bank and puts
 * them on the other bank. Deciding which banks to take from and place to 
 * comes from the toBank variable from the Action Class
 * @param action   The action to be applied to the state
 * @return A new HWState with the action applied
 *//*  ww w.  j  a v a2s.  com*/
public HWState applyAction(HWAction action) {
    ArrayList<Person> newNorth = new ArrayList<>(this.northBank);
    ArrayList<Person> newSouth = new ArrayList<>(this.southBank);

    if (action.toBank == RiverBank.NORTH) {
        for (int i = 0; i < action.raft.size(); i++) {
            newSouth.remove(action.raft.get(i));
            newNorth.add(action.raft.get(i));
        }
        return new HWState(newNorth, newSouth, RiverBank.NORTH);
    }

    for (int i = 0; i < action.raft.size(); i++) {
        newNorth.remove(action.raft.get(i));
        newSouth.add(action.raft.get(i));
    }
    return new HWState(newNorth, newSouth, RiverBank.SOUTH);
}

From source file:com.docdoku.server.rest.InstanceMessageBodyWriter.java

private void generateInstanceStream(PartUsageLink usageLink, double tx, double ty, double tz, double rx,
        double ry, double rz, List<Integer> filteredPath, List<Integer> instanceIds)
        throws JAXBException, IOException {

    //List<InstanceDTO> instancesDTO = new ArrayList<InstanceDTO>();

    PartMaster pm = usageLink.getComponent();
    PartRevision partR = pm.getLastRevision();
    PartIteration partI = partR.getLastIteration();

    String partIterationId = new StringBuilder().append(pm.getNumber()).append("-").append(partR.getVersion())
            .append("-").append(partI.getIteration()).toString();

    List<GeometryDTO> files = new ArrayList<GeometryDTO>();
    List<InstanceAttributeDTO> attributes = new ArrayList<InstanceAttributeDTO>();

    for (Geometry geometry : partI.getGeometries()) {
        files.add(mapper.map(geometry, GeometryDTO.class));
    }//from w  w  w.ja v a 2s .c  o m

    for (InstanceAttribute attr : partI.getInstanceAttributes().values()) {
        attributes.add(mapper.map(attr, InstanceAttributeDTO.class));
    }

    for (CADInstance instance : usageLink.getCadInstances()) {

        //compute absolutes values
        double atx = tx + getRelativeTxAfterParentRotation(rx, ry, rz, instance.getTx(), instance.getTy(),
                instance.getTz());
        double aty = ty + getRelativeTyAfterParentRotation(rx, ry, rz, instance.getTx(), instance.getTy(),
                instance.getTz());
        double atz = tz + getRelativeTzAfterParentRotation(rx, ry, rz, instance.getTx(), instance.getTy(),
                instance.getTz());
        double arx = rx + instance.getRx();
        double ary = ry + instance.getRy();
        double arz = rz + instance.getRz();
        instanceIds.add(instance.getId());
        String id = StringUtils.join(instanceIds.toArray(), "-");

        if (!partI.isAssembly() && partI.getGeometries().size() > 0 && filteredPath.isEmpty()) {
            if (getAddComma())
                getEntityStream().write(getComma());

            getMarshaller().marshallToJSON(
                    new InstanceDTO(id, partIterationId, atx, aty, atz, arx, ary, arz, files, attributes),
                    getEntityStream());
            setAddComma(true);
        } else {
            for (PartUsageLink component : partI.getComponents()) {
                ArrayList<Integer> copyInstanceIds = new ArrayList<Integer>(instanceIds);
                if (filteredPath.isEmpty()) {
                    generateInstanceStream(component, atx, aty, atz, arx, ary, arz, filteredPath,
                            copyInstanceIds);
                } else if (component.getId() == filteredPath.get(0)) {
                    ArrayList<Integer> copyWithoutCurrentId = new ArrayList<Integer>(filteredPath);
                    copyWithoutCurrentId.remove(0);
                    generateInstanceStream(component, atx, aty, atz, arx, ary, arz, copyWithoutCurrentId,
                            copyInstanceIds);
                }
            }
        }
    }
}

From source file:ca.uhn.fhir.validation.FhirValidator.java

/**
 * Removes a validator module from this validator. You may register as many modules as you like, and remove them at any time.
 * //ww  w .j  a  v a2s.c  o m
 * @param theValidator
 *           The validator module. Must not be null.
 */
public synchronized void unregisterValidatorModule(IValidatorModule theValidator) {
    Validate.notNull(theValidator, "theValidator must not be null");
    ArrayList<IValidatorModule> newValidators = new ArrayList<IValidatorModule>(myValidators.size() + 1);
    newValidators.addAll(myValidators);
    newValidators.remove(theValidator);

    myValidators = newValidators;
}

From source file:gov.nih.nci.ispy.web.ajax.DynamicReportGenerator.java

public Map removeTmpGeneric(String type, String elem) {
    HttpSession session = ExecutionContext.get().getSession(false);
    ArrayList al = new ArrayList();
    if (session.getAttribute(type) != null) {
        al = (ArrayList) session.getAttribute(type);
    }/*ww w .  j  a  va  2s. c om*/
    al.remove(elem); // nuke it
    session.setAttribute(type, al); //put back in session
    String tmpElems = "";
    for (int i = 0; i < al.size(); i++)
        tmpElems += al.get(i) + "<br/>";

    Map results = new HashMap();
    results.put("count", al.size());
    results.put("elements", tmpElems);
    return results;
}

From source file:gov.nih.nci.firebird.selenium2.tests.profile.credentials.AbstractCredentialsTest.java

private <T extends ListItem> T getDifferentListEntry(List<T> list, T currentItem) {
    ArrayList<T> copy = Lists.newArrayList(list);
    copy.remove(currentItem);
    return Iterables.getFirst(copy, null);
}

From source file:com.github.sevntu.checkstyle.ordering.MethodOrder.java

public MethodOrder moveMethodBy(Method method, int indexShift) {
    final int currentIndex = getMethodIndex(method);
    final int newIndex = currentIndex + indexShift;
    if (0 <= newIndex && newIndex < methods.size()) {
        final ArrayList<Method> newOrdering = new ArrayList<>(currentOrdering);
        newOrdering.remove(currentIndex);
        newOrdering.add(newIndex, method);
        return new MethodOrder(this, newOrdering);
    } else {/*  w  w w  . j  ava  2  s  .  c  o  m*/
        throw new IllegalArgumentException(
                String.format("Trying to move method #%d by %d positions", currentIndex, newIndex));
    }
}