Java Code Examples for javax.management.ImmutableDescriptor#getFieldValues()

The following examples show how to use javax.management.ImmutableDescriptor#getFieldValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 2
Source File: ImmutableArrayFieldTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 3
Source File: UnionTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 4
Source File: UnionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 5
Source File: UnionTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 6
Source File: ImmutableArrayFieldTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 7
Source File: UnionTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 8
Source File: ImmutableArrayFieldTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 9
Source File: UnionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 10
Source File: ImmutableArrayFieldTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 11
Source File: UnionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 12
Source File: UnionTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 13
Source File: ImmutableArrayFieldTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 14
Source File: ImmutableArrayFieldTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 15
Source File: UnionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 16
Source File: ImmutableArrayFieldTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 17
Source File: UnionTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 18
Source File: ImmutableArrayFieldTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}
 
Example 19
Source File: UnionTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
Example 20
Source File: ImmutableArrayFieldTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean ok = true;
    ImmutableDescriptor d = new ImmutableDescriptor(
            new String[] {
                "strings", "ints", "booleans",
            },
            new Object[] {
                new String[] {"foo"},
                new int[] {5},
                new boolean[] {false},
            });

    String[] strings = (String[]) d.getFieldValue("strings");
    strings[0] = "bar";
    strings = (String[]) d.getFieldValue("strings");
    if (!strings[0].equals("foo")) {
        System.out.println("FAILED: modified string array field");
        ok = false;
    }

    int[] ints = (int[]) d.getFieldValue("ints");
    ints[0] = 0;
    ints = (int[]) d.getFieldValue("ints");
    if (ints[0] != 5) {
        System.out.println("FAILED: modified int array field");
        ok = false;
    }

    boolean[] bools = (boolean[]) d.getFieldValue("booleans");
    bools[0] = true;
    bools = (boolean[]) d.getFieldValue("booleans");
    if (bools[0]) {
        System.out.println("FAILED: modified boolean array field");
        ok = false;
    }

    Object[] values = d.getFieldValues("strings", "ints", "booleans");
    ((String[]) values[0])[0] = "bar";
    ((int[]) values[1])[0] = 0;
    ((boolean[]) values[2])[0] = true;
    values = d.getFieldValues("strings", "ints", "booleans");
    if (!((String[]) values[0])[0].equals("foo") ||
            ((int[]) values[1])[0] != 5 ||
            ((boolean[]) values[2])[0]) {
        System.out.println("FAILED: getFieldValues modifiable: " +
                Arrays.deepToString(values));
    }

    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("Array field values were modifiable");
}