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:org.apache.storm.verify.VerifyUtils.java

public static void verifyHbase(String hBaseUrl, String tableName, String columnFamily,
        Map<String, Class> columnNamesToTypes, List<String> expectedRows) throws Exception {
    List<String> lines = new ArrayList<String>();
    final Configuration hbConfig = HBaseConfiguration.create();
    hbConfig.set("hbase.rootdir", hBaseUrl);
    HTable table = new HTable(hbConfig, tableName);
    ResultScanner results = table.getScanner(columnFamily.getBytes());
    for (Result result = results.next(); (result != null); result = results.next()) {
        String line = "";
        for (Map.Entry<String, Class> columnNameAndType : columnNamesToTypes.entrySet()) {
            byte[] bytes = result.getValue(columnFamily.getBytes(), columnNameAndType.getKey().getBytes());
            String colVal = toString(bytes, columnNameAndType.getValue());
            line += colVal + FIELD_SEPERATOR;
        }//www  . ja v a2 s  .c o  m
        line = StringUtils.removeEnd(line, FIELD_SEPERATOR);
        lines.add(line);
    }

    Collections.sort(lines);
    Collections.sort(expectedRows);
    assert lines.equals(expectedRows) : "expectedRows = " + expectedRows + " actualRows = " + lines;
}

From source file:org.wso2.carbon.apimgt.core.util.APIUtils.java

/**
 * Checks generic lists for equality independent of the order of elements in the lists.
 *
 * Note that order of the elements in the lists will be changed as a result of sorting,
 * but this is not a concern usually since the order does not matter.
 * @param list1 T list//from  w w w  . jav  a2  s .  com
 * @param list2 T list
 * @param comparator Comparator class
 * @return true if elements in lists are equal irrespective of order
 */
public static <T> boolean isListsEqualIgnoreOrder(List<T> list1, List<T> list2, Comparator<T> comparator) {
    if (list1 == null && list2 == null) {
        return true;
    }

    if (list1 == null || list2 == null || list1.size() != list2.size()) {
        return false;
    }

    // Sort lists so that the order of elements don't affect the equal check.
    // Note that order of the elements in the lists will be changed as a result but this is not a concern since
    // the order does not matter
    Collections.sort(list1, comparator);
    Collections.sort(list2, comparator);
    return list1.equals(list2);
}

From source file:com.google.code.ssm.util.jndi.JndiChangeNotifier.java

/**
 * Check if current value bounded to JNDI key is different than previous, if yes then invoked
 * {@link AddressChangeListener#changeAddresses(List)} method.
 *//*ww  w.  j av  a2 s.c om*/
public void check() {
    List<InetSocketAddress> newAddrs = getAddresses();
    if (newAddrs != null && !newAddrs.equals(currentAddrs)) {

        if (addressChangeListener != null) {
            currentAddrs = newAddrs;
            addressChangeListener.changeAddresses(newAddrs);
        } else {
            LOGGER.error("Address change listener is null for JNDI key {}, cannot notify about new value {}",
                    getJndiKey(), newAddrs);
        }
    }
}

From source file:com.cgrunge.ParameterValidator.java

public boolean isListEmpty(List<Object> obj) {
    return obj.equals(Collections.<Object>emptyList());
}

From source file:de.decoit.rt.rest.RtRestTicketResponseParser.java

private static String editTicketToString(RtTicket ticket, RtTicket oldTicket) {
    StringBuilder sb = new StringBuilder();
    Joiner commaJoiner = Joiner.on(",").skipNulls();

    // Ticket queue
    if (!oldTicket.getQueue().equals(ticket.getQueue())) {
        sb.append("Queue: ");
        sb.append(ticket.getQueue());/*from w w  w . j a  v  a  2s. co m*/
        sb.append("\n");
    }

    // Owner
    if (!oldTicket.getOwner().equals(ticket.getOwner())) {
        sb.append("Owner: ");
        sb.append(ticket.getOwner());
        sb.append("\n");
    }

    // Subject
    if (!oldTicket.getSubject().equals(ticket.getSubject())) {
        sb.append("Subject: ");
        sb.append(ticket.getSubject());
        sb.append("\n");
    }

    // Status
    if (oldTicket.getStatus() != ticket.getStatus()) {
        sb.append("Status: ");
        sb.append(ticket.getStatus());
        sb.append("\n");
    }

    // Priority
    if (oldTicket.getPriority() != ticket.getPriority()) {
        sb.append("Priority: ");
        sb.append(ticket.getPriority());
        sb.append("\n");
    }

    // Initial Priority
    if (oldTicket.getInitialPriority() != ticket.getInitialPriority()) {
        sb.append("InitialPriority: ");
        sb.append(ticket.getInitialPriority());
        sb.append("\n");
    }

    // Final Priority
    if (oldTicket.getFinalPriority() != ticket.getFinalPriority()) {
        sb.append("FinalPriority: ");
        sb.append(ticket.getFinalPriority());
        sb.append("\n");
    }

    // Requestors
    List<String> oldRequestorsList = oldTicket.getRequestors();
    List<String> newRequestorsList = ticket.getRequestors();
    boolean requestorsEqual = false;
    if (oldRequestorsList.size() == newRequestorsList.size()) {
        Collections.sort(oldRequestorsList);
        Collections.sort(newRequestorsList);

        if (oldRequestorsList.equals(newRequestorsList)) {
            requestorsEqual = true;
        }
    }
    if (!requestorsEqual) {
        sb.append("Requestors: ");
        sb.append(commaJoiner.join(ticket.getRequestors()));
        sb.append("\n");
    }

    // CC
    List<String> oldCcList = oldTicket.getCc();
    List<String> newCcList = ticket.getCc();
    boolean ccEqual = false;
    if (oldCcList.size() == newCcList.size()) {
        Collections.sort(oldCcList);
        Collections.sort(newCcList);

        if (oldCcList.equals(newCcList)) {
            ccEqual = true;
        }
    }
    if (!ccEqual) {
        sb.append("Cc: ");
        sb.append(commaJoiner.join(ticket.getCc()));
        sb.append("\n");
    }

    // AdminCC
    List<String> oldAdminCcList = oldTicket.getAdminCc();
    List<String> newAdminCcList = ticket.getAdminCc();
    boolean adminCcEqual = false;
    if (oldAdminCcList.size() == newAdminCcList.size()) {
        Collections.sort(oldAdminCcList);
        Collections.sort(newAdminCcList);

        if (oldAdminCcList.equals(newAdminCcList)) {
            adminCcEqual = true;
        }
    }
    if (!adminCcEqual) {
        sb.append("AdminCc: ");
        sb.append(commaJoiner.join(ticket.getAdminCc()));
        sb.append("\n");
    }

    // Starts
    if (ticket.getStarts() != null && !ticket.getStarts().equals(oldTicket.getStarts())) {
        sb.append("Starts: ");
        sb.append(formatDateString(ticket.getStarts()));
        sb.append("\n");
    }

    // Started
    if (ticket.getStarted() != null && !ticket.getStarted().equals(oldTicket.getStarted())) {
        sb.append("Started: ");
        sb.append(formatDateString(ticket.getStarted()));
        sb.append("\n");
    }

    // Due
    if (ticket.getDue() != null && !ticket.getDue().equals(oldTicket.getDue())) {
        sb.append("Due: ");
        sb.append(formatDateString(ticket.getDue()));
        sb.append("\n");
    }

    // Resolved
    if (ticket.getResolved() != null && !ticket.getResolved().equals(oldTicket.getResolved())) {
        sb.append("Resolved: ");
        sb.append(formatDateString(ticket.getResolved()));
        sb.append("\n");
    }

    // Told
    if (ticket.getTold() != null && !ticket.getTold().equals(oldTicket.getTold())) {
        sb.append("Told: ");
        sb.append(formatDateString(ticket.getTold()));
        sb.append("\n");
    }

    // Time estimated
    if (oldTicket.getTimeEstimated() != ticket.getTimeEstimated()) {
        sb.append("TimeEstimated: ");
        sb.append(ticket.getTimeEstimated());
        sb.append("\n");
    }

    // Time worked
    if (oldTicket.getTimeWorked() != ticket.getTimeWorked()) {
        sb.append("TimeWorked: ");
        sb.append(ticket.getTimeWorked());
        sb.append("\n");
    }

    // Time left
    if (oldTicket.getTimeLeft() != ticket.getTimeLeft()) {
        sb.append("TimeLeft: ");
        sb.append(ticket.getTimeLeft());
        sb.append("\n");
    }

    // Text
    if (ticket.getText() != null) {
        sb.append("Text: ");
        sb.append(ticket.getText().replaceAll("\n", "\n "));
        sb.append("\n");
    }

    if (ticket.getCustomFields() != null) {
        for (Entry<String, String> e : ticket.getCustomFields().entrySet()) {
            sb.append("CF.{");
            sb.append(e.getKey());
            sb.append("}: ");
            sb.append(e.getValue());
            sb.append("\n");
        }
    }

    return sb.toString();
}

From source file:com.chboeh.lightspeed.demo.util.ShuffleTest.java

@Test
public void testShuffle() {
    List<Question> randQuestions = new ArrayList(questions);
    Shuffle.shuffleQuestions(randQuestions);
    assertFalse(randQuestions.equals(questions));
}

From source file:io.jenkins.blueocean.jsextensions.JenkinsJSExtensions.java

private synchronized void refreshCache(List<PluginWrapper> latestPlugins) {
    if (!latestPlugins.equals(pluginCache)) {
        pluginCache.clear();/*from  w  w  w.  j  av  a 2 s.com*/
        pluginCache.addAll(latestPlugins);
        refreshCache(pluginCache);
    }
    for (PluginWrapper pluginWrapper : pluginCache) {
        //skip probing plugin if already read
        if (jsExtensionCache.get(pluginWrapper.getLongName()) != null) {
            continue;
        }
        try {
            Enumeration<URL> dataResources = pluginWrapper.classLoader
                    .getResources("jenkins-js-extension.json");
            while (dataResources.hasMoreElements()) {
                URL dataRes = dataResources.nextElement();
                StringWriter fileContentBuffer = new StringWriter();

                LOGGER.debug("Reading 'jenkins-js-extension.json' from '{}'.", dataRes);

                try {
                    IOUtils.copy(dataRes.openStream(), fileContentBuffer, Charset.forName("UTF-8"));
                    Map ext = mapper.readValue(dataRes.openStream(), Map.class);
                    String pluginId = getGav(ext);
                    if (pluginId != null) {
                        jsExtensionCache.put(pluginId, ext);
                    } else {
                        LOGGER.error(String.format("Plugin %s JS extension has missing hpiPluginId",
                                pluginWrapper.getLongName()));
                    }
                } catch (Exception e) {
                    LOGGER.error("Error reading 'jenkins-js-extension.json' from '" + dataRes
                            + "'. Extensions defined in the host plugin will not be active.", e);
                }
            }
        } catch (IOException e) {
            LOGGER.error(String.format("Error locating jenkins-js-extension.json for plugin %s",
                    pluginWrapper.getLongName()));
        }
    }
}

From source file:io.jenkins.blueocean.jsextensions.JenkinsJSExtensions.java

private void refreshCacheIfNeeded() {
    List<PluginWrapper> latestPlugins = Jenkins.getActiveInstance().getPluginManager().getPlugins();
    if (!latestPlugins.equals(pluginCache)) {
        refreshCache(latestPlugins);/*from w w w .j  ava2 s .c  o m*/
    }
}

From source file:pl.edu.icm.comac.vis.server.service.DbGraphIdService.java

/**
 * Just find a proper id and info if the graph exists.
 *
 * @return array, first element is valid id, second element not null means
 * that this graph already exists./*from  ww w. ja v  a  2  s .  c  o m*/
 */
protected String[] findId(List<String> nodes) {
    String[] res = new String[2];
    List<String> arrayList = new ArrayList<>(new HashSet(nodes));
    Collections.sort(arrayList);
    int hash = arrayList.hashCode();
    boolean ok = false;

    do {
        String id = formatHashCodeAsId(hash);
        res[0] = id;
        try {
            List<String> existing = getNodes(id);
            List<String> exS = new ArrayList<>(existing);
            Collections.sort(exS);
            if (exS.equals(arrayList)) {
                ok = true;
                res[1] = "ok";

            }
        } catch (UnknownGraphException ue) {
            res[1] = null;
            ok = true;
        }

        hash++;

    } while (!ok);

    return res;
}

From source file:org.apache.drill.optiq.DrillJoinRel.java

private int implementInput(DrillImplementor implementor, int i, int offset, RelNode input) {
    final int inputId = implementor.visitChild(this, i, input);
    assert uniqueFieldNames(input.getRowType());
    final List<String> fields = getRowType().getFieldNames();
    final List<String> inputFields = input.getRowType().getFieldNames();
    final List<String> outputFields = fields.subList(offset, offset + inputFields.size());
    if (!outputFields.equals(inputFields)) {
        // Ensure that input field names are the same as output field names.
        // If there are duplicate field names on left and right, fields will get
        // lost.//from w  w  w  . j  av  a 2  s  .c  o m
        return rename(implementor, inputId, inputFields, outputFields);
    } else {
        return inputId;
    }
}