List of usage examples for java.util Arrays deepEquals
public static boolean deepEquals(Object[] a1, Object[] a2)
From source file:org.apache.sqoop.connector.idf.TestCSVIntermediateDataFormat.java
@Test public void testObjectArrayInObjectArrayOut() { //Test escapable sequences too. //byte[0] = -112, byte[1] = 54 - 2's complements Schema schema = new Schema("test"); schema.addColumn(new FixedPoint("1", 8L, true)).addColumn(new FixedPoint("2", 2L, true)) .addColumn(new Text("3")).addColumn(new Text("4")).addColumn(new Binary("5")) .addColumn(new Text("6")).addColumn(new org.apache.sqoop.schema.type.Enum("7")); dataFormat = new CSVIntermediateDataFormat(schema); Object[] in = new Object[7]; in[0] = new Long(10); in[1] = new Integer(34); in[2] = "54"; in[3] = "random data"; in[4] = new byte[] { (byte) -112, (byte) 54 }; in[5] = new String(new char[] { 0x0A }); in[6] = "TEST_ENUM"; Object[] inCopy = new Object[7]; System.arraycopy(in, 0, inCopy, 0, in.length); // Modifies the input array, so we use the copy to confirm dataFormat.setObjectData(in);/*from ww w . j a va2 s . c o m*/ assertTrue(Arrays.deepEquals(inCopy, dataFormat.getObjectData())); }
From source file:org.apache.geode.pdx.internal.PdxInstanceImpl.java
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#0 o1=<" + this + "> o2=<" + // obj + ">"); return false; }// www . jav a2 s. c o m if (!(obj instanceof PdxInstanceImpl)) { // if (!result) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#1 o1=<" + this + "> o2=<" + // obj + ">"); // } return false; } final PdxInstanceImpl other = (PdxInstanceImpl) obj; PdxReaderImpl ur2 = other.getUnmodifiableReader(); PdxReaderImpl ur1 = getUnmodifiableReader(); if (!ur1.getPdxType().getClassName().equals(ur2.getPdxType().getClassName())) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#2 o1=<" + this + "> o2=<" + // obj + ">"); return false; } SortedSet<PdxField> myFields = ur1.getPdxType().getSortedIdentityFields(); SortedSet<PdxField> otherFields = ur2.getPdxType().getSortedIdentityFields(); if (!myFields.equals(otherFields)) { // It is not ok to modify myFields and otherFields in place so make copies myFields = new TreeSet<PdxField>(myFields); otherFields = new TreeSet<PdxField>(otherFields); addDefaultFields(myFields, otherFields); addDefaultFields(otherFields, myFields); } Iterator<PdxField> myFieldIterator = myFields.iterator(); Iterator<PdxField> otherFieldIterator = otherFields.iterator(); while (myFieldIterator.hasNext()) { PdxField myType = myFieldIterator.next(); PdxField otherType = otherFieldIterator.next(); switch (myType.getFieldType()) { case CHAR: case BOOLEAN: case BYTE: case SHORT: case INT: case LONG: case DATE: case FLOAT: case DOUBLE: case STRING: case BOOLEAN_ARRAY: case CHAR_ARRAY: case BYTE_ARRAY: case SHORT_ARRAY: case INT_ARRAY: case LONG_ARRAY: case FLOAT_ARRAY: case DOUBLE_ARRAY: case STRING_ARRAY: case ARRAY_OF_BYTE_ARRAYS: { ByteSource myBuffer = ur1.getRaw(myType); ByteSource otherBuffer = ur2.getRaw(otherType); if (!myBuffer.equals(otherBuffer)) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#4 o1=<" + this + "> // o2=<" + obj + ">"); return false; } } break; case OBJECT_ARRAY: { Object[] myArray = ur1.readObjectArray(myType); Object[] otherArray = ur2.readObjectArray(otherType); if (!Arrays.deepEquals(myArray, otherArray)) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#5 o1=<" + this + "> // o2=<" + obj + ">"); return false; } } break; case OBJECT: { Object myObject = ur1.readObject(myType); Object otherObject = ur2.readObject(otherType); if (myObject != otherObject) { if (myObject == null) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#6 o1=<" + this + "> // o2=<" + obj + ">"); return false; } if (otherObject == null) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#7 o1=<" + this + "> // o2=<" + obj + ">"); return false; } if (myObject.getClass().isArray()) { // for bug 42976 Class<?> myComponentType = myObject.getClass().getComponentType(); Class<?> otherComponentType = otherObject.getClass().getComponentType(); if (!myComponentType.equals(otherComponentType)) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#8 o1=<" + this + "> // o2=<" + obj + ">"); return false; } if (myComponentType.isPrimitive()) { ByteSource myBuffer = getRaw(myType); ByteSource otherBuffer = other.getRaw(otherType); if (!myBuffer.equals(otherBuffer)) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#9 o1=<" + this + // "> o2=<" + obj + ">"); return false; } } else { if (!Arrays.deepEquals((Object[]) myObject, (Object[]) otherObject)) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#10 o1=<" + this + // "> o2=<" + obj + ">"); return false; } } } else if (!myObject.equals(otherObject)) { // GemFireCacheImpl.getInstance().getLogger().info("DEBUG equals#11 fn=" + // myType.getFieldName() + " myFieldClass=" + myObject.getClass() + " // otherFieldCLass=" + otherObject.getClass() + " o1=<" + this + "> o2=<" + obj + ">" // + "myObj=<" + myObject + "> otherObj=<" + otherObject + ">"); return false; } } } break; default: throw new InternalGemFireException("Unhandled field type " + myType.getFieldType()); } } return true; }
From source file:com.opengamma.analytics.financial.instrument.payment.CouponONSpreadDefinition.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/* ww w . j ava 2s. c o m*/ if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } final CouponONSpreadDefinition other = (CouponONSpreadDefinition) obj; if (Double.compare(_spread, other._spread) != 0) { return false; } if (!Arrays.deepEquals(_fixingPeriodAccrualFactor, other._fixingPeriodAccrualFactor)) { return false; } if (!Arrays.deepEquals(_fixingPeriodDate, other._fixingPeriodDate)) { return false; } if (!ObjectUtils.equals(_index, other._index)) { return false; } return true; }
From source file:org.knime.al.util.noveltydetection.kernel.KernelCalculator.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//w ww .j a v a 2 s .c o m if (obj == null) { return false; } if (!(obj instanceof KernelCalculator)) { return false; } final KernelCalculator other = (KernelCalculator) obj; if (m_colCount != other.m_colCount) { return false; } if (m_kernelFunction == null) { if (other.m_kernelFunction != null) { return false; } } else if (!m_kernelFunction.equals(other.m_kernelFunction)) { return false; } if (m_rowCount != other.m_rowCount) { return false; } if (!Arrays.deepEquals(m_trainingData, other.m_trainingData)) { return false; } return true; }
From source file:org.apache.sqoop.connector.idf.TestCSVIntermediateDataFormat.java
@Test public void testStringFullRangeOfCharacters() { Schema schema = new Schema("test"); schema.addColumn(new Text("1")); dataFormat = new CSVIntermediateDataFormat(schema); char[] allCharArr = new char[256]; for (int i = 0; i < allCharArr.length; ++i) { allCharArr[i] = (char) i; }/*from w w w . j a va 2 s . c om*/ String strData = new String(allCharArr); Object[] in = { strData }; Object[] inCopy = new Object[1]; System.arraycopy(in, 0, inCopy, 0, in.length); // Modifies the input array, so we use the copy to confirm dataFormat.setObjectData(in); assertEquals(strData, dataFormat.getObjectData()[0]); assertTrue(Arrays.deepEquals(inCopy, dataFormat.getObjectData())); }
From source file:org.apache.sqoop.connector.idf.TestCSVIntermediateDataFormat.java
@Test public void testByteArrayFullRangeOfCharacters() { Schema schema = new Schema("test"); schema.addColumn(new Binary("1")); dataFormat = new CSVIntermediateDataFormat(schema); byte[] allCharByteArr = new byte[256]; for (int i = 0; i < allCharByteArr.length; ++i) { allCharByteArr[i] = (byte) i; }// www. j a va 2 s . com Object[] in = { allCharByteArr }; Object[] inCopy = new Object[1]; System.arraycopy(in, 0, inCopy, 0, in.length); // Modifies the input array, so we use the copy to confirm dataFormat.setObjectData(in); assertTrue(Arrays.deepEquals(inCopy, dataFormat.getObjectData())); }
From source file:hivemall.utils.math.MatrixUtils.java
/** * Lanczos tridiagonalization for a symmetric matrix C to make s * s tridiagonal matrix T. * * @see http://www.cas.mcmaster.ca/~qiao/publications/spie05.pdf * @param C target symmetric matrix/* ww w.ja v a2 s.c o m*/ * @param a initial vector * @param T result is stored here */ public static void lanczosTridiagonalization(@Nonnull final RealMatrix C, @Nonnull final double[] a, @Nonnull final RealMatrix T) { Preconditions.checkArgument(Arrays.deepEquals(C.getData(), C.transpose().getData()), "Target matrix C must be a symmetric matrix"); Preconditions.checkArgument(C.getColumnDimension() == a.length, "Column size of A and length of a should be same"); Preconditions.checkArgument(T.getRowDimension() == T.getColumnDimension(), "T must be a square matrix"); int s = T.getRowDimension(); // initialize T with zeros T.setSubMatrix(new double[s][s], 0, 0); RealVector a0 = new ArrayRealVector(a.length); RealVector r = new ArrayRealVector(a); double beta0 = 1.d; for (int i = 0; i < s; i++) { RealVector a1 = r.mapDivide(beta0); RealVector Ca1 = C.operate(a1); double alpha1 = a1.dotProduct(Ca1); r = Ca1.add(a1.mapMultiply(-1.d * alpha1)).add(a0.mapMultiply(-1.d * beta0)); double beta1 = r.getNorm(); T.setEntry(i, i, alpha1); if (i - 1 >= 0) { T.setEntry(i, i - 1, beta0); } if (i + 1 < s) { T.setEntry(i, i + 1, beta1); } a0 = a1.copy(); beta0 = beta1; } }
From source file:org.voltdb.TestParameterSet.java
public void testRoundtrip() throws IOException { Byte byteparam = new Byte((byte) 2); Short shortparam = new Short(Short.MAX_VALUE); Integer intparam = new Integer(Integer.MIN_VALUE); Long longparam = new Long(Long.MAX_VALUE - 1); Double doubleparam = new Double(Double.MAX_VALUE - 1); String stringparam = new String("ABCDE"); TimestampType dateparam = new TimestampType(); // current time BigDecimal bigdecimalparam = new BigDecimal(7654321).setScale(VoltDecimalHelper.kDefaultScale); VoltTable volttableparam = new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.INTEGER)); volttableparam.addRow(Integer.MAX_VALUE); byte[] bytearray = new byte[] { (byte) 'f', (byte) 'o', (byte) 'o' }; short[] shortarray = new short[] { Short.MAX_VALUE, Short.MIN_VALUE, (short) 5 }; int[] intarray = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE, 5 }; double[] doublearray = new double[] { Double.MAX_VALUE, Double.MIN_VALUE, 5.5 }; String[] stringarray = new String[] { "ABC", "DEF", "HIJ" }; TimestampType[] datearray = new TimestampType[] { new TimestampType(), new TimestampType(), new TimestampType() }; BigDecimal bdtmp1 = new BigDecimal(7654321).setScale(VoltDecimalHelper.kDefaultScale); BigDecimal bdtmp2 = new BigDecimal(654321).setScale(VoltDecimalHelper.kDefaultScale); BigDecimal bdtmp3 = new BigDecimal(54321).setScale(VoltDecimalHelper.kDefaultScale); BigDecimal[] bigdecimalarray = new BigDecimal[] { bdtmp1, bdtmp2, bdtmp3 }; VoltTable vttmp1 = new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.INTEGER), new VoltTable.ColumnInfo("bar", VoltType.STRING)); vttmp1.addRow(Integer.MAX_VALUE, "ry@nlikestheyankees"); VoltTable vttmp2 = new VoltTable(new VoltTable.ColumnInfo("bar", VoltType.INTEGER), new VoltTable.ColumnInfo("bar", VoltType.STRING)); vttmp2.addRow(Integer.MIN_VALUE, null); VoltTable vttmp3 = new VoltTable(new VoltTable.ColumnInfo("far", VoltType.INTEGER), new VoltTable.ColumnInfo("bar", VoltType.STRING)); vttmp3.addRow(new Integer(5), ""); VoltTable[] volttablearray = new VoltTable[] { vttmp1, vttmp2, vttmp3 }; assertTrue(bigdecimalparam.scale() == VoltDecimalHelper.kDefaultScale); assertTrue(bdtmp1.scale() == VoltDecimalHelper.kDefaultScale); assertTrue(bdtmp2.scale() == VoltDecimalHelper.kDefaultScale); assertTrue(bdtmp3.scale() == VoltDecimalHelper.kDefaultScale); ParameterSet pset = ParameterSet.fromArrayNoCopy(byteparam, shortparam, intparam, longparam, doubleparam, stringparam, dateparam, bigdecimalparam, volttableparam, bytearray, shortarray, intarray, doublearray, stringarray, datearray, bigdecimalarray, volttablearray); ByteBuffer buf = ByteBuffer.allocate(pset.getSerializedSize()); pset.flattenToBuffer(buf);//from w w w .j a va 2 s . c o m buf.flip(); ParameterSet pset2 = ParameterSet.fromByteBuffer(buf); Object[] pset1array = pset.toArray(); Object[] pset2array = pset2.toArray(); assertTrue(Arrays.deepEquals(pset1array, pset2array)); }
From source file:org.wso2.carbon.identity.oauth2.token.AccessTokenIssuerTest.java
/** * Exception thrown when issuing access token by the Grant Handler * * @throws Exception//from w w w . ja v a 2 s. c om */ @Test(dataProvider = "scopeDataProvider") public void testIssueWithScopes(String[] scopes, String expectedScopeString) throws Exception { when(OAuth2Util.buildScopeString(Matchers.<String[]>anyObject())).thenCallRealMethod(); AuthorizationGrantHandler dummyGrantHandler = getMockGrantHandlerForSuccess(false); OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO(); reqDTO.setGrantType(DUMMY_GRANT_TYPE); OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext(); oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID); reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext); reqDTO.setScope((String[]) ArrayUtils.clone(scopes)); final ResponseHeader responseHeader = new ResponseHeader(); responseHeader.setKey("Header"); responseHeader.setValue("HeaderValue"); final ResponseHeader[] responseHeaders = new ResponseHeader[] { responseHeader }; // Mock Issue when(dummyGrantHandler.issue(any(OAuthTokenReqMessageContext.class))).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { OAuthTokenReqMessageContext context = invocationOnMock.getArgumentAt(0, OAuthTokenReqMessageContext.class); // set some response headers context.addProperty(OAuthConstants.RESPONSE_HEADERS_PROPERTY, responseHeaders); String[] scopeArray = context.getOauth2AccessTokenReqDTO().getScope(); context.setScope(scopeArray); return new OAuth2AccessTokenRespDTO(); } }); HashMap<String, AuthorizationGrantHandler> authorizationGrantHandlers = new HashMap<>(); authorizationGrantHandlers.put(DUMMY_GRANT_TYPE, dummyGrantHandler); mockOAuth2ServerConfiguration(authorizationGrantHandlers); OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO); assertNotNull(tokenRespDTO); assertFalse(tokenRespDTO.isError()); assertEquals(tokenRespDTO.getAuthorizedScopes(), expectedScopeString); // Assert response headers set by the grant handler assertNotNull(tokenRespDTO.getResponseHeaders()); assertTrue(Arrays.deepEquals(tokenRespDTO.getResponseHeaders(), responseHeaders)); }
From source file:org.wso2.carbon.identity.oauth2.token.AccessTokenIssuerTest.java
@Test(dataProvider = "grantTypeDataProvider") public void testIssueWithOpenIdScope(String grantType) throws Exception { OAuth2AccessTokenReqDTO reqDTO = new OAuth2AccessTokenReqDTO(); reqDTO.setGrantType(grantType);/*from w w w. j av a2 s.co m*/ reqDTO.setScope((String[]) ArrayUtils.clone(SCOPES_WITH_OPENID)); OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext(); oAuthClientAuthnContext.setClientId(SOME_CLIENT_ID); reqDTO.setoAuthClientAuthnContext(oAuthClientAuthnContext); setupOIDCScopeTest(grantType, true); OAuth2AccessTokenRespDTO tokenRespDTO = AccessTokenIssuer.getInstance().issue(reqDTO); assertNotNull(tokenRespDTO); assertFalse(tokenRespDTO.isError()); assertTrue(Arrays.deepEquals(tokenRespDTO.getAuthorizedScopes().split(" "), SCOPES_WITH_OPENID)); assertNotNull(tokenRespDTO.getIDToken()); assertEquals(tokenRespDTO.getIDToken(), ID_TOKEN); }