/** * Test if a type system contains the type * * @param typeSystem * the type system * @param type * the type to look for * @return <code>true</code> if the type system provides the type, * <code>false</code> otherwise */ public static boolean hasType ( final TypeSystem typeSystem, final TypeDefinition type ) { final Set<TypeSystem> ctx = new HashSet<> (); return hasType ( ctx, typeSystem, type ); }
/** * Test if a type system contains the type * * @param typeSystem * the type system * @param type * the type to look for * @return <code>true</code> if the type system provides the type, * <code>false</code> otherwise */ public static boolean hasType ( final TypeSystem typeSystem, final TypeDefinition type ) { final Set<TypeSystem> ctx = new HashSet<> (); return hasType ( ctx, typeSystem, type ); }
private static boolean hasType ( final Set<TypeSystem> ctx, final TypeSystem typeSystem, final TypeDefinition type ) { if ( ctx.contains ( typeSystem ) ) { return false; } ctx.add ( typeSystem ); if ( typeSystem.getTypes ().contains ( type ) ) { return true; } for ( final TypeSystem include : typeSystem.getIncludes () ) { if ( hasType ( ctx, include, type ) ) { return true; } } return false; } }
private static boolean hasType ( final Set<TypeSystem> ctx, final TypeSystem typeSystem, final TypeDefinition type ) { if ( ctx.contains ( typeSystem ) ) { return false; } ctx.add ( typeSystem ); if ( typeSystem.getTypes ().contains ( type ) ) { return true; } for ( final TypeSystem include : typeSystem.getIncludes () ) { if ( hasType ( ctx, include, type ) ) { return true; } } return false; } }