Example usage for java.util ArrayList equals

List of usage examples for java.util ArrayList equals

Introduction

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

Prototype

public boolean equals(Object o) 

Source Link

Usage

From source file:edu.umd.cs.guitar.ripper.WebRipperMonitor.java

public static boolean areTwoUrlsTheSame(String url1, String url2) {
    ArrayList<String> urlList1 = variablesInUrl(url1);
    ArrayList<String> urlList2 = variablesInUrl(url2);
    Collections.sort(urlList1);/* ww  w.  j  av  a  2 s  . c  o m*/
    Collections.sort(urlList2);

    if (urlList1.equals(urlList2))
        return true;
    else
        return false;
}

From source file:eionet.cr.util.sesame.ResultCompareUtil.java

/**
 *
 * @param result1//from  w w w .  j  a  va  2 s .c o m
 * @param result2
 * @return
 * @throws Exception
 */
private static boolean compare(TupleQueryResult result1, TupleQueryResult result2) throws Exception {

    int numOfUnequalRows = 0;
    int i = -1;
    boolean hasNext1 = false;
    boolean hasNext2 = false;
    do {
        i++;

        if (i % 5000 == 0) {
            System.out.println("At row#" + i);
        }

        hasNext1 = result1.hasNext();
        hasNext2 = result2.hasNext();
        if (hasNext1 && hasNext2) {

            BindingSet bindingSet1 = result1.next();
            BindingSet bindingSet2 = result2.next();
            Set<String> names1 = bindingSet1.getBindingNames();
            if (i == 0) {

                Set<String> names2 = bindingSet1.getBindingNames();
                if (!names1.equals(names2)) {
                    throw new Exception("Binding sets not equal:\n" + names1 + "\n" + names2);
                }
            }

            ArrayList<String> values1 = new ArrayList<String>();
            ArrayList<String> values2 = new ArrayList<String>();
            for (String name : names1) {

                Value value1 = bindingSet1.getValue(name);
                Value value2 = bindingSet2.getValue(name);

                String str1 = value1.stringValue();
                String str2 = value2.stringValue();

                values1.add("0.0".equals(str1) ? "0" : str1);
                values2.add("0.0".equals(str2) ? "0" : str2);
            }

            if (!values1.equals(values2)) {
                numOfUnequalRows++;
                System.out.println("Row #" + i + " is different:\n1: " + values1 + "\n2: " + values2);
                return false;
            }
        }
    } while (hasNext1 && hasNext2);

    System.out.println("numOfUnequalRows = " + numOfUnequalRows);

    if (!hasNext1 && hasNext2) {
        throw new CRException("At row#" + i + " result2 has next, but result1 does not!");
    } else if (hasNext1 && !hasNext2) {
        throw new CRException("At row#" + i + " result1 has next, but result2 does not!");
    }

    return numOfUnequalRows == 0;
}

From source file:org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory.java

/**
 * Build a jbi descriptor from the specified binary data.
 * The descriptor is validated against the schema, but no
 * semantic validation is performed./*from  ww  w . j  a va  2s  .c  o m*/
 *
 * @param bytes hold the content of the JBI descriptor xml document
 * @return the Descriptor object
 */
public static Descriptor buildDescriptor(final byte[] bytes) {
    try {
        // Validate descriptor
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XSD_SCHEMA_LANGUAGE);
        Schema schema = schemaFactory.newSchema(DescriptorFactory.class.getResource(JBI_DESCRIPTOR_XSD));
        Validator validator = schema.newValidator();
        validator.setErrorHandler(new ErrorHandler() {
            public void warning(SAXParseException exception) throws SAXException {
                //log.debug("Validation warning on " + url + ": " + exception);
            }

            public void error(SAXParseException exception) throws SAXException {
                //log.info("Validation error on " + url + ": " + exception);
            }

            public void fatalError(SAXParseException exception) throws SAXException {
                throw exception;
            }
        });
        validator.validate(new StreamSource(new ByteArrayInputStream(bytes)));
        // Parse descriptor
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        Document doc = docBuilder.parse(new ByteArrayInputStream(bytes));
        Element jbi = doc.getDocumentElement();
        Descriptor desc = new Descriptor();
        desc.setVersion(Double.parseDouble(getAttribute(jbi, VERSION)));
        Element child = getFirstChildElement(jbi);
        if (COMPONENT.equals(child.getLocalName())) {
            ComponentDesc component = new ComponentDesc();
            component.setType(child.getAttribute(TYPE));
            component.setComponentClassLoaderDelegation(getAttribute(child, COMPONENT_CLASS_LOADER_DELEGATION));
            component.setBootstrapClassLoaderDelegation(getAttribute(child, BOOTSTRAP_CLASS_LOADER_DELEGATION));
            List<SharedLibraryList> sls = new ArrayList<SharedLibraryList>();
            DocumentFragment ext = null;
            for (Element e = getFirstChildElement(child); e != null; e = getNextSiblingElement(e)) {
                if (IDENTIFICATION.equals(e.getLocalName())) {
                    component.setIdentification(readIdentification(e));
                } else if (COMPONENT_CLASS_NAME.equals(e.getLocalName())) {
                    component.setComponentClassName(getText(e));
                    component.setDescription(getAttribute(e, DESCRIPTION));
                } else if (COMPONENT_CLASS_PATH.equals(e.getLocalName())) {
                    ClassPath componentClassPath = new ClassPath();
                    ArrayList<String> l = new ArrayList<String>();
                    for (Element e2 = getFirstChildElement(e); e2 != null; e2 = getNextSiblingElement(e2)) {
                        if (PATH_ELEMENT.equals(e2.getLocalName())) {
                            l.add(getText(e2));
                        }
                    }
                    componentClassPath.setPathList(l);
                    component.setComponentClassPath(componentClassPath);
                } else if (BOOTSTRAP_CLASS_NAME.equals(e.getLocalName())) {
                    component.setBootstrapClassName(getText(e));
                } else if (BOOTSTRAP_CLASS_PATH.equals(e.getLocalName())) {
                    ClassPath bootstrapClassPath = new ClassPath();
                    ArrayList<String> l = new ArrayList<String>();
                    for (Element e2 = getFirstChildElement(e); e2 != null; e2 = getNextSiblingElement(e2)) {
                        if (PATH_ELEMENT.equals(e2.getLocalName())) {
                            l.add(getText(e2));
                        }
                    }
                    bootstrapClassPath.setPathList(l);
                    component.setBootstrapClassPath(bootstrapClassPath);
                } else if (SHARED_LIBRARY.equals(e.getLocalName())) {
                    SharedLibraryList sl = new SharedLibraryList();
                    sl.setName(getText(e));
                    sl.setVersion(getAttribute(e, VERSION));
                    sls.add(sl);
                } else {
                    if (ext == null) {
                        ext = doc.createDocumentFragment();
                    }
                    ext.appendChild(e);
                }
            }
            component.setSharedLibraries(sls.toArray(new SharedLibraryList[sls.size()]));
            if (ext != null) {
                InstallationDescriptorExtension descriptorExtension = new InstallationDescriptorExtension();
                descriptorExtension.setDescriptorExtension(ext);
                component.setDescriptorExtension(descriptorExtension);
            }
            desc.setComponent(component);
        } else if (SHARED_LIBRARY.equals(child.getLocalName())) {
            SharedLibraryDesc sharedLibrary = new SharedLibraryDesc();
            sharedLibrary.setClassLoaderDelegation(getAttribute(child, CLASS_LOADER_DELEGATION));
            sharedLibrary.setVersion(getAttribute(child, VERSION));
            for (Element e = getFirstChildElement(child); e != null; e = getNextSiblingElement(e)) {
                if (IDENTIFICATION.equals(e.getLocalName())) {
                    sharedLibrary.setIdentification(readIdentification(e));
                } else if (SHARED_LIBRARY_CLASS_PATH.equals(e.getLocalName())) {
                    ClassPath sharedLibraryClassPath = new ClassPath();
                    ArrayList<String> l = new ArrayList<String>();
                    for (Element e2 = getFirstChildElement(e); e2 != null; e2 = getNextSiblingElement(e2)) {
                        if (PATH_ELEMENT.equals(e2.getLocalName())) {
                            l.add(getText(e2));
                        }
                    }
                    sharedLibraryClassPath.setPathList(l);
                    sharedLibrary.setSharedLibraryClassPath(sharedLibraryClassPath);
                }
            }
            desc.setSharedLibrary(sharedLibrary);
        } else if (SERVICE_ASSEMBLY.equals(child.getLocalName())) {
            ServiceAssemblyDesc serviceAssembly = new ServiceAssemblyDesc();
            ArrayList<ServiceUnitDesc> sus = new ArrayList<ServiceUnitDesc>();
            for (Element e = getFirstChildElement(child); e != null; e = getNextSiblingElement(e)) {
                if (IDENTIFICATION.equals(e.getLocalName())) {
                    serviceAssembly.setIdentification(readIdentification(e));
                } else if (SERVICE_UNIT.equals(e.getLocalName())) {
                    ServiceUnitDesc su = new ServiceUnitDesc();
                    for (Element e2 = getFirstChildElement(e); e2 != null; e2 = getNextSiblingElement(e2)) {
                        if (IDENTIFICATION.equals(e2.getLocalName())) {
                            su.setIdentification(readIdentification(e2));
                        } else if (TARGET.equals(e2.getLocalName())) {
                            Target target = new Target();
                            for (Element e3 = getFirstChildElement(e2); e3 != null; e3 = getNextSiblingElement(
                                    e3)) {
                                if (ARTIFACTS_ZIP.equals(e3.getLocalName())) {
                                    target.setArtifactsZip(getText(e3));
                                } else if (COMPONENT_NAME.equals(e3.getLocalName())) {
                                    target.setComponentName(getText(e3));
                                }
                            }
                            su.setTarget(target);
                        }
                    }
                    sus.add(su);
                } else if (CONNECTIONS.equals(e.getLocalName())) {
                    Connections connections = new Connections();
                    ArrayList<Connection> cns = new ArrayList<Connection>();
                    for (Element e2 = getFirstChildElement(e); e2 != null; e2 = getNextSiblingElement(e2)) {
                        if (CONNECTION.equals(e2.getLocalName())) {
                            Connection cn = new Connection();
                            for (Element e3 = getFirstChildElement(e2); e3 != null; e3 = getNextSiblingElement(
                                    e3)) {
                                if (CONSUMER.equals(e3.getLocalName())) {
                                    Consumer consumer = new Consumer();
                                    consumer.setInterfaceName(readAttributeQName(e3, INTERFACE_NAME));
                                    consumer.setServiceName(readAttributeQName(e3, SERVICE_NAME));
                                    consumer.setEndpointName(getAttribute(e3, ENDPOINT_NAME));
                                    cn.setConsumer(consumer);
                                } else if (PROVIDER.equals(e3.getLocalName())) {
                                    Provider provider = new Provider();
                                    provider.setServiceName(readAttributeQName(e3, SERVICE_NAME));
                                    provider.setEndpointName(getAttribute(e3, ENDPOINT_NAME));
                                    cn.setProvider(provider);
                                }
                            }
                            cns.add(cn);
                        }
                    }
                    connections.setConnections(cns.toArray(new Connection[cns.size()]));
                    serviceAssembly.setConnections(connections);
                }
            }
            serviceAssembly.setServiceUnits(sus.toArray(new ServiceUnitDesc[sus.size()]));
            desc.setServiceAssembly(serviceAssembly);
        } else if (SERVICES.equals(child.getLocalName())) {
            Services services = new Services();
            services.setBindingComponent(
                    Boolean.valueOf(getAttribute(child, BINDING_COMPONENT)).booleanValue());
            ArrayList<Provides> provides = new ArrayList<Provides>();
            ArrayList<Consumes> consumes = new ArrayList<Consumes>();
            for (Element e = getFirstChildElement(child); e != null; e = getNextSiblingElement(e)) {
                if (PROVIDES.equals(e.getLocalName())) {
                    Provides p = new Provides();
                    p.setInterfaceName(readAttributeQName(e, INTERFACE_NAME));
                    p.setServiceName(readAttributeQName(e, SERVICE_NAME));
                    p.setEndpointName(getAttribute(e, ENDPOINT_NAME));
                    provides.add(p);
                } else if (CONSUMES.equals(e.getLocalName())) {
                    Consumes c = new Consumes();
                    c.setInterfaceName(readAttributeQName(e, INTERFACE_NAME));
                    c.setServiceName(readAttributeQName(e, SERVICE_NAME));
                    c.setEndpointName(getAttribute(e, ENDPOINT_NAME));
                    c.setLinkType(getAttribute(e, LINK_TYPE));
                    consumes.add(c);
                }
            }
            services.setProvides(provides.toArray(new Provides[provides.size()]));
            services.setConsumes(consumes.toArray(new Consumes[consumes.size()]));
            desc.setServices(services);
        }
        checkDescriptor(desc);
        return desc;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.jaspersoft.android.jaspermobile.activities.repository.support.FilterManager.java

public boolean isOnlyReport(ArrayList<String> filters) {
    return filters.equals(getFiltersByType(Type.ONLY_REPORT));
}

From source file:com.jaspersoft.android.jaspermobile.activities.repository.support.FilterManager.java

public boolean isOnlyDashboard(ArrayList<String> filters) {
    return filters.equals(getFiltersByType(Type.ONLY_DASHBOARD));
}

From source file:com.gabrielluz.megasenaanalyzer.MegaSenaAnalyzer.java

public boolean hasAlreadyWon(int a1, int a2, int a3, int a4, int a5, int a6) {
    boolean won = false;
    ArrayList<Integer> inputArray = new ArrayList<>();
    inputArray.add(a1);//  www .  j  a  v  a 2 s  . c o  m
    inputArray.add(a2);
    inputArray.add(a3);
    inputArray.add(a4);
    inputArray.add(a5);
    inputArray.add(a6);

    Collections.sort(inputArray);

    for (ArrayList<Integer> temp : this._pickedNumbers) {
        if (temp.equals(inputArray)) {
            won = true;
        }
    }
    return won;
}

From source file:org.apache.spark.streaming.JavaWriteAheadLogSuiteHandle.java

@Test
public void testCustomWAL() {
    SparkConf conf = new SparkConf();
    conf.set("spark.streaming.driver.writeAheadLog.class", JavaWriteAheadLogSuite.class.getName());
    WriteAheadLog wal = WriteAheadLogUtils.createLogForDriver(conf, null, null);

    String data1 = "data1";
    WriteAheadLogRecordHandle handle = wal.write(ByteBuffer.wrap(data1.getBytes()), 1234);
    Assert.assertTrue(handle instanceof JavaWriteAheadLogSuiteHandle);
    Assert.assertTrue(new String(wal.read(handle).array()).equals(data1));

    wal.write(ByteBuffer.wrap("data2".getBytes()), 1235);
    wal.write(ByteBuffer.wrap("data3".getBytes()), 1236);
    wal.write(ByteBuffer.wrap("data4".getBytes()), 1237);
    wal.clean(1236, false);/*from  w  ww . j a v  a2s.c o m*/

    java.util.Iterator<java.nio.ByteBuffer> dataIterator = wal.readAll();
    ArrayList<String> readData = new ArrayList<String>();
    while (dataIterator.hasNext()) {
        readData.add(new String(dataIterator.next().array()));
    }
    Assert.assertTrue(readData.equals(Arrays.asList("data3", "data4")));
}

From source file:com.motlee.android.adapter.ImageAdapter.java

public boolean setURLs(ArrayList<PhotoItem> photos) {
    if (!photos.equals(mOriginalPhotoList)) {
        Collections.sort(photos);

        this.mPhotoList.clear();

        //mPhotoList.add(HEADER);

        // Set last position in list we load into ImageAdapter
        // Equals MAX_SIZE or total photos size whichever is smaller
        int lastPosition = MAX_SIZE;
        if (lastPosition > photos.size()) {
            lastPosition = photos.size();
        }/*ww w  . j a  v  a 2s .  c  o m*/

        // Adds all images to URLS list (starting from back, sorted by date, asceding)
        for (int i = 0; i < lastPosition; i++) {
            this.mPhotoList.add(photos.get(i));
        }

        int minSize = 1;
        if (photos.size() > 0) {
            minSize = MIN_SIZE;
        }

        // Adds placeholder if photos list is not larger than MIN_SIZE
        for (int i = lastPosition; i < minSize; i++) {
            this.mPhotoList.add(NO_PHOTO);
        }

        this.mOriginalPhotoList = new ArrayList<PhotoItem>(photos);
        this.notifyDataSetChanged();
        return true;
    } else {
        return false;
    }
}

From source file:util.io.Mirror.java

private static Mirror chooseMirror(Mirror[] mirrorArr, Mirror oldMirror, String name, Class caller)
        throws TvBrowserException {
    Mirror[] oldMirrorArr = mirrorArr;//from  w w w  .j a va2  s  . com

    /* remove the old mirror from the mirrorlist */
    if (oldMirror != null) {
        ArrayList<Mirror> mirrors = new ArrayList<Mirror>();
        for (Mirror mirror : mirrorArr) {
            if (oldMirror != mirror) {
                mirrors.add(mirror);
            }
        }
        mirrorArr = new Mirror[mirrors.size()];
        mirrors.toArray(mirrorArr);
    }

    // Get the total weight
    int totalWeight = 0;
    for (Mirror mirror : mirrorArr) {
        totalWeight += mirror.getWeight();
    }

    // Choose a weight
    int chosenWeight = RandomUtils.nextInt(totalWeight);

    // Find the chosen mirror
    int currWeight = 0;
    for (Mirror mirror : mirrorArr) {
        currWeight += mirror.getWeight();
        if (currWeight > chosenWeight) {
            // Check whether this is the old mirror or Mirror is Blocked
            if (((mirror == oldMirror) || BLOCKEDSERVERS.contains(getServerBase(mirror.getUrl())))
                    && (mirrorArr.length > 1)) {
                // We chose the old mirror -> chose another one
                ArrayList<Mirror> oldList = new ArrayList<Mirror>(oldMirrorArr.length);
                for (Mirror m : oldMirrorArr) {
                    oldList.add(m);
                }
                ArrayList<Mirror> currentList = new ArrayList<Mirror>(mirrorArr.length);
                for (Mirror m : mirrorArr) {
                    currentList.add(m);
                }
                Comparator<Mirror> comp = new Comparator<Mirror>() {

                    @Override
                    public int compare(Mirror m1, Mirror m2) {
                        return m1.getUrl().compareTo(m2.getUrl());
                    }
                };
                Collections.sort(oldList, comp);
                Collections.sort(currentList, comp);
                if (oldList.equals(currentList)) {
                    // avoid stack overflow
                    return mirror;
                }
                return chooseMirror(mirrorArr, oldMirror, name, caller);
            } else {
                return mirror;
            }
        }
    }

    // We didn't find a mirror? This should not happen -> throw exception
    StringBuilder buf = new StringBuilder();
    for (Mirror mirror : oldMirrorArr) {
        buf.append(mirror.getUrl()).append('\n');
    }

    throw new TvBrowserException(caller, "error.2", "No mirror found\ntried following mirrors: ", name,
            buf.toString());
}

From source file:org.apache.axis2.context.externalize.ActivateUtils.java

/**
 * Compares the two collections to see if they are equivalent.
 * /*from   ww w  .  j av  a2s . com*/
 * @param a1  The first collection
 * @param a2  The second collection
 * @param strict  Indicates whether strict checking is required.  Strict
 *                checking means that the two collections must have the
 *                same elements in the same order.  Non-strict checking
 *                means that the two collections must have the same 
 *                elements, but the order is not significant.
 * @return TRUE if the two collections are equivalent
 *         FALSE, otherwise
 */
public static boolean isEquivalent(ArrayList a1, ArrayList a2, boolean strict) {
    if ((a1 != null) && (a2 != null)) {
        // check number of elements in lists
        int size1 = a1.size();
        int size2 = a2.size();

        if (size1 != size2) {
            // trace point
            if (log.isTraceEnabled()) {
                log.trace("ObjectStateUtils:isEquivalent(ArrayList,ArrayList): FALSE - size mismatch [" + size1
                        + "] != [" + size2 + "]");
            }
            return false;
        }

        if (strict) {
            // Strict checking
            // The lists must contain the same elements in the same order.
            return (a1.equals(a2));
        } else {
            // Non-strict checking
            // The lists must contain the same elements but the order is not required.
            Iterator i1 = a1.iterator();

            while (i1.hasNext()) {
                Object obj1 = i1.next();

                if (!a2.contains(obj1)) {
                    // trace point
                    if (log.isTraceEnabled()) {
                        log.trace(
                                "ObjectStateUtils:isEquivalent(ArrayList,ArrayList): FALSE - mismatch with element ["
                                        + obj1.getClass().getName() + "] ");
                    }
                    return false;
                }
            }

            return true;
        }

    } else if ((a1 == null) && (a2 == null)) {
        return true;
    } else if ((a1 != null) && (a2 == null)) {
        if (a1.size() == 0) {
            return true;
        }
        return false;
    } else if ((a1 == null) && (a2 != null)) {
        if (a2.size() == 0) {
            return true;
        }
        return false;
    } else {
        // mismatch

        // trace point
        if (log.isTraceEnabled()) {
            log.trace("ObjectStateUtils:isEquivalent(ArrayList,ArrayList): FALSE - mismatch in lists");
        }
        return false;
    }
}