Example usage for java.util List equals

List of usage examples for java.util List equals

Introduction

In this page you can find the example usage for java.util List equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this list for equality.

Usage

From source file:com.flexive.tests.embedded.WorkflowTest.java

private void assertStepOrder(List<? extends Step> actualSteps, List<? extends Step> expectedSteps,
        boolean expectedEqual) {
    final boolean eq = actualSteps.equals(expectedSteps);
    if (eq != expectedEqual) {
        Assert.fail("Expected " + (expectedEqual ? "same" : "different") + " step order - got: "
                + FxSharedUtils.getSelectableObjectIdList(actualSteps) + ", expected: "
                + FxSharedUtils.getSelectableObjectIdList(expectedSteps));
    }//from ww  w  .  j  av  a  2 s  .  c o  m
}

From source file:com.ebay.pulsar.analytics.metricstore.db.RDMBSTest.java

@SuppressWarnings("unchecked")
@Test/*from   w  w w  . j  a  va2s .  c o m*/
public void testRDBMS() {
    String driver2 = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://locahost:3306/test";
    String userName = "root";
    String userPwd = "";
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(driver2);
    bds.setUrl(url);
    bds.setUsername(userName);
    bds.setPassword(userPwd);
    DBFactory.setDs(bds);
    List<String> result = new ArrayList<String>();
    result.add("result");
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = Mockito.mock(NamedParameterJdbcTemplate.class);
    when(namedParameterJdbcTemplate.query(Matchers.anyString(), Matchers.any(Map.class),
            Matchers.any(ResultSetExtractor.class))).thenReturn(result);
    RDBMS db = new RDBMS(driver2, url, userName, userPwd);
    db.setDriver(driver2);
    db.setNamedParameterJdbcTemplate(namedParameterJdbcTemplate);
    db.setUrl(url);
    db.setUserName(userName);
    db.setUserPwd(userPwd);
    assertEquals(namedParameterJdbcTemplate, db.getNamedParameterJdbcTemplate());
    Map<String, String> map = new HashMap<String, String>();
    assertTrue(result.equals(db.queryForList("test", map, 10)));

}

From source file:edu.cornell.kfs.module.receiptProcessing.batch.CsvBatchInputFileTypeBase.java

/**
 * Validates the CSV file content against the CSVEnum items as header
 * 1. content header must match CSVEnum order/value
 * 2. each data row should have same size as the header
 * //from w w w.  j  a v a  2s . c  om
 * @param expectedHeaderList        expected CSV header String list 
 * @param fileContents              contents to validate 
 * 
 * @throws IOException
 */
private void validateCSVFileInput(final List<String> expectedHeaderList, InputStream fileContents)
        throws IOException {

    //use csv reader to parse the csv content
    CSVReader csvReader = new CSVReader(new InputStreamReader(fileContents));
    List<String> inputHeaderList = Arrays.asList(csvReader.readNext());

    String errorMessage = null;

    // validate
    if (!CollectionUtils.isEqualCollection(expectedHeaderList, inputHeaderList)) {
        errorMessage = "CSV Batch Input File contains incorrect number of headers";
        //collection has same elements, now check the exact content orders by looking at the toString comparisons
    } else if (!expectedHeaderList.equals(inputHeaderList)) {
        errorMessage = "CSV Batch Input File headers are different";
    } else {

        //check the content size as well if headers are validated
        int line = 1;
        List<String> inputDataList = null;
        while ((inputDataList = Arrays.asList(csvReader.readNext())) != null && errorMessage != null) {
            //if the data list size does not match header list (its missing data)
            if (inputDataList.size() != expectedHeaderList.size()) {
                errorMessage = "line " + line + " layout does not match the header";
            }
            line++;
        }
    }

    if (errorMessage != null) {
        LOG.error(errorMessage);
        throw new RuntimeException(errorMessage);
    }
}

From source file:com.cloudbees.diff.ContextualPatch.java

private boolean patchCreatesNewFileThatAlreadyExists(SinglePatch patch, List<String> originalFile)
        throws PatchException {
    if (patch.hunks.length != 1)
        return false;
    Hunk hunk = patch.hunks[0];//from  ww w. j  av a  2  s  .c  om
    if (hunk.baseStart != 0 || hunk.baseCount != 0 || hunk.modifiedStart != 1
            || hunk.modifiedCount != originalFile.size())
        return false;

    List<String> target = new ArrayList<String>(hunk.modifiedCount);
    applyHunk(target, hunk);
    return target.equals(originalFile);
}

From source file:org.zanata.service.impl.TranslationServiceImpl.java

/**
 * @return true if the content was changed, false otherwise
 *///from  w w  w.j av  a  2  s .c  o m
private boolean setContentIfChanged(@Nonnull HTextFlowTarget hTextFlowTarget,
        @Nonnull List<String> contentsToSave) {
    if (!contentsToSave.equals(hTextFlowTarget.getContents())) {
        hTextFlowTarget.setContents(contentsToSave);
        return true;
    } else {
        return false;
    }
}

From source file:com.dlshouwen.jspc.zwpc.controller.SelfEvaluateController.java

private String getItemForHtml(List<EvalItem> items, ServletContext sc) {
    String result = "", preHtml;
    String beizhu = "";
    if (!items.equals(null) && items.size() > 0) {
        for (int i = 0; i < items.size(); i++) {
            preHtml = "<li class='item-table-list-li'>" + "<div class='item-table-list-box'>"
                    + "<i class='fa fa-edit' style='display:none;' onclick=\'editItem(\""
                    + items.get(i).getEvalItem_id() + "\",\"" + items.get(i).getType() + "\")\'></i>"
                    + "<i class='fa fa-times' style='display:none;' id='" + items.get(i).getEvalItem_id()
                    + "' onclick=\'deleteItem(\"" + items.get(i).getEvalItem_id() + "\")\'></i>"
                    + "<table class='table  table-responsive item-table-list' width='100%' border='0' cellspacing='0' cellpadding='0'>"
                    + "<tr>";
            String bDate = DateUtils.getYearMonth(items.get(i).getBeginDate());
            String eDate = DateUtils.getYearMonth(items.get(i).getEndDate());
            String level = CodeTableUtils.getValue(sc, "ryjb", items.get(i).getLevel());
            String grade = CodeTableUtils.getValue(sc, "hjdj", items.get(i).getGrade());
            level = StringUtils.isEmpty(level) ? "" : level;
            grade = StringUtils.isEmpty(grade) ? "" : grade;
            result += preHtml;/*from   w  ww .j  a  va 2  s  .  c  om*/
            result += "<td class='first_td'>" + bDate + "-" + eDate + "</td>";
            result += "<td>" + items.get(i).getName() + "</td>";
            result += "<td>" + level + grade + "</td>";
            //                result += "<td><a target='_blank' href='" + sc.getContextPath() + "/jspc/zwpc/zwpc/downloadFile?itemId=" + items.get(i).getEvalItem_id() + "' class='table-tc-fj-open'  ></a></td>";
            if (StringUtils.isNotEmpty(items.get(i).getAttach())) {
                String sourceURL = AttributeUtils.getAttributeContent(sc, "source_webapp_file_postion");
                result += "<td><a target='_blank' href='" + sourceURL + items.get(i).getAttach()
                        + "' class='table-tc-fj-open'  ></a></td>";
            } else {
                result += "<td>&nbsp;&nbsp;</td>";
            }
            beizhu = items.get(i).getDescription();
            beizhu = StringUtils.isEmpty(beizhu) ? "" : beizhu;
            if ("".equals(beizhu)) {
                result += "</tr></table><div class='exp_description'>" + beizhu + "</div></li>";
            } else {
                result += "</tr></table><div class='exp_description' title='" + beizhu + "'>" + beizhu
                        + "</div></li>";
            }
        }
    } else {
        result = "<div class='div_zanwu'></div>";
    }
    return result;
}

From source file:nz.govt.natlib.ndha.manualdeposit.jobmanagement.JobQueueManagement.java

private boolean checkAndMoveJobs(final List<UploadJob> jobsToCheck) {
    LOG.debug("Start checkAndMoveJobs");
    boolean itemsMoved = false;
    for (int i = 0; i < jobsToCheck.size(); i++) {
        UploadJob job = jobsToCheck.get(i);
        if (jobsToCheck.equals(jobQueueAwaitingCleanup)) {
            if (job.getJobState() != UploadJob.JobState.AwaitingCleanup) {
                jobsToCheck.remove(job);
                itemsMoved = true;//from   www .  j  a va2 s. c  o  m
            }
        } else {
            switch (job.getJobState()) {
            case Running:
                if (!jobsToCheck.equals(jobQueueRunning)) {
                    jobsToCheck.remove(job);
                    jobQueueRunning.add(job);
                    itemsMoved = true;
                }
                break;
            case Requested:
            case Pending:
            case Batching:
                if (!jobsToCheck.equals(jobQueuePending)) {
                    jobsToCheck.remove(job);
                    jobQueuePending.add(job);
                    itemsMoved = true;
                }
                break;
            case Failed:
                if (!jobsToCheck.equals(jobQueueFailed)) {
                    jobsToCheck.remove(job);
                    jobQueueFailed.add(job);
                    itemsMoved = true;
                }
                break;
            case Deposited:
                if (!jobsToCheck.equals(jobQueueDeposited)) {
                    jobsToCheck.remove(job);
                    jobQueueDeposited.add(job);
                    itemsMoved = true;
                }
                break;
            case AwaitingCleanup:
            case Complete:
                if ((jobsToCheck != jobQueueInPermanent) && (jobsToCheck != jobQueueAwaitingCleanup)) {
                    jobsToCheck.remove(job);
                    if (job.getJobState() == UploadJob.JobState.AwaitingCleanup) {
                        jobQueueInPermanent.add(job);
                    }
                    jobQueueAwaitingCleanup.add(job);
                    itemsMoved = true;
                }
                break;
            default:
                break;
            }
        }
    }
    LOG.debug("End checkAndMoveJobs");
    return itemsMoved;
}

From source file:org.apache.calcite.test.CalciteAssert.java

/** @see Matchers#returnsUnordered(String...) */
static Function<ResultSet, Void> checkResult(final boolean sort, final boolean head, final String... lines) {
    return new Function<ResultSet, Void>() {
        public Void apply(ResultSet resultSet) {
            try {
                final List<String> expectedList = Lists.newArrayList(lines);
                if (sort) {
                    Collections.sort(expectedList);
                }//from ww w.j  a  v  a2  s  . co  m
                final List<String> actualList = Lists.newArrayList();
                CalciteAssert.toStringList(resultSet, actualList);
                if (sort) {
                    Collections.sort(actualList);
                }
                final List<String> trimmedActualList;
                if (head && actualList.size() > expectedList.size()) {
                    trimmedActualList = actualList.subList(0, expectedList.size());
                } else {
                    trimmedActualList = actualList;
                }
                if (!trimmedActualList.equals(expectedList)) {
                    assertThat(Util.lines(trimmedActualList), equalTo(Util.lines(expectedList)));
                }
                return null;
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    };
}

From source file:org.thymeleaf.util.EvaluationUtilTest.java

@Test
public void convertToListTest() {

    {/*from  w  ww . j  av  a2  s .  c  o  m*/
        final List<Object> result = EvaluationUtil.evaluateAsList(null);
        Assert.assertTrue(result != null && result.size() == 0);
    }

    {
        final Set<Object> set = new LinkedHashSet<Object>();
        set.add(Integer.valueOf(2));
        set.add(Integer.valueOf(43));
        final List<Object> list = new ArrayList<Object>();
        list.add(Integer.valueOf(2));
        list.add(Integer.valueOf(43));

        final List<Object> result = EvaluationUtil.evaluateAsList(set);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final Map<Object, Object> map = new LinkedHashMap<Object, Object>();
        map.put("a", Integer.valueOf(2));
        map.put("b", Integer.valueOf(43));
        final List<Object> list = new ArrayList<Object>();
        list.add(new EvaluationUtil.MapEntry<Object, Object>("a", Integer.valueOf(2)));
        list.add(new EvaluationUtil.MapEntry<Object, Object>("b", Integer.valueOf(43)));

        final List<Object> result = EvaluationUtil.evaluateAsList(map);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final byte[] arr0 = new byte[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final byte[] arr = new byte[2];
        arr[0] = (byte) 23;
        arr[1] = (byte) -127;
        final List<Object> list = new ArrayList<Object>();
        list.add(Byte.valueOf((byte) 23));
        list.add(Byte.valueOf((byte) -127));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final short[] arr0 = new short[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final short[] arr = new short[2];
        arr[0] = (short) 23;
        arr[1] = (short) -127;
        final List<Object> list = new ArrayList<Object>();
        list.add(Short.valueOf((short) 23));
        list.add(Short.valueOf((short) -127));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final int[] arr0 = new int[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final int[] arr = new int[2];
        arr[0] = 23;
        arr[1] = -127;
        final List<Object> list = new ArrayList<Object>();
        list.add(Integer.valueOf(23));
        list.add(Integer.valueOf(-127));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final long[] arr0 = new long[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final long[] arr = new long[2];
        arr[0] = 23L;
        arr[1] = -127L;
        final List<Object> list = new ArrayList<Object>();
        list.add(Long.valueOf(23L));
        list.add(Long.valueOf(-127L));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final float[] arr0 = new float[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final float[] arr = new float[2];
        arr[0] = 23.0f;
        arr[1] = -127.1f;
        final List<Object> list = new ArrayList<Object>();
        list.add(Float.valueOf(23.0f));
        list.add(Float.valueOf(-127.1f));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && result.size() == list.size());
        for (int i = 0; i < result.size(); i++) {
            Assert.assertTrue(result.get(i) != null && result.get(i) instanceof Float
                    && (((Float) result.get(i)).compareTo((Float) list.get(i)) == 0));
        }
    }

    {
        final double[] arr0 = new double[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final double[] arr = new double[2];
        arr[0] = 23.0d;
        arr[1] = -127.1d;
        final List<Object> list = new ArrayList<Object>();
        list.add(Double.valueOf(23.0d));
        list.add(Double.valueOf(-127.1d));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && result.size() == list.size());
        for (int i = 0; i < result.size(); i++) {
            Assert.assertTrue(result.get(i) != null && result.get(i) instanceof Double
                    && (((Double) result.get(i)).compareTo((Double) list.get(i)) == 0));
        }
    }

    {
        final boolean[] arr0 = new boolean[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final boolean[] arr = new boolean[2];
        arr[0] = true;
        arr[1] = false;
        final List<Object> list = new ArrayList<Object>();
        list.add(Boolean.TRUE);
        list.add(Boolean.FALSE);

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final char[] arr0 = new char[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final char[] arr = new char[3];
        arr[0] = 'a';
        arr[1] = 'x';
        arr[2] = (char) 0;
        final List<Object> list = new ArrayList<Object>();
        list.add(Character.valueOf('a'));
        list.add(Character.valueOf('x'));
        list.add(Character.valueOf((char) 0));

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final Class<?>[] arr0 = new Class<?>[0];
        final List<Object> list0 = new ArrayList<Object>();
        final List<Object> result0 = EvaluationUtil.evaluateAsList(arr0);
        Assert.assertTrue(result0 != null && result0 instanceof List && list0.equals(result0));

        final Class<?>[] arr = new Class<?>[2];
        arr[0] = EvaluationUtil.class;
        arr[1] = EvaluationUtilTest.class;
        final List<Object> list = new ArrayList<Object>();
        list.add(EvaluationUtil.class);
        list.add(EvaluationUtilTest.class);

        final List<Object> result = EvaluationUtil.evaluateAsList(arr);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

    {
        final List<Object> list = new ArrayList<Object>();
        list.add(EvaluationUtil.class);

        final List<Object> result = EvaluationUtil.evaluateAsList(EvaluationUtil.class);
        Assert.assertTrue(result != null && result instanceof List && list.equals(result));
    }

}

From source file:dk.netarkivet.common.utils.FileUtils.java

/**
 * @param theFile/*from ww  w.j a  v  a  2  s .co  m*/
 *            A file to make relative
 * @param theDir
 *            A directory
 * @return the filepath of the theFile relative to theDir. null, if
 *         theFile is not relative to theDir. null, if theDir is not a
 *         directory.
 */
public static String relativeTo(File theFile, File theDir) {
    ArgumentNotValid.checkNotNull(theFile, "File theFile");
    ArgumentNotValid.checkNotNull(theDir, "File theDir");
    if (!theDir.isDirectory()) {
        log.trace("The File '" + theDir.getAbsolutePath() + "' does not represent a directory. Null returned");
        return null;
    }

    List<String> filePathList = new ArrayList<String>();
    List<String> theDirPath = new ArrayList<String>();
    File tempFile = theFile.getAbsoluteFile();

    filePathList.add(tempFile.getName());
    while ((tempFile = tempFile.getParentFile()) != null) {
        filePathList.add(tempFile.getName());
    }

    tempFile = theDir.getAbsoluteFile();
    theDirPath.add(tempFile.getName());
    while ((tempFile = tempFile.getParentFile()) != null) {
        theDirPath.add(tempFile.getName());
    }

    // check, at the path prefix is the same
    List<String> sublist = filePathList.subList(theDirPath.size() - 2, filePathList.size());
    if (!theDirPath.equals(sublist)) {
        log.trace("The file '" + theFile.getAbsolutePath() + "' is not relative to the directory '"
                + theDir.getAbsolutePath() + "'. Null returned");
        return null;
    }

    List<String> relativeList = filePathList.subList(0, theDirPath.size() - 2);

    StringBuffer sb = new StringBuffer();
    Collections.reverse(relativeList);
    for (String aRelativeList : relativeList) {
        sb.append(aRelativeList);
        sb.append(File.separatorChar);
    }
    sb.deleteCharAt(sb.length() - 1); // remove last separatorChar
    return sb.toString();

}