Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

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

Prototype

public Object[] toArray() 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Usage

From source file:com.thoughtworks.go.domain.ConsoleStreamerTest.java

@Test
public void streamProcessesAllLines() throws Exception {
    String[] expected = new String[] { "First line", "Second line", "Third line" };
    final ArrayList<String> actual = new ArrayList<>();

    ConsoleStreamer console = new ConsoleStreamer(makeConsoleFile(expected).toPath(), 0L);
    console.stream(new Consumer<String>() {
        @Override//from   w w  w .j a va  2s .co  m
        public void accept(String s) {
            actual.add(s);
        }
    });
    assertArrayEquals(expected, actual.toArray());
    assertEquals(3L, console.totalLinesConsumed());
}

From source file:com.thoughtworks.go.domain.ConsoleStreamerTest.java

@Test
public void streamAssumesNegativeStartLineIsZero() throws Exception {
    String[] expected = new String[] { "First line", "Second line", "Third line" };
    final ArrayList<String> actual = new ArrayList<>();

    ConsoleStreamer console = new ConsoleStreamer(makeConsoleFile(expected).toPath(), -1L);
    console.stream(new Consumer<String>() {
        @Override/* w w  w  .ja  va  2s  .  c  o  m*/
        public void accept(String s) {
            actual.add(s);
        }
    });
    assertArrayEquals(expected, actual.toArray());
    assertEquals(3L, console.totalLinesConsumed());
}

From source file:com.amalto.core.plugin.base.xslt.XSLTTransformerPluginBean.java

public static String stripeOuterBracket(String rowData) {
    ArrayList<String> result = new ArrayList<>();
    int aggregate = 0;
    int cordon = 0;
    for (int i = 0; i < rowData.length(); i++) {
        char ch = rowData.charAt(i);
        if (ch == '[') {
            aggregate++;/*  www .  jav a 2 s. c  o  m*/
            if (aggregate == 1) {
                cordon = i;
            }
        } else if (ch == ']') {
            aggregate--;
            if (aggregate == 0) {
                result.add(rowData.substring(cordon + 1, i));
            }
        } else if (aggregate == 0) {
            result.add(ch + ""); //$NON-NLS-1$
        }
    }
    return StringUtils.join(result.toArray(), ","); //$NON-NLS-1$
}

From source file:easycare.alc.service.report.HstPrescriptionReportBeanTest.java

@Test
public void shouldDisplaySignatureDetails() {
    String title = "Dr";
    String fullName = String.format("%s %s %s", title, SIGNATURE_FIRST_NAME, SIGNATURE_LAST_NAME);
    String expected = "Electronic Signature";

    when(messageSource.getTitleMessage(DR)).thenReturn(title);
    when(hstPrescription.getPhysicianTitle()).thenReturn(DR);

    HstPrescriptionReportBean sut = createTestObject();

    ArrayList<String> args = Lists.newArrayList(fullName, SIGNATURE_NPI);
    when(messageSource.getMessage(REPORT_PDF_SIGNATURE_DETAILS_KEY, args.toArray())).thenReturn(expected);

    String actual = sut.getSignatureDetails();

    assertThat(actual, is(expected));//from w ww  .  j  a  v a 2 s. c o  m
}

From source file:com.espertech.esper.support.util.ArrayAssertionUtil.java

/**
 * Iterate through the views collection and check the presence of all values supplied in the exact same order,
 * using the event bean underlying to compare
 * @param iterator is the iterator to iterate over and check returned values
 * @param expectedValues is an array of expected underlying events
 *//*from  w  w  w  .  j  a  va  2 s.  co  m*/
public static void assertEqualsExactOrderUnderlying(Iterator<EventBean> iterator, Object[] expectedValues) {
    ArrayList<Object> underlyingValues = new ArrayList<Object>();
    while (iterator.hasNext()) {
        underlyingValues.add(iterator.next().getUnderlying());
    }

    try {
        iterator.next();
        TestCase.fail();
    } catch (NoSuchElementException ex) {
        // Expected exception - next called after hasNext returned false, for testing
    }

    Object[] data = null;
    if (underlyingValues.size() > 0) {
        data = underlyingValues.toArray();
    }

    assertEqualsExactOrder(data, expectedValues);
}

From source file:springobjectmapper.AbstractRepository.java

public List<T> query(IQuery query, int first, int count) {
    ArrayList<Object> args = new ArrayList<Object>(Arrays.asList(query.arguments()));
    String baseQuery = query.select(dialect);
    String orderedQuery = dialect.appendOrder(baseQuery, query.order());
    String betweenQuery = dialect.selectBetween(orderedQuery, args, first, count);
    return template.query(properties.parse(betweenQuery), rowMapper(), args.toArray());
}

From source file:gov.loc.repository.bagger.ui.NewBagFrame.java

private void layoutBagVersionSelection(JPanel contentPane, int row) {
    //contents//w  ww.j a  v  a2 s. com
    // Bag version dropdown list
    JLabel bagVersionLabel = new JLabel(bagView.getPropertyMessage("bag.label.version"));
    bagVersionLabel.setToolTipText(bagView.getPropertyMessage("bag.versionlist.help"));
    ArrayList<String> versionModel = new ArrayList<String>();
    Version[] vals = Version.values();
    for (int i = 0; i < vals.length; i++) {
        versionModel.add(vals[i].versionString);
    }

    bagVersionList = new JComboBox(versionModel.toArray());
    bagVersionList.setName(bagView.getPropertyMessage("bag.label.versionlist"));
    bagVersionList.setSelectedItem(Version.V0_96.versionString);
    bagVersionList.setToolTipText(bagView.getPropertyMessage("bag.versionlist.help"));

    GridBagConstraints glbc = null;

    JLabel spacerLabel = new JLabel();
    glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 5, 50, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.WEST);
    contentPane.add(bagVersionLabel, glbc);
    glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 40, 50, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.CENTER);
    contentPane.add(bagVersionList, glbc);
    glbc = LayoutUtil.buildGridBagConstraints(2, row, 1, 1, 40, 50, GridBagConstraints.NONE,
            GridBagConstraints.EAST);
    contentPane.add(spacerLabel, glbc);
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePostOrderIteratorTest.java

/**
 * The trie is://from www .  j ava  2  s . c om
 *  /
 *  0
 *  1
 *  2
 */
@Test
public void testVerticalTrie1TraversalWithSize2() {
    UrlTrie trie = new UrlTrie(_property, Arrays.asList(_property + "0", _property + "01", _property + "012"));
    UrlTriePostOrderIterator iterator = new UrlTriePostOrderIterator(trie, 2);
    ArrayList<String> chars = new ArrayList<>();
    while (iterator.hasNext()) {
        Pair<String, UrlTrieNode> next = iterator.next();
        chars.add(next.getLeft());
    }
    Assert.assertEquals(new String[] { _property + "01", _property + "0", _property }, chars.toArray());
}

From source file:easycare.alc.service.report.HstPrescriptionReportBeanTest.java

@Test
public void shouldDisplaySignedAt() {
    String expected = "Signed at";

    HstPrescriptionReportBean sut = createTestObject();

    ArrayList<String> args = Lists.newArrayList(FORMATTED_SIGNED_CET.toLowerCase(), FORMATTED_SIGNED_TZ);
    when(messageSource.getMessage(REPORT_PDF_SIGNATURE_SIGNED_AT_KEY, args.toArray())).thenReturn(expected);

    String actual = sut.getSignedAt();

    assertThat(actual, is(expected));//from w w w.  j av  a2 s  .c  o m
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePostOrderIteratorTest.java

/**
 * The trie is://from   w  w  w.  j a v a  2s  . c o m
 *  /
 *  0
 *  1
 *  2
 */
@Test
public void testVerticalTrie1TraversalWithSize3() {
    UrlTrie trie = new UrlTrie(_property, Arrays.asList(_property + "0", _property + "01", _property + "012"));
    UrlTriePostOrderIterator iterator = new UrlTriePostOrderIterator(trie, 3);
    ArrayList<String> chars = new ArrayList<>();
    while (iterator.hasNext()) {
        Pair<String, UrlTrieNode> next = iterator.next();
        chars.add(next.getLeft());
    }
    //the root node is a leaf node
    Assert.assertEquals(new String[] { _property }, chars.toArray());
}