List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:com.espertech.esper.collection.TestPermutationEnumeration.java
private void tryPermutation(int numElements, int[][] expectedValues) { /*/*from w w w . j a v a 2 s. co m*/ Total: 4 * 3 * 2 = 24 = 6! (6 faculty) Example:8 n / 6 = first number == index 1, total {1}, remains {0, 2, 3} remainder 8 - 1 * 6 == 2 n / 2 = second number == index 1, total {1, 2}, remain {0, 3} remainder 2 - 1 * 2 == 0 == total {1, 2, 0, 3} Example:21 out {0, 1, 2, 3} 21 / 6 == index 3 -> in {3}, out {0, 1, 2} remainder 21 - 3 * 6 == 3 3 / 2 = second number == index 1 -> in {3, 1}, remain {0, 2} remainder 3 - 1 * 2 == 1 == index 1 -> in {3, 1, 2} out {0} */ PermutationEnumeration enumeration = new PermutationEnumeration(numElements); int count = 0; while (enumeration.hasMoreElements()) { int[] result = enumeration.nextElement(); int[] expected = expectedValues[count]; log.debug(".tryPermutation result=" + Arrays.toString(result)); log.debug(".tryPermutation expected=" + Arrays.toString(result)); count++; assertTrue("Mismatch in count=" + count, Arrays.equals(result, expected)); } assertEquals(count, expectedValues.length); try { enumeration.nextElement(); fail(); } catch (NoSuchElementException ex) { // Expected } }
From source file:net.sf.taverna.t2.reference.RegisterLargeByteArrayTest.java
@Test public void register1kByteArray() throws Exception { byte[] bytes = readBinaryData("1k.bin"); ApplicationContext context = new RavenAwareClassPathXmlApplicationContext( "registrationAndTraversalTestContext.xml"); ReferenceService rs = (ReferenceService) context.getBean("t2reference.service.referenceService"); T2Reference reference = rs.register(bytes, 0, true, dummyContext); System.out.println("Registered 1k with rs " + rs); Object returnedObject = rs.renderIdentifier(reference, Object.class, dummyContext); byte[] newbytes = (byte[]) returnedObject; assertEquals("There bytes should be of the same length", bytes.length, newbytes.length); //assertNotSame(bytes, newbytes); assertTrue("The bytes should have the same content", Arrays.equals(bytes, newbytes)); }
From source file:com.couchbase.lite.DatabaseAttachmentTest.java
/** * in DatabaseAttachment_Tests.m/*from w w w . ja va2 s. com*/ * - (void) test10_Attachments */ @SuppressWarnings("unchecked") public void testAttachments() throws Exception { BlobStore attachments = database.getAttachmentStore(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); // Add a revision and an attachment to it: Status status = new Status(Status.OK); byte[] attach1 = "This is the body of attach1".getBytes(); Map<String, Object> props = new HashMap<String, Object>(); props.put("foo", 1); props.put("bar", false); props.put("_attachments", getAttachmentsDict(attach1, "attach", "text/plain", false)); RevisionInternal rev1 = database.putRevision(new RevisionInternal(props), null, false, status); Assert.assertEquals(Status.CREATED, status.getCode()); AttachmentInternal att = database.getAttachment(rev1, "attach"); Assert.assertNotNull(att); Log.i(TAG, new String(att.getContent())); Assert.assertTrue(Arrays.equals(attach1, att.getContent())); Assert.assertEquals("text/plain", att.getContentType()); Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding()); // Check the attachment dict: Map<String, Object> itemDict = new HashMap<String, Object>(); itemDict.put("content_type", "text/plain"); itemDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); itemDict.put("length", 27); itemDict.put("stub", true); itemDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", itemDict); RevisionInternal gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: itemDict.remove("stub"); itemDict.put("data", Base64.encodeBytes(attach1)); gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true); RevisionInternal expandedRev = gotRev1.copy(); Assert.assertTrue(database.expandAttachments(expandedRev, 0, false, true, status)); Assert.assertEquals(attachmentDict, expandedRev.getAttachments()); // Add a second revision that doesn't update the attachment: props = new HashMap<String, Object>(); props.put("_id", rev1.getDocID()); props.put("foo", 2); props.put("bazz", false); props.put("_attachments", getAttachmentsStub("attach")); RevisionInternal rev2 = database.putRevision(new RevisionInternal(props), rev1.getRevID(), false, status); Assert.assertEquals(Status.CREATED, status.getCode()); // Add a third revision of the same document: byte[] attach2 = "<html>And this is attach2</html>".getBytes(); props = new HashMap<String, Object>(); props.put("_id", rev2.getDocID()); props.put("foo", 2); props.put("bazz", false); props.put("_attachments", getAttachmentsDict(attach2, "attach", "text/html", false)); RevisionInternal rev3 = database.putRevision(new RevisionInternal(props), rev2.getRevID(), false, status); Assert.assertEquals(Status.CREATED, status.getCode()); // Check the 2nd revision's attachment: att = database.getAttachment(rev2, "attach"); Assert.assertNotNull(att); Assert.assertEquals("text/plain", att.getContentType()); Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding()); Assert.assertTrue(Arrays.equals(attach1, att.getContent())); expandedRev = rev2.copy(); Assert.assertTrue(database.expandAttachments(expandedRev, 2, false, true, status)); attachmentDict = new HashMap<String, Object>(); itemDict = new HashMap<String, Object>(); itemDict.put("stub", true); itemDict.put("revpos", 1); attachmentDict.put("attach", itemDict); Assert.assertEquals(attachmentDict, expandedRev.getAttachments()); // Check the 3rd revision's attachment: att = database.getAttachment(rev3, "attach"); Assert.assertNotNull(att); Assert.assertEquals("text/html", att.getContentType()); Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding()); Assert.assertTrue(Arrays.equals(attach2, att.getContent())); expandedRev = rev3.copy(); Assert.assertTrue(database.expandAttachments(expandedRev, 2, false, true, status)); attachmentDict = new HashMap<String, Object>(); itemDict = new HashMap<String, Object>(); itemDict.put("content_type", "text/html"); itemDict.put("data", "PGh0bWw+QW5kIHRoaXMgaXMgYXR0YWNoMjwvaHRtbD4="); itemDict.put("digest", "sha1-s14XRTXlwvzYfjo1t1u0rjB+ZUA="); itemDict.put("length", 32); itemDict.put("revpos", 3); attachmentDict.put("attach", itemDict); Map<String, Object> data = expandedRev.getAttachments(); Assert.assertEquals(attachmentDict, expandedRev.getAttachments()); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<BlobKey> expected = new HashSet<BlobKey>(); expected.add(BlobStore.keyForBlob(attach1)); expected.add(BlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); database.compact(); // This clears the body of the first revision Assert.assertEquals(1, attachments.count()); Set<BlobKey> expected2 = new HashSet<BlobKey>(); expected2.add(BlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationLocation.java
/** * @param certHashBase64 the base64 encoded certificate hash * @param hashAlgoId the hash algorithm id * @return verification certificate for a given certificate hash or null * if not found//from w w w .j a v a 2 s. co m */ public X509Certificate getVerificationCert(String certHashBase64, String hashAlgoId) { byte[] certHash = decodeBase64(certHashBase64); for (byte[] certBytes : verificationCerts) { try { log.trace("Calculating certificate hash using algorithm {}", hashAlgoId); if (Arrays.equals(certHash, hash(hashAlgoId, certBytes))) { return readCertificate(certBytes); } } catch (Exception e) { log.error("Failed to calculate certificate hash using " + "algorithm identifier " + hashAlgoId, e); } } return null; }
From source file:edu.umn.msi.tropix.common.io.IOContextsTest.java
@Test(groups = "unit") public void inputForStream() throws IOException { final ByteArrayInputStream inputStream = new ByteArrayInputStream("Moo Cow".getBytes()); final InputContext inputContext = InputContexts.forInputStream(inputStream); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); inputContext.get(outputStream);// www . ja v a2 s .co m assert Arrays.equals(outputStream.toByteArray(), "Moo Cow".getBytes()); }
From source file:my.adam.smo.EncryptionTest.java
@Test public void symmetricEncryptionGaveDifferentCryptogramForSamePlainText() { ApplicationContext clientContext = new ClassPathXmlApplicationContext("Context.xml"); SymmetricEncryptionBox box = clientContext.getBean(SymmetricEncryptionBox.class); int plainTextLength = 17; Random random = new Random(); byte[] plainText = new byte[plainTextLength]; random.nextBytes(plainText);//from www .j a va 2 s . c o m byte[] cryptogram1 = box.encrypt(plainText); byte[] cryptogram2 = box.encrypt(plainText); Assert.assertFalse("cryptograms are same", Arrays.equals(cryptogram1, cryptogram2)); byte[] decrypted1 = box.decrypt(cryptogram1); Assert.assertTrue("unable to decrypt", Arrays.equals(plainText, decrypted1)); byte[] decrypted2 = box.decrypt(cryptogram2); Assert.assertTrue("unable to decrypt", Arrays.equals(plainText, decrypted2)); }
From source file:org.jfree.data.function.PolynomialFunction2D.java
/** * Tests this function for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean.// w w w. j a va2s. com */ @Override public boolean equals(Object obj) { if (!(obj instanceof PolynomialFunction2D)) { return false; } PolynomialFunction2D that = (PolynomialFunction2D) obj; return Arrays.equals(this.coefficients, that.coefficients); }
From source file:org.brekka.phalanx.core.services.impl.AbstractCryptoService.java
private InternalSecretKeyToken decodeSecretKey(byte[] encoded, UUID idOfData) { ByteBuffer buffer = ByteBuffer.wrap(encoded); byte[] marker = new byte[SK_MAGIC_MARKER.length]; buffer.get(marker);/*from ww w. j a v a2 s . c o m*/ if (!Arrays.equals(SK_MAGIC_MARKER, marker)) { throw new PhalanxException(PhalanxErrorCode.CP213, "CryptoData item '%s' does not appear to contain a secret key", idOfData); } int profileId = buffer.getInt(); byte[] keyId = new byte[16]; buffer.get(keyId); UUID symCryptoDataId = toUUID(keyId); CryptoProfile cryptoProfile = cryptoProfileService.retrieveProfile(profileId); byte[] data = new byte[encoded.length - (SK_MAGIC_MARKER.length + 20)]; buffer.get(data); SecretKey secretKey = phoenixSymmetric.toSecretKey(data, cryptoProfile); SymedCryptoData symedCryptoData = new SymedCryptoData(); symedCryptoData.setId(symCryptoDataId); symedCryptoData.setProfile(profileId); return new InternalSecretKeyToken(secretKey, symedCryptoData); }
From source file:components.PasswordDemo.java
/** * Checks the passed-in array against the correct password. * After this method returns, you should invoke eraseArray * on the passed-in array./*from w w w .j av a 2 s .c o m*/ */ private static boolean isPasswordCorrect(char[] input) { boolean isCorrect = true; char[] correctPassword = { 'b', 'u', 'g', 'a', 'b', 'o', 'o' }; if (input.length != correctPassword.length) { isCorrect = false; } else { isCorrect = Arrays.equals(input, correctPassword); } //Zero out the password. Arrays.fill(correctPassword, '0'); return isCorrect; }
From source file:com.espertech.esper.collection.TestNumberSetShiftGroupEnumeration.java
private void tryPermutation(int[] numberSet, int[][] expectedValues) { NumberSetShiftGroupEnumeration enumeration = new NumberSetShiftGroupEnumeration(numberSet); int count = 0; while (enumeration.hasMoreElements()) { log.debug(".tryPermutation count=" + count); int[] result = enumeration.nextElement(); int[] expected = expectedValues[count]; log.debug(".tryPermutation result=" + Arrays.toString(result)); log.debug(".tryPermutation expected=" + Arrays.toString(expected)); assertSet(expected, result);/*from ww w . j a v a2 s .c om*/ count++; assertTrue("Mismatch in count=" + count, Arrays.equals(result, expected)); } assertEquals(count, expectedValues.length); try { enumeration.nextElement(); fail(); } catch (NoSuchElementException ex) { // Expected } }