/** * PUBLIC: Grabs the name for display. The name returned is the * first display (variant) name found, when the basenames of the * give topic have been sorted using the comparator. If there is no * display name, then the last base name found is returned, * corresponding to the least constrained scope. * * @param object The topic whose name is being grabbed; formally an object. * @return A name to display; an object implementing TopicNameIF or * VariantNameIF, null if the topic has no basenames. * @exception Throws OntopiaRuntimeException if object is not a topic. */ @Override public NameIF grab(TopicIF object) { return subGrabber.grab(object); }
@Override public G next() { return grabber.grab(iter.next()); }
@Override public G grab(O object) { if (object == null) return null; if (cache.containsKey(object)) return cache.get(object); G grabbed = grabber.grab(object); cache.put(object, grabbed); return grabbed; }
@Override public boolean ok(T object) { return decider.ok(grabber.grab(object)); }
@Override public String toString(T object) { return stringifier.toString(grabber.grab(object)); }
/** * Returns a string representation of the type property of the typed * object. * * @param typed An object implementing TypedIF. * @return The string that results from applying the configured * stringifier to the type extracted from the typed object. */ @Override public String toString(T typed) { TopicIF type = grabber.grab(typed); return topic_stringifier.toString(type); }
/** * Refreshes the map by looping over the nested collection * and regrabbing keys and values. Any changes done to the previous * collection will be lost. */ @Override public void refresh() { if (grabbed_map == null) grabbed_map = new HashMap<KG, Collection<VG>>(); else grabbed_map.clear(); // Loop over all objects in the collection Iterator<O> iter = coll.iterator(); while (iter.hasNext()) { O object = iter.next(); KG grabbed_key = key_grabber.grab(object); VG grabbed_value = value_grabber.grab(object); if (!grabbed_map.containsKey(grabbed_key)) grabbed_map.put(grabbed_key, new HashSet<VG>()); grabbed_map.get(grabbed_key).add(grabbed_value); } grabbed = true; }
/** * Refreshes the collection by looping over the nested collection * and regrabbing its items. Any changes done to the previous * collection will be lost. */ @Override public void refresh() { grabbed_coll = new ArrayList<G>(); Iterator<O> iter = coll.iterator(); while (iter.hasNext()) { G grabbed = grabber.grab(iter.next()); // Add grabbed to the grabbed collection if accepted by the decider if (decider == null || decider.ok(grabbed)) grabbed_coll.add(grabbed); } grabbed = true; }
/** * implementing method which is required for Comparator interface. */ @Override public int compare(TopicIF o1, TopicIF o2) { // this method is time-critical, since it is called n*log(n) times // for every list of topics. could probably do more to make it // faster. if (o1 == null) return 1; if (o2 == null) return -1; String n1 = nameStringifier.toString(nameGrabber.grab(o1)); String n2 = nameStringifier.toString(nameGrabber.grab(o2)); if (n1 == null) return 1; if (n2 == null) return -1; return n1.compareToIgnoreCase(n2); }
obj = iter.next(); if (obj instanceof TopicIF) { Object name = nameGrabber.grab(obj); if (name != null) names.add(name);
public void testNameGrabber5A() { List basenameScope = new ArrayList(); basenameScope.add(topicPlay); List variantScope = new ArrayList(); variantScope.add(topicSort); GrabberIF grabber = new NameGrabber(basenameScope, variantScope); assertTrue("wrong base name grabbed", ((TopicNameIF) grabber.grab(topic5)).equals(basename5A)); }
public void testNameGrabber5C() { List variantScope = new ArrayList(); variantScope.add(topicSort); GrabberIF grabber = new NameGrabber(Collections.EMPTY_LIST, variantScope); assertTrue("wrong base name grabbed", ((TopicNameIF) grabber.grab(topic5)).equals(basename5A)); } }
@Override public int compare(TopicIF o1, TopicIF o2) { if (o1 == null) return 1; if (o2 == null) return -1; String n1 = nameStringifier.toString(nameGrabber.grab(o1)); if (n1 == null) return 1; // prefix if (metadataDecider.ok(o1)) { n1 = "META" + n1; } else { if (descriptionDecider.ok(o1)) n1 = "ZZZDESC" + n1; } String n2 = nameStringifier.toString(nameGrabber.grab(o2)); if (n2 == null) return -1; // prefix if (metadataDecider.ok(o2)) { n2 = "META" + n2; } else { if (descriptionDecider.ok(o2)) n2 = "ZZZDESC" + n2; } return n1.compareToIgnoreCase(n2); }
public void testNameGrabber5B() { GrabberIF grabber = new NameGrabber(Collections.EMPTY_LIST); assertTrue("wrong base name grabbed", ((TopicNameIF) grabber.grab(topic5)).equals(basename5B)); }
public void testCachedGrabber() { CachedGrabber grb = new CachedGrabber(new SubstringGrabber(5, 15)); String str = "Jazz is not dead, it just smells funny!"; testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); str.replace(' ', '-'); testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); grb.refresh(); testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); str.replace('-', '_'); testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); grb.setGrabber(new UpperCaseGrabber()); testGrabber(grb.grab(str), grb.grab(str), grb.getGrabber().grab(str)); grb.refresh(); testGrabber(grb.grab(str), grb.getGrabber().grab(str), grb.getGrabber().grab(str.substring(2))); }