예제 #1
0
 /**
  * Determines if two Records are identical. This compares the name, type, class, and rdata (with
  * names canonicalized). The TTLs are not compared.
  *
  * @param arg The record to compare to
  * @return true if the records are equal, false otherwise.
  */
 public boolean equals(Object arg) {
   if (arg == null || !(arg instanceof Record)) return false;
   Record r = (Record) arg;
   if (type != r.type || dclass != r.dclass || !name.equals(r.name)) return false;
   byte[] array1 = rdataToWireCanonical();
   byte[] array2 = r.rdataToWireCanonical();
   return Arrays.equals(array1, array2);
 }
예제 #2
0
 @Override
 public boolean equals(Object o) {
   if (o instanceof MethodSignature) {
     MethodSignature ms = (MethodSignature) o;
     return ms.name.equals(name) && Arrays.equals(args, ms.args);
   }
   return false;
 }
 private static boolean eq(Object a, Object b) {
   if (a == b) {
     return true;
   }
   if (a == null) {
     return false;
   }
   if (a.getClass().isArray()) {
     return Arrays.equals((Object[]) a, (Object[]) b);
   }
   return a.equals(b);
 }
예제 #4
0
  private int compare(Revision a, Revision b) {
    if (Arrays.equals(a._id, b._id)) return 0;

    Version va = getVersion(a);
    Version vb = getVersion(b);
    int n = va.compareTo(vb);
    if (n != 0) return n;

    if (a.created != b.created) return a.created > b.created ? 1 : -1;

    for (int i = 0; i < a._id.length; i++)
      if (a._id[i] != b._id[i]) return a._id[i] > b._id[i] ? 1 : -1;

    return 0;
  }
예제 #5
0
  public String verify(JarFile jar, String... algorithms) throws IOException {
    if (algorithms == null || algorithms.length == 0) algorithms = new String[] {"MD5", "SHA"};
    else if (algorithms.length == 1 && algorithms[0].equals("-")) return null;

    try {
      Manifest m = jar.getManifest();
      if (m.getEntries().isEmpty()) return "No name sections";

      for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ) {
        JarEntry je = e.nextElement();
        if (MANIFEST_ENTRY.matcher(je.getName()).matches()) continue;

        Attributes nameSection = m.getAttributes(je.getName());
        if (nameSection == null) return "No name section for " + je.getName();

        for (String algorithm : algorithms) {
          try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            String expected = nameSection.getValue(algorithm + "-Digest");
            if (expected != null) {
              byte digest[] = Base64.decodeBase64(expected);
              copy(jar.getInputStream(je), md);
              if (!Arrays.equals(digest, md.digest()))
                return "Invalid digest for "
                    + je.getName()
                    + ", "
                    + expected
                    + " != "
                    + Base64.encodeBase64(md.digest());
            } else reporter.error("could not find digest for " + algorithm + "-Digest");
          } catch (NoSuchAlgorithmException nsae) {
            return "Missing digest algorithm " + algorithm;
          }
        }
      }
    } catch (Exception e) {
      return "Failed to verify due to exception: " + e.getMessage();
    }
    return null;
  }
 /**
  * Check that the two parameter sets are equal
  *
  * @param params1 first parameter set
  * @param params2 second parameter set
  * @return true if the two parameter sets are equal - all the objects' equals() returns true
  */
 private boolean parametersEqual(Object[] params1, Object[] params2) {
   if (params1 == null) params1 = new Object[0];
   if (params2 == null) params2 = new Object[0];
   return Arrays.equals(params1, params2);
 }
예제 #7
0
  /**
   * Test the converter.
   *
   * @throws URISyntaxException
   */
  public static void testConverter() throws URISyntaxException {
    {
      // Test collections as value
      TestReturnTypes trt = set(TestReturnTypes.class, Arrays.asList(55));
      assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean()));
      assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte()));
      assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort()));
      assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt()));
      assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong()));
      assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat()));
      assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble()));
      assertEquals(Arrays.asList(true), trt.rBooleans());
      assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes());
      assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts());
      assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts());
      assertEquals(Arrays.asList(new Long(55L)), trt.rLongs());
      assertEquals(Arrays.asList(new Float(55F)), trt.rFloats());
      assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles());
      assertEquals(Arrays.asList("55"), trt.rStrings());
      assertEquals(Arrays.asList(new URI("55")), trt.rURIs());

      assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean()));
      assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte()));
      assertTrue(Arrays.equals(new Short[] {55}, trt.raShort()));
      assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt()));
      assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong()));
      assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat()));
      assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble()));
      assertTrue(Arrays.equals(new String[] {"55"}, trt.raString()));
      assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI()));
    }
    {
      // Test primitive arrays as value
      TestReturnTypes trt = set(TestReturnTypes.class, new int[] {55});
      assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean()));
      assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte()));
      assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort()));
      assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt()));
      assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong()));
      assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat()));
      assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble()));
      assertEquals(Arrays.asList(true), trt.rBooleans());
      assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes());
      assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts());
      assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts());
      assertEquals(Arrays.asList(new Long(55L)), trt.rLongs());
      assertEquals(Arrays.asList(new Float(55F)), trt.rFloats());
      assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles());
      assertEquals(Arrays.asList("55"), trt.rStrings());
      assertEquals(Arrays.asList(new URI("55")), trt.rURIs());

      assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean()));
      assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte()));
      assertTrue(Arrays.equals(new Short[] {55}, trt.raShort()));
      assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt()));
      assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong()));
      assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat()));
      assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble()));
      assertTrue(Arrays.equals(new String[] {"55"}, trt.raString()));
      assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI()));
    }

    {
      // Test single value
      TestReturnTypes trt = set(TestReturnTypes.class, 55);
      assertEquals(true, trt.rpBoolean());
      assertEquals(55, trt.rpByte());
      assertEquals(55, trt.rpShort());
      assertEquals(55, trt.rpInt());
      assertEquals(55L, trt.rpLong());
      assertEquals(55.0D, trt.rpDouble());
      assertEquals(55.0F, trt.rpFloat());
      assertEquals((Boolean) true, trt.rBoolean());
      assertEquals(new Byte((byte) 55), trt.rByte());
      assertEquals(new Short((short) 55), trt.rShort());
      assertEquals(Integer.valueOf(55), trt.rInt());
      assertEquals(new Long(55L), trt.rLong());
      assertEquals(new Float(55F), trt.rFloat());
      assertEquals(new Double(55), trt.rDouble());
      assertEquals("55", trt.rString());
      assertEquals(new URI("55"), trt.rURI());
      assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean()));
      assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte()));
      assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort()));
      assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt()));
      assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong()));
      assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat()));
      assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble()));
      assertEquals(Arrays.asList(true), trt.rBooleans());
      assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes());
      assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts());
      assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts());
      assertEquals(Arrays.asList(new Long(55L)), trt.rLongs());
      assertEquals(Arrays.asList(new Float(55F)), trt.rFloats());
      assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles());
      assertEquals(Arrays.asList("55"), trt.rStrings());
      assertEquals(Arrays.asList(new URI("55")), trt.rURIs());

      assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean()));
      assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte()));
      assertTrue(Arrays.equals(new Short[] {55}, trt.raShort()));
      assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt()));
      assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong()));
      assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat()));
      assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble()));
      assertTrue(Arrays.equals(new String[] {"55"}, trt.raString()));
      assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI()));
    }
  }