Example usage for java.util ArrayList set

List of usage examples for java.util ArrayList set

Introduction

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

Prototype

public E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this list with the specified element.

Usage

From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java

public static void normalizeFeatureL1(ArrayList<Double> sample) {
      int sum = 0;

      for (int i = 0; i < sample.size(); i++) {
          double val = sample.get(i);
          if (val < 0)
              val = -1 * val;

          sum += val;
      }/*  w  ww .  j av  a  2s .co  m*/

      for (int i = 0; i < sample.size(); i++) {
          double v;
          if (sum == 0)
              v = 0;
          else
              v = sample.get(i) / sum;// *100;

          sample.set(i, v);
      }
  }

From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFParseQQFriendFlag.java

public Object evaluate(DeferredObject[] arguments) throws HiveException {
    assert (arguments.length == 2);

    if (arguments[0].get() == null || arguments[1].get() == null) {
        return null;
    }/*  w  w w .ja  v  a 2 s .c  o  m*/

    Text s = (Text) converters[0].convert(arguments[0].get());
    Text regex = (Text) converters[1].convert(arguments[1].get());

    ArrayList<Text> result = new ArrayList<Text>();
    ArrayList<String> strArray = new ArrayList<String>(Arrays.asList("0", "0", "0", "0", "0"));

    for (String str : s.toString().split(regex.toString())) {
        //LOG.info("strrrr: " + str);
        if (str.equals("1001")) {
            strArray.set(0, "1");
        } else if (str.equals("1002")) {
            strArray.set(1, "1");
        } else if (str.equals("1003")) {
            strArray.set(2, "1");
        } else if (str.equals("1004")) {
            strArray.set(3, "1");
        } else if (Integer.valueOf(str).intValue() >= 3000 && Integer.valueOf(str).intValue() <= 3500) {
            strArray.set(4, str);
        }
    }

    for (String str : strArray) {
        result.add(new Text(str));
    }

    return result;
}

From source file:ca.uhn.fhir.rest.param.ParameterUtil.java

static List<String> splitParameterString(String theInput, char theDelimiter, boolean theUnescapeComponents) {
    ArrayList<String> retVal = new ArrayList<String>();
    if (theInput != null) {
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < theInput.length(); i++) {
            char next = theInput.charAt(i);
            if (next == theDelimiter) {
                if (i == 0) {
                    b.append(next);/*from  w ww  .  j  a  v a2 s.c  o  m*/
                } else {
                    char prevChar = theInput.charAt(i - 1);
                    if (prevChar == '\\') {
                        b.append(next);
                    } else {
                        if (b.length() > 0) {
                            retVal.add(b.toString());
                            b.setLength(0);
                        }
                    }
                }
            } else {
                b.append(next);
            }
        }
        if (b.length() > 0) {
            retVal.add(b.toString());
        }
    }

    if (theUnescapeComponents) {
        for (int i = 0; i < retVal.size(); i++) {
            retVal.set(i, unescape(retVal.get(i)));
        }
    }

    return retVal;
}

From source file:com.github.haixing_hu.bean.DefaultProperty.java

@Override
public final void setIndexedValue(final int index, final Object value) {
    final ArrayList<Object> list = getIndexedValue();
    checkType(value);// ww w  .  j av a  2  s .  c o m
    list.set(index, value);
}

From source file:edu.uci.ics.hyracks.algebricks.core.jobgen.impl.JobBuilder.java

private <E> void addAtPos(ArrayList<E> a, E elem, int pos) {
    int n = a.size();
    if (n > pos) {
        a.set(pos, elem);
    } else {//from  w w  w.  j  av  a 2  s.c om
        for (int k = n; k < pos; k++) {
            a.add(null);
        }
        a.add(elem);
    }
}

From source file:org.libreplan.business.planner.entities.ShareDivision.java

private ArrayList<Share> fromWrappers(List<ShareWrapper> wrapped) {
    ArrayList<Share> newShares = new ArrayList<Share>(shares.size());
    for (int i = 0; i < wrapped.size(); i++) {
        newShares.add(null);/*from w  w  w  . ja v  a  2 s .com*/
    }
    for (ShareWrapper shareWrapper : wrapped) {
        newShares.set(shareWrapper.originalPosition, shareWrapper.share);
    }
    return newShares;
}

From source file:org.archiviststoolkit.importer.TabSubjectImportHandler.java

/**
 * Map input columns to real columns./*from w w  w . jav  a 2  s.com*/
 *
 * @param dataList the list to patch.
 * @return the patched list.
 */
public ArrayList mapColumn(ArrayList dataList) {

    for (int loop = 0; loop < dataList.size(); loop++) {
        String name = (String) dataList.get(loop);

        name = name.replace(' ', '_');
        name = name.toLowerCase();
        name = name.replace('/', '_');
        name = name.replace('-', '_');
        dataList.set(loop, name);

    }

    return (dataList);
}

From source file:edu.cmu.sphinx.speakerid.SpeakerCluster.java

/**
 * Returns a 2 * n length array where n is the numbers of intervals assigned
 * to the speaker modeled by this cluster every pair of elements with
 * indexes (2 * i, 2 * i + 1) represents the start time and the length for
 * each interval/*from   www . ja  v a2 s  .  co m*/
 * 
 * We may need a delay parameter to this function because the segments may
 * not be exactly consecutive
 *
 * @return a list of segments for speaker
 */
public ArrayList<Segment> getSpeakerIntervals() {
    Iterator<Segment> it = segmentSet.iterator();
    Segment curent = new Segment(0, 0), previous = it.next();
    int start = previous.getStartTime();
    int length = previous.getLength();
    int idx = 0;
    ArrayList<Segment> ret = new ArrayList<Segment>();
    ret.add(previous);
    while (it.hasNext()) {
        curent = it.next();
        start = ret.get(idx).getStartTime();
        length = ret.get(idx).getLength();
        if ((start + length) == curent.getStartTime()) {
            ret.set(idx, new Segment(start, length + curent.getLength()));
        } else {
            idx++;
            ret.add(curent);
        }
        previous = curent;
    }
    return ret;
}

From source file:com.ge.research.semtk.load.DataCleaner.java

/**
 * Take a row of data and perform splits, returning a set of rows.
 * @param row the input row of data/*from w  w w. j  a  va  2 s .  co m*/
 * @return rows of data containing split fields
 */
private ArrayList<ArrayList<String>> performSplits(ArrayList<String> row) {

    ArrayList<ArrayList<String>> rows = new ArrayList<ArrayList<String>>();
    rows.add(row); // start with the input row

    String delimiter;
    String header;
    String value;
    for (int i = 0; i < row.size(); i++) { // for each value in the row         
        value = row.get(i);
        header = headers.get(i);
        delimiter = columnsToSplit.get(header);

        if (delimiter != null && value.contains(delimiter)) { // if this value needs to be split

            String[] splitValues = value.split(delimiter); // split the value
            ArrayList<ArrayList<String>> rowsNew = new ArrayList<ArrayList<String>>();

            // for each previous row, replace with new set of rows with split values
            for (ArrayList<String> rowOld : rows) {
                for (String splitValue : splitValues) {
                    ArrayList<String> rowNew = (ArrayList<String>) rowOld.clone();
                    rowNew.set(i, splitValue.trim()); // replace the unsplit value with the split value  (trim to remove unwanted spaces, e.g. after commas)
                    rowsNew.add(rowNew);
                }
            }
            rows = rowsNew; // overwrite old rows with new rows 
        }
    }
    return rows;
}

From source file:levelBuilder.DialogMaker.java

/**
 * Displays properties of the currently selected node.
 * Also allows changing of most node properties. 
 */// www. j ava2s .c o  m
private static void nodePropertiesWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "probSet":
                //parsing new probSet string to double[]
                ArrayList<double[]> probSets = selectedNode.getProbSets();
                if (probSetField.getText().equals(""))
                    probSets.remove(strategy);
                else {
                    String[] probSetInput = probSetField.getText().split(",");
                    int numChildren = probSetInput.length;
                    double[] newProbSet = new double[numChildren];
                    for (int c = 0; c < numChildren; c++)
                        newProbSet[c] = Double.parseDouble(probSetInput[c]);
                    if (probSets.size() > strategy)//TODO is this right?
                        probSets.add(strategy, newProbSet);
                    else
                        probSets.set(strategy, newProbSet);
                }
                selectedNode.setProbSets(probSets);
            case "npc":
                if (isNPCBoxChecked)
                    selectedNode.setNPC();
                else
                    selectedNode.setPC();
            case "text":
                dg.changeNodeText(selectedNode, textField.getText());
            case "strategy":
                strategy = Integer.parseInt(strategyField.getText());
            }
        }
    }

    JPanel fieldPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel labelPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel masterPanel = new JPanel(new GridLayout(0, 3, 0, 0));

    //Buttons, ckeckboxes, textboxes, and labels
    textField = new JTextField("May I buy your wand?", 10);
    fieldPanel.add(textField);
    labelPanel.add(new JLabel("Node Text"));
    JButton button1 = new JButton("Change");
    button1.setActionCommand("text");
    button1.addActionListener(new ActionHandler());
    buttonPanel.add(button1);

    npcBox = new JCheckBox();
    npcBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.DESELECTED)
                isNPCBoxChecked = false;
            else
                isNPCBoxChecked = true;
        }
    });
    fieldPanel.add(npcBox);
    labelPanel.add(new JLabel("NPC"));
    JButton button2 = new JButton("Change");
    button2.setActionCommand("npc");
    button2.addActionListener(new ActionHandler());
    buttonPanel.add(button2);

    childrenField = new JTextField("child1,child2", 10);
    fieldPanel.add(childrenField);
    labelPanel.add(new JLabel("Children"));
    JButton button3 = new JButton("");
    buttonPanel.add(button3);

    probSetField = new JTextField("0.1,0.9", 10);
    fieldPanel.add(probSetField);
    labelPanel.add(new JLabel("Probability set"));
    JButton button4 = new JButton("Change");
    button4.setActionCommand("probSet");
    button4.addActionListener(new ActionHandler());
    buttonPanel.add(button4);

    strategyField = new JTextField("0", 10);
    fieldPanel.add(strategyField);
    labelPanel.add(new JLabel("Strategy"));
    JButton button5 = new JButton("Change");
    button5.setActionCommand("strategy");
    button5.addActionListener(new ActionHandler());
    buttonPanel.add(button5);

    masterPanel.add(buttonPanel);
    masterPanel.add(fieldPanel);
    masterPanel.add(labelPanel);

    JFrame frame = new JFrame("Node Properties");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fieldPanel.setOpaque(true);
    frame.setContentPane(masterPanel);
    frame.pack();
    frame.setLocation(windowWidth, verticalWindowPlacement);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height;
}