protected void collectFires(Collection<Object> evAndListeners) { R<?> r = result.get(); if (r != null) { r.collectFires(evAndListeners); } else { removeListeners(); } }
public void resultChanged(LookupEvent ev) { R r = result.get(); if (r != null) { r.resultChanged(ev); } else { removeListeners(); } }
protected void beforeLookup(Lookup.Template t) { R r = result.get(); if (r != null) { r.beforeLookup(t); } else { removeListeners(); } }
/** Clones the reference list to given Storage. * @param storage storage to clone to */ public void cloneList(AbstractLookup.Storage<?> storage) { ReferenceIterator it = new ReferenceIterator(this); while (it.next()) { ReferenceToResult<?> current = it.current(); ReferenceToResult<?> newRef = current.cloneRef(); newRef.next = storage.registerReferenceToResult(newRef); newRef.caches = current.caches; if (current.caches == current) { current.getResult().initItems(storage); } } }
/** Unregisters a template from the has map. */ private final void unregisterTemplate(Template<?> template) { synchronized (ProxyLookup.this) { ImmutableInternalData id = getData(); if (id == null) { return; } setData(id.removeTemplate(this, template), getData().getLookups(false), null, null); } }
@Override protected Collection<? extends Item<T>> allItems(boolean callBeforeLookup) { if (callBeforeLookup) { reference.lookup.beforeLookup(reference.template); } return allItemsWithoutBeforeLookup(); }
public final <T> Result<T> lookup(Lookup.Template<T> template) { synchronized (ProxyLookup.this) { ImmutableInternalData[] res = { null }; R<T> newR = getData().findResult(this, res, template); setData(res[0], getData().getLookups(false), null, null); return newR; } }
protected void beforeLookup(Lookup.Template t) { Lookup.Result r = checkResult(); if (r instanceof WaitableResult) { ((WaitableResult) r).beforeLookup(t); } }
/** Remove instance. * @param inst instance */ public final void remove(Object inst) { removePair(new SimpleItem<Object>(inst)); }
/** Remove instance added with a convertor. * @param inst instance * @param conv convertor, if <code>conv==null</code> it is same like * remove(Object) */ public final <T,R> void remove(T inst, Convertor<T,R> conv) { removePair(new ConvertingItem<T,R>(inst, conv)); }
/** The method to add instance to the lookup with. * @param inst instance */ public final void add(Object inst) { addPair(new SimpleItem<Object>(inst)); }
/** Checks whether item is instance of this node. */ public boolean accepts(AbstractLookup.Pair<?> item) { if (getType() == Object.class) { // Object.class return true; } return item.instanceOf(getType()); }
/** Compares two items. */ @Override public int compare(Pair<?> i1, Pair<?> i2) { int result = i1.getIndex() - i2.getIndex(); if (result == 0) { if (i1 != i2) { throw new DuplicatedPairException(i1, i2); } return 0; } return result; }
private void setInstancesCache(Collection c) { if (isSimple()) { // mark it as being used reference.caches = reference; return; } setReferences(1, c); }
/** Getter for the delegates. * @return the array of lookups we delegate to * @since 1.19 */ protected final Lookup[] getLookups() { synchronized (ProxyLookup.this) { return getData().getLookups(true); } }
/** Creates a weak refernece to a new result R in context of lookup * for given template */ private ReferenceToResult(R<T> result, AbstractLookup lookup, Template<T> template) { super(result, activeQueue()); this.template = template; this.lookup = lookup; getResult().reference = this; }
/** Ok, register listeners to all classes and super classes. */ public synchronized void addLookupListener(LookupListener l) { listeners = modifyListenerList(true, l, listeners); }
/** A change in lookup occured. * @param ev event describing the change * */ public void resultChanged(LookupEvent anEvent) { collectFires(null); }
/** Access to all instances in the result. * @return collection of all instances */ @Override public java.util.Collection<T> allInstances() { return allInstances(true); } @SuppressWarnings("unchecked")
/** Items are stored directly in the allItems. */ @Override public Collection<? extends Item<T>> allItems() { return allItems(true); } @Override