Java Code Examples for javax.management.openmbean.CompositeType#keySet()

The following examples show how to use javax.management.openmbean.CompositeType#keySet() . 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: LazyCompositeData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code 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;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 2
Source File: LazyCompositeData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code 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;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 3
Source File: LazyCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code 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;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 4
Source File: LegacyTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testJsonObjectInComplexValue() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT);
    ModelNode complexValueType = new ModelNode();
    complexValueType.get("value", DESCRIPTION).set("A  value");
    complexValueType.get("value", TYPE).set(ModelType.OBJECT);
    description.get(VALUE_TYPE).set(complexValueType);

    TypeConverter converter = getConverter(description);

    CompositeType type = assertCast(CompositeType.class, converter.getOpenType());
    Set<String> keys = type.keySet();
    Assert.assertEquals(1, keys.size());

    Assert.assertEquals(SimpleType.STRING, type.getType("value"));

    ModelNode node = new ModelNode();
    node.get("value", "long").set(1L);
    node.get("value", "string").set("test");

    CompositeData data = assertCast(CompositeData.class, converter.fromModelNode(node));
    Assert.assertEquals(type, data.getCompositeType());
    Assert.assertEquals(ModelNode.fromJSONString(node.toJSONString(false)), converter.toModelNode(data));

}
 
Example 5
Source File: TypeConverters.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Object fromModelNode(ModelNode node) {
    if (node == null || !node.isDefined()) {
        return null;
    }

    final OpenType<?> openType = getOpenType();
    if (openType instanceof CompositeType) {
        final CompositeType compositeType = (CompositeType)openType;
        //Create a composite
        final Map<String, Object> items = new HashMap<String, Object>();
        for (String attrName : compositeType.keySet()) {
            TypeConverter converter = getConverter(typeNode.get(attrName, TYPE), typeNode.get(attrName, VALUE_TYPE));
            items.put(attrName, converter.fromModelNode(node.get(attrName)));
        }

        try {
            return new CompositeDataSupport(compositeType, items);
        } catch (OpenDataException e) {
            throw new RuntimeException(e);
        }
    } else {
        return node.toJSONString(false);
    }
}
 
Example 6
Source File: LazyCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code 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;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 7
Source File: LazyCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code 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;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 8
Source File: LazyCompositeData.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code 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;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example 9
Source File: LazyCompositeData.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 10
Source File: LazyCompositeData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 11
Source File: LazyCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 12
Source File: AttributeHelper.java    From cuba with Apache License 2.0 5 votes vote down vote up
private static String compositeToString(CompositeData compositeData) {
    if (canConvertToTrueObject(compositeData)) {
        try {
            Object trueObject = convertToTrueObject(compositeData);
            return String.valueOf(trueObject);
        }
        catch (Exception e) {
            return e.getClass().getName() + " " + e.getMessage();
        }
    }

    CompositeType type = compositeData.getCompositeType();

    StringBuilder b = new StringBuilder();
    b.append("[");
    List<String> keys = new ArrayList<>(type.keySet());
    Collections.sort(keys); // alphabetically
    for (String key: keys) {
        b.append(key).append(": ");
        Object value = compositeData.get(key);
        b.append(convertToString(value));
        if (keys.indexOf(key) != keys.size() - 1) {
            b.append(", ");
        }
    }
    b.append("]\n");
    return b.toString();
}
 
Example 13
Source File: LazyCompositeData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 14
Source File: JMXJsonServlet.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
Example 15
Source File: LazyCompositeData.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 16
Source File: TypeVersionMapper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the specified version of a {@linkplain CompositeType} instance.
 * @param type The current (latest) version of {@linkplain CompositeType}
 * @param version The version identifier (eg. {@linkplain TypeVersionMapper#V5})
 * @return Returns the {@linkplain CompositeType} corresponding to the requested
 *         version.
 * @throws OpenDataException
 */
CompositeType getVersionedCompositeType(CompositeType type, String version)
    throws OpenDataException
{
    Predicate<String> filter = getFilter(type.getTypeName(), version);
    if (filter == null) {
        return type;
    }

    List<String> itemNames = new ArrayList<>();
    List<String> itemDesc = new ArrayList<>();
    List<OpenType<?>> itemTypes = new ArrayList<>();

    for(String item : type.keySet()) {
        if (filter.test(item)) {
            itemNames.add(item);
            itemDesc.add(type.getDescription(item));
            itemTypes.add(getVersionedType(
                type.getType(item),
                version
            ));
        }
    }
    return new CompositeType(
        type.getTypeName(),
        version != null ? version + " " + type.getDescription() : type.getDescription(),
        itemNames.toArray(new String[itemNames.size()]),
        itemDesc.toArray(new String[itemDesc.size()]),
        itemTypes.toArray(new OpenType<?>[itemTypes.size()])
    );
}
 
Example 17
Source File: LazyCompositeData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 18
Source File: ModelControllerMBeanTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void checkComplexTypeInfo(CompositeType composite, boolean expressions, String prefix) {
    Set<String> keys = composite.keySet();
    Assert.assertEquals(2, keys.size());
    assertCompositeType(composite, "int-value", expressions ? String.class.getName() : Integer.class.getName(), (prefix != null ? prefix : "") + "int-value");
    assertCompositeType(composite, "bigdecimal-value", expressions ? String.class.getName() : BigDecimal.class.getName(), (prefix != null ? prefix : "") + "bigdecimal-value");
}
 
Example 19
Source File: SdcInfoContentGenerator.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      if (value instanceof Double && (((Double) value).isInfinite() || ((Double) value).isNaN())) {
        jg.writeString(n.toString());
      } else {
        jg.writeNumber(n.toString());
      }
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else if (value instanceof GaugeValue) {
      ((GaugeValue)value).serialize(jg);
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
Example 20
Source File: JSONBean.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static void writeObject(JsonWriter writer, Object value) throws IOException {
  if (value == null) {
    writer.nullValue();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      writer.beginArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(writer, item);
      }
      writer.endArray();
    } else if (value instanceof Number) {
      Number n = (Number) value;
      if (Double.isFinite(n.doubleValue())) {
        writer.value(n);
      } else {
        writer.value(n.toString());
      }
    } else if (value instanceof Boolean) {
      Boolean b = (Boolean) value;
      writer.value(b);
    } else if (value instanceof CompositeData) {
      CompositeData cds = (CompositeData) value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      writer.beginObject();
      for (String key : keys) {
        writeAttribute(writer, key, null, cds.get(key));
      }
      writer.endObject();
    } else if (value instanceof TabularData) {
      TabularData tds = (TabularData) value;
      writer.beginArray();
      for (Object entry : tds.values()) {
        writeObject(writer, entry);
      }
      writer.endArray();
    } else {
      writer.value(value.toString());
    }
  }
}