List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:com.opengamma.analytics.math.linearalgebra.LUDecompositionCommonsResultTest.java
@Test public void testSolvers() { assertTrue(Arrays.equals(RESULT_1D.getData(), LU.solve(RESULT_1D.getData()))); assertTrue(Arrays.equals(RESULT_1D.getData(), LU.solve(new DoubleMatrix1D(RESULT_1D.getData())).getData())); assertRealMatrixEquals(RESULT_2D, LU.solve(new DoubleMatrix2D(RESULT_2D.getData()))); }
From source file:com.couchbase.touchdb.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { TDBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); TDStatus status = new TDStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); TDRevision rev1 = database.putRevision(new TDRevision(rev1Properties), null, false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); TDAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(TDDatabase.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); TDRevision rev2 = database.putRevision(new TDRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());/*w w w. jav a 2 s . co m*/ Assert.assertEquals(TDStatus.OK, status.getCode()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); TDRevision rev3 = database.putRevision(new TDRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: TDAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: TDAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<TDBlobKey> expected = new HashSet<TDBlobKey>(); expected.add(TDBlobStore.keyForBlob(attach1)); expected.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<TDBlobKey> expected2 = new HashSet<TDBlobKey>(); expected2.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:edu.utdallas.bigsecret.cipher.test.TestAesEcb.java
@Test public void testDecryptByteArrayInt() { byte[] key = Bytes.toBytes("1234567890123456"); try {//from w w w . j ava2s . com AesEcb cip = new AesEcb(key); byte[] originalData = Bytes.toBytes("mr. anderson, we missed you"); System.out.println("Original Data: "); printArray(originalData); byte[] encData = cip.encrypt(originalData); System.out.println("Encrypted Data: "); printArray(encData); byte[] pad = new byte[2]; pad[0] = 1; pad[1] = 0; byte[] padded = ArrayUtils.addAll(pad, encData); byte[] decData = cip.decrypt(padded, 2); System.out.println("Decrypted Data: "); printArray(decData); if (!Arrays.equals(originalData, decData)) { fail("AesEcb encryption decryption mechanism failed. Data changes after encryption and decryption!!"); } } catch (Exception e) { fail("AesEcb encrypt test failed."); e.printStackTrace(); } }
From source file:de.berlin.magun.nfcmime.core.RfidDAO.java
/** * Reads URI records from NDEF records//w ww .j ava 2s. co m * @param tag * @return an ArrayList of URIs, represented as Strings. */ public ArrayList<String> getUriRecords(Tag tag) { readRecords(tag); if (this.records != null) { ArrayList<String> uriStrings = new ArrayList<String>(); for (int i = 0; i < this.records.length; i++) { if (this.records[i].getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(this.records[i].getType(), NdefRecord.RTD_URI)) { uriStrings.add(EncodingUtils.getString(ArrayUtils.remove(records[i].getPayload(), 0), "UTF-8")); } } return uriStrings; } else { return null; } }
From source file:edu.utdallas.bigsecret.cipher.test.TestAesCtr.java
@Test public void testDecryptByteArrayInt() { byte[] key = Bytes.toBytes("1234567890123456"); try {/*w ww . jav a 2 s .c o m*/ AesCtr cip = new AesCtr(key); byte[] originalData = Bytes.toBytes("He is the one."); System.out.println("Original Data: "); printArray(originalData); byte[] encData = cip.encrypt(originalData); System.out.println("Encrypted Data: "); printArray(encData); byte[] pad = new byte[2]; pad[0] = 1; pad[1] = 0; byte[] padded = ArrayUtils.addAll(pad, encData); byte[] decData = cip.decrypt(padded, 2); System.out.println("Decrypted Data: "); printArray(decData); if (!Arrays.equals(originalData, decData)) { fail("AesCtr encryption decryption mechanism failed. Data changes after encryption and decryption!!"); } } catch (Exception e) { fail("AesCtr encrypt test failed."); e.printStackTrace(); } }
From source file:com.couchbase.cblite.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { CBLBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); CBLStatus status = new CBLStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); CBLRevision rev1 = database.putRevision(new CBLRevision(rev1Properties), null, false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); CBLAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); CBLRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(CBLDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(CBLDatabase.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); CBLRevision rev2 = database.putRevision(new CBLRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());// www . java2s . co m Assert.assertEquals(CBLStatus.OK, status.getCode()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); CBLRevision rev3 = database.putRevision(new CBLRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: CBLAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: CBLAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<CBLBlobKey> expected = new HashSet<CBLBlobKey>(); expected.add(CBLBlobStore.keyForBlob(attach1)); expected.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<CBLBlobKey> expected2 = new HashSet<CBLBlobKey>(); expected2.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:com.gs.jrpip.client.AuthenticatedUrl.java
@Override public boolean equals(Object o) { if (this == o) { return true; }/* w w w . j a v a 2 s . c o m*/ if (!(o instanceof AuthenticatedUrl)) { return false; } AuthenticatedUrl authenticatedUrl = (AuthenticatedUrl) o; if (this.credentials == null ? authenticatedUrl.credentials != null : !this.credentials.equals(authenticatedUrl.credentials)) { return false; } if (this.url == null ? authenticatedUrl.url != null : !this.url.equals(authenticatedUrl.url)) { return false; } return Arrays.equals(this.cookies, authenticatedUrl.cookies); }
From source file:edu.oregonstate.eecs.mcplan.domains.cosmic.TripBusSetAction.java
@Override public boolean equals(final Object obj) { if (!(obj instanceof TripBusSetAction)) { return false; }/*from w ww. j av a 2s.c om*/ final TripBusSetAction that = (TripBusSetAction) obj; return Arrays.equals(bus, that.bus); }
From source file:com.redhat.rcm.nexus.security.RemoteUserAuthenticationRealm.java
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { setCredentialsMatcher(credentialsMatcher); if (token instanceof UsernamePasswordToken) { final UsernamePasswordToken tok = (UsernamePasswordToken) token; if (Arrays.equals(REMOTE_USER_PASSWORD_CHARS, REMOTE_USER_PASSWORD_CHARS)) { logger.info("creating remote-user authentication info for: " + tok.getUsername()); final String remoteUser = tok.getUsername(); return new RemoteUserInfo(remoteUser, getName()); }/*from ww w .j a va 2s .c o m*/ } logger.warn("PASS-THROUGH: creating conventional authentication info..."); return delegate.getAuthenticationInfo(token); }
From source file:com.qhrtech.emr.launcher.TemplateLauncherManager.java
private boolean mapsEqual(Map<File, byte[]> m1, Map<File, byte[]> m2) { if (m1.size() != m2.size()) { return false; }/*from w ww .java2 s. c o m*/ for (Map.Entry<File, byte[]> entry : m1.entrySet()) { File key = entry.getKey(); byte[] m1Value = entry.getValue(); byte[] m2Value = m2.get(key); if (m2Value == null || !Arrays.equals(m1Value, m2Value)) { return false; } } return true; }