Example usage for java.util Arrays equals

List of usage examples for java.util Arrays equals

Introduction

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

Prototype

public static boolean equals(Object[] a, Object[] a2) 

Source Link

Document

Returns true if the two specified arrays of Objects are equal to one another.

Usage

From source file:com.phoenixst.collections.AllPredicate.java

public boolean equals(Object object) {
    if (object == this) {
        return true;
    }/* ww w . j  a  v a 2  s  . co  m*/
    if (!(object instanceof AllPredicate)) {
        return false;
    }
    AllPredicate pred = (AllPredicate) object;
    return Arrays.equals(predicateArray, pred.predicateArray);
}

From source file:net.kaczmarzyk.spring.data.jpa.domain.EqualEnum.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (!super.equals(obj))
        return false;
    if (getClass() != obj.getClass())
        return false;
    EqualEnum<?> other = (EqualEnum<?>) obj;
    if (!Arrays.equals(searchedNames, other.searchedNames))
        return false;
    return true;/* w  w w.  jav  a 2s  .  co  m*/
}

From source file:android.syncml.pim.PropertyNode.java

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof PropertyNode)) {
        return false;
    }//from  w  w  w . java2  s .c  om

    PropertyNode node = (PropertyNode) obj;

    if (propName == null || !propName.equals(node.propName)) {
        return false;
    } else if (!paramMap.equals(node.paramMap)) {
        return false;
    } else if (!paramMap_TYPE.equals(node.paramMap_TYPE)) {
        return false;
    } else if (!propGroupSet.equals(node.propGroupSet)) {
        return false;
    }

    if (propValue_bytes != null && Arrays.equals(propValue_bytes, node.propValue_bytes)) {
        return true;
    } else {
        // Log.d("@@@", propValue + ", " + node.propValue);
        if (!propValue.equals(node.propValue)) {
            return false;
        }

        // The value in propValue_vector is not decoded even if it should be
        // decoded by BASE64 or QUOTED-PRINTABLE. When the size of propValue_vector
        // is 1, the encoded value is stored in propValue, so we do not have to
        // check it.
        return (propValue_vector.equals(node.propValue_vector) || propValue_vector.size() == 1
                || node.propValue_vector.size() == 1);
    }
}

From source file:org.jasig.portlet.test.mvc.tests.PortletPrefrencesTest.java

protected void testPreference(PortletPreferences preferences, Map<String, Object> model, String pref,
        String expectedValue, String[] expectedValues) {
    final String value = preferences.getValue(pref, "DEFAULT");
    final String[] values = preferences.getValues(pref, new String[] { "DEFAULT" });
    model.put(pref + "_value",
            expectedValue == value || (expectedValue != null && expectedValue.equals(value)));
    model.put(pref + "_values", Arrays.equals(expectedValues, values));
}

From source file:griffon.plugins.domain.methods.MethodSignature.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    MethodSignature that = (MethodSignature) o;

    return returnType.equals(that.returnType) && methodName.equals(that.methodName)
            && Arrays.equals(parameterClassnames, that.parameterClassnames) && isStatic == that.isStatic;
}

From source file:hr.caellian.m3l.util.nbt.NbtSerializable.java

/**
 * @param other Object to compare this object with.
 * @return True if the objects contain equal data, false if not.
 *//*from   www.  j ava2s.  c om*/
@Override
public boolean equals(Object other) {
    if (this == other) {
        return true;
    }
    if (!(other instanceof NbtSerializable)) {
        return false;
    }
    if (!super.equals(other)) {
        return false;
    }

    NbtSerializable that = (NbtSerializable) other;

    return Arrays.equals(getDataValue(), that.getDataValue());

}

From source file:org.nd4j.linalg.api.test.NDArrayTests.java

@Test
public void testScalarOps() {
    INDArray n = Nd4j.create(Nd4j.ones(27).data(), new int[] { 3, 3, 3 });
    assertEquals(27d, n.length(), 1e-1);
    n.checkDimensions(n.addi(Nd4j.scalar(1d)));
    n.checkDimensions(n.subi(Nd4j.scalar(1.0d)));
    n.checkDimensions(n.muli(Nd4j.scalar(1.0d)));
    n.checkDimensions(n.divi(Nd4j.scalar(1.0d)));

    n = Nd4j.create(Nd4j.ones(27).data(), new int[] { 3, 3, 3 });
    assertEquals(27, n.sum(Integer.MAX_VALUE).getDouble(0), 1e-1);
    INDArray a = n.slice(2);/*from w  ww.  j  a  va  2  s  .  c o m*/
    assertEquals(true, Arrays.equals(new int[] { 3, 3 }, a.shape()));
    n.data().destroy();

}

From source file:com.mirth.connect.connectors.tests.StreamHandlerTests.java

@Test
public void readSingleMessage() throws Exception {
    byte[] testBytes = testMessageBytes;
    BatchStreamReader batchStreamHandler;
    StreamHandler streamHandler;/*  w w  w  . j a v  a2  s.  c  o m*/
    ByteArrayOutputStream bos;
    InputStream is;
    int maxRead;

    // Create regular LLP frame with HL7 message
    bos = new ByteArrayOutputStream();
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    // Create an input stream from the bytes
    is = new ByteArrayInputStream(bos.toByteArray());
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    // Assert that the bytes returned from the stream handler are correct
    assertTrue(Arrays.equals(testBytes, streamHandler.read()));

    // Create LLP frame with extra bytes at the beginning
    bos = new ByteArrayOutputStream();
    bos.write("Testing".getBytes(testMessageCharset));
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    // Create an input stream from the bytes
    is = new ByteArrayInputStream(bos.toByteArray());
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    // Assert that the bytes returned from the stream handler are correct
    assertTrue(Arrays.equals(testBytes, streamHandler.read()));

    // Create LLP frame with extra bytes at the end
    bos = new ByteArrayOutputStream();
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    bos.write("Testing".getBytes(testMessageCharset));
    // Create an input stream from the bytes
    is = new ByteArrayInputStream(bos.toByteArray());
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    // Assert that the bytes returned from the stream handler are correct
    assertTrue(Arrays.equals(testBytes, streamHandler.read()));

    // Create LLP frame with extra bytes at the beginning and end
    bos = new ByteArrayOutputStream();
    bos.write("Testing".getBytes(testMessageCharset));
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    bos.write("Testing".getBytes(testMessageCharset));
    // Create an input stream from the bytes
    is = new ByteArrayInputStream(bos.toByteArray());
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    // Assert that the bytes returned from the stream handler are correct
    assertTrue(Arrays.equals(testBytes, streamHandler.read()));

    class FailingByteArrayInputStream extends ByteArrayInputStream {
        private int maxRead;
        private int numRead;

        public FailingByteArrayInputStream(byte[] buf, int maxRead) {
            super(buf);
            this.maxRead = maxRead;
            numRead = 0;
        }

        @Override
        public int read() {
            if (++numRead > maxRead) {
                throw new RuntimeException("fail");
            }
            return super.read();
        }
    }

    // Create regular LLP frame
    bos = new ByteArrayOutputStream();
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    // Create an input stream that will throw an exception
    maxRead = 50;
    is = new FailingByteArrayInputStream(bos.toByteArray(), maxRead);
    // Allow the stream handler to return data when an exception occurs
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    ((FrameStreamHandler) streamHandler).setReturnDataOnException(true);
    // Assert that the bytes returned from the stream handler are correct
    assertTrue(Arrays.equals(Arrays.copyOf(testBytes, maxRead - llpStartBytes.length), streamHandler.read()));

    class FailingFilterInputStream extends FilterInputStream {
        private int maxRead;
        private int numRead;
        private boolean fail = true;

        public FailingFilterInputStream(InputStream in, int maxRead) {
            super(in);
            this.maxRead = maxRead;
            numRead = 0;
        }

        public void toggleFail() {
            fail = !fail;
        }

        @Override
        public int read() throws IOException {
            if (numRead >= maxRead && fail) {
                throw new SocketTimeoutException("fail");
            }
            int result = super.read();
            numRead++;
            return result;
        }
    }

    // Create regular LLP frame
    bos = new ByteArrayOutputStream();
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    // Create an input stream that will throw an exception
    maxRead = 50;
    is = new FailingFilterInputStream(new ByteArrayInputStream(bos.toByteArray()), maxRead);
    // Allow the stream handler to return data when an exception occurs
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    ((FrameStreamHandler) streamHandler).setReturnDataOnException(true);
    // Assert that the bytes returned from the stream handler are correct
    assertTrue(Arrays.equals(Arrays.copyOf(testBytes, maxRead - llpStartBytes.length), streamHandler.read()));

    // Create regular LLP frame
    bos = new ByteArrayOutputStream();
    bos.write(llpStartBytes);
    bos.write(testBytes);
    bos.write(llpEndBytes);
    // Create an input stream that will throw an exception
    maxRead = 50;
    is = new FailingFilterInputStream(new ByteArrayInputStream(bos.toByteArray()), maxRead);
    // Allow the stream handler to return data when an exception occurs
    batchStreamHandler = new DefaultBatchStreamReader(is);
    streamHandler = new FrameStreamHandler(is, null, batchStreamHandler, defaultMLLPProps);
    ((FrameStreamHandler) streamHandler).setReturnDataOnException(true);
    // Get the first set of bytes
    byte[] firstBytes = streamHandler.read();
    // Turn failing off and get the rest of the bytes
    ((FailingFilterInputStream) is).toggleFail();
    byte[] nextBytes = streamHandler.read();
    // Assert that the concatenation of both byte arrays is equivalent to the original message
    assertTrue(Arrays.equals(testBytes, ArrayUtils.addAll(firstBytes, nextBytes)));
}

From source file:ly.count.android.api.CountlyStoreTests.java

public void testEvents_prefIsEmptyString() {
    // the following two calls will result in the pref being an empty string
    store.addEvent("eventKey", null, Countly.currentTimestamp(), 1, 0.0d);
    store.removeEvents(store.eventsList());
    assertTrue(Arrays.equals(new String[0], store.events()));
}

From source file:org.jfree.chart.demo.RightPanel.java

public void redraw() {
    // TODO Auto-generated method stub
    if (Arrays.equals(Name, Name1) != true) {
        comboBox.removeAllItems();//w w  w .  j a  v a 2 s .c  om
        for (int i = 0; i < Name.length; i++)
            comboBox.addItem(Name[i]);
    }
}