Example usage for javax.management.openmbean TabularData keySet

List of usage examples for javax.management.openmbean TabularData keySet

Introduction

In this page you can find the example usage for javax.management.openmbean TabularData keySet.

Prototype

public Set<?> keySet();

Source Link

Document

Returns a set view of the keys (ie the index values) of the CompositeData values (ie the rows) contained in this TabularData instance.

Usage

From source file:com.proofpoint.jmx.JmxHttpModule.java

@SuppressWarnings("unchecked")
private static List<Map<String, Object>> toList(TabularData data) {
    ImmutableList.Builder<Map<String, Object>> builder = ImmutableList.builder();

    // never trust JMX to do the right thing
    Set<List<?>> keySet = (Set<List<?>>) data.keySet();
    if (keySet != null) {
        for (List<?> key : keySet) {
            if (key != null && !key.isEmpty()) {
                Object[] index = key.toArray(new Object[key.size()]);
                CompositeData value = data.get(index);
                if (value != null) {
                    builder.add(toMap(value));
                }/*from   w w w .  j a v  a 2  s  .c  o  m*/
            }
        }
    }
    return builder.build();
}

From source file:org.jolokia.converter.object.StringToOpenTypeConverterTest.java

@Test
public void tabularTypeInFullRepresentation() throws OpenDataException, MalformedObjectNameException {
    TabularType type = getSampleTabularTypeForComplexTabularData();
    String json = "{ \"indexNames\" : [ \"user\", \"street\" ], " + "  \"values\" : [ "
            + "      { \"user\" : { \"name\" : \"roland\", \"age\" : 44 }, "
            + "        \"street\" : \"homestreet\", " + "        \"oname\" : \"java.lang:type=Memory\" "
            + "      }]" + "}";
    TabularData data = (TabularData) converter.convertToObject(type, json);
    assertNotNull(data);//from  w ww . j  a  v  a  2 s.c  om
    Set keySet = data.keySet();
    assertEquals(keySet.size(), 1);
    List keys = (List) keySet.iterator().next();
    assertEquals(keys.size(), 2);
    assertTrue(keys.contains("homestreet"));
    CompositeData cd = checkCompositeKey(keys);
    CompositeData row = data.get(new Object[] { cd, "homestreet" });
    assertEquals(row.get("user"), cd);
    assertEquals(row.get("street"), "homestreet");
    assertEquals(row.get("oname"), new ObjectName("java.lang:type=Memory"));
}