/** return _true_ iff this polymorphic object supports the specified interface. Synonymous with "does the argument class have this as an instance". Actually it shouldn't be. Review. */ public <X extends T> boolean supports( Class<X> t ) { X supporter = findExistingView( t ); return supporter != null || this.canSupport( t ); }
/** * Answer a polymorphic object that presents <i>this</i> in a way which satisfies type * t. * @param t A type * @return A polymorphic instance, possibly but not necessarily this, that conforms to t. */ protected final <X extends T> X asInternal( Class<X> t ) { X other = findExistingView( t ); return other == null ? this.convertTo( t ) : other; }
/** Answer true iff this polymorphic object already has a valid view of type <code>t</code> in its ring (so .as()ing it doesn't need to construct a new object). */ protected <X extends T> boolean alreadyHasView( Class<X> t ) { return findExistingView( t ) != null; }
/** find an existing view in the ring which is an instance of _t_ and return it; otherwise return null. If _this_ is an instance, the search takes care to find it first. */ private <X extends T> X findExistingView( Class<X> t ) { Polymorphic<T> r = this; for (;;) { if (t.isInstance( r ) && r.isValid()) return t.cast( r ); r = r.ring; if (r == this) return null; } }
/** Answer true iff this polymorphic object already has a valid view of type <code>t</code> in its ring (so .as()ing it doesn't need to construct a new object). */ protected <X extends T> boolean alreadyHasView( Class<X> t ) { return findExistingView( t ) != null; }
/** find an existing view in the ring which is an instance of _t_ and return it; otherwise return null. If _this_ is an instance, the search takes care to find it first. */ private <X extends T> X findExistingView( Class<X> t ) { Polymorphic<T> r = this; for (;;) { if (t.isInstance( r ) && r.isValid()) return t.cast( r ); r = r.ring; if (r == this) return null; } }
/** * Answer a polymorphic object that presents <i>this</i> in a way which satisfies type * t. * @param t A type * @return A polymorphic instance, possibly but not necessarily this, that conforms to t. */ protected final <X extends T> X asInternal( Class<X> t ) { X other = findExistingView( t ); return other == null ? this.convertTo( t ) : other; }
/** return _true_ iff this polymorphic object supports the specified interface. Synonymous with "does the argument class have this as an instance". Actually it shouldn't be. Review. */ public <X extends T> boolean supports( Class<X> t ) { X supporter = findExistingView( t ); return supporter != null || this.canSupport( t ); }