List of usage examples for com.google.common.collect SortedSetMultimap keys
Multiset<K> keys();
From source file:org.eclipse.ziggurat.inject.BindingManager.java
@SuppressWarnings("unchecked") public static void registerBindings() { Map<Class, Collection<PriorityClass>> map = new HashMap<Class, Collection<PriorityClass>>(); Supplier<SortedSet<PriorityClass>> factory = new Supplier<SortedSet<PriorityClass>>() { @Override//from w w w .j a v a 2s . c o m public SortedSet<PriorityClass> get() { SortedSet<PriorityClass> sorted = new TreeSet<PriorityClass>(new Comparator<PriorityClass>() { @Override public int compare(PriorityClass o1, PriorityClass o2) { int result = new Integer(o1.priority).compareTo(o2.priority); if (result == 0 && !o1.equals(o2)) { result = -1; } return result; } }); return sorted; } }; SortedSetMultimap<Class, PriorityClass> multi = Multimaps.newSortedSetMultimap(map, factory); IConfigurationElement[] elements = Platform.getExtensionRegistry() .getConfigurationElementsFor(ZigguratInject.PLUGIN_ID, EXT_POINT); for (IConfigurationElement e : elements) { String theInterface = e.getAttribute("interface"); String theImpl = e.getAttribute("impl"); String name = e.getAttribute("name"); Class theInterfaceC = loadClass(e, theInterface); Class theImplC = loadClass(e, theImpl); int priority = 0; String prio = e.getAttribute("priority"); if (prio != null && prio.length() > 0) { try { priority = Integer.parseInt(prio); } catch (NumberFormatException ex) { } } if (theInterfaceC != null && theImplC != null && theInterfaceC.isAssignableFrom(theImplC)) { PriorityClass priorityClass = new PriorityClass(); priorityClass.aClass = theImplC; priorityClass.priority = priority; priorityClass.name = name; multi.put(theInterfaceC, priorityClass); } } for (Class c : multi.keys()) { PriorityClass last = null; // for each priority class if name is present a binding is created with the given name for (PriorityClass pc : multi.get(c)) { if (pc.name != null && pc.name.length() > 0) { InjectorFactory.getDefault().addBinding(c).implementedBy(pc.aClass).named(pc.name); } last = pc; } if (last != null) { // the binding by default is made by a class with no name InjectorFactory.getDefault().addBinding(c).implementedBy(last.aClass); } } }