本文整理匯總了Java中javax.management.openmbean.CompositeType.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java CompositeType.getType方法的具體用法?Java CompositeType.getType怎麽用?Java CompositeType.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.openmbean.CompositeType
的用法示例。
在下文中一共展示了CompositeType.getType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isTypeMatched
import javax.management.openmbean.CompositeType; //導入方法依賴的package包/類
/**
* 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;
}
示例2: validateType
import javax.management.openmbean.CompositeType; //導入方法依賴的package包/類
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]);
}
}
}