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:Main.java

public static boolean getFrequentElementBinary(int[] sample) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;/*from   w  w  w.  jav  a 2 s  . com*/

    for (int col = 0; col < sample.length; col++) {
        // System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(sample[col])) {
            map.put(sample[col], id++);
            count.add(1);
            uniId.add(sample[col]);
        } else {
            no = map.get(sample[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        // System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    // System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    if (maxId == 1)
        return true;
    else
        return false;
}

From source file:com.wst.cls.HTTPBaseIO.java

public static ArrayList paramToArray(String param) throws UnsupportedEncodingException {
    ArrayList arr = null;//from  w  w  w .j  a  v  a 2  s  .  co m
    if (param != null) {
        String[] p = param.split("&");
        if (param.toLowerCase().contains("&")) {
            ArrayList p2 = new ArrayList();
            int j = 0;
            for (String p1 : p) {
                if (p1.toLowerCase().startsWith("amp;")) {
                    p2.set(j - 1, p2.get(j - 1) + "&" + p1.substring(4));
                    j--;
                }
                p2.add(p1);
                j++;
            }
            p2.toArray(p);
        }

        for (String p1 : p) {
            String[] item = p1.split("=");
            if (item.length == 2) {
                if (arr == null) {
                    arr = new ArrayList();
                }
                // item[0]=URLDecoder.decode(item[0],charset);
                // item[1]=URLDecoder.decode(item[1],charset);  
                arr.add(item);
            }
        }
    }
    return arr;
}

From source file:de.ingrid.portal.global.UtilsFileHelper.java

/**
 * Sort long values in ArrayList//  w w w .  j  ava  2s  .  co  m
 * 
 * @param fileArray
 */
public static void sortFileByDate(ArrayList<Long> fileArray) {
    boolean unsort = true;
    long temp;

    while (unsort) {
        unsort = false;
        for (int i = 0; i < fileArray.size() - 1; i++)
            if (fileArray.get(i) > fileArray.get(i + 1)) {
                temp = fileArray.get(i);
                fileArray.set(i, fileArray.get(i + 1));
                fileArray.set(i + 1, temp);
                unsort = true;
            }
    }

}

From source file:id.zelory.tanipedia.util.Utils.java

public static ArrayList<Berita> getRandomBerita(Context context, String alamat) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayList<Berita> beritaArrayList = null;
    try {//from   w  w w  . jav a  2s .c om
        beritaArrayList = mapper.readValue(PrefUtils.ambilString(context, "berita"),
                mapper.getTypeFactory().constructCollectionType(ArrayList.class, Berita.class));
    } catch (IOException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < 5; i++) {
        int x = randInt(0, beritaArrayList.size() - 1);
        if (beritaArrayList.get(x).getAlamat().equals(alamat)) {
            beritaArrayList.remove(x);
            i--;
        } else {
            beritaArrayList.set(i, beritaArrayList.get(x));
            beritaArrayList.remove(x);
        }
    }

    for (int i = 5; i < beritaArrayList.size(); i++)
        beritaArrayList.remove(i);

    return beritaArrayList;
}

From source file:android.databinding.tool.util.XmlEditor.java

private static boolean replace(ArrayList<String> lines, Position start, Position end, String text) {
    fixPosition(lines, start);/*from   w  w w .jav a  2 s  .  com*/
    fixPosition(lines, end);
    if (start.line != end.line) {
        String startLine = lines.get(start.line);
        String newStartLine = startLine.substring(0, start.charIndex) + text;
        lines.set(start.line, newStartLine);
        for (int i = start.line + 1; i < end.line; i++) {
            String line = lines.get(i);
            lines.set(i, replaceWithSpaces(line, 0, line.length() - 1));
        }
        String endLine = lines.get(end.line);
        String newEndLine = replaceWithSpaces(endLine, 0, end.charIndex - 1);
        lines.set(end.line, newEndLine);
        return true;
    } else if (end.charIndex - start.charIndex >= text.length()) {
        String line = lines.get(start.line);
        int endTextIndex = start.charIndex + text.length();
        String replacedText = replaceRange(line, start.charIndex, endTextIndex, text);
        String spacedText = replaceWithSpaces(replacedText, endTextIndex, end.charIndex - 1);
        lines.set(start.line, spacedText);
        return true;
    } else {
        String line = lines.get(start.line);
        String newLine = replaceWithSpaces(line, start.charIndex, end.charIndex - 1);
        lines.set(start.line, newLine);
        return false;
    }
}

From source file:picard.analysis.TheoreticalSensitivity.java

public static List<ArrayList<Double>> proportionsAboveThresholds(final List<ArrayList<Integer>> lists,
        final List<Double> thresholds) {
    final ArrayList<ArrayList<Double>> result = new ArrayList<>();

    for (final ArrayList<Integer> list : lists) {
        final ArrayList<Double> newRow = new ArrayList<>(Collections.nCopies(thresholds.size(), 0.0));
        Collections.sort(list);/*from   w  w  w .ja v a  2  s  .com*/
        int n = 0;
        int j = 0; //index within the ordered sample
        while (n < thresholds.size() && j < list.size()) {
            if (thresholds.get(n) > list.get(j))
                j++;
            else
                newRow.set(n++, (double) (list.size() - j) / list.size());
        }
        result.add(newRow);
    }
    return result;
}

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 .ja v  a 2s.  c  o  m*/
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:edu.jhuapl.bsp.detector.OpenMath.java

public static void arrayAdd(ArrayList<Integer> list, int x) {
    for (int i = 0; list != null && i < list.size(); i++) {
        list.set(i, list.get(i) + x);
    }/*from  ww  w .j  av a  2 s.  co  m*/
}

From source file:ch.njol.skript.command.Commands.java

@Nullable
public final static ScriptCommand loadCommand(final SectionNode node) {
    final String key = node.getKey();
    if (key == null)
        return null;
    final String s = ScriptLoader.replaceOptions(key);

    int level = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) == '[') {
            level++;/*  w  ww  . j  av  a2  s .c o m*/
        } else if (s.charAt(i) == ']') {
            if (level == 0) {
                Skript.error("Invalid placement of [optional brackets]");
                return null;
            }
            level--;
        }
    }
    if (level > 0) {
        Skript.error("Invalid amount of [optional brackets]");
        return null;
    }

    Matcher m = commandPattern.matcher(s);
    final boolean a = m.matches();
    assert a;

    final String command = "" + m.group(1).toLowerCase();
    final ScriptCommand existingCommand = commands.get(command);
    if (existingCommand != null && existingCommand.getLabel().equals(command)) {
        final File f = existingCommand.getScript();
        Skript.error("A command with the name /" + command + " is already defined"
                + (f == null ? "" : " in " + f.getName()));
        return null;
    }

    final String arguments = m.group(3) == null ? "" : m.group(3);
    final StringBuilder pattern = new StringBuilder();

    List<Argument<?>> currentArguments = new ArrayList<Argument<?>>();
    m = argumentPattern.matcher(arguments);
    int lastEnd = 0;
    int optionals = 0;
    for (int i = 0; m.find(); i++) {
        pattern.append(escape("" + arguments.substring(lastEnd, m.start())));
        optionals += StringUtils.count(arguments, '[', lastEnd, m.start());
        optionals -= StringUtils.count(arguments, ']', lastEnd, m.start());

        lastEnd = m.end();

        ClassInfo<?> c;
        c = Classes.getClassInfoFromUserInput("" + m.group(2));
        final NonNullPair<String, Boolean> p = Utils.getEnglishPlural("" + m.group(2));
        if (c == null)
            c = Classes.getClassInfoFromUserInput(p.getFirst());
        if (c == null) {
            Skript.error("Unknown type '" + m.group(2) + "'");
            return null;
        }
        final Parser<?> parser = c.getParser();
        if (parser == null || !parser.canParse(ParseContext.COMMAND)) {
            Skript.error("Can't use " + c + " as argument of a command");
            return null;
        }

        final Argument<?> arg = Argument.newInstance(m.group(1), c, m.group(3), i, !p.getSecond(),
                optionals > 0);
        if (arg == null)
            return null;
        currentArguments.add(arg);

        if (arg.isOptional() && optionals == 0) {
            pattern.append('[');
            optionals++;
        }
        pattern.append("%" + (arg.isOptional() ? "-" : "")
                + Utils.toEnglishPlural(c.getCodeName(), p.getSecond()) + "%");
    }

    pattern.append(escape("" + arguments.substring(lastEnd)));
    optionals += StringUtils.count(arguments, '[', lastEnd);
    optionals -= StringUtils.count(arguments, ']', lastEnd);
    for (int i = 0; i < optionals; i++)
        pattern.append(']');

    String desc = "/" + command + " ";
    final boolean wasLocal = Language.setUseLocal(true); // use localised class names in description
    try {
        desc += StringUtils.replaceAll(pattern, "(?<!\\\\)%-?(.+?)%", new Callback<String, Matcher>() {
            @Override
            public String run(final @Nullable Matcher m) {
                assert m != null;
                final NonNullPair<String, Boolean> p = Utils.getEnglishPlural("" + m.group(1));
                final String s = p.getFirst();
                return "<" + Classes.getClassInfo(s).getName().toString(p.getSecond()) + ">";
            }
        });
    } finally {
        Language.setUseLocal(wasLocal);
    }
    desc = unescape(desc);
    desc = "" + desc.trim();

    node.convertToEntries(0);
    commandStructure.validate(node);
    if (!(node.get("trigger") instanceof SectionNode))
        return null;

    final String usage = ScriptLoader.replaceOptions(node.get("usage", desc));
    final String description = ScriptLoader.replaceOptions(node.get("description", ""));
    ArrayList<String> aliases = new ArrayList<String>(
            Arrays.asList(ScriptLoader.replaceOptions(node.get("aliases", "")).split("\\s*,\\s*/?")));
    if (aliases.get(0).startsWith("/"))
        aliases.set(0, aliases.get(0).substring(1));
    else if (aliases.get(0).isEmpty())
        aliases = new ArrayList<String>(0);
    final String permission = ScriptLoader.replaceOptions(node.get("permission", ""));
    final String permissionMessage = ScriptLoader.replaceOptions(node.get("permission message", ""));
    final SectionNode trigger = (SectionNode) node.get("trigger");
    if (trigger == null)
        return null;
    final String[] by = ScriptLoader.replaceOptions(node.get("executable by", "console,players"))
            .split("\\s*,\\s*|\\s+(and|or)\\s+");
    int executableBy = 0;
    for (final String b : by) {
        if (b.equalsIgnoreCase("console") || b.equalsIgnoreCase("the console")) {
            executableBy |= ScriptCommand.CONSOLE;
        } else if (b.equalsIgnoreCase("players") || b.equalsIgnoreCase("player")) {
            executableBy |= ScriptCommand.PLAYERS;
        } else {
            Skript.warning(
                    "'executable by' should be either be 'players', 'console', or both, but found '" + b + "'");
        }
    }

    if (!permissionMessage.isEmpty() && permission.isEmpty()) {
        Skript.warning("command /" + command + " has a permission message set, but not a permission");
    }

    if (Skript.debug() || node.debug())
        Skript.debug("command " + desc + ":");

    final File config = node.getConfig().getFile();
    if (config == null) {
        assert false;
        return null;
    }

    Commands.currentArguments = currentArguments;
    final ScriptCommand c;
    try {
        c = new ScriptCommand(config, command, "" + pattern.toString(), currentArguments, description, usage,
                aliases, permission, permissionMessage, executableBy, ScriptLoader.loadItems(trigger));
    } finally {
        Commands.currentArguments = null;
    }

    registerCommand(c);

    if (Skript.logVeryHigh() && !Skript.debug())
        Skript.info("registered command " + desc);
    currentArguments = null;
    return c;
}

From source file:edu.iu.daal_pca.Service.java

public static void printAprioriItemsets(HomogenNumericTable largeItemsetsTable,
        HomogenNumericTable largeItemsetsSupportTable) {
    /* Get sizes of tables to store large item sets */
    int nItemsInLargeItemsets = (int) largeItemsetsTable.getNumberOfRows();
    int largeItemsetCount = (int) largeItemsetsSupportTable.getNumberOfRows();
    int nItemsetToPrint = 20;

    /* Get item sets and their support values */
    IntBuffer bufLargeItemsets = IntBuffer
            .allocate(nItemsInLargeItemsets * (int) largeItemsetsTable.getNumberOfColumns());
    bufLargeItemsets = largeItemsetsTable.getBlockOfRows(0, nItemsInLargeItemsets, bufLargeItemsets);
    int[] largeItemsets = new int[bufLargeItemsets.capacity()];
    bufLargeItemsets.get(largeItemsets);

    IntBuffer bufLargeItemsetsSupportData = IntBuffer
            .allocate(largeItemsetCount * (int) largeItemsetsSupportTable.getNumberOfColumns());
    bufLargeItemsetsSupportData = largeItemsetsSupportTable.getBlockOfRows(0, largeItemsetCount,
            bufLargeItemsetsSupportData);
    int[] largeItemsetsSupportData = new int[bufLargeItemsetsSupportData.capacity()];
    bufLargeItemsetsSupportData.get(largeItemsetsSupportData);

    ArrayList<ArrayList<Integer>> largeItemsetsVector = new ArrayList<ArrayList<Integer>>(largeItemsetCount);

    for (int i = 0; i < largeItemsetCount; i++) {
        largeItemsetsVector.add(new ArrayList<Integer>());
    }//w w w . ja  v  a 2s .  c o m

    for (int i = 0; i < nItemsInLargeItemsets; i++) {
        largeItemsetsVector.get(largeItemsets[2 * i]).add(largeItemsets[2 * i + 1]);
    }

    ArrayList<Integer> supportVector = new ArrayList<Integer>(largeItemsetCount);
    for (int i = 0; i < largeItemsetCount; i++) {
        supportVector.add(0);
    }

    for (int i = 0; i < largeItemsetCount; i++) {
        int index = largeItemsetsSupportData[2 * i];
        supportVector.set(index, largeItemsetsSupportData[2 * i + 1]);
    }

    System.out.println("Apriori example program results");

    System.out.println("Last " + nItemsetToPrint + " large itemsets: ");
    System.out.println("Itemset\t\t\tSupport");

    int iMin = ((largeItemsetCount > nItemsetToPrint) ? largeItemsetCount - nItemsetToPrint : 0);
    for (int i = iMin; i < largeItemsetCount; i++) {
        System.out.print("{");
        for (int l = 0; l < largeItemsetsVector.get(i).size() - 1; l++) {
            System.out.print(largeItemsetsVector.get(i).get(l) + ", ");
        }
        System.out.print(largeItemsetsVector.get(i).get(largeItemsetsVector.get(i).size() - 1) + "}\t\t");

        System.out.println(supportVector.get(i));
    }
}