/** * If the {@link Attribute} is unique, this method retrieves the Thing that possesses it. * * @return The Thing which is connected to a unique {@link Attribute}. */ @CheckReturnValue @Nullable default Thing owner() { Iterator<Thing> owners = owners().iterator(); if(owners.hasNext()) { return owners.next(); } else { return null; } }
/** * Check if the given {@link Attribute} conforms to the has syntax and structural requirements * @param attribute {@link Attribute} to check * @return true if the {@link Attribute} is target of has relation */ private static boolean isHasResourceResource(Attribute attribute){ AttributeType attributeType = attribute.type(); // TODO: Make sure this is tested boolean plays = attributeType.playing().map(Role::label) .allMatch(c -> c.equals(HAS_VALUE.getLabel(attributeType.label()))); return attribute.owners().findAny().isPresent() && plays; } }