private String stringify(TopicIF type, TopicIF roleType) { Collection scope = Collections.singleton(roleType); StringifierIF grabber = new GrabberStringifier(new NameGrabber(scope), DEF_NAME_STRINGIFIER); return grabber.toString(type); }
/** * PUBLIC: Gets a stringifier that will return the sort names of * topics, when they have one. If the topics have no sort name, * one of the topic names will be used instead. * * @return StringifierIF; the string this stringifier returns will be a * variant name of its given topic, selected according to the * logic in SortNameGrabber. * @since 1.1 */ public static StringifierIF<TopicIF> getSortNameStringifier() { return new GrabberStringifier<TopicIF, NameIF>(TopicCharacteristicGrabbers.getSortNameGrabber(), new NameStringifier()); }
/** * PUBLIC: Gets a stringifier that will return the topic name it * determines to match the given scope best. There are no guarantees * as to <em>which</em> topic name it will return if more than one * topic name match equally well. * * @param scope collection of TopicIF objects; the given scope * @return stringifierIF; the string this stringifier returns will be a * topic name of its given topic, selected according to the * logic in TopicNameGrabber. */ public static StringifierIF<TopicIF> getTopicNameStringifier(Collection<TopicIF> scope) { return new GrabberStringifier<TopicIF, TopicNameIF>(new TopicNameGrabber(scope), new NameStringifier()); }
/** * Constructor used to make a comparator which will compare * Associations using the context provided. */ public AssociationComparator(Collection<TopicIF> context) { this.scopes = context; if (scopes == null) scopes = Collections.emptyList(); StringifierIF<TopicIF> bts = new GrabberStringifier<TopicIF, TopicNameIF>(new TopicNameGrabber(scopes), new NameStringifier()); tc = new StringifierComparator<TopicIF>(new GrabberStringifier<TopicIF, String>(new GrabberGrabber<TopicIF, String>(new StringifierGrabber<TopicIF>(bts), new UpperCaseGrabber()))); }
/** * PUBLIC: Gets a stringifier that will return * the variant that it determines to match the given scope * best. There are no guarantees as to <em>which</em> variant name * it will return if more than one variant name matches equally well. * * @param scope collection of TopicIF objects; the given scope * @return stringifierIF; the string this stringifier returns will be a * variant name of its given topic, selected according to the * logic in VariantNameGrabber. */ public static StringifierIF<TopicIF> getVariantNameStringifier(Collection<TopicIF> scope) { return new GrabberStringifier<TopicIF, VariantNameIF>(new TopicVariantNameGrabber(scope), new NameStringifier()); }
/** * INTERNAL: initialisation of Stringifier and Comparators */ private void init(TopicMapIF tm, Collection context) { TopicIF display = tm.getTopicBySubjectIdentifier(PSI.getXTMDisplay()); TopicIF sort = tm.getTopicBySubjectIdentifier(PSI.getXTMSort()); // ----- initialisation // for output of theme class topic basename Collection vnc = new ArrayList(context); if (display != null) vnc.add(display); stringifier = new GrabberStringifier(new ContextNameGrabber(context, vnc), new NameStringifier()); // for string sorting use case-insensitive Lexical Comparator lexicalComparator = LexicalComparator.CASE_SENSITIVE; // for topic sorting (themes) vnc = new ArrayList(context); if (sort != null) vnc.add(sort); topicComparator = new TopicComparator(context, vnc); }
/** * PUBLIC: Gets a stringifier that will return the name it * determines matches the given scopes best. There is no guarantee * as to <em>which</em> name it will return if more than one name * matches equally well. * * @param tnscope collection of TopicIF objects; the scope applied to * topic names * @param vnscope collection of TopicIF objects; the scope applied to * variant names * @return the configured stringifier * @since 1.3.2 */ public static StringifierIF<TopicIF> getStringifier(Collection<TopicIF> tnscope, Collection<TopicIF> vnscope) { if (tnscope == null || tnscope.isEmpty()) { if (vnscope == null || vnscope.isEmpty()) return getDefaultStringifier(); else return getVariantNameStringifier(vnscope); } else if (vnscope == null || vnscope.isEmpty()) return getTopicNameStringifier(tnscope); else return new GrabberStringifier<TopicIF, NameIF>(new NameGrabber(tnscope, vnscope, false), new NameStringifier()); }
stringifier = new GrabberStringifier(nameGrabber, nameStringifier); stringifier = new GrabberStringifier(new NameGrabber(basenameScope, variantScope, false), nameStringifier); stringifier = new GrabberStringifier(nameGrabber, nameStringifier); else stringifier = nameStringifier; stringifier = new GrabberStringifier(nameGrabber, nameStringifier); else stringifier = nameStringifier;
public void testStringifierComparator() { UpperCaseGrabber upg = new UpperCaseGrabber(); GrabberStringifier grb = new GrabberStringifier(upg); testComparator(new StringifierComparator(grb).compare(upg.grab("foobar"), "FOOBAR"), 0, 1); }