/** * INTERNAL: Grabs the topic which is the type of the given typedIF * * @param typed the given object; internally typecast to TypedIF * @return object which is the type; an object implementing TopicIF */ @Override public TopicIF grab(T typed) { return typed.getType(); }
/** * INTERNAL: Compares the given typedIF objects using the * comparator given to the constructor * * @param obj1 an object; typecast to TypedIF by the grabber * @param obj2 an object; typecast to TypedIF by the grabber * @return int; result from the comparator given to the constructor, when it compares the * types of the given objects */ @Override public int compare(TypedIF obj1, TypedIF obj2) { //! return subcomparator.compare(grabber.grab(obj1), grabber.grab(obj2)); return subcomparator.compare(obj1.getType(), obj2.getType()); }
/** * INTERNAL: Returns true if the TypedIF object is an instance the * given type. */ public static boolean isInstanceOf(TypedIF typed, TopicIF type) { return (type != null && type.equals(typed.getType())); }
@Override public boolean ok(Object object) { if (object instanceof TypedIF) { TypedIF typed = (TypedIF) object; return oktypes.contains(typed.getType()); } return false; } }
protected boolean isInstanceOf(TypedIF object, Collection types) { if (types == null) return true; return types.contains(object.getType()); }
@Override public boolean evaluate(TypedIF typed) { return Objects.equals(typed.getType(), type); } }
/** * INTERNAL: Returns the topic which types the singly typed object * <code>typed</code> and all of its supertypes. * * @param typed a typedIF object * @return a collection of topicIF objects; the type and all * supertypes of the given typedIF object. */ public Collection<TopicIF> getSupertypes(TypedIF typed) { if (typed.getType() == null) return new ArrayList<TopicIF>(); return supertypesWalker.walkTopics(typed.getType()); }
private void writeType(TypedIF obj, ContentHandler dh) throws SAXException { if (obj.getType() == null || ((obj instanceof TopicNameIF) && isDefaultNameType(obj.getType()))) return; dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "type", EMPTY_ATTR_LIST); writeTopicRef(obj.getType(), dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "type"); }
@Override public void processEvent(Object object, String event, T added, T old_value) { // Register type objects.add(added.getType(), added); } }
/** * INTERNAL: Finds first characteristic of a specified type. * * @param objects A collection of TypedIF objects. * @return The first object that has the specified type. * * @since 2.0 */ public static <T extends TypedIF> T getByType(Collection<T> objects, TopicIF type) { Iterator<T> it = objects.iterator(); while (it.hasNext()) { T typed = it.next(); if (type.equals(typed.getType())) return typed; } return null; }
@Override public void processEvent(Object object, String event, T new_value, T removed) { // Unregister type objects.remove(removed.getType(), removed); } }
@Override public boolean ok(Object object) { if (object instanceof TypedIF) { TopicIF type = ((TypedIF) object).getType(); if (type == null) return false; Iterator it = type.getSubjectIdentifiers().iterator(); while (it.hasNext()) if (okpsis.contains(it.next())) return true; } return false; } }
protected static String makeTypedKey(TypedIF typed) { return typed.getType().getObjectId(); }
/** * INTERNAL: Modifies the accumulated collection to also include the * types of the typed objects. */ public static Collection getTypes(Collection typed, Collection accumulated) { // Loop over typed objects Iterator iter = typed.iterator(); while (iter.hasNext()) { Object object = iter.next(); if (object instanceof TypedIF) accumulated.add(((TypedIF)object).getType()); else accumulated.add(((TopicIF)object).getTypes()); } return accumulated; }
protected void writeInstanceOf(TypedIF typed, ContentHandler dh) throws SAXException { TopicIF type = typed.getType(); if (type != null && filterOk(type)) { dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, INSTANCE_OF, EMPTY_ATTR_LIST); writeTopicRef(type, dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, INSTANCE_OF); } }
/** * INTERNAL: Serialize the type for a given typed topic map construct. If the * construct is not typed, nothing will be serialized. * * @param obj the typed topic map construct to be used. */ private void serializeType(TypedIF obj) throws IOException { TopicIF type = obj.getType(); if (type != null) { writer.pair(TYPE, getTopicRef(type)); } }
protected static String makeTypedKey(TypedIF typed, TopicMapIF othertm) { TopicIF othertype = MergeUtils.findTopic(othertm, typed.getType()); return othertype.getObjectId(); }
public void setType(TypedIF typed, Topic type) { if (type == null) { return; } TopicIF resolved = topic.resolve(typed.getTopicMap(), type); if (!typed.getType().equals(resolved)) { typed.setType(resolved); } } }
private void writeType(TypedIF object) { TopicIF topic = object.getType(); if (topic == null) { throw new OntopiaRuntimeException("TypedIF had null type: " + object); } startElement("type", topicRef(topic)); endElement("type"); }
public void testType() { assertTrue("type null initially", typed.getType() != null); TopicIF type = builder.makeTopic(); typed.setType(type); assertTrue("type identity not retained", typed.getType().equals(type)); try { typed.setType(null); fail("type could be set to null"); } catch (NullPointerException e) { } }