@Test public void testPartEquals() throws Exception { Assert.assertTrue( ParsecEqualsUtil.partEquals( new ByteArrayPart("abc", new byte[] {1,2,3}), new ByteArrayPart("abc", new byte[] {1,2,3}) ) ); Assert.assertFalse( ParsecEqualsUtil.partEquals( new ByteArrayPart("abc", new byte[] {1,2,3}), new ByteArrayPart("abc", new byte[] {4,5,6}) ) ); File file1 = new File("src/test/java/com/yahoo/parsec/clients/ParsecEqualsUtilTest.java"), file2 = new File("src/test/java/com/yahoo/parsec/clients/ParsecAsyncHttpRequestTest.java"); Assert.assertTrue(ParsecEqualsUtil.partEquals(new FilePart("abc", file1), new FilePart("abc", file1))); Assert.assertFalse(ParsecEqualsUtil.partEquals(new FilePart("abc", file1), new FilePart("def", file1))); Assert.assertFalse(ParsecEqualsUtil.partEquals(new FilePart("abc", file1), new FilePart("abc", file2))); Assert.assertTrue(ParsecEqualsUtil.partEquals(new StringPart("abc", "def"), new StringPart("abc", "def"))); Assert.assertFalse(ParsecEqualsUtil.partEquals(new StringPart("abc", "def"), new StringPart("def", "def"))); Assert.assertFalse(ParsecEqualsUtil.partEquals(new StringPart("abc", "def"), new StringPart("abc", "abc"))); }
static boolean partEquals(final Part lhs, final Part rhs) { if (!lhs.equals(rhs)) { if (lhs.getClass() != rhs.getClass()) { return false; } if (!new EqualsBuilder() .append(lhs.getCharset(), rhs.getCharset()) .append(lhs.getContentId(), rhs.getContentId()) .append(lhs.getContentType(), rhs.getContentType()) .append(lhs.getDispositionType(), rhs.getDispositionType()) .append(lhs.getName(), rhs.getName()) .append(lhs.getTransferEncoding(), rhs.getTransferEncoding()) .isEquals()) { return false; } switch (lhs.getClass().getSimpleName()) { case "ByteArrayPart": if (!Arrays.equals(((ByteArrayPart) lhs).getBytes(), ((ByteArrayPart) rhs).getBytes())) { return false; } break; case "FilePart": if (!((FilePart) lhs).getFile().equals(((FilePart) rhs).getFile())) { return false; } break; case "StringPart": if (!((StringPart) lhs).getValue().equals(((StringPart) rhs).getValue())) { return false; } break; default: return false; } } return true; }
ParsecEqualsUtil { static boolean partEquals(final Part lhs, final Part rhs) { if (!lhs.equals(rhs)) { if (lhs.getClass() != rhs.getClass()) { return false; } if (!new EqualsBuilder() .append(lhs.getCharset(), rhs.getCharset()) .append(lhs.getContentId(), rhs.getContentId()) .append(lhs.getContentType(), rhs.getContentType()) .append(lhs.getDispositionType(), rhs.getDispositionType()) .append(lhs.getName(), rhs.getName()) .append(lhs.getTransferEncoding(), rhs.getTransferEncoding()) .isEquals()) { return false; } switch (lhs.getClass().getSimpleName()) { case "ByteArrayPart": if (!Arrays.equals(((ByteArrayPart) lhs).getBytes(), ((ByteArrayPart) rhs).getBytes())) { return false; } break; case "FilePart": if (!((FilePart) lhs).getFile().equals(((FilePart) rhs).getFile())) { return false; } break; case "StringPart": if (!((StringPart) lhs).getValue().equals(((StringPart) rhs).getValue())) { return false; } break; default: return false; } } return true; } }
ParsecEqualsUtil { static boolean partEquals(final Part lhs, final Part rhs) { if (!lhs.equals(rhs)) { if (lhs.getClass() != rhs.getClass()) { return false; } if (!new EqualsBuilder() .append(lhs.getCharset(), rhs.getCharset()) .append(lhs.getContentId(), rhs.getContentId()) .append(lhs.getContentType(), rhs.getContentType()) .append(lhs.getDispositionType(), rhs.getDispositionType()) .append(lhs.getName(), rhs.getName()) .append(lhs.getTransferEncoding(), rhs.getTransferEncoding()) .isEquals()) { return false; } switch (lhs.getClass().getSimpleName()) { case "ByteArrayPart": if (!Arrays.equals(((ByteArrayPart) lhs).getBytes(), ((ByteArrayPart) rhs).getBytes())) { return false; } break; case "FilePart": if (!((FilePart) lhs).getFile().equals(((FilePart) rhs).getFile())) { return false; } break; case "StringPart": if (!((StringPart) lhs).getValue().equals(((StringPart) rhs).getValue())) { return false; } break; default: return false; } } return true; } private  ParsecEqualsUtil(); }
ParsecEqualsUtil { static boolean partEquals(final Part lhs, final Part rhs) { if (!lhs.equals(rhs)) { if (lhs.getClass() != rhs.getClass()) { return false; } if (!new EqualsBuilder() .append(lhs.getCharset(), rhs.getCharset()) .append(lhs.getContentId(), rhs.getContentId()) .append(lhs.getContentType(), rhs.getContentType()) .append(lhs.getDispositionType(), rhs.getDispositionType()) .append(lhs.getName(), rhs.getName()) .append(lhs.getTransferEncoding(), rhs.getTransferEncoding()) .isEquals()) { return false; } switch (lhs.getClass().getSimpleName()) { case "ByteArrayPart": if (!Arrays.equals(((ByteArrayPart) lhs).getBytes(), ((ByteArrayPart) rhs).getBytes())) { return false; } break; case "FilePart": if (!((FilePart) lhs).getFile().equals(((FilePart) rhs).getFile())) { return false; } break; case "StringPart": if (!((StringPart) lhs).getValue().equals(((StringPart) rhs).getValue())) { return false; } break; default: return false; } } return true; } private  ParsecEqualsUtil();  }
ParsecEqualsUtil { static boolean partEquals(final Part lhs, final Part rhs) { if (!lhs.equals(rhs)) { if (lhs.getClass() != rhs.getClass()) { return false; } if (!new EqualsBuilder() .append(lhs.getCharset(), rhs.getCharset()) .append(lhs.getContentId(), rhs.getContentId()) .append(lhs.getContentType(), rhs.getContentType()) .append(lhs.getDispositionType(), rhs.getDispositionType()) .append(lhs.getName(), rhs.getName()) .append(lhs.getTransferEncoding(), rhs.getTransferEncoding()) .isEquals()) { return false; } switch (lhs.getClass().getSimpleName()) { case "ByteArrayPart": if (!Arrays.equals(((ByteArrayPart) lhs).getBytes(), ((ByteArrayPart) rhs).getBytes())) { return false; } break; case "FilePart": if (!((FilePart) lhs).getFile().equals(((FilePart) rhs).getFile())) { return false; } break; case "StringPart": if (!((StringPart) lhs).getValue().equals(((StringPart) rhs).getValue())) { return false; } break; default: return false; } } return true; } private  ParsecEqualsUtil();   }