fail();
}
}
+
+ @Test
+ public void testParentAttribute() {
+ String[] path = { "CPUs/0/Current_thread",
+ "CPUs/0",
+ "CPUs" };
+ try {
+ int q = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+ for (int i = 0; i < path.length; i++) {
+ String name = ssq.getFullAttributePath(q);
+ assertEquals(path[i], name);
+ q = ssq.getParentAttributeQuark(q);
+ }
+ assertEquals(-1, q);
+ q = ssq.getParentAttributeQuark(q);
+ assertEquals(-1, q);
+ } catch (AttributeNotFoundException e) {
+ fail();
+ }
+ }
+
}
return targetNode.getQuark();
}
+ /**
+ * Get the parent attribute of this attribute
+ *
+ * @return The parent attribute
+ */
+ public Attribute getParentAttribute() {
+ return this.parent;
+ }
+
+ /**
+ * Get the parent quark of this attribute
+ *
+ * @return The quark of the parent attribute
+ */
+ public int getParentAttributeQuark() {
+ return this.parent.getQuark();
+ }
+
/* The methods how to access children are left to derived classes */
/**
return listOfChildren;
}
+ /**
+ * Returns the parent quark of the attribute. The root attribute has no
+ * parent and will return <code>-1</code>
+ *
+ * @param quark
+ * The quark of the attribute
+ * @return Quark of the parent attribute or <code>-1</code> for the root
+ * attribute
+ */
+ public int getParentAttributeQuark(int quark) {
+ if (quark == -1) {
+ return quark;
+ }
+ return attributeList.get(quark).getParentAttributeQuark();
+ }
+
private void addSubAttributes(List<Integer> list, Attribute curAttribute,
boolean recursive) {
for (Attribute childNode : curAttribute.getSubAttributes()) {
return ret;
}
+ @Override
+ public int getParentAttributeQuark(int quark) {
+ return getAttributeTree().getParentAttributeQuark(quark);
+ }
+
@Override
public List<Integer> getQuarks(String... pattern) {
List<Integer> quarks = new LinkedList<>();
*/
String getFullAttributePath(int attributeQuark);
+ /**
+ * Returns the parent quark of the attribute.
+ *
+ * @param attributeQuark
+ * The quark of the attribute
+ * @return Quark of the parent attribute or <code>-1</code> if root quark or
+ * no parent.
+ * @since 3.0
+ */
+ int getParentAttributeQuark(int attributeQuark);
+
/**
* @name Query methods
*/