Java Code Examples for javax.management.openmbean.CompositeType.getType()

The following are Jave code examples for showing how to use getType() of the javax.management.openmbean.CompositeType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OpenJSharp   File: LazyCompositeData.java   Source Code and License Vote up 5 votes
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 */
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
    if (type1 == type2) return true;

    // We can't use CompositeType.isValue() since it returns false
    // if the type name doesn't match.
    Set<String> allItems = type1.keySet();

    // Check all items in the type1 exist in type2
    if (!type2.keySet().containsAll(allItems))
        return false;

    for (String item: allItems) {
        OpenType<?> ot1 = type1.getType(item);
        OpenType<?> ot2 = type2.getType(item);
        if (ot1 instanceof CompositeType) {
            if (! (ot2 instanceof CompositeType))
                return false;
            if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
                return false;
        } else if (ot1 instanceof TabularType) {
            if (! (ot2 instanceof TabularType))
                return false;
            if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
                return false;
        } else if (!ot1.equals(ot2)) {
            return false;
        }
    }
    return true;
}
 
Example 2
Project: openjdk-jdk10   File: VMOptionOpenDataTest.java   Source Code and License Vote up 5 votes
private static void validateType(CompositeData data) {
    CompositeType type = data.getCompositeType();
    Set<String> keys = Arrays.stream(names).collect(Collectors.toSet());
    if (!type.keySet().equals(keys)) {
        throw new RuntimeException("key not matched: " + type.keySet().toString());
    }
    for (int i=0; i < names.length; i++) {
        OpenType t = type.getType(names[i]);
        if (t != types[i]) {
            throw new AssertionError(names[i] + ": type not matched: " +
                t + " expected: " + types[i]);
        }
    }
}