Java Code Examples for java.util.Hashtable.equals()

The following are Jave code examples for showing how to use equals() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: SimpleSerialization.java   View Source Code Vote up 5 votes
public static void main(final String[] args) throws Exception {
    Hashtable<String, String> h1 = new Hashtable<>();

    System.err.println("*** BEGIN TEST ***");

    h1.put("key", "value");

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
        oos.writeObject(h1);
    }

    final byte[] data = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(data);
    final Object deserializedObject;
    try (ObjectInputStream ois = new ObjectInputStream(bais)) {
        deserializedObject = ois.readObject();
    }

    if(!h1.getClass().isInstance(deserializedObject)) {
         throw new RuntimeException("Result not assignable to type of h1");
    }

    if (false == h1.equals(deserializedObject)) {
         Hashtable<String, String> d1 = (Hashtable<String, String>) h1;
        for(Map.Entry entry: h1.entrySet()) {
            System.err.println("h1.key::" + entry.getKey() + " d1.containsKey()::" + d1.containsKey((String) entry.getKey()));
            System.err.println("h1.value::" + entry.getValue() + " d1.contains()::" + d1.contains(entry.getValue()));
            System.err.println("h1.value == d1.value " + entry.getValue().equals(d1.get((String) entry.getKey())));
        }

        throw new RuntimeException(getFailureText(h1, deserializedObject));
    }
}
 
Example 2
Project: openjdk-jdk10   File: SimpleSerialization.java   View Source Code Vote up 5 votes
public static void main(final String[] args) throws Exception {
    Hashtable<String, String> h1 = new Hashtable<>();

    System.err.println("*** BEGIN TEST ***");

    h1.put("key", "value");

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
        oos.writeObject(h1);
    }

    final byte[] data = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(data);
    final Object deserializedObject;
    try (ObjectInputStream ois = new ObjectInputStream(bais)) {
        deserializedObject = ois.readObject();
    }

    if(!h1.getClass().isInstance(deserializedObject)) {
         throw new RuntimeException("Result not assignable to type of h1");
    }

    if (false == h1.equals(deserializedObject)) {
         Hashtable<String, String> d1 = (Hashtable<String, String>) h1;
        for(Map.Entry entry: h1.entrySet()) {
            System.err.println("h1.key::" + entry.getKey() + " d1.containsKey()::" + d1.containsKey((String) entry.getKey()));
            System.err.println("h1.value::" + entry.getValue() + " d1.contains()::" + d1.contains(entry.getValue()));
            System.err.println("h1.value == d1.value " + entry.getValue().equals(d1.get((String) entry.getKey())));
        }

        throw new RuntimeException(getFailureText(h1, deserializedObject));
    }
}