Java Examples for java.util.ArrayList

The following java examples will help you to understand the usage of java.util.ArrayList. These source code samples are taken from different open source projects.

Example 1
Project: android_platform_libcore-master  File: ArrayListTest.java View source code
/**
     * java.util.ArrayList#ArrayList(java.util.Collection)
     */
public void test_ConstructorLjava_util_Collection() {
    // Test for method java.util.ArrayList(java.util.Collection)
    ArrayList al = new ArrayList(Arrays.asList(objArray));
    assertTrue("arrayList created from collection has incorrect size", al.size() == objArray.length);
    for (int counter = 0; counter < objArray.length; counter++) assertTrue("arrayList created from collection has incorrect elements", al.get(counter) == objArray[counter]);
    try {
        new ArrayList(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }
}
Example 2
Project: android-libcore64-master  File: ArrayListTest.java View source code
/**
     * java.util.ArrayList#ArrayList(java.util.Collection)
     */
public void test_ConstructorLjava_util_Collection() {
    // Test for method java.util.ArrayList(java.util.Collection)
    ArrayList al = new ArrayList(Arrays.asList(objArray));
    assertTrue("arrayList created from collection has incorrect size", al.size() == objArray.length);
    for (int counter = 0; counter < objArray.length; counter++) assertTrue("arrayList created from collection has incorrect elements", al.get(counter) == objArray[counter]);
    try {
        new ArrayList(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }
}
Example 3
Project: queueing-simulation-master  File: CustomCategoryURLGeneratorTests.java View source code
/**
     * Some checks for the equals() method.
     */
public void testEquals() {
    CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator();
    CustomCategoryURLGenerator g2 = new CustomCategoryURLGenerator();
    assertTrue(g1.equals(g2));
    List u1 = new java.util.ArrayList();
    u1.add("URL A1");
    u1.add("URL A2");
    u1.add("URL A3");
    g1.addURLSeries(u1);
    assertFalse(g1.equals(g2));
    List u2 = new java.util.ArrayList();
    u2.add("URL A1");
    u2.add("URL A2");
    u2.add("URL A3");
    g2.addURLSeries(u2);
    assertTrue(g1.equals(g2));
}
Example 4
Project: RoboBuggy-master  File: CustomCategoryURLGeneratorTest.java View source code
/**
     * Some checks for the equals() method.
     */
@Test
public void testEquals() {
    CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator();
    CustomCategoryURLGenerator g2 = new CustomCategoryURLGenerator();
    assertEquals(g1, g2);
    List<String> u1 = new java.util.ArrayList<String>();
    u1.add("URL A1");
    u1.add("URL A2");
    u1.add("URL A3");
    g1.addURLSeries(u1);
    assertFalse(g1.equals(g2));
    List<String> u2 = new java.util.ArrayList<String>();
    u2.add("URL A1");
    u2.add("URL A2");
    u2.add("URL A3");
    g2.addURLSeries(u2);
    assertEquals(g1, g2);
}
Example 5
Project: molgenis-master  File: FileExtensionUtils.java View source code
public static String findExtensionFromPossibilities(String fileName, Set<String> fileExtensions) {
    String name = fileName.toLowerCase();
    List<String> possibleExtensions = new ArrayList<String>();
    for (String extention : fileExtensions) {
        if (name.endsWith('.' + extention)) {
            possibleExtensions.add(extention);
        }
    }
    String longestExtension = null;
    for (String possibleExtension : possibleExtensions) {
        if (null == longestExtension) {
            longestExtension = possibleExtension;
            continue;
        } else {
            if (longestExtension.length() < possibleExtension.length())
                longestExtension = possibleExtension;
        }
    }
    return longestExtension;
}
Example 6
Project: schach-master  File: ListReader.java View source code
public static ArrayList<String> loadStrings(File aFile) {
    ArrayList<String> pVec = new ArrayList<String>();
    if (!aFile.exists())
        return pVec;
    try {
        BufferedReader pReader = new BufferedReader(new FileReader(aFile));
        String pLine;
        while ((pLine = pReader.readLine()) != null) {
            pLine = pLine.trim();
            if (pLine.startsWith("#") || pLine.equals(""))
                continue;
            pVec.add(pLine);
        }
        pReader.close();
    } catch (IOException aE) {
        aE.printStackTrace();
    }
    return pVec;
}
Example 7
Project: compomics-utilities-master  File: KeyUtils.java View source code
/**
     * Returns the key corresponding to a list of integers.
     *
     * @param list the list
     *
     * @return a key in the form of a string
     */
public static String getKey(ArrayList<Integer> list) {
    StringBuilder stringBuilder = new StringBuilder(2 * list.size());
    for (Integer value : list) {
        if (stringBuilder.length() > 0) {
            stringBuilder.append(SEPARATOR);
        }
        stringBuilder.append(value);
    }
    return stringBuilder.toString();
}
Example 8
Project: ARTPart-master  File: ArrayListTest.java View source code
/**
     * java.util.ArrayList#ArrayList(java.util.Collection)
     */
public void test_ConstructorLjava_util_Collection() {
    // Test for method java.util.ArrayList(java.util.Collection)
    ArrayList al = new ArrayList(Arrays.asList(objArray));
    assertTrue("arrayList created from collection has incorrect size", al.size() == objArray.length);
    for (int counter = 0; counter < objArray.length; counter++) assertTrue("arrayList created from collection has incorrect elements", al.get(counter) == objArray[counter]);
    try {
        new ArrayList(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }
}
Example 9
Project: j2objc-master  File: ArrayListTest.java View source code
/**
     * @tests java.util.ArrayList#add(int, java.lang.Object)
     */
public void test_addILjava_lang_Object() {
    // Test for method void java.util.ArrayList.add(int, java.lang.Object)
    Object o;
    alist.add(50, o = new Object());
    assertTrue("Failed to add Object", alist.get(50) == o);
    assertTrue("Failed to fix up list after insert", alist.get(51) == objArray[50] && (alist.get(52) == objArray[51]));
    Object oldItem = alist.get(25);
    alist.add(25, null);
    assertNull("Should have returned null", alist.get(25));
    assertTrue("Should have returned the old item from slot 25", alist.get(26) == oldItem);
    alist.add(0, o = new Object());
    assertEquals("Failed to add Object", alist.get(0), o);
    assertEquals(alist.get(1), objArray[0]);
    assertEquals(alist.get(2), objArray[1]);
    oldItem = alist.get(0);
    alist.add(0, null);
    assertNull("Should have returned null", alist.get(0));
    assertEquals("Should have returned the old item from slot 0", alist.get(1), oldItem);
    try {
        alist.add(-1, new Object());
        fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
        assertNotNull(e.getMessage());
    }
    try {
        alist.add(-1, null);
        fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
        assertNotNull(e.getMessage());
    }
    try {
        alist.add(alist.size() + 1, new Object());
        fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
        assertNotNull(e.getMessage());
    }
    try {
        alist.add(alist.size() + 1, null);
        fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
        assertNotNull(e.getMessage());
    }
}
Example 10
Project: android-sdk-sources-for-api-level-23-master  File: ArrayListTest.java View source code
/**
     * java.util.ArrayList#ArrayList(java.util.Collection)
     */
public void test_ConstructorLjava_util_Collection() {
    // Test for method java.util.ArrayList(java.util.Collection)
    ArrayList al = new ArrayList(Arrays.asList(objArray));
    assertTrue("arrayList created from collection has incorrect size", al.size() == objArray.length);
    for (int counter = 0; counter < objArray.length; counter++) assertTrue("arrayList created from collection has incorrect elements", al.get(counter) == objArray[counter]);
    try {
        new ArrayList(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    }
}
Example 11
Project: openjdk-master  File: RuntimeParameterAnnotationsForGenericMethodTest.java View source code
@Override
public List<TestCase> generateTestCases() {
    List<TestCase> testCases = new ArrayList<>();
    for (TestAnnotationInfos annotations : getAllCombinationsOfAnnotations()) {
        // generate: public class Test extends java.util.ArrayList<Integer>
        TestCase testCase = new TestCase();
        TestCase.TestClassInfo clazz = testCase.addClassInfo("java.util.ArrayList<Integer>", ClassType.CLASS, "Test");
        TestCase.TestParameterInfo parameter = clazz.addMethodInfo("add(java.lang.Integer)", "public").addParameter("Integer", "i");
        annotations.annotate(parameter);
        TestCase.TestParameterInfo synParameter = clazz.addMethodInfo("add(java.lang.Object)", true, "public").addParameter("Object", "i");
        annotations.annotate(synParameter);
        testCases.add(testCase);
    }
    return testCases;
}
Example 12
Project: Mint-Programming-Language-master  File: Arc.java View source code
@Override
public Pointer apply(SmartList<Pointer> args) throws MintException {
    int x = PointerTools.dereferenceInt(args.get(0));
    int y = PointerTools.dereferenceInt(args.get(1));
    int width = PointerTools.dereferenceInt(args.get(2));
    int height = PointerTools.dereferenceInt(args.get(3));
    int startAngle = PointerTools.dereferenceInt(args.get(4));
    int arcAngle = PointerTools.dereferenceInt(args.get(5));
    ArrayList<Integer> dim = new ArrayList<Integer>();
    dim.add(x);
    dim.add(y);
    dim.add(width);
    dim.add(height);
    dim.add(startAngle);
    dim.add(arcAngle);
    return Heap.allocateShape(new Shape(Shape.ARC, dim));
}
Example 13
Project: ohmagePhone-master  File: TimestampPromptBuilder.java View source code
@Override
public void build(Prompt prompt, String id, String displayType, String displayLabel, String promptText, String abbreviatedText, String explanationText, String defaultValue, String condition, String skippable, String skipLabel, ArrayList<KVLTriplet> properties) {
    TimestampPrompt timestampPrompt = (TimestampPrompt) prompt;
    timestampPrompt.setId(id);
    timestampPrompt.setDisplayType(displayType);
    timestampPrompt.setDisplayLabel(displayLabel);
    timestampPrompt.setPromptText(promptText);
    timestampPrompt.setAbbreviatedText(abbreviatedText);
    timestampPrompt.setExplanationText(explanationText);
    timestampPrompt.setDefaultValue(defaultValue);
    timestampPrompt.setCondition(condition);
    timestampPrompt.setSkippable(skippable);
    timestampPrompt.setSkipLabel(skipLabel);
    timestampPrompt.setProperties(properties);
}
Example 14
Project: LambdaDojo-master  File: S403StreamInsteadOfFor.java View source code
private void processStatistics() {
    // 乱数のリストを作成
    Random random = new Random();
    List<Double> numbers = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        numbers.add(random.nextDouble());
    }
    // 平均を算出
    double ave = 0.0;
    for (Double x : numbers) {
        ave += x;
    }
    ave /= numbers.size();
    // 分散を算出
    double variance = 0.0;
    for (Double x : numbers) {
        variance += (x - ave) * (x - ave);
    }
    variance /= numbers.size();
    System.out.println("Average: " + ave);
    System.out.println("Diverse: " + variance);
}
Example 15
Project: btpka3.github.com-master  File: SpringTest.java View source code
public static void main(String[] args) throws BeansException {
    final int THREAD_COUNT = 10;
    ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext.xml");
    CuratorFramework client = (CuratorFramework) appCtx.getBean("zkClient");
    List<Thread> list = new ArrayList<Thread>();
    // 创建并启动线程
    for (int i = 0; i < THREAD_COUNT; i++) {
        Thread t = new Thread(new MyTask(client, i));
        t.start();
        list.add(t);
    }
    // 等待线程结束
    for (int i = 0; i < THREAD_COUNT; i++) {
        Thread t = list.get(i);
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Example 16
Project: expenditures-master  File: MissionProcessProvider.java View source code
@Override
public Collection getSearchResults(Map<String, String> argsMap, String value, int maxCount) {
    final String currentValue = StringUtils.trim(value);
    final List<MissionProcess> result = new ArrayList<MissionProcess>();
    final MissionSystem missionSystem = MissionSystem.getInstance();
    for (final MissionProcess missionProcess : missionSystem.getMissionProcessesSet()) {
        String[] processIdParts = missionProcess.getProcessNumber().split("/M");
        if (missionProcess.getProcessIdentification().equals(currentValue) || processIdParts[processIdParts.length - 1].equals(currentValue)) {
            result.add(missionProcess);
        }
    }
    return result;
}
Example 17
Project: xbnjava-master  File: ElimDupsFromUnorderedListXmpl.java View source code
public static final void main(String[] ignored) {
    int[] ai = new int[] { 0, 0, 1, 4, 2, 3, 4 };
    ArrayList<Integer> ali = new ArrayList<Integer>(ai.length);
    for (int i : ai) {
        ali.add(i);
    }
    System.out.println(Arrays.toString(ali.toArray()) + "  (original)");
    //Delete dups
    for (int i = 0; i < ali.size(); i++) {
        Integer I = ali.get(i);
        int iA = ali.indexOf(I);
        if (iA != -1) {
            int iB = ali.lastIndexOf(I);
            if (iB != iA) {
                //remove second
                ali.remove(iB);
                System.out.println(Arrays.toString(ali.toArray()));
            }
        }
    }
    System.out.println(Arrays.toString(ali.toArray()) + "     (final)");
}
Example 18
Project: sonar-java-master  File: CollectionCallingItselfCheck.java View source code
void fun() {
    List<String> strings = new ArrayList<String>();
    strings.add("Hello");
    // Compliant - does not compile, as there is no method "add(List<String>)" in List. The method invocation is not resolved
    strings.add(strings);
    // Noncompliant {{Remove or correct this "addAll" call.}}
    strings.addAll(strings);
    // Noncompliant {{Remove or correct this "containsAll" call.}}
    strings.containsAll(strings);
    // Noncompliant {{Remove or correct this "removeAll" call.}}
    strings.removeAll(strings);
    // Noncompliant [[sc=5;ec=31]] {{Remove or correct this "retainAll" call.}}
    strings.retainAll(strings);
    strings.wait();
    strings.foo();
}
Example 19
Project: milton2-master  File: SendMailScratch.java View source code
public static void main(String[] arr) {
    String host = "XXX";
    String user = "XXX";
    String password = "XXX";
    int port = 465;
    RemoteSmtpMailSender sender = new RemoteSmtpMailSender(host, user, password, port);
    sender.setUseSsl(true);
    sender.start();
    StandardMessageImpl sm = new StandardMessageImpl();
    sm.setFrom(MailboxAddress.parse("[email protected]"));
    List<MailboxAddress> to = new ArrayList();
    to.add(MailboxAddress.parse("[email protected]"));
    sm.setTo(to);
    sm.setSubject("hello!");
    sender.sendMail(sm);
}
Example 20
Project: castor-master  File: NodeBuilder.java View source code
/**
     * Build the object we expect when we unmarshal 'input.xml'.
     */
public Object buildInstance() {
    NodeList nodeList = new NodeList();
    Node nodeOne = new Node();
    nodeOne.setNodeNum(1);
    Node nodeTwo = new Node();
    nodeTwo.setNodeNum(2);
    Node nodeThree = new Node();
    nodeThree.setNodeNum(3);
    List siblings = new ArrayList();
    siblings.add(nodeTwo);
    siblings.add(nodeThree);
    nodeOne.setSiblings(siblings);
    siblings = new ArrayList();
    siblings.add(nodeOne);
    siblings.add(nodeThree);
    nodeTwo.setSiblings(siblings);
    siblings = new ArrayList();
    siblings.add(nodeOne);
    siblings.add(nodeTwo);
    nodeThree.setSiblings(siblings);
    nodeList.addNode(nodeOne);
    nodeList.addNode(nodeTwo);
    nodeList.addNode(nodeThree);
    return nodeList;
}
Example 21
Project: tapestry-model-master  File: MethodDescriptorFactoryImpl.java View source code
public ArrayList<IMethodDescriptor> buildMethodDescriptors(Class type, BeanInfo beanInfo) {
    ArrayList<IMethodDescriptor> result = new ArrayList<IMethodDescriptor>();
    for (MethodDescriptor beanMethodDescriptor : beanInfo.getMethodDescriptors()) {
        if (!Utils.isExcluded(beanMethodDescriptor.getMethod().getName(), methodExcludes)) {
            TynamoMethodDescriptorImpl methodDescriptor = new TynamoMethodDescriptorImpl(type, beanMethodDescriptor.getMethod().getName(), beanMethodDescriptor.getMethod().getReturnType(), beanMethodDescriptor.getMethod().getParameterTypes());
            //				methodDescriptor.setDisplayName(Utils.unCamelCase(beanMethodDescriptor.getDisplayName()));
            result.add(methodDescriptor);
        }
    }
    return result;
}
Example 22
Project: eclipse.jdt.ui-master  File: ControlBodyUpdates.java View source code
private void foo() {
    for (int i = 0; i < arraylists.get(0); i++) arraylists = null;
    for (int intValue : ints) arraylists = new ArrayList(arraylists.size());
    while (ints.length != 0) arraylists = null;
    if (arraylists == null)
        arraylists = null;
    int[] newRange = new int[8];
    for (int i = 0; i < arraylists.get(0); i++) {
        arraylists = null;
    }
    for (int intValue : ints) {
        arraylists = new ArrayList(arraylists.size());
    }
    while (ints.length != 0) {
        arraylists = null;
    }
    if (arraylists == null) {
        arraylists = null;
    }
    if (newRange[0] > 0)
        // line number start at 0!
        fNewStart = newRange[0] - 1;
    else
        fNewStart = 0;
    if (newRange[0] > 0) {
        // line number start at 0!
        fNewStart = newRange[0] - 1;
    } else {
        fNewStart = 0;
    }
}
Example 23
Project: TFC2-master  File: DungeonSchemManager.java View source code
public void loadRooms(String theme, ArrayList<String> roomNames, String path) {
    DungeonTheme themeObject;
    if (themeMap.containsKey(theme.toLowerCase()))
        themeObject = themeMap.get(theme.toLowerCase());
    else
        themeObject = new DungeonTheme(theme);
    themeObject.loadRooms(roomNames, path);
    themeMap.put(theme.toLowerCase(), themeObject);
}
Example 24
Project: violetumleditor-master  File: MenuUtils.java View source code
public static void alterMenuBar(JMenuBar menuBar) {
    MenuElement[] subMenuElements = menuBar.getSubElements();
    List<MenuElement> menuEntryStack = new ArrayList<MenuElement>();
    if (subMenuElements.length > 0) {
        menuEntryStack.addAll(Arrays.asList(subMenuElements));
    }
    while (!menuEntryStack.isEmpty()) {
        MenuElement menuElement = menuEntryStack.get(0);
        if (menuElement instanceof JMenuItem) {
            final JMenuItem menuItem = (JMenuItem) menuElement;
            menuItem.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    System.out.println(menuItem.getName());
                }
            });
        }
        MenuElement[] subElements = menuElement.getSubElements();
        if (subElements.length > 0) {
            menuEntryStack.addAll(Arrays.asList(subElements));
        }
        menuEntryStack.remove(0);
    }
}
Example 25
Project: CodingSpectator-master  File: ControlBodyUpdates.java View source code
private void foo() {
    for (int i = 0; i < arraylists.get(0); i++) arraylists = null;
    for (int intValue : ints) arraylists = new ArrayList(arraylists.size());
    while (ints.length != 0) arraylists = null;
    if (arraylists == null)
        arraylists = null;
    int[] newRange = new int[8];
    for (int i = 0; i < arraylists.get(0); i++) {
        arraylists = null;
    }
    for (int intValue : ints) {
        arraylists = new ArrayList(arraylists.size());
    }
    while (ints.length != 0) {
        arraylists = null;
    }
    if (arraylists == null) {
        arraylists = null;
    }
    if (newRange[0] > 0)
        // line number start at 0!
        fNewStart = newRange[0] - 1;
    else
        fNewStart = 0;
    if (newRange[0] > 0) {
        // line number start at 0!
        fNewStart = newRange[0] - 1;
    } else {
        fNewStart = 0;
    }
}