public class Relation<K, V> implements Freezable<Relation<K,V>> { // TODO: add , Map<K, Collection<V>>, but requires API changes
private Map<K, Set<V>> data;
- Constructor<Set<V>> setCreator;
+ Constructor<? extends Set<V>> setCreator;
Object[] setComparatorParam;
- public static <K,V> Relation<K, V> of(Map<K, Set<V>> map, Class<?> setCreator) {
- return new Relation(map, setCreator);
+ public static <K, V> Relation<K, V> of(Map<K, Set<V>> map, Class<?> setCreator) {
+ return new Relation<K, V>(map, setCreator);
}
- public static <K,V> Relation<K, V> of(Map<K, Set<V>> map, Class setCreator, Comparator<V> setComparator) {
- return new Relation(map, setCreator, setComparator);
+ public static <K,V> Relation<K, V> of(Map<K, Set<V>> map, Class<?> setCreator, Comparator<V> setComparator) {
+ return new Relation<K, V>(map, setCreator, setComparator);
}
- public Relation(Map<K, Set<V>> map, Class<Set<V>> setCreator) {
+ public Relation(Map<K, Set<V>> map, Class<?> setCreator) {
this(map, setCreator, null);
}
- public Relation(Map<K, Set<V>> map, Class<Set<V>> setCreator, Comparator<V> setComparator) {
+ @SuppressWarnings("unchecked")
+ public Relation(Map<K, Set<V>> map, Class<?> setCreator, Comparator<V> setComparator) {
try {
setComparatorParam = setComparator == null ? null : new Object[]{setComparator};
if (setComparator == null) {
- this.setCreator = setCreator.getConstructor();
+ this.setCreator = ((Class<? extends Set<V>>)setCreator).getConstructor();
this.setCreator.newInstance(setComparatorParam); // check to make sure compiles
} else {
- this.setCreator = setCreator.getConstructor(Comparator.class);
+ this.setCreator = ((Class<? extends Set<V>>)setCreator).getConstructor(Comparator.class);
this.setCreator.newInstance(setComparatorParam); // check to make sure compiles
}
- data = map == null ? new HashMap() : map;
+ data = map == null ? new HashMap<K, Set<V>>() : map;
} catch (Exception e) {
throw (RuntimeException) new IllegalArgumentException("Can't create new set").initCause(e);
}
}
public Set<Entry<K, V>> keyValueSet() {
- Set<Entry<K, V>> result = new LinkedHashSet();
+ Set<Entry<K, V>> result = new LinkedHashSet<Entry<K, V>>();
for (K key : data.keySet()) {
for (V value : data.get(key)) {
- result.add(new SimpleEntry(key, value));
+ result.add(new SimpleEntry<K, V>(key, value));
}
}
return result;
return false;
if (o.getClass() != this.getClass())
return false;
- return data.equals(((Relation) o).data);
+ return data.equals(((Relation<?, ?>) o).data);
}
// public V get(Object key) {
}
public Set<V> values() {
- return values(new LinkedHashSet());
+ return values(new LinkedHashSet<V>());
}
public <C extends Collection<V>> C values(C result) {
}
public Set<V> removeAll(Collection<K> toBeRemoved) {
- Set<V> result = new LinkedHashSet();
+ Set<V> result = new LinkedHashSet<V>();
for (K key : toBeRemoved) {
try {
final Set<V> removals = data.remove(key);
import com.sun.javadoc.Doc;
import com.sun.javadoc.Tag;
-import com.sun.tools.doclets.formats.html.markup.RawHtml;
-import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.taglets.Taglet;
+import com.sun.tools.doclets.internal.toolkit.taglets.TagletOutput;
import com.sun.tools.doclets.internal.toolkit.taglets.TagletWriter;
/**
* The ICUTagletAdapter class is the abstract base class that adapts the ICUTaglet class to different implementations of the JavaDoc API.
* The methods in this class are meant to minimize the dual maintenance nature of supporting multiple JavaDoc APIs.
*
- * This adapter supports the v8 JavaDoc API
+ * This adapter supports the v7 and earlier JavaDoc API
*/
public abstract class ICUTagletAdapter implements Taglet {
-
+
public abstract String toString(Tag tag);
public abstract String toString(Tag[] tags);
- public Content getTagletOutput(Tag tag, TagletWriter writer)
- throws IllegalArgumentException {
-
- // addContext doesn't except nulls so filter them out
- String encodedText = toString(tag);
- if(encodedText == null) return null;
-
- Content out = writer.getOutputInstance();
- out.addContent(new RawHtml(encodedText));
-
- return out;
- }
-
- public Content getTagletOutput(Doc holder, TagletWriter writer)
- throws IllegalArgumentException {
-
- Content out = writer.getOutputInstance();
- Tag[] tags = holder.tags(getName());
- if (tags.length == 0) {
- return null;
+ public TagletOutput getTagletOutput(Tag tag, TagletWriter writer)
+ throws IllegalArgumentException {
+
+ TagletOutput out = writer.getTagletOutputInstance();
+ out.setOutput(toString(tag));
+ return out;
}
- // addContext doesn't except nulls so filter them out
- String encodedText = toString(tags[0]);
- if(encodedText == null) return null;
+ public TagletOutput getTagletOutput(Doc holder, TagletWriter writer)
+ throws IllegalArgumentException {
- out.addContent(new RawHtml(encodedText));
- return out;
- }
+ TagletOutput out = writer.getTagletOutputInstance();
+ Tag[] tags = holder.tags(getName());
+ if (tags.length == 0) {
+ return null;
+ }
+ out.setOutput(toString(tags[0]));
+ return out;
+ }
}