target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void startsWithWithEmptyTags() { assertFalse(EMPTY_TAGS.startsWith("test")); }
public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; }
Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } }
Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } Tags(String... values); }
Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); }
Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); }
@Test public void jdbcUrlNoPort() { RelationalServiceInfo serviceInfo = createServiceInfo("dbtype: assertEquals("jdbc:jdbcdbtype: }
@ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; }
@Test public void jdbcUrlNoUsernamePassword() { RelationalServiceInfo serviceInfo = createServiceInfo("dbtype: assertEquals("jdbc:jdbcdbtype: }
@ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; }
@Test public void jdbcUrlNoPassword() { RelationalServiceInfo serviceInfo = createServiceInfo("dbtype: assertEquals("jdbc:jdbcdbtype: }
@ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; }
@Test public void jdbcUrlWithQuery() { RelationalServiceInfo serviceInfo = createServiceInfo("dbtype: assertEquals("jdbc:jdbcdbtype: }
@ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); }
RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; }
@Test public void givenPlainQueryWhenFindEntityExpectFirstEntityReturned() { Query<TestComposite> query = module.newQueryBuilder( TestComposite.class ).newQuery( composites ); assertEquals( "A", query.find().a().get() ); assertEquals( 6, query.count() ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testTemplate() { new TestBuilder( "Rickard" ).newInstance( module); }
public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } protected ValueBuilderTemplate( Class<T> type ); }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } protected ValueBuilderTemplate( Class<T> type ); T newInstance(Module module); }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } protected ValueBuilderTemplate( Class<T> type ); T newInstance(Module module); }
@Test public void testAnonymousTemplate() { new ValueBuilderTemplate<TestValue>(TestValue.class) { @Override protected void build( TestValue prototype ) { prototype.name().set( "Rickard" ); } }.newInstance( module ); }
public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } protected ValueBuilderTemplate( Class<T> type ); }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } protected ValueBuilderTemplate( Class<T> type ); T newInstance(Module module); }
ValueBuilderTemplate { public T newInstance(Module module) { ValueBuilder<T> builder = module.newValueBuilder( type ); build( builder.prototype() ); return builder.newInstance(); } protected ValueBuilderTemplate( Class<T> type ); T newInstance(Module module); }
@Test public void givenClassWithInterfacesWhenGetInterfacesWithMethodsThenGetCorrectSet() { HashSet<Class<?>> interfaces = new HashSet<Class<?>>(); interfaces.add( B.class ); Set<Class<?>> types = interfacesWithMethods( interfaces ); assertThat( "one interface returned", types.size(), equalTo( 1 ) ); assertThat( "correct interface returned", types.contains( B.class ), is( true ) ); }
public static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ) { Set<Class<?>> newSet = new LinkedHashSet<Class<?>>(); for( Class type : interfaces ) { if( type.isInterface() && type.getDeclaredMethods().length > 0 ) { newSet.add( type ); } } return newSet; }
Classes { public static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ) { Set<Class<?>> newSet = new LinkedHashSet<Class<?>>(); for( Class type : interfaces ) { if( type.isInterface() && type.getDeclaredMethods().length > 0 ) { newSet.add( type ); } } return newSet; } }
Classes { public static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ) { Set<Class<?>> newSet = new LinkedHashSet<Class<?>>(); for( Class type : interfaces ) { if( type.isInterface() && type.getDeclaredMethods().length > 0 ) { newSet.add( type ); } } return newSet; } }
Classes { public static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ) { Set<Class<?>> newSet = new LinkedHashSet<Class<?>>(); for( Class type : interfaces ) { if( type.isInterface() && type.getDeclaredMethods().length > 0 ) { newSet.add( type ); } } return newSet; } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); }
Classes { public static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ) { Set<Class<?>> newSet = new LinkedHashSet<Class<?>>(); for( Class type : interfaces ) { if( type.isInterface() && type.getDeclaredMethods().length > 0 ) { newSet.add( type ); } } return newSet; } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); static final Function<Type, Type> WRAPPER_CLASS; static final Function<Type, Type> PRIMITIVE_CLASS; static final Function<Type, Class<?>> RAW_CLASS; static final Function<AccessibleObject, Type> TYPE_OF; static final Function<Type, Iterable<Class<?>>> CLASS_HIERARCHY; static final Function<Type, Iterable<Type>> INTERFACES_OF; static final Function<Type, Iterable<Type>> TYPES_OF; }
@Test public void givenClassNameWhenToUriThenUriIsReturned() { assertThat( "URI is correct", Classes.toURI( A.class ), equalTo( "urn:qi4j:type:org.qi4j.api.util.ClassesTest-A" ) ); }
public static String toURI( final Class clazz ) throws NullPointerException { return toURI( clazz.getName() ); }
Classes { public static String toURI( final Class clazz ) throws NullPointerException { return toURI( clazz.getName() ); } }
Classes { public static String toURI( final Class clazz ) throws NullPointerException { return toURI( clazz.getName() ); } }
Classes { public static String toURI( final Class clazz ) throws NullPointerException { return toURI( clazz.getName() ); } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); }
Classes { public static String toURI( final Class clazz ) throws NullPointerException { return toURI( clazz.getName() ); } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); static final Function<Type, Type> WRAPPER_CLASS; static final Function<Type, Type> PRIMITIVE_CLASS; static final Function<Type, Class<?>> RAW_CLASS; static final Function<AccessibleObject, Type> TYPE_OF; static final Function<Type, Iterable<Class<?>>> CLASS_HIERARCHY; static final Function<Type, Iterable<Type>> INTERFACES_OF; static final Function<Type, Iterable<Type>> TYPES_OF; }
@Test public void givenUriWhenToClassNameThenClassNameIsReturned() { assertThat( "Class name is correct", Classes.toClassName( "urn:qi4j:type:org.qi4j.api.util.ClassesTest-A" ), equalTo( "org.qi4j.api.util.ClassesTest$A" ) ); }
public static String toClassName( String uri ) throws NullPointerException { uri = uri.substring( "urn:qi4j:type:".length() ); uri = denormalizeURIToClass( uri ); return uri; }
Classes { public static String toClassName( String uri ) throws NullPointerException { uri = uri.substring( "urn:qi4j:type:".length() ); uri = denormalizeURIToClass( uri ); return uri; } }
Classes { public static String toClassName( String uri ) throws NullPointerException { uri = uri.substring( "urn:qi4j:type:".length() ); uri = denormalizeURIToClass( uri ); return uri; } }
Classes { public static String toClassName( String uri ) throws NullPointerException { uri = uri.substring( "urn:qi4j:type:".length() ); uri = denormalizeURIToClass( uri ); return uri; } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); }
Classes { public static String toClassName( String uri ) throws NullPointerException { uri = uri.substring( "urn:qi4j:type:".length() ); uri = denormalizeURIToClass( uri ); return uri; } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); static final Function<Type, Type> WRAPPER_CLASS; static final Function<Type, Type> PRIMITIVE_CLASS; static final Function<Type, Class<?>> RAW_CLASS; static final Function<AccessibleObject, Type> TYPE_OF; static final Function<Type, Iterable<Class<?>>> CLASS_HIERARCHY; static final Function<Type, Iterable<Type>> INTERFACES_OF; static final Function<Type, Iterable<Type>> TYPES_OF; }
@Test public void givenTypeVariableWhenResolveThenResolved() { for( Method method : Type1.class.getMethods() ) { Type type = method.getGenericReturnType(); TypeVariable typeVariable = (TypeVariable) type; Type resolvedType = Classes.resolveTypeVariable( typeVariable, method.getDeclaringClass(), Type1.class ); System.out.println( type + "=" + resolvedType ); } }
public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ) { Type type = resolveTypeVariable( name, declaringClass, new HashMap<TypeVariable, Type>(), topClass ); if( type == null ) { type = Object.class; } return type; }
Classes { public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ) { Type type = resolveTypeVariable( name, declaringClass, new HashMap<TypeVariable, Type>(), topClass ); if( type == null ) { type = Object.class; } return type; } }
Classes { public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ) { Type type = resolveTypeVariable( name, declaringClass, new HashMap<TypeVariable, Type>(), topClass ); if( type == null ) { type = Object.class; } return type; } }
Classes { public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ) { Type type = resolveTypeVariable( name, declaringClass, new HashMap<TypeVariable, Type>(), topClass ); if( type == null ) { type = Object.class; } return type; } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); }
Classes { public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ) { Type type = resolveTypeVariable( name, declaringClass, new HashMap<TypeVariable, Type>(), topClass ); if( type == null ) { type = Object.class; } return type; } static Specification<Class<?>> isAssignableFrom( final Class clazz); static Specification<Object> instanceOf( final Class clazz); static Specification<Class<?>> hasModifier( final int classModifier ); static Function<Type, Iterable<T>> forClassHierarchy( final Function<Class<?>, Iterable<T>> function ); static Function<Type, Iterable<T>> forTypes( final Function<Type, Iterable<T>> function ); static Set<Class<?>> interfacesWithMethods( Set<Class<?>> interfaces ); static String getSimpleGenericName( Type type ); static AnnotationType getAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ); static Specification<Member> memberNamed( final String name ); static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ); static String toURI( final Class clazz ); static String toURI( String className ); static String toClassName( String uri ); static String normalizeClassToURI( String className ); static String denormalizeURIToClass( String uriPart ); static final Function<Type, Type> WRAPPER_CLASS; static final Function<Type, Type> PRIMITIVE_CLASS; static final Function<Type, Class<?>> RAW_CLASS; static final Function<AccessibleObject, Type> TYPE_OF; static final Function<Type, Iterable<Class<?>>> CLASS_HIERARCHY; static final Function<Type, Iterable<Type>> INTERFACES_OF; static final Function<Type, Iterable<Type>> TYPES_OF; }
@Test public void testTemplate() throws UnitOfWorkCompletionException { new UnitOfWorkTemplate<Void, RuntimeException>() { @Override protected Void withUnitOfWork( UnitOfWork uow ) throws RuntimeException { new EntityBuilderTemplate<TestEntity>(TestEntity.class) { @Override protected void build( TestEntity prototype ) { prototype.name().set( "Rickard" ); } }.newInstance( module ); return null; } }.withModule( module ); }
public RESULT withModule(Module module) throws ThrowableType, UnitOfWorkCompletionException { int loop = 0; ThrowableType ex = null; do { UnitOfWork uow = module.newUnitOfWork( usecase ); try { RESULT result = withUnitOfWork( uow ); if (complete) { try { uow.complete(); return result; } catch( ConcurrentEntityModificationException e ) { ex = (ThrowableType) e; } } } catch (Throwable e) { ex = (ThrowableType) e; } finally { uow.discard(); } } while (loop++ < retries); throw ex; }
UnitOfWorkTemplate { public RESULT withModule(Module module) throws ThrowableType, UnitOfWorkCompletionException { int loop = 0; ThrowableType ex = null; do { UnitOfWork uow = module.newUnitOfWork( usecase ); try { RESULT result = withUnitOfWork( uow ); if (complete) { try { uow.complete(); return result; } catch( ConcurrentEntityModificationException e ) { ex = (ThrowableType) e; } } } catch (Throwable e) { ex = (ThrowableType) e; } finally { uow.discard(); } } while (loop++ < retries); throw ex; } }
UnitOfWorkTemplate { public RESULT withModule(Module module) throws ThrowableType, UnitOfWorkCompletionException { int loop = 0; ThrowableType ex = null; do { UnitOfWork uow = module.newUnitOfWork( usecase ); try { RESULT result = withUnitOfWork( uow ); if (complete) { try { uow.complete(); return result; } catch( ConcurrentEntityModificationException e ) { ex = (ThrowableType) e; } } } catch (Throwable e) { ex = (ThrowableType) e; } finally { uow.discard(); } } while (loop++ < retries); throw ex; } protected UnitOfWorkTemplate(); protected UnitOfWorkTemplate( int retries, boolean complete ); protected UnitOfWorkTemplate( Usecase usecase, int retries, boolean complete ); }
UnitOfWorkTemplate { public RESULT withModule(Module module) throws ThrowableType, UnitOfWorkCompletionException { int loop = 0; ThrowableType ex = null; do { UnitOfWork uow = module.newUnitOfWork( usecase ); try { RESULT result = withUnitOfWork( uow ); if (complete) { try { uow.complete(); return result; } catch( ConcurrentEntityModificationException e ) { ex = (ThrowableType) e; } } } catch (Throwable e) { ex = (ThrowableType) e; } finally { uow.discard(); } } while (loop++ < retries); throw ex; } protected UnitOfWorkTemplate(); protected UnitOfWorkTemplate( int retries, boolean complete ); protected UnitOfWorkTemplate( Usecase usecase, int retries, boolean complete ); RESULT withModule(Module module); }
UnitOfWorkTemplate { public RESULT withModule(Module module) throws ThrowableType, UnitOfWorkCompletionException { int loop = 0; ThrowableType ex = null; do { UnitOfWork uow = module.newUnitOfWork( usecase ); try { RESULT result = withUnitOfWork( uow ); if (complete) { try { uow.complete(); return result; } catch( ConcurrentEntityModificationException e ) { ex = (ThrowableType) e; } } } catch (Throwable e) { ex = (ThrowableType) e; } finally { uow.discard(); } } while (loop++ < retries); throw ex; } protected UnitOfWorkTemplate(); protected UnitOfWorkTemplate( int retries, boolean complete ); protected UnitOfWorkTemplate( Usecase usecase, int retries, boolean complete ); RESULT withModule(Module module); }
@Test public void testMappingOfInteger() throws Exception { assertEquals( 5, mapToType( Integer.class, "5" ) ); assertEquals( -5, mapToType( Integer.class, "-5" ) ); assertEquals( Integer.class, mapToType( Integer.class, "5" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfLong() throws Exception { assertEquals( 5L, mapToType( Long.class, "5" ) ); assertEquals( 5876328476238746238L, mapToType( Long.class, "5876328476238746238" ) ); assertEquals( Long.class, mapToType( Long.class, "5" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfBoolean() throws Exception { assertEquals( false, mapToType( Boolean.class, "false" ) ); assertEquals( true, mapToType( Boolean.class, "true" ) ); assertEquals( Boolean.class, mapToType( Boolean.class, "false" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void givenPlainQueryWhenOrderByFirstPropertyExpectOrderedResult() { Query<TestComposite> query = module.newQueryBuilder( TestComposite.class ).newQuery( composites ); TestComposite template = templateFor( TestComposite.class ); query.orderBy( orderBy( template.a() ) ); verifyOrder( query, "612345" ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testMappingOfFloat() throws Exception { assertEquals( 5.1234f, mapToType( Float.class, "5.1234" ) ); assertEquals( 5876328476.6238f, mapToType( Float.class, "5876328476.6238" ) ); assertEquals( Float.class, mapToType( Float.class, "5" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfDouble() throws Exception { assertEquals( 5.1234, mapToType( Double.class, "5.1234" ) ); assertEquals( 5876328476.623823, mapToType( Double.class, "5876328476.623823" ) ); assertEquals( Double.class, mapToType( Double.class, "5" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfBigDecimal() throws Exception { assertEquals( new BigDecimal( 3 ), mapToType( BigDecimal.class, "3" ) ); assertEquals( new BigDecimal( "12345.67891011" ), mapToType( BigDecimal.class, "12345.67891011" ) ); assertEquals( BigDecimal.class, mapToType( BigDecimal.class, "5" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfBigInteger() throws Exception { assertEquals( new BigInteger( "20", 16 ), mapToType( BigInteger.class, "32" ) ); assertEquals( new BigInteger( "1234567891011" ), mapToType( BigInteger.class, "1234567891011" ) ); assertEquals( BigInteger.class, mapToType( BigInteger.class, "5" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfEnum() throws Exception { assertEquals( TestEnum.FIRST, mapToType( TestEnum.class, "FIRST" ) ); assertEquals( TestEnum.SECOND, mapToType( TestEnum.class, "SECOND" ) ); assertEquals( TestEnum.class, mapToType( TestEnum.class, "SECOND" ).getClass() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfIntegerArray() throws Exception { Object[] value = (Object[]) mapToType( Integer[].class, "5,4 , 3 ,2,1" ); assertEquals( 5, value.length ); assertEquals( 5, value[ 0 ] ); assertEquals( 4, value[ 1 ] ); assertEquals( 3, value[ 2 ] ); assertEquals( 2, value[ 3 ] ); assertEquals( 1, value[ 4 ] ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfStringArray() throws Exception { { Object[] value = (Object[]) mapToType( String[].class, "5,4 , 3 ,2,1" ); assertEquals( 5, value.length ); assertEquals( "5", value[ 0 ] ); assertEquals( "4 ", value[ 1 ] ); assertEquals( " 3 ", value[ 2 ] ); assertEquals( "2", value[ 3 ] ); assertEquals( "1", value[ 4 ] ); } { Object[] value = (Object[]) mapToType( String[].class, "5,4 ,\" 3, \", \" 2\" ,1" ); assertEquals( "5", value[ 0 ] ); assertEquals( "4 ", value[ 1 ] ); assertEquals( " 3, ", value[ 2 ] ); assertEquals( " 2", value[ 3 ] ); assertEquals( "1", value[ 4 ] ); assertEquals( 5, value.length ); } }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfBooleanArray() throws Exception { Object[] value = (Object[]) mapToType( Boolean[].class, " true,false, false, true ,true,false" ); assertEquals( true, value[ 0 ] ); assertEquals( false, value[ 1 ] ); assertEquals( false, value[ 2 ] ); assertEquals( true, value[ 3 ] ); assertEquals( true, value[ 4 ] ); assertEquals( false, value[ 5 ] ); assertEquals( 6, value.length ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfList() throws Exception { Type type = Testing.class.getDeclaredMethod( "list" ).getGenericReturnType(); List<String> value = (List<String>) mapToType( type, "5,4 ,\" 3, \", \" 2\" ,1" ); assertEquals( "5", value.get( 0 ) ); assertEquals( "4 ", value.get( 1 ) ); assertEquals( " 3, ", value.get( 2 ) ); assertEquals( " 2", value.get( 3 ) ); assertEquals( "1", value.get( 4 ) ); assertEquals( 5, value.size() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testMappingOfSet() throws Exception { Type type = Testing.class.getDeclaredMethod( "set" ).getGenericReturnType(); Set<String> value = (Set<String>) mapToType( type, "5,4 ,\" 3, \", \" 2\" ,1" ); assertTrue( value.contains( "5" ) ); assertTrue( value.contains( "4 " ) ); assertTrue( value.contains( " 3, " ) ); assertTrue( value.contains( " 2" ) ); assertTrue( value.contains( "1" ) ); assertEquals( 5, value.size() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void givenPlainQueryWhenOrderBySecondPropertyExpectOrderedResult() { Query<TestComposite> query = module.newQueryBuilder( TestComposite.class ).newQuery( composites ); TestComposite template = templateFor( TestComposite.class ); query.orderBy( orderBy( template.b() ) ); verifyOrder( query, "123456" ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testMappingOfMap() throws Exception { Type type = Testing.class.getDeclaredMethod( "map" ).getGenericReturnType(); Map<String, String> value = (Map<String, String>) mapToType( type, "first:5,second:4 , third:\" 3, \", fourth: \" 2\" ,fifth : 1" ); assertEquals( "5", value.get( "first" ) ); assertEquals( "4 ", value.get( "second" ) ); assertEquals( " 3, ", value.get( " third" ) ); assertEquals( " 2", value.get( " fourth" ) ); assertEquals( " 1", value.get( "fifth " ) ); assertEquals( 5, value.size() ); }
private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
PropertyMapper { private static Object mapToType( Type propertyType, Object value ) { final String stringValue = value.toString(); MappingStrategy strategy; if( propertyType instanceof Class ) { Class type = (Class) propertyType; if( type.isArray() ) { strategy = STRATEGY.get( Array.class ); } else if( Enum.class.isAssignableFrom( Classes.RAW_CLASS.map( propertyType) ) ) { strategy = STRATEGY.get( Enum.class ); } else { strategy = STRATEGY.get( type ); } } else if( propertyType instanceof ParameterizedType ) { ParameterizedType type = ( (ParameterizedType) propertyType ); if( type.getRawType() instanceof Class ) { Class clazz = (Class) type.getRawType(); if( List.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( List.class ); } else if( Set.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Set.class ); } else if( Map.class.isAssignableFrom( clazz ) ) { strategy = STRATEGY.get( Map.class ); } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } } else { throw new IllegalArgumentException( propertyType + " is not supported." ); } if( strategy == null ) { throw new IllegalArgumentException( propertyType + " is not supported." ); } return strategy.map( propertyType, stringValue ); } static void map( Properties props, Composite composite ); static void map( InputStream propertyInputStream, Composite composite ); static Properties getProperties( final Composite composite ); }
@Test public void testQualifiedNameWithDollar() { assertEquals( "Name containing dollar is modified", "Test-Test", new QualifiedName( TypeName.nameOf( "Test$Test" ), "satisfiedBy" ).type() ); }
public String type() { return typeName.normalized(); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public String type() { return typeName.normalized(); } }
QualifiedName implements Comparable<QualifiedName>, Serializable { public String type() { return typeName.normalized(); } QualifiedName( TypeName typeName, String name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public String type() { return typeName.normalized(); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public String type() { return typeName.normalized(); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
@Test( expected = NullArgumentException.class ) public void nonNullArguments4() { QualifiedName.fromQN( null ); }
public static QualifiedName fromQN( String qualifiedName ) { NullArgumentException.validateNotEmpty( "qualifiedName", qualifiedName ); int idx = qualifiedName.lastIndexOf( ":" ); if( idx == -1 ) { throw new IllegalArgumentException( "Name '" + qualifiedName + "' is not a qualified name" ); } final String type = qualifiedName.substring( 0, idx ); final String name = qualifiedName.substring( idx + 1 ); return new QualifiedName( TypeName.nameOf( type ), name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromQN( String qualifiedName ) { NullArgumentException.validateNotEmpty( "qualifiedName", qualifiedName ); int idx = qualifiedName.lastIndexOf( ":" ); if( idx == -1 ) { throw new IllegalArgumentException( "Name '" + qualifiedName + "' is not a qualified name" ); } final String type = qualifiedName.substring( 0, idx ); final String name = qualifiedName.substring( idx + 1 ); return new QualifiedName( TypeName.nameOf( type ), name ); } }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromQN( String qualifiedName ) { NullArgumentException.validateNotEmpty( "qualifiedName", qualifiedName ); int idx = qualifiedName.lastIndexOf( ":" ); if( idx == -1 ) { throw new IllegalArgumentException( "Name '" + qualifiedName + "' is not a qualified name" ); } final String type = qualifiedName.substring( 0, idx ); final String name = qualifiedName.substring( idx + 1 ); return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromQN( String qualifiedName ) { NullArgumentException.validateNotEmpty( "qualifiedName", qualifiedName ); int idx = qualifiedName.lastIndexOf( ":" ); if( idx == -1 ) { throw new IllegalArgumentException( "Name '" + qualifiedName + "' is not a qualified name" ); } final String type = qualifiedName.substring( 0, idx ); final String name = qualifiedName.substring( idx + 1 ); return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromQN( String qualifiedName ) { NullArgumentException.validateNotEmpty( "qualifiedName", qualifiedName ); int idx = qualifiedName.lastIndexOf( ":" ); if( idx == -1 ) { throw new IllegalArgumentException( "Name '" + qualifiedName + "' is not a qualified name" ); } final String type = qualifiedName.substring( 0, idx ); final String name = qualifiedName.substring( idx + 1 ); return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
@Test( expected = NullArgumentException.class ) public void nonNullArguments5() { QualifiedName.fromAccessor( null ); }
public static QualifiedName fromAccessor( AccessibleObject method ) { NullArgumentException.validateNotNull( "method", method ); return fromClass( ((Member)method).getDeclaringClass(), ((Member)method).getName() ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromAccessor( AccessibleObject method ) { NullArgumentException.validateNotNull( "method", method ); return fromClass( ((Member)method).getDeclaringClass(), ((Member)method).getName() ); } }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromAccessor( AccessibleObject method ) { NullArgumentException.validateNotNull( "method", method ); return fromClass( ((Member)method).getDeclaringClass(), ((Member)method).getName() ); } QualifiedName( TypeName typeName, String name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromAccessor( AccessibleObject method ) { NullArgumentException.validateNotNull( "method", method ); return fromClass( ((Member)method).getDeclaringClass(), ((Member)method).getName() ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromAccessor( AccessibleObject method ) { NullArgumentException.validateNotNull( "method", method ); return fromClass( ((Member)method).getDeclaringClass(), ((Member)method).getName() ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
@Test( expected = NullArgumentException.class ) public void nonNullArguments6() { QualifiedName.fromClass( null, "satisfiedBy" ); }
public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
@Test( expected = NullArgumentException.class ) public void nonNullArguments7() { QualifiedName.fromClass( null, null ); }
public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
QualifiedName implements Comparable<QualifiedName>, Serializable { public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); } QualifiedName( TypeName typeName, String name ); static QualifiedName fromAccessor( AccessibleObject method ); static QualifiedName fromClass( Class type, String name ); static QualifiedName fromName( String type, String name ); static QualifiedName fromQN( String qualifiedName ); String type(); String name(); String toURI(); String toNamespace(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode(); int compareTo( QualifiedName other ); }
@Test public void testClassScannerJar() { Assert.assertEquals( 121, Iterables.count( getClasses( Test.class ) )); }
public static Iterable<Class<?>> getClasses( final Class<?> seedClass ) { CodeSource codeSource = seedClass.getProtectionDomain().getCodeSource(); if( codeSource == null ) { return Iterables.empty(); } URL location = codeSource.getLocation(); if( !location.getProtocol().equals( "file" ) ) { throw new IllegalArgumentException( "Can only enumerate classes from file system locations. URL is:" + location ); } final File file; try { file = new File( location.toURI().getPath() ); } catch( URISyntaxException e ) { throw new IllegalArgumentException( "The file location of codebase is invalid. Can not convert to URI. URL is:" + location ); } if( file.getName().endsWith( ".jar" ) ) { try { final String packageName = seedClass.getPackage().getName().replace( '.', '/' ); JarFile jarFile = new JarFile( file ); Iterable<JarEntry> entries = Iterables.iterable( jarFile.entries() ); try { return Iterables.toList( filter( new ValidClass(), map( new Function<JarEntry, Class<?>>() { public Class map( JarEntry jarEntry ) { String name = jarEntry.getName(); name = name.substring( 0, name.length() - 6 ); name = name.replace( '/', '.' ); try { return seedClass.getClassLoader().loadClass( name ); } catch( ClassNotFoundException e ) { return null; } } } , filter( new Specification<JarEntry>() { public boolean satisfiedBy( JarEntry jarEntry ) { return jarEntry.getName() .startsWith( packageName ) && jarEntry.getName() .endsWith( ".class" ); } }, entries ) ) ) ); } finally { jarFile.close(); } } catch( IOException e ) { throw new IllegalArgumentException( "Could not open jar file " + file, e ); } } else { final File path = new File( file, seedClass.getPackage().getName().replace( '.', File.separatorChar ) ); Iterable<File> files = getFiles( path, new Specification<File>() { public boolean satisfiedBy( File file ) { return file.getName().endsWith( ".class" ); } } ); return filter( new ValidClass(), map( new Function<File, Class<?>>() { public Class<?> map( File f ) { String fileName = f.getAbsolutePath().substring( file.toString().length() + 1 ); fileName = fileName.replace( File.separatorChar, '.' ) .substring( 0, fileName.length() - 6 ); try { return seedClass.getClassLoader().loadClass( fileName ); } catch( ClassNotFoundException e ) { return null; } } }, files ) ); } }
ClassScanner { public static Iterable<Class<?>> getClasses( final Class<?> seedClass ) { CodeSource codeSource = seedClass.getProtectionDomain().getCodeSource(); if( codeSource == null ) { return Iterables.empty(); } URL location = codeSource.getLocation(); if( !location.getProtocol().equals( "file" ) ) { throw new IllegalArgumentException( "Can only enumerate classes from file system locations. URL is:" + location ); } final File file; try { file = new File( location.toURI().getPath() ); } catch( URISyntaxException e ) { throw new IllegalArgumentException( "The file location of codebase is invalid. Can not convert to URI. URL is:" + location ); } if( file.getName().endsWith( ".jar" ) ) { try { final String packageName = seedClass.getPackage().getName().replace( '.', '/' ); JarFile jarFile = new JarFile( file ); Iterable<JarEntry> entries = Iterables.iterable( jarFile.entries() ); try { return Iterables.toList( filter( new ValidClass(), map( new Function<JarEntry, Class<?>>() { public Class map( JarEntry jarEntry ) { String name = jarEntry.getName(); name = name.substring( 0, name.length() - 6 ); name = name.replace( '/', '.' ); try { return seedClass.getClassLoader().loadClass( name ); } catch( ClassNotFoundException e ) { return null; } } } , filter( new Specification<JarEntry>() { public boolean satisfiedBy( JarEntry jarEntry ) { return jarEntry.getName() .startsWith( packageName ) && jarEntry.getName() .endsWith( ".class" ); } }, entries ) ) ) ); } finally { jarFile.close(); } } catch( IOException e ) { throw new IllegalArgumentException( "Could not open jar file " + file, e ); } } else { final File path = new File( file, seedClass.getPackage().getName().replace( '.', File.separatorChar ) ); Iterable<File> files = getFiles( path, new Specification<File>() { public boolean satisfiedBy( File file ) { return file.getName().endsWith( ".class" ); } } ); return filter( new ValidClass(), map( new Function<File, Class<?>>() { public Class<?> map( File f ) { String fileName = f.getAbsolutePath().substring( file.toString().length() + 1 ); fileName = fileName.replace( File.separatorChar, '.' ) .substring( 0, fileName.length() - 6 ); try { return seedClass.getClassLoader().loadClass( fileName ); } catch( ClassNotFoundException e ) { return null; } } }, files ) ); } } }
ClassScanner { public static Iterable<Class<?>> getClasses( final Class<?> seedClass ) { CodeSource codeSource = seedClass.getProtectionDomain().getCodeSource(); if( codeSource == null ) { return Iterables.empty(); } URL location = codeSource.getLocation(); if( !location.getProtocol().equals( "file" ) ) { throw new IllegalArgumentException( "Can only enumerate classes from file system locations. URL is:" + location ); } final File file; try { file = new File( location.toURI().getPath() ); } catch( URISyntaxException e ) { throw new IllegalArgumentException( "The file location of codebase is invalid. Can not convert to URI. URL is:" + location ); } if( file.getName().endsWith( ".jar" ) ) { try { final String packageName = seedClass.getPackage().getName().replace( '.', '/' ); JarFile jarFile = new JarFile( file ); Iterable<JarEntry> entries = Iterables.iterable( jarFile.entries() ); try { return Iterables.toList( filter( new ValidClass(), map( new Function<JarEntry, Class<?>>() { public Class map( JarEntry jarEntry ) { String name = jarEntry.getName(); name = name.substring( 0, name.length() - 6 ); name = name.replace( '/', '.' ); try { return seedClass.getClassLoader().loadClass( name ); } catch( ClassNotFoundException e ) { return null; } } } , filter( new Specification<JarEntry>() { public boolean satisfiedBy( JarEntry jarEntry ) { return jarEntry.getName() .startsWith( packageName ) && jarEntry.getName() .endsWith( ".class" ); } }, entries ) ) ) ); } finally { jarFile.close(); } } catch( IOException e ) { throw new IllegalArgumentException( "Could not open jar file " + file, e ); } } else { final File path = new File( file, seedClass.getPackage().getName().replace( '.', File.separatorChar ) ); Iterable<File> files = getFiles( path, new Specification<File>() { public boolean satisfiedBy( File file ) { return file.getName().endsWith( ".class" ); } } ); return filter( new ValidClass(), map( new Function<File, Class<?>>() { public Class<?> map( File f ) { String fileName = f.getAbsolutePath().substring( file.toString().length() + 1 ); fileName = fileName.replace( File.separatorChar, '.' ) .substring( 0, fileName.length() - 6 ); try { return seedClass.getClassLoader().loadClass( fileName ); } catch( ClassNotFoundException e ) { return null; } } }, files ) ); } } }
ClassScanner { public static Iterable<Class<?>> getClasses( final Class<?> seedClass ) { CodeSource codeSource = seedClass.getProtectionDomain().getCodeSource(); if( codeSource == null ) { return Iterables.empty(); } URL location = codeSource.getLocation(); if( !location.getProtocol().equals( "file" ) ) { throw new IllegalArgumentException( "Can only enumerate classes from file system locations. URL is:" + location ); } final File file; try { file = new File( location.toURI().getPath() ); } catch( URISyntaxException e ) { throw new IllegalArgumentException( "The file location of codebase is invalid. Can not convert to URI. URL is:" + location ); } if( file.getName().endsWith( ".jar" ) ) { try { final String packageName = seedClass.getPackage().getName().replace( '.', '/' ); JarFile jarFile = new JarFile( file ); Iterable<JarEntry> entries = Iterables.iterable( jarFile.entries() ); try { return Iterables.toList( filter( new ValidClass(), map( new Function<JarEntry, Class<?>>() { public Class map( JarEntry jarEntry ) { String name = jarEntry.getName(); name = name.substring( 0, name.length() - 6 ); name = name.replace( '/', '.' ); try { return seedClass.getClassLoader().loadClass( name ); } catch( ClassNotFoundException e ) { return null; } } } , filter( new Specification<JarEntry>() { public boolean satisfiedBy( JarEntry jarEntry ) { return jarEntry.getName() .startsWith( packageName ) && jarEntry.getName() .endsWith( ".class" ); } }, entries ) ) ) ); } finally { jarFile.close(); } } catch( IOException e ) { throw new IllegalArgumentException( "Could not open jar file " + file, e ); } } else { final File path = new File( file, seedClass.getPackage().getName().replace( '.', File.separatorChar ) ); Iterable<File> files = getFiles( path, new Specification<File>() { public boolean satisfiedBy( File file ) { return file.getName().endsWith( ".class" ); } } ); return filter( new ValidClass(), map( new Function<File, Class<?>>() { public Class<?> map( File f ) { String fileName = f.getAbsolutePath().substring( file.toString().length() + 1 ); fileName = fileName.replace( File.separatorChar, '.' ) .substring( 0, fileName.length() - 6 ); try { return seedClass.getClassLoader().loadClass( fileName ); } catch( ClassNotFoundException e ) { return null; } } }, files ) ); } } static Iterable<Class<?>> getClasses( final Class<?> seedClass ); static Specification<Class<?>> matches( String regex ); }
ClassScanner { public static Iterable<Class<?>> getClasses( final Class<?> seedClass ) { CodeSource codeSource = seedClass.getProtectionDomain().getCodeSource(); if( codeSource == null ) { return Iterables.empty(); } URL location = codeSource.getLocation(); if( !location.getProtocol().equals( "file" ) ) { throw new IllegalArgumentException( "Can only enumerate classes from file system locations. URL is:" + location ); } final File file; try { file = new File( location.toURI().getPath() ); } catch( URISyntaxException e ) { throw new IllegalArgumentException( "The file location of codebase is invalid. Can not convert to URI. URL is:" + location ); } if( file.getName().endsWith( ".jar" ) ) { try { final String packageName = seedClass.getPackage().getName().replace( '.', '/' ); JarFile jarFile = new JarFile( file ); Iterable<JarEntry> entries = Iterables.iterable( jarFile.entries() ); try { return Iterables.toList( filter( new ValidClass(), map( new Function<JarEntry, Class<?>>() { public Class map( JarEntry jarEntry ) { String name = jarEntry.getName(); name = name.substring( 0, name.length() - 6 ); name = name.replace( '/', '.' ); try { return seedClass.getClassLoader().loadClass( name ); } catch( ClassNotFoundException e ) { return null; } } } , filter( new Specification<JarEntry>() { public boolean satisfiedBy( JarEntry jarEntry ) { return jarEntry.getName() .startsWith( packageName ) && jarEntry.getName() .endsWith( ".class" ); } }, entries ) ) ) ); } finally { jarFile.close(); } } catch( IOException e ) { throw new IllegalArgumentException( "Could not open jar file " + file, e ); } } else { final File path = new File( file, seedClass.getPackage().getName().replace( '.', File.separatorChar ) ); Iterable<File> files = getFiles( path, new Specification<File>() { public boolean satisfiedBy( File file ) { return file.getName().endsWith( ".class" ); } } ); return filter( new ValidClass(), map( new Function<File, Class<?>>() { public Class<?> map( File f ) { String fileName = f.getAbsolutePath().substring( file.toString().length() + 1 ); fileName = fileName.replace( File.separatorChar, '.' ) .substring( 0, fileName.length() - 6 ); try { return seedClass.getClassLoader().loadClass( fileName ); } catch( ClassNotFoundException e ) { return null; } } }, files ) ); } } static Iterable<Class<?>> getClasses( final Class<?> seedClass ); static Specification<Class<?>> matches( String regex ); }
@Test public void testConstant() { String str = ""; for( String string : Iterables.limit( 3, Iterables.constant( "123" ) ) ) { str += string; } assertThat( str, CoreMatchers.equalTo( "123123123" ) ); }
public static <T> Iterable<T> constant( final T item ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return true; } @Override public T next() { return item; } @Override public void remove() { } }; } }; }
Iterables { public static <T> Iterable<T> constant( final T item ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return true; } @Override public T next() { return item; } @Override public void remove() { } }; } }; } }
Iterables { public static <T> Iterable<T> constant( final T item ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return true; } @Override public T next() { return item; } @Override public void remove() { } }; } }; } }
Iterables { public static <T> Iterable<T> constant( final T item ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return true; } @Override public T next() { return item; } @Override public void remove() { } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> Iterable<T> constant( final T item ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return true; } @Override public T next() { return item; } @Override public void remove() { } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testUnique() { String str = ""; for( String string : Iterables.unique( Iterables.flatten( numbers, numbers, numbers ) )) { str += string; } assertThat( str, CoreMatchers.equalTo( "123" ) ); }
public static <T> Iterable<T> unique( final Iterable<T> iterable) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { Set<T> items = new HashSet<T>(); T nextItem; @Override public boolean hasNext() { while(iterator.hasNext()) { nextItem = iterator.next(); if (items.add( nextItem )) return true; } return false; } @Override public T next() { if (nextItem == null && !hasNext()) throw new NoSuchElementException( ); return nextItem; } @Override public void remove() { } }; } }; }
Iterables { public static <T> Iterable<T> unique( final Iterable<T> iterable) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { Set<T> items = new HashSet<T>(); T nextItem; @Override public boolean hasNext() { while(iterator.hasNext()) { nextItem = iterator.next(); if (items.add( nextItem )) return true; } return false; } @Override public T next() { if (nextItem == null && !hasNext()) throw new NoSuchElementException( ); return nextItem; } @Override public void remove() { } }; } }; } }
Iterables { public static <T> Iterable<T> unique( final Iterable<T> iterable) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { Set<T> items = new HashSet<T>(); T nextItem; @Override public boolean hasNext() { while(iterator.hasNext()) { nextItem = iterator.next(); if (items.add( nextItem )) return true; } return false; } @Override public T next() { if (nextItem == null && !hasNext()) throw new NoSuchElementException( ); return nextItem; } @Override public void remove() { } }; } }; } }
Iterables { public static <T> Iterable<T> unique( final Iterable<T> iterable) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { Set<T> items = new HashSet<T>(); T nextItem; @Override public boolean hasNext() { while(iterator.hasNext()) { nextItem = iterator.next(); if (items.add( nextItem )) return true; } return false; } @Override public T next() { if (nextItem == null && !hasNext()) throw new NoSuchElementException( ); return nextItem; } @Override public void remove() { } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> Iterable<T> unique( final Iterable<T> iterable) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { Set<T> items = new HashSet<T>(); T nextItem; @Override public boolean hasNext() { while(iterator.hasNext()) { nextItem = iterator.next(); if (items.add( nextItem )) return true; } return false; } @Override public T next() { if (nextItem == null && !hasNext()) throw new NoSuchElementException( ); return nextItem; } @Override public void remove() { } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testAddAll() { List<String> strings = Iterables.toList( numbers ); assertThat( strings.toString(), equalTo( "[1, 2, 3]" ) ); assertThat( Iterables.toList( numberLongs ).toString(), equalTo( "[1, 2, 3]" ) ); }
public static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) { for( T item : iterable ) { collection.add( item ); } return collection; }
Iterables { public static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) { for( T item : iterable ) { collection.add( item ); } return collection; } }
Iterables { public static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) { for( T item : iterable ) { collection.add( item ); } return collection; } }
Iterables { public static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) { for( T item : iterable ) { collection.add( item ); } return collection; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T, C extends Collection<T>> C addAll( C collection, Iterable<? extends T> iterable ) { for( T item : iterable ) { collection.add( item ); } return collection; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void givenPlainQueryWhenOrderByTwoPropertiesExpectOrderedResult() { Query<TestComposite> query = module.newQueryBuilder( TestComposite.class ).newQuery( composites ); TestComposite template = templateFor( TestComposite.class ); query.orderBy( orderBy( template.a() ), orderBy( template.b() ) ); verifyOrder( query, "162345" ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testCount() { assertThat( Iterables.count( numbers ), equalTo( 3L ) ); }
public static long count( Iterable<?> iterable ) { long c = 0; Iterator<?> iterator = iterable.iterator(); while( iterator.hasNext() ) { iterator.next(); c++; } return c; }
Iterables { public static long count( Iterable<?> iterable ) { long c = 0; Iterator<?> iterator = iterable.iterator(); while( iterator.hasNext() ) { iterator.next(); c++; } return c; } }
Iterables { public static long count( Iterable<?> iterable ) { long c = 0; Iterator<?> iterator = iterable.iterator(); while( iterator.hasNext() ) { iterator.next(); c++; } return c; } }
Iterables { public static long count( Iterable<?> iterable ) { long c = 0; Iterator<?> iterator = iterable.iterator(); while( iterator.hasNext() ) { iterator.next(); c++; } return c; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static long count( Iterable<?> iterable ) { long c = 0; Iterator<?> iterator = iterable.iterator(); while( iterator.hasNext() ) { iterator.next(); c++; } return c; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testFilter() { assertThat( Iterables.first( Iterables.filter( Specifications.in( "2" ), numbers ) ), equalTo( "2" ) ); }
public static <X> Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ) { return new FilterIterable<X>( i, specification ); }
Iterables { public static <X> Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ) { return new FilterIterable<X>( i, specification ); } }
Iterables { public static <X> Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ) { return new FilterIterable<X>( i, specification ); } }
Iterables { public static <X> Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ) { return new FilterIterable<X>( i, specification ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <X> Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ) { return new FilterIterable<X>( i, specification ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testFirst() { assertThat( Iterables.first( numbers ), equalTo( "1" ) ); assertThat( Iterables.first( Collections.<Object>emptyList() ), CoreMatchers.<Object>nullValue() ); }
public static <X> X first( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); if( iter.hasNext() ) { return iter.next(); } else { return null; } }
Iterables { public static <X> X first( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); if( iter.hasNext() ) { return iter.next(); } else { return null; } } }
Iterables { public static <X> X first( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); if( iter.hasNext() ) { return iter.next(); } else { return null; } } }
Iterables { public static <X> X first( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); if( iter.hasNext() ) { return iter.next(); } else { return null; } } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <X> X first( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); if( iter.hasNext() ) { return iter.next(); } else { return null; } } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testLast() { assertThat( Iterables.last( numbers ), equalTo( "3" ) ); assertThat( Iterables.last( Collections.<Object>emptyList() ), CoreMatchers.<Object>nullValue() ); }
public static <X> X last( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); X item = null; while( iter.hasNext() ) item = iter.next(); return item; }
Iterables { public static <X> X last( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); X item = null; while( iter.hasNext() ) item = iter.next(); return item; } }
Iterables { public static <X> X last( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); X item = null; while( iter.hasNext() ) item = iter.next(); return item; } }
Iterables { public static <X> X last( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); X item = null; while( iter.hasNext() ) item = iter.next(); return item; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <X> X last( Iterable<? extends X> i ) { Iterator<? extends X> iter = i.iterator(); X item = null; while( iter.hasNext() ) item = iter.next(); return item; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testFolding() { assertThat( Iterables.fold( new Function<Integer, Integer>() { int sum = 0; @Override public Integer map( Integer number ) { return sum += number; } }, numberIntegers ), equalTo( 6 ) ); }
public static <FROM, TO> TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ) { return last( map( function, i ) ); }
Iterables { public static <FROM, TO> TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ) { return last( map( function, i ) ); } }
Iterables { public static <FROM, TO> TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ) { return last( map( function, i ) ); } }
Iterables { public static <FROM, TO> TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ) { return last( map( function, i ) ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <FROM, TO> TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ) { return last( map( function, i ) ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testAppend() { assertThat( Iterables.toList(Iterables.append( "C", Iterables.iterable( "A","B" ) )).toString(), equalTo( "[A, B, C]" ) ); }
public static <T, C extends T> Iterable<T> append( final C item, final Iterable<T> iterable ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { T last = item; @Override public boolean hasNext() { if(iterator.hasNext()) { return true; } else { return last != null; } } @Override public T next() { if (iterator.hasNext() ) return iterator.next(); else try { return last; } finally { last = null; } } @Override public void remove() { } }; } }; }
Iterables { public static <T, C extends T> Iterable<T> append( final C item, final Iterable<T> iterable ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { T last = item; @Override public boolean hasNext() { if(iterator.hasNext()) { return true; } else { return last != null; } } @Override public T next() { if (iterator.hasNext() ) return iterator.next(); else try { return last; } finally { last = null; } } @Override public void remove() { } }; } }; } }
Iterables { public static <T, C extends T> Iterable<T> append( final C item, final Iterable<T> iterable ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { T last = item; @Override public boolean hasNext() { if(iterator.hasNext()) { return true; } else { return last != null; } } @Override public T next() { if (iterator.hasNext() ) return iterator.next(); else try { return last; } finally { last = null; } } @Override public void remove() { } }; } }; } }
Iterables { public static <T, C extends T> Iterable<T> append( final C item, final Iterable<T> iterable ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { T last = item; @Override public boolean hasNext() { if(iterator.hasNext()) { return true; } else { return last != null; } } @Override public T next() { if (iterator.hasNext() ) return iterator.next(); else try { return last; } finally { last = null; } } @Override public void remove() { } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T, C extends T> Iterable<T> append( final C item, final Iterable<T> iterable ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterator<T> iterator = iterable.iterator(); return new Iterator<T>() { T last = item; @Override public boolean hasNext() { if(iterator.hasNext()) { return true; } else { return last != null; } } @Override public T next() { if (iterator.hasNext() ) return iterator.next(); else try { return last; } finally { last = null; } } @Override public void remove() { } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testReverse() { assertThat( Iterables.reverse( numbers ).toString(), equalTo( "[3, 2, 1]" ) ); assertThat( Iterables.reverse( Collections.<Object>emptyList() ), equalTo( (Object) Collections.<Object>emptyList() ) ); }
public static <X> Iterable<X> reverse( Iterable<X> iterable ) { List<X> list = toList( iterable ); Collections.reverse( list ); return list; }
Iterables { public static <X> Iterable<X> reverse( Iterable<X> iterable ) { List<X> list = toList( iterable ); Collections.reverse( list ); return list; } }
Iterables { public static <X> Iterable<X> reverse( Iterable<X> iterable ) { List<X> list = toList( iterable ); Collections.reverse( list ); return list; } }
Iterables { public static <X> Iterable<X> reverse( Iterable<X> iterable ) { List<X> list = toList( iterable ); Collections.reverse( list ); return list; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <X> Iterable<X> reverse( Iterable<X> iterable ) { List<X> list = toList( iterable ); Collections.reverse( list ); return list; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testMatchesAny() { assertThat( Iterables.matchesAny( Specifications.in( "2" ), numbers ), equalTo( true ) ); assertThat( Iterables.matchesAny( Specifications.in( "4" ), numbers ), equalTo( false ) ); }
public static <T> boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = false; for( T item : iterable ) { if( specification.satisfiedBy( item ) ) { result = true; break; } } return result; }
Iterables { public static <T> boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = false; for( T item : iterable ) { if( specification.satisfiedBy( item ) ) { result = true; break; } } return result; } }
Iterables { public static <T> boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = false; for( T item : iterable ) { if( specification.satisfiedBy( item ) ) { result = true; break; } } return result; } }
Iterables { public static <T> boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = false; for( T item : iterable ) { if( specification.satisfiedBy( item ) ) { result = true; break; } } return result; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = false; for( T item : iterable ) { if( specification.satisfiedBy( item ) ) { result = true; break; } } return result; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testMatchesAll() { assertThat( Iterables.matchesAll( Specifications.in( "1", "2", "3" ), numbers ), equalTo( true ) ); assertThat( Iterables.matchesAll( Specifications.in( "2", "3", "4" ), numbers ), equalTo( false ) ); }
public static <T> boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = true; for( T item : iterable ) { if( !specification.satisfiedBy( item ) ) { result = false; } } return result; }
Iterables { public static <T> boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = true; for( T item : iterable ) { if( !specification.satisfiedBy( item ) ) { result = false; } } return result; } }
Iterables { public static <T> boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = true; for( T item : iterable ) { if( !specification.satisfiedBy( item ) ) { result = false; } } return result; } }
Iterables { public static <T> boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = true; for( T item : iterable ) { if( !specification.satisfiedBy( item ) ) { result = false; } } return result; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ) { boolean result = true; for( T item : iterable ) { if( !specification.satisfiedBy( item ) ) { result = false; } } return result; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testFlatten() { assertThat( Iterables.toList( Iterables.flatten( numbers, numbers ) ) .toString(), equalTo( "[1, 2, 3, 1, 2, 3]" ) ); Iterable<? extends Number> flatten = Iterables.flatten( numberIntegers, numberLongs ); assertThat( Iterables.toList( flatten ) .toString(), equalTo( "[1, 2, 3, 1, 2, 3]" ) ); }
public static <X, I extends Iterable<? extends X>> Iterable<X> flatten( I... multiIterator ) { return new FlattenIterable<X, I>( Arrays.asList( multiIterator ) ); }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flatten( I... multiIterator ) { return new FlattenIterable<X, I>( Arrays.asList( multiIterator ) ); } }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flatten( I... multiIterator ) { return new FlattenIterable<X, I>( Arrays.asList( multiIterator ) ); } }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flatten( I... multiIterator ) { return new FlattenIterable<X, I>( Arrays.asList( multiIterator ) ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flatten( I... multiIterator ) { return new FlattenIterable<X, I>( Arrays.asList( multiIterator ) ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void givenPlainQueryWhenMaxedResultExpectLimitedResult() { Query<TestComposite> query = module.newQueryBuilder( TestComposite.class ).newQuery( composites ); query.maxResults( 5 ); verifyOrder( query, "62345" ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testFlattenIterables() { Iterable<List<String>> iterable = Iterables.iterable( numbers, numbers ); assertThat( Iterables.toList( Iterables.flattenIterables( iterable ) ) .toString(), equalTo( "[1, 2, 3, 1, 2, 3]" ) ); }
public static <X, I extends Iterable<? extends X>> Iterable<X> flattenIterables( Iterable<I> multiIterator ) { return new FlattenIterable<X, I>( multiIterator ); }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flattenIterables( Iterable<I> multiIterator ) { return new FlattenIterable<X, I>( multiIterator ); } }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flattenIterables( Iterable<I> multiIterator ) { return new FlattenIterable<X, I>( multiIterator ); } }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flattenIterables( Iterable<I> multiIterator ) { return new FlattenIterable<X, I>( multiIterator ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <X, I extends Iterable<? extends X>> Iterable<X> flattenIterables( Iterable<I> multiIterator ) { return new FlattenIterable<X, I>( multiIterator ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testMix() { assertThat( Iterables.toList(Iterables.mix( Iterables.iterable( "A","B","C" ),Iterables.iterable( "1","2","3","4","5" ),Iterables.iterable( "X","Y","Z" ) )).toString(), equalTo( "[A, 1, X, B, 2, Y, C, 3, Z, 4, 5]" )); }
public static <T> Iterable<T> mix( final Iterable<T>... iterables ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterable<Iterator<T>> iterators = toList(map( new Function<Iterable<T>, Iterator<T>>() { @Override public Iterator<T> map( Iterable<T> iterable ) { return iterable.iterator(); } }, Iterables.iterable( iterables) )); return new Iterator<T>() { Iterator<Iterator<T>> iterator; Iterator<T> iter; @Override public boolean hasNext() { for( Iterator<T> iterator : iterators ) { if (iterator.hasNext()) { return true; } } return false; } @Override public T next() { if (iterator == null) { iterator = iterators.iterator(); } while (iterator.hasNext()) { iter = iterator.next(); if (iter.hasNext()) return iter.next(); } iterator = null; return next(); } @Override public void remove() { if (iter != null) iter.remove(); } }; } }; }
Iterables { public static <T> Iterable<T> mix( final Iterable<T>... iterables ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterable<Iterator<T>> iterators = toList(map( new Function<Iterable<T>, Iterator<T>>() { @Override public Iterator<T> map( Iterable<T> iterable ) { return iterable.iterator(); } }, Iterables.iterable( iterables) )); return new Iterator<T>() { Iterator<Iterator<T>> iterator; Iterator<T> iter; @Override public boolean hasNext() { for( Iterator<T> iterator : iterators ) { if (iterator.hasNext()) { return true; } } return false; } @Override public T next() { if (iterator == null) { iterator = iterators.iterator(); } while (iterator.hasNext()) { iter = iterator.next(); if (iter.hasNext()) return iter.next(); } iterator = null; return next(); } @Override public void remove() { if (iter != null) iter.remove(); } }; } }; } }
Iterables { public static <T> Iterable<T> mix( final Iterable<T>... iterables ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterable<Iterator<T>> iterators = toList(map( new Function<Iterable<T>, Iterator<T>>() { @Override public Iterator<T> map( Iterable<T> iterable ) { return iterable.iterator(); } }, Iterables.iterable( iterables) )); return new Iterator<T>() { Iterator<Iterator<T>> iterator; Iterator<T> iter; @Override public boolean hasNext() { for( Iterator<T> iterator : iterators ) { if (iterator.hasNext()) { return true; } } return false; } @Override public T next() { if (iterator == null) { iterator = iterators.iterator(); } while (iterator.hasNext()) { iter = iterator.next(); if (iter.hasNext()) return iter.next(); } iterator = null; return next(); } @Override public void remove() { if (iter != null) iter.remove(); } }; } }; } }
Iterables { public static <T> Iterable<T> mix( final Iterable<T>... iterables ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterable<Iterator<T>> iterators = toList(map( new Function<Iterable<T>, Iterator<T>>() { @Override public Iterator<T> map( Iterable<T> iterable ) { return iterable.iterator(); } }, Iterables.iterable( iterables) )); return new Iterator<T>() { Iterator<Iterator<T>> iterator; Iterator<T> iter; @Override public boolean hasNext() { for( Iterator<T> iterator : iterators ) { if (iterator.hasNext()) { return true; } } return false; } @Override public T next() { if (iterator == null) { iterator = iterators.iterator(); } while (iterator.hasNext()) { iter = iterator.next(); if (iter.hasNext()) return iter.next(); } iterator = null; return next(); } @Override public void remove() { if (iter != null) iter.remove(); } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> Iterable<T> mix( final Iterable<T>... iterables ) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final Iterable<Iterator<T>> iterators = toList(map( new Function<Iterable<T>, Iterator<T>>() { @Override public Iterator<T> map( Iterable<T> iterable ) { return iterable.iterator(); } }, Iterables.iterable( iterables) )); return new Iterator<T>() { Iterator<Iterator<T>> iterator; Iterator<T> iter; @Override public boolean hasNext() { for( Iterator<T> iterator : iterators ) { if (iterator.hasNext()) { return true; } } return false; } @Override public T next() { if (iterator == null) { iterator = iterators.iterator(); } while (iterator.hasNext()) { iter = iterator.next(); if (iter.hasNext()) return iter.next(); } iterator = null; return next(); } @Override public void remove() { if (iter != null) iter.remove(); } }; } }; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testMap() { assertThat( Iterables.toList( Iterables.map( new Function<String, String>() { public String map( String s ) { return s + s; } }, numbers ) ).toString(), equalTo( "[11, 22, 33]" ) ); Iterable<List<String>> numberIterable = Iterables.iterable( numbers, numbers, numbers ); assertThat( Iterables.toList( Iterables.map( new Function<Collection, Integer>() { @Override public Integer map( Collection collection ) { return collection.size(); } }, numberIterable ) ).toString(), equalTo( "[3, 3, 3]" ) ); }
public static <FROM, TO> Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ) { return new MapIterable<FROM, TO>( from, function ); }
Iterables { public static <FROM, TO> Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ) { return new MapIterable<FROM, TO>( from, function ); } }
Iterables { public static <FROM, TO> Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ) { return new MapIterable<FROM, TO>( from, function ); } }
Iterables { public static <FROM, TO> Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ) { return new MapIterable<FROM, TO>( from, function ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <FROM, TO> Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ) { return new MapIterable<FROM, TO>( from, function ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testCast() { Iterable<Long> values = numberLongs; Iterable<Number> numbers = Iterables.cast(values); }
public static <T, C> Iterable<T> cast( Iterable<C> iterable ) { Iterable iter = iterable; return iter; }
Iterables { public static <T, C> Iterable<T> cast( Iterable<C> iterable ) { Iterable iter = iterable; return iter; } }
Iterables { public static <T, C> Iterable<T> cast( Iterable<C> iterable ) { Iterable iter = iterable; return iter; } }
Iterables { public static <T, C> Iterable<T> cast( Iterable<C> iterable ) { Iterable iter = iterable; return iter; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T, C> Iterable<T> cast( Iterable<C> iterable ) { Iterable iter = iterable; return iter; } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testDebug() { assertThat( Iterables.first( Iterables.debug( "Filtered number:{0}", Iterables.filter( Specifications.in( "2" ), Iterables.debug( "Number:{0}", numbers ) ) ) ), equalTo( "2" ) ); }
public static <T> Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ) { final MessageFormat msgFormat = new MessageFormat( format ); return map( new Function<T, T>() { @Override public T map( T t ) { if( functions.length == 0 ) debugLogger.info( msgFormat.format( new Object[]{t} ) ); else { String[] mapped = new String[functions.length]; for( int i = 0; i < functions.length; i++ ) { Function<T, String> function = functions[i]; mapped[i] = function.map( t ); debugLogger.info( msgFormat.format( mapped ) ); } } return t; } }, iterable ); }
Iterables { public static <T> Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ) { final MessageFormat msgFormat = new MessageFormat( format ); return map( new Function<T, T>() { @Override public T map( T t ) { if( functions.length == 0 ) debugLogger.info( msgFormat.format( new Object[]{t} ) ); else { String[] mapped = new String[functions.length]; for( int i = 0; i < functions.length; i++ ) { Function<T, String> function = functions[i]; mapped[i] = function.map( t ); debugLogger.info( msgFormat.format( mapped ) ); } } return t; } }, iterable ); } }
Iterables { public static <T> Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ) { final MessageFormat msgFormat = new MessageFormat( format ); return map( new Function<T, T>() { @Override public T map( T t ) { if( functions.length == 0 ) debugLogger.info( msgFormat.format( new Object[]{t} ) ); else { String[] mapped = new String[functions.length]; for( int i = 0; i < functions.length; i++ ) { Function<T, String> function = functions[i]; mapped[i] = function.map( t ); debugLogger.info( msgFormat.format( mapped ) ); } } return t; } }, iterable ); } }
Iterables { public static <T> Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ) { final MessageFormat msgFormat = new MessageFormat( format ); return map( new Function<T, T>() { @Override public T map( T t ) { if( functions.length == 0 ) debugLogger.info( msgFormat.format( new Object[]{t} ) ); else { String[] mapped = new String[functions.length]; for( int i = 0; i < functions.length; i++ ) { Function<T, String> function = functions[i]; mapped[i] = function.map( t ); debugLogger.info( msgFormat.format( mapped ) ); } } return t; } }, iterable ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ) { final MessageFormat msgFormat = new MessageFormat( format ); return map( new Function<T, T>() { @Override public T map( T t ) { if( functions.length == 0 ) debugLogger.info( msgFormat.format( new Object[]{t} ) ); else { String[] mapped = new String[functions.length]; for( int i = 0; i < functions.length; i++ ) { Function<T, String> function = functions[i]; mapped[i] = function.map( t ); debugLogger.info( msgFormat.format( mapped ) ); } } return t; } }, iterable ); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testCache() { final int[] count = new int[1]; Iterable<String> b = Iterables.cache(Iterables.filter( Specifications.and( new Specification<String>() { @Override public boolean satisfiedBy( String item ) { count[0] = count[0]+1; return true; } }, Specifications.in( "B" )), Iterables.iterable( "A", "B", "C" ))); assertThat( count[0], equalTo( 0 ) ); Iterables.toList( b ); assertThat( count[0], equalTo( 3 ) ); Iterables.toList( b ); assertThat( count[0], equalTo( 3 ) ); }
public static <T> Iterable<T> cache(Iterable<T> iterable) { return new CacheIterable<T>(iterable); }
Iterables { public static <T> Iterable<T> cache(Iterable<T> iterable) { return new CacheIterable<T>(iterable); } }
Iterables { public static <T> Iterable<T> cache(Iterable<T> iterable) { return new CacheIterable<T>(iterable); } }
Iterables { public static <T> Iterable<T> cache(Iterable<T> iterable) { return new CacheIterable<T>(iterable); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
Iterables { public static <T> Iterable<T> cache(Iterable<T> iterable) { return new CacheIterable<T>(iterable); } static Iterable<T> empty(); static Iterable<T> constant( final T item ); static Iterable<T> limit( final int limitItems, final Iterable<T> iterable ); static Iterable<T> unique( final Iterable<T> iterable); static C addAll( C collection, Iterable<? extends T> iterable ); static long count( Iterable<?> iterable ); static Iterable<X> filter( Specification<? super X> specification, Iterable<X> i ); static X first( Iterable<? extends X> i ); static X single( Iterable<? extends X> i ); static Iterable<X> skip( final int skip, final Iterable<X> iterable); static X last( Iterable<? extends X> i ); static Iterable<X> reverse( Iterable<X> iterable ); static boolean matchesAny( Specification<? super T> specification, Iterable<T> iterable ); static boolean matchesAll( Specification<? super T> specification, Iterable<T> iterable ); static Iterable<X> flatten( I... multiIterator ); static Iterable<X> flattenIterables( Iterable<I> multiIterator ); static Iterable<T> mix( final Iterable<T>... iterables ); static Iterable<TO> map( Function<? super FROM, TO> function, Iterable<FROM> from ); static Iterable<T> iterable( Enumeration<T> enumeration ); static Iterable<T> iterable( C... items ); static Iterable<T> cast( Iterable<C> iterable ); static Function<FROM, TO> cast(); static TO fold( Function<? super FROM, TO> function, Iterable<? extends FROM> i ); static Iterable<T> prepend( final C item, final Iterable<T> iterable ); static Iterable<T> append( final C item, final Iterable<T> iterable ); static Iterable<T> debug( String format, final Iterable<T> iterable, final Function<T, String>... functions ); static Iterable<T> cache(Iterable<T> iterable); static List<T> toList( Iterable<T> iterable ); static Object[] toArray(Iterable<Object> iterable); static T[] toArray(Class<T> componentType, Iterable<T> iterable); }
@Test public void testTRUE() { Assert.assertThat( Specifications.<Object>TRUE().satisfiedBy( new Object() ), equalTo( true ) ); }
public static <T> Specification<T> TRUE() { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return true; } }; }
Specifications { public static <T> Specification<T> TRUE() { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return true; } }; } }
Specifications { public static <T> Specification<T> TRUE() { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return true; } }; } }
Specifications { public static <T> Specification<T> TRUE() { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return true; } }; } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
Specifications { public static <T> Specification<T> TRUE() { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return true; } }; } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
@Test public void testNot() { Assert.assertThat( Specifications.not( Specifications.<Object>TRUE() ) .satisfiedBy( new Object() ), equalTo( false ) ); }
public static <T> Specification<T> not( final Specification<T> specification ) { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return !specification.satisfiedBy( instance ); } }; }
Specifications { public static <T> Specification<T> not( final Specification<T> specification ) { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return !specification.satisfiedBy( instance ); } }; } }
Specifications { public static <T> Specification<T> not( final Specification<T> specification ) { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return !specification.satisfiedBy( instance ); } }; } }
Specifications { public static <T> Specification<T> not( final Specification<T> specification ) { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return !specification.satisfiedBy( instance ); } }; } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
Specifications { public static <T> Specification<T> not( final Specification<T> specification ) { return new Specification<T>() { public boolean satisfiedBy( T instance ) { return !specification.satisfiedBy( instance ); } }; } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
@Test public void testAnd() { Specification<Object> trueSpec = Specifications.<Object>TRUE(); Specification<Object> falseSpec = Specifications.not( Specifications.<Object>TRUE() ); Assert.assertThat( Specifications.and( falseSpec, falseSpec ).satisfiedBy( new Object() ), equalTo( false ) ); Assert.assertThat( Specifications.and( trueSpec, falseSpec ).satisfiedBy( new Object() ), equalTo( false ) ); Assert.assertThat( Specifications.and( falseSpec, trueSpec ).satisfiedBy( new Object() ), equalTo( false ) ); Assert.assertThat( Specifications.and( trueSpec, trueSpec ).satisfiedBy( new Object() ), equalTo( true ) ); }
public static <T> AndSpecification<T> and( final Specification<T>... specifications ) { return and( Iterables.iterable( specifications )); }
Specifications { public static <T> AndSpecification<T> and( final Specification<T>... specifications ) { return and( Iterables.iterable( specifications )); } }
Specifications { public static <T> AndSpecification<T> and( final Specification<T>... specifications ) { return and( Iterables.iterable( specifications )); } }
Specifications { public static <T> AndSpecification<T> and( final Specification<T>... specifications ) { return and( Iterables.iterable( specifications )); } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
Specifications { public static <T> AndSpecification<T> and( final Specification<T>... specifications ) { return and( Iterables.iterable( specifications )); } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
@Test public void testOr() { Specification<Object> trueSpec = Specifications.<Object>TRUE(); Specification<Object> falseSpec = Specifications.not( Specifications.<Object>TRUE() ); Assert.assertThat( Specifications.or( falseSpec, falseSpec ).satisfiedBy( new Object() ), equalTo( false ) ); Assert.assertThat( Specifications.or( trueSpec, falseSpec ).satisfiedBy( new Object() ), equalTo( true ) ); Assert.assertThat( Specifications.or( falseSpec, trueSpec ).satisfiedBy( new Object() ), equalTo( true ) ); Assert.assertThat( Specifications.or( trueSpec, trueSpec ).satisfiedBy( new Object() ), equalTo( true ) ); }
public static <T> OrSpecification<T> or( final Specification<T>... specifications ) { return or( Iterables.iterable( specifications ) ); }
Specifications { public static <T> OrSpecification<T> or( final Specification<T>... specifications ) { return or( Iterables.iterable( specifications ) ); } }
Specifications { public static <T> OrSpecification<T> or( final Specification<T>... specifications ) { return or( Iterables.iterable( specifications ) ); } }
Specifications { public static <T> OrSpecification<T> or( final Specification<T>... specifications ) { return or( Iterables.iterable( specifications ) ); } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
Specifications { public static <T> OrSpecification<T> or( final Specification<T>... specifications ) { return or( Iterables.iterable( specifications ) ); } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
@Test public void givenPlainQueryWhenFirstResultIsBeyondFirstElementExpectLimitedResult() { Query<TestComposite> query = module.newQueryBuilder( TestComposite.class ).newQuery( composites ); query.firstResult( 2 ); verifyOrder( query, "3451" ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testIn() { Assert.assertThat( Specifications.in( "1", "2", "3" ).satisfiedBy( "2" ), equalTo( true ) ); Assert.assertThat( Specifications.in( "1", "2", "3" ).satisfiedBy( "4" ), equalTo( false ) ); }
public static <T> Specification<T> in( final T... allowed ) { return in( Iterables.iterable( allowed ) ); }
Specifications { public static <T> Specification<T> in( final T... allowed ) { return in( Iterables.iterable( allowed ) ); } }
Specifications { public static <T> Specification<T> in( final T... allowed ) { return in( Iterables.iterable( allowed ) ); } }
Specifications { public static <T> Specification<T> in( final T... allowed ) { return in( Iterables.iterable( allowed ) ); } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
Specifications { public static <T> Specification<T> in( final T... allowed ) { return in( Iterables.iterable( allowed ) ); } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
@Test public void testTranslate() { Function<Object, String> stringifier = new Function<Object, String>() { @Override public String map( Object s ) { return s.toString(); } }; Assert.assertTrue( Specifications.translate( stringifier, Specifications.in( "3" ) ).satisfiedBy( 3L ) ); }
public static <FROM,TO> Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification) { return new Specification<FROM>() { @Override public boolean satisfiedBy( FROM item ) { return specification.satisfiedBy( function.map( item ) ); } }; }
Specifications { public static <FROM,TO> Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification) { return new Specification<FROM>() { @Override public boolean satisfiedBy( FROM item ) { return specification.satisfiedBy( function.map( item ) ); } }; } }
Specifications { public static <FROM,TO> Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification) { return new Specification<FROM>() { @Override public boolean satisfiedBy( FROM item ) { return specification.satisfiedBy( function.map( item ) ); } }; } }
Specifications { public static <FROM,TO> Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification) { return new Specification<FROM>() { @Override public boolean satisfiedBy( FROM item ) { return specification.satisfiedBy( function.map( item ) ); } }; } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
Specifications { public static <FROM,TO> Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification) { return new Specification<FROM>() { @Override public boolean satisfiedBy( FROM item ) { return specification.satisfiedBy( function.map( item ) ); } }; } static Specification<T> TRUE(); static Specification<T> not( final Specification<T> specification ); static AndSpecification<T> and( final Specification<T>... specifications ); static AndSpecification<T> and( final Iterable<Specification<T>> specifications ); static OrSpecification<T> or( final Specification<T>... specifications ); static OrSpecification<T> or( final Iterable<Specification<T>> specifications ); static Specification<T> in( final T... allowed ); static Specification<T> in( final Iterable<T> allowed ); static Specification<T> notNull(); static Specification<FROM> translate( final Function<FROM,TO> function, final Specification<? super TO> specification); }
@Test public void testCompose() { assertThat( Functions.<Object, String, Integer>compose().map( length, stringifier ).map( 12345L ), equalTo( 5 ) ); assertThat( compose( length, stringifier ).map( 12345L ), equalTo( 5 ) ); }
public static <A,B,C> Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose() { return new Function2<Function<? super B, C>, Function<A, B>, Function<A, C>>() { @Override public Function<A, C> map( Function<? super B, C> bcFunction, Function<A, B> abFunction ) { return compose( bcFunction, abFunction ); } }; }
Functions { public static <A,B,C> Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose() { return new Function2<Function<? super B, C>, Function<A, B>, Function<A, C>>() { @Override public Function<A, C> map( Function<? super B, C> bcFunction, Function<A, B> abFunction ) { return compose( bcFunction, abFunction ); } }; } }
Functions { public static <A,B,C> Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose() { return new Function2<Function<? super B, C>, Function<A, B>, Function<A, C>>() { @Override public Function<A, C> map( Function<? super B, C> bcFunction, Function<A, B> abFunction ) { return compose( bcFunction, abFunction ); } }; } }
Functions { public static <A,B,C> Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose() { return new Function2<Function<? super B, C>, Function<A, B>, Function<A, C>>() { @Override public Function<A, C> map( Function<? super B, C> bcFunction, Function<A, B> abFunction ) { return compose( bcFunction, abFunction ); } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <A,B,C> Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose() { return new Function2<Function<? super B, C>, Function<A, B>, Function<A, C>>() { @Override public Function<A, C> map( Function<? super B, C> bcFunction, Function<A, B> abFunction ) { return compose( bcFunction, abFunction ); } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testFromMap() { Map<String,String> map = new HashMap<String, String>( ); map.put( "A","1" ); map.put( "B","2" ); map.put( "C","3" ); assertThat( Iterables.toList( Iterables.filter( Specifications.notNull(), Iterables.map( Functions.fromMap( map ), Iterables.iterable( "A", "B", "D" ) ) ) ).toString(), equalTo( "[1, 2]" )); }
public static <FROM,TO> Function<FROM,TO> fromMap( final Map<FROM,TO> map) { return new Function<FROM,TO>() { @Override public TO map( FROM from ) { return map.get( from ); } }; }
Functions { public static <FROM,TO> Function<FROM,TO> fromMap( final Map<FROM,TO> map) { return new Function<FROM,TO>() { @Override public TO map( FROM from ) { return map.get( from ); } }; } }
Functions { public static <FROM,TO> Function<FROM,TO> fromMap( final Map<FROM,TO> map) { return new Function<FROM,TO>() { @Override public TO map( FROM from ) { return map.get( from ); } }; } }
Functions { public static <FROM,TO> Function<FROM,TO> fromMap( final Map<FROM,TO> map) { return new Function<FROM,TO>() { @Override public TO map( FROM from ) { return map.get( from ); } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <FROM,TO> Function<FROM,TO> fromMap( final Map<FROM,TO> map) { return new Function<FROM,TO>() { @Override public TO map( FROM from ) { return map.get( from ); } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testWithDefault() { assertThat( Iterables.toList( Iterables.map( Functions.withDefault( "DEFAULT" ), Iterables.iterable( "123", null, "456" ) ) ).toString(), equalTo( "[123, DEFAULT, 456]" ) ); }
public static <T> Function<T,T> withDefault( final T defaultValue) { return new Function<T, T>() { @Override public T map( T from ) { if (from == null) return defaultValue; else return from; } }; }
Functions { public static <T> Function<T,T> withDefault( final T defaultValue) { return new Function<T, T>() { @Override public T map( T from ) { if (from == null) return defaultValue; else return from; } }; } }
Functions { public static <T> Function<T,T> withDefault( final T defaultValue) { return new Function<T, T>() { @Override public T map( T from ) { if (from == null) return defaultValue; else return from; } }; } }
Functions { public static <T> Function<T,T> withDefault( final T defaultValue) { return new Function<T, T>() { @Override public T map( T from ) { if (from == null) return defaultValue; else return from; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <T> Function<T,T> withDefault( final T defaultValue) { return new Function<T, T>() { @Override public T map( T from ) { if (from == null) return defaultValue; else return from; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testLongSum() { assertThat( last( map( longSum(), iterable( 1, 2L, 3F, 4D ) ) ), equalTo( 10L ) ); }
public static final Function<Number, Long> longSum() { return new Function<Number, Long>() { long sum; @Override public Long map( Number number ) { sum += number.longValue(); return sum; } }; }
Functions { public static final Function<Number, Long> longSum() { return new Function<Number, Long>() { long sum; @Override public Long map( Number number ) { sum += number.longValue(); return sum; } }; } }
Functions { public static final Function<Number, Long> longSum() { return new Function<Number, Long>() { long sum; @Override public Long map( Number number ) { sum += number.longValue(); return sum; } }; } }
Functions { public static final Function<Number, Long> longSum() { return new Function<Number, Long>() { long sum; @Override public Long map( Number number ) { sum += number.longValue(); return sum; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static final Function<Number, Long> longSum() { return new Function<Number, Long>() { long sum; @Override public Long map( Number number ) { sum += number.longValue(); return sum; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testIntSum() { assertThat( last( map( intSum(), iterable( 1, 2L, 3F, 4D ) ) ), equalTo( 10 ) ); }
public static Function<Number, Integer> intSum() { return new Function<Number, Integer>() { int sum; @Override public Integer map( Number number ) { sum += number.intValue(); return sum; } }; }
Functions { public static Function<Number, Integer> intSum() { return new Function<Number, Integer>() { int sum; @Override public Integer map( Number number ) { sum += number.intValue(); return sum; } }; } }
Functions { public static Function<Number, Integer> intSum() { return new Function<Number, Integer>() { int sum; @Override public Integer map( Number number ) { sum += number.intValue(); return sum; } }; } }
Functions { public static Function<Number, Integer> intSum() { return new Function<Number, Integer>() { int sum; @Override public Integer map( Number number ) { sum += number.intValue(); return sum; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static Function<Number, Integer> intSum() { return new Function<Number, Integer>() { int sum; @Override public Integer map( Number number ) { sum += number.intValue(); return sum; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testCount() { assertThat( last( map( count( in( "X" ) ), iterable( "X","Y","X","X","Y" ) ) ), equalTo( 3 ) ); }
public static <T> Function<T, Integer> count( final Specification<T> specification) { return new Function<T, Integer>() { int count; @Override public Integer map( T item ) { if (specification.satisfiedBy( item )) count++; return count; } }; }
Functions { public static <T> Function<T, Integer> count( final Specification<T> specification) { return new Function<T, Integer>() { int count; @Override public Integer map( T item ) { if (specification.satisfiedBy( item )) count++; return count; } }; } }
Functions { public static <T> Function<T, Integer> count( final Specification<T> specification) { return new Function<T, Integer>() { int count; @Override public Integer map( T item ) { if (specification.satisfiedBy( item )) count++; return count; } }; } }
Functions { public static <T> Function<T, Integer> count( final Specification<T> specification) { return new Function<T, Integer>() { int count; @Override public Integer map( T item ) { if (specification.satisfiedBy( item )) count++; return count; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <T> Function<T, Integer> count( final Specification<T> specification) { return new Function<T, Integer>() { int count; @Override public Integer map( T item ) { if (specification.satisfiedBy( item )) count++; return count; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testIndexOf() { assertThat( last( map( indexOf( in( "D" ) ), iterable( "A","B","C","D","D" ) ) ), equalTo( 3 ) ); }
public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void testIndexOf2() { assertThat( indexOf( "D", iterable( "A","B","C","D","D" )), equalTo( 3 ) ); }
public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <T> Function<T, Integer> indexOf( final Specification<T> specification) { return new Function<T, Integer>() { int index = -1; int current = 0; @Override public Integer map( T item ) { if (index == -1 && specification.satisfiedBy( item )) index = current; current++; return index; } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void givenWhereQueryWhenWhereClauseLimitsToRangeExpectLimitedResult() { final QueryBuilder<TestComposite> qb = module.newQueryBuilder( TestComposite.class ); TestComposite template = templateFor( TestComposite.class ); Query<TestComposite> query = qb.where( and( ge( template.b(), 3 ), lt( template.b(), 5 ) ) ).newQuery( composites ); verifyOrder( query, "34" ); }
public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
QueryBuilderFactoryImpl implements QueryBuilderFactory { public <T> QueryBuilder<T> newQueryBuilder( final Class<T> resultType ) { NotQueryableException.throwIfNotQueryable( resultType ); final ServiceReference<EntityFinder> serviceReference; try { serviceReference = finder.findService( EntityFinder.class ); return new QueryBuilderImpl<T>( serviceReference.get(), resultType, null ); } catch( IllegalArgumentException e ) { return new QueryBuilderImpl<T>( null, resultType, null ); } } QueryBuilderFactoryImpl( ServiceFinder finder ); QueryBuilder<T> newQueryBuilder( final Class<T> resultType ); }
@Test public void testComparator() { Comparator<Integer> comparator = Functions.comparator( new Function<Integer, Comparable>() { @Override public Comparable map( Integer integer ) { return integer.toString(); } } ); List<Integer> integers = Iterables.toList( Iterables.iterable( 1, 5, 3, 6, 8 ) ); Collections.sort( integers, comparator ); assertThat( integers.toString(), equalTo( "[1, 3, 5, 6, 8]" )); }
public static <T> Comparator<T> comparator( final Function<T, Comparable> comparableFunction) { return new Comparator<T>() { Map<T, Comparable> compareKeys = new HashMap<T, Comparable>(); public int compare( T o1, T o2 ) { Comparable key1 = compareKeys.get( o1 ); if (key1 == null) { key1 = comparableFunction.map( o1 ); compareKeys.put(o1, key1); } Comparable key2 = compareKeys.get( o2 ); if (key2 == null) { key2 = comparableFunction.map( o2 ); compareKeys.put(o2, key2); } return key1.compareTo( key2 ); } }; }
Functions { public static <T> Comparator<T> comparator( final Function<T, Comparable> comparableFunction) { return new Comparator<T>() { Map<T, Comparable> compareKeys = new HashMap<T, Comparable>(); public int compare( T o1, T o2 ) { Comparable key1 = compareKeys.get( o1 ); if (key1 == null) { key1 = comparableFunction.map( o1 ); compareKeys.put(o1, key1); } Comparable key2 = compareKeys.get( o2 ); if (key2 == null) { key2 = comparableFunction.map( o2 ); compareKeys.put(o2, key2); } return key1.compareTo( key2 ); } }; } }
Functions { public static <T> Comparator<T> comparator( final Function<T, Comparable> comparableFunction) { return new Comparator<T>() { Map<T, Comparable> compareKeys = new HashMap<T, Comparable>(); public int compare( T o1, T o2 ) { Comparable key1 = compareKeys.get( o1 ); if (key1 == null) { key1 = comparableFunction.map( o1 ); compareKeys.put(o1, key1); } Comparable key2 = compareKeys.get( o2 ); if (key2 == null) { key2 = comparableFunction.map( o2 ); compareKeys.put(o2, key2); } return key1.compareTo( key2 ); } }; } }
Functions { public static <T> Comparator<T> comparator( final Function<T, Comparable> comparableFunction) { return new Comparator<T>() { Map<T, Comparable> compareKeys = new HashMap<T, Comparable>(); public int compare( T o1, T o2 ) { Comparable key1 = compareKeys.get( o1 ); if (key1 == null) { key1 = comparableFunction.map( o1 ); compareKeys.put(o1, key1); } Comparable key2 = compareKeys.get( o2 ); if (key2 == null) { key2 = comparableFunction.map( o2 ); compareKeys.put(o2, key2); } return key1.compareTo( key2 ); } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
Functions { public static <T> Comparator<T> comparator( final Function<T, Comparable> comparableFunction) { return new Comparator<T>() { Map<T, Comparable> compareKeys = new HashMap<T, Comparable>(); public int compare( T o1, T o2 ) { Comparable key1 = compareKeys.get( o1 ); if (key1 == null) { key1 = comparableFunction.map( o1 ); compareKeys.put(o1, key1); } Comparable key2 = compareKeys.get( o2 ); if (key2 == null) { key2 = comparableFunction.map( o2 ); compareKeys.put(o2, key2); } return key1.compareTo( key2 ); } }; } static Function2<Function<? super B,C>,Function<A,B>, Function<A,C>> compose(); static Function<FROM,TO> compose( final Function<? super MIDDLE,TO> outer, final Function<FROM,MIDDLE> inner); static Function<FROM,TO> identity(); static Function<FROM,TO> fromMap( final Map<FROM,TO> map); static Function<T,T> withDefault( final T defaultValue); static final Function<Number, Long> longSum(); static Function<Number, Integer> intSum(); static Function<T, Integer> count( final Specification<T> specification); static Function<T, Integer> indexOf( final Specification<T> specification); static int indexOf(T item, Iterable<T> iterable); static Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function); static Comparator<T> comparator( final Function<T, Comparable> comparableFunction); }
@Test public void givenManyAssociationContainsQueryWhenExecutedThenReturnCorrect() throws EntityFinderException { QueryBuilder<Person> qb = qbf.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Domain value = Network.domains().iterator().next(); Query<Person> query = qb.where( QueryExpressions.contains( person.interests(), value ) ) .newQuery( Network.persons() ); for (Person person1 : query) { System.out.println( person1.name() ); } verifyOrderedResults( query, "Joe Doe", "Vivian Smith" ); }
@Override public <T> Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ) { return list(resultType, whereClause, orderBySegments, firstResult, maxResults, variables).iterator(); }
IterableQuerySource implements QuerySource { @Override public <T> Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ) { return list(resultType, whereClause, orderBySegments, firstResult, maxResults, variables).iterator(); } }
IterableQuerySource implements QuerySource { @Override public <T> Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ) { return list(resultType, whereClause, orderBySegments, firstResult, maxResults, variables).iterator(); } IterableQuerySource( final Iterable iterable ); }
IterableQuerySource implements QuerySource { @Override public <T> Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ) { return list(resultType, whereClause, orderBySegments, firstResult, maxResults, variables).iterator(); } IterableQuerySource( final Iterable iterable ); @Override T find( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ); @Override long count( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ); @Override Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ); }
IterableQuerySource implements QuerySource { @Override public <T> Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ) { return list(resultType, whereClause, orderBySegments, firstResult, maxResults, variables).iterator(); } IterableQuerySource( final Iterable iterable ); @Override T find( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ); @Override long count( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ); @Override Iterator<T> iterator( Class<T> resultType, Specification<Composite> whereClause, Iterable<OrderBy> orderBySegments, Integer firstResult, Integer maxResults, Map<String, Object> variables ); }
@Test public void whenAskingForDependencyGivenThatGraphContainsCyclicDepThenDetectTheError() throws Exception { Thing thing1 = new Thing(); Thing thing2 = new Thing(); Thing thing3 = new Thing(); Thing thing4 = new Thing(); Thing thing5 = new Thing(); Thing thing6 = new Thing(); Thing thing7 = new Thing(); thing1.uses.add( thing3 ); thing2.uses.add( thing3 ); thing3.uses.add( thing4 ); thing4.uses.add( thing5 ); thing5.uses.add( thing1 ); thing1.uses.add( thing6 ); thing7.uses.add( thing1 ); thing7.uses.add( thing2 ); thing7.uses.add( thing4 ); List<Thing> data = new ArrayList<Thing>(); data.add( thing7 ); data.add( thing4 ); data.add( thing1 ); data.add( thing3 ); data.add( thing6 ); data.add( thing5 ); data.add( thing2 ); randomize( data ); UsageGraph<Thing> deps = new UsageGraph<Thing>( data, new Userator(), false ); try { List<Thing> resolved = deps.resolveOrder(); Assert.fail( "Cyclic Dependency Not Detected." ); } catch( BindingException e ) { } }
public List<K> resolveOrder() throws BindingException { if( resolved == null ) { buildUsageGraph(); resolved = new LinkedList<K>(); for( K item : data ) { int pos = resolved.size(); for( K entry : resolved ) { if( transitiveUse( entry, item ) ) { pos = resolved.indexOf( entry ); break; } } resolved.add( pos, item ); } } return resolved; }
UsageGraph { public List<K> resolveOrder() throws BindingException { if( resolved == null ) { buildUsageGraph(); resolved = new LinkedList<K>(); for( K item : data ) { int pos = resolved.size(); for( K entry : resolved ) { if( transitiveUse( entry, item ) ) { pos = resolved.indexOf( entry ); break; } } resolved.add( pos, item ); } } return resolved; } }
UsageGraph { public List<K> resolveOrder() throws BindingException { if( resolved == null ) { buildUsageGraph(); resolved = new LinkedList<K>(); for( K item : data ) { int pos = resolved.size(); for( K entry : resolved ) { if( transitiveUse( entry, item ) ) { pos = resolved.indexOf( entry ); break; } } resolved.add( pos, item ); } } return resolved; } UsageGraph( Collection<K> data, Use<K> use, boolean allowCyclic ); }
UsageGraph { public List<K> resolveOrder() throws BindingException { if( resolved == null ) { buildUsageGraph(); resolved = new LinkedList<K>(); for( K item : data ) { int pos = resolved.size(); for( K entry : resolved ) { if( transitiveUse( entry, item ) ) { pos = resolved.indexOf( entry ); break; } } resolved.add( pos, item ); } } return resolved; } UsageGraph( Collection<K> data, Use<K> use, boolean allowCyclic ); boolean transitiveUse( K source, K other ); void invalidate(); List<K> resolveOrder(); }
UsageGraph { public List<K> resolveOrder() throws BindingException { if( resolved == null ) { buildUsageGraph(); resolved = new LinkedList<K>(); for( K item : data ) { int pos = resolved.size(); for( K entry : resolved ) { if( transitiveUse( entry, item ) ) { pos = resolved.indexOf( entry ); break; } } resolved.add( pos, item ); } } return resolved; } UsageGraph( Collection<K> data, Use<K> use, boolean allowCyclic ); boolean transitiveUse( K source, K other ); void invalidate(); List<K> resolveOrder(); }
@Test public void whenAskingForResolveOrderGivenThatGraphContainsCyclicDepThenDetectTheError() throws Exception { Thing thing1 = new Thing(); Thing thing2 = new Thing(); Thing thing3 = new Thing(); Thing thing4 = new Thing(); Thing thing5 = new Thing(); Thing thing6 = new Thing(); Thing thing7 = new Thing(); thing1.uses.add( thing3 ); thing2.uses.add( thing3 ); thing3.uses.add( thing4 ); thing4.uses.add( thing5 ); thing5.uses.add( thing1 ); thing1.uses.add( thing6 ); thing7.uses.add( thing1 ); thing7.uses.add( thing2 ); thing7.uses.add( thing4 ); List<Thing> data = new ArrayList<Thing>(); data.add( thing7 ); data.add( thing4 ); data.add( thing1 ); data.add( thing3 ); data.add( thing6 ); data.add( thing5 ); data.add( thing2 ); randomize( data ); UsageGraph<Thing> deps = new UsageGraph<Thing>( data, new Userator(), false ); try { assertTrue( deps.transitiveUse( thing1, thing3 ) ); Assert.fail( "Cyclic Dependency Not Detected." ); } catch( BindingException e ) { } }
public boolean transitiveUse( K source, K other ) throws BindingException { if( transitive == null ) { buildUsageGraph(); } return transitive.containsKey( source ) && transitive.get( source ).contains( other ); }
UsageGraph { public boolean transitiveUse( K source, K other ) throws BindingException { if( transitive == null ) { buildUsageGraph(); } return transitive.containsKey( source ) && transitive.get( source ).contains( other ); } }
UsageGraph { public boolean transitiveUse( K source, K other ) throws BindingException { if( transitive == null ) { buildUsageGraph(); } return transitive.containsKey( source ) && transitive.get( source ).contains( other ); } UsageGraph( Collection<K> data, Use<K> use, boolean allowCyclic ); }
UsageGraph { public boolean transitiveUse( K source, K other ) throws BindingException { if( transitive == null ) { buildUsageGraph(); } return transitive.containsKey( source ) && transitive.get( source ).contains( other ); } UsageGraph( Collection<K> data, Use<K> use, boolean allowCyclic ); boolean transitiveUse( K source, K other ); void invalidate(); List<K> resolveOrder(); }
UsageGraph { public boolean transitiveUse( K source, K other ) throws BindingException { if( transitive == null ) { buildUsageGraph(); } return transitive.containsKey( source ) && transitive.get( source ).contains( other ); } UsageGraph( Collection<K> data, Use<K> use, boolean allowCyclic ); boolean transitiveUse( K source, K other ); void invalidate(); List<K> resolveOrder(); }
@Test public void testInvoke() throws Throwable { JRubyComposite domain = module.newTransientBuilder( JRubyComposite.class ).newInstance(); Assert.assertEquals( "do1() in Ruby mixin.", domain.do1() ); }
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { Class declaringClass = method.getDeclaringClass(); IRubyObject rubyObject = rubyObjects.get( declaringClass ); if( rubyObject == null ) { try { rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } catch( RaiseException e ) { if( e.getException() instanceof RubyNameError ) { String script = getFunction( method ); runtime.evalScriptlet( script ); rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } else { throw e; } } IRubyObject meRuby = JavaEmbedUtils.javaToRuby( runtime, me ); RubyClass rubyClass = meRuby.getMetaClass(); if( !rubyClass.isFrozen() ) { SetterDynamicMethod setter = new SetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); GetterDynamicMethod getter = new GetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); Method[] compositeMethods = me.getClass().getInterfaces()[ 0 ].getMethods(); for( Method compositeMethod : compositeMethods ) { if( Property.class.isAssignableFrom( compositeMethod.getReturnType() ) ) { rubyClass.addMethod( compositeMethod.getName() + "=", setter ); rubyClass.addMethod( compositeMethod.getName(), getter ); } } rubyClass.freeze( ThreadContext.newContext( runtime ) ); } RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); rubyObjectAdapter.setInstanceVariable( rubyObject, "@this", meRuby ); rubyObjects.put( declaringClass, rubyObject ); } IRubyObject rubyResult; if( args != null ) { IRubyObject[] rubyArgs = new IRubyObject[args.length]; for( int i = 0; i < args.length; i++ ) { Object arg = args[ i ]; rubyArgs[ i ] = JavaEmbedUtils.javaToRuby( runtime, arg ); } rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName(), rubyArgs ); } else { rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName() ); } Object result = JavaEmbedUtils.rubyToJava( runtime, rubyResult, method.getReturnType() ); return result; } catch( Exception e ) { e.printStackTrace(); throw e; } }
JRubyMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { Class declaringClass = method.getDeclaringClass(); IRubyObject rubyObject = rubyObjects.get( declaringClass ); if( rubyObject == null ) { try { rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } catch( RaiseException e ) { if( e.getException() instanceof RubyNameError ) { String script = getFunction( method ); runtime.evalScriptlet( script ); rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } else { throw e; } } IRubyObject meRuby = JavaEmbedUtils.javaToRuby( runtime, me ); RubyClass rubyClass = meRuby.getMetaClass(); if( !rubyClass.isFrozen() ) { SetterDynamicMethod setter = new SetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); GetterDynamicMethod getter = new GetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); Method[] compositeMethods = me.getClass().getInterfaces()[ 0 ].getMethods(); for( Method compositeMethod : compositeMethods ) { if( Property.class.isAssignableFrom( compositeMethod.getReturnType() ) ) { rubyClass.addMethod( compositeMethod.getName() + "=", setter ); rubyClass.addMethod( compositeMethod.getName(), getter ); } } rubyClass.freeze( ThreadContext.newContext( runtime ) ); } RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); rubyObjectAdapter.setInstanceVariable( rubyObject, "@this", meRuby ); rubyObjects.put( declaringClass, rubyObject ); } IRubyObject rubyResult; if( args != null ) { IRubyObject[] rubyArgs = new IRubyObject[args.length]; for( int i = 0; i < args.length; i++ ) { Object arg = args[ i ]; rubyArgs[ i ] = JavaEmbedUtils.javaToRuby( runtime, arg ); } rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName(), rubyArgs ); } else { rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName() ); } Object result = JavaEmbedUtils.rubyToJava( runtime, rubyResult, method.getReturnType() ); return result; } catch( Exception e ) { e.printStackTrace(); throw e; } } }
JRubyMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { Class declaringClass = method.getDeclaringClass(); IRubyObject rubyObject = rubyObjects.get( declaringClass ); if( rubyObject == null ) { try { rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } catch( RaiseException e ) { if( e.getException() instanceof RubyNameError ) { String script = getFunction( method ); runtime.evalScriptlet( script ); rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } else { throw e; } } IRubyObject meRuby = JavaEmbedUtils.javaToRuby( runtime, me ); RubyClass rubyClass = meRuby.getMetaClass(); if( !rubyClass.isFrozen() ) { SetterDynamicMethod setter = new SetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); GetterDynamicMethod getter = new GetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); Method[] compositeMethods = me.getClass().getInterfaces()[ 0 ].getMethods(); for( Method compositeMethod : compositeMethods ) { if( Property.class.isAssignableFrom( compositeMethod.getReturnType() ) ) { rubyClass.addMethod( compositeMethod.getName() + "=", setter ); rubyClass.addMethod( compositeMethod.getName(), getter ); } } rubyClass.freeze( ThreadContext.newContext( runtime ) ); } RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); rubyObjectAdapter.setInstanceVariable( rubyObject, "@this", meRuby ); rubyObjects.put( declaringClass, rubyObject ); } IRubyObject rubyResult; if( args != null ) { IRubyObject[] rubyArgs = new IRubyObject[args.length]; for( int i = 0; i < args.length; i++ ) { Object arg = args[ i ]; rubyArgs[ i ] = JavaEmbedUtils.javaToRuby( runtime, arg ); } rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName(), rubyArgs ); } else { rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName() ); } Object result = JavaEmbedUtils.rubyToJava( runtime, rubyResult, method.getReturnType() ); return result; } catch( Exception e ) { e.printStackTrace(); throw e; } } }
JRubyMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { Class declaringClass = method.getDeclaringClass(); IRubyObject rubyObject = rubyObjects.get( declaringClass ); if( rubyObject == null ) { try { rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } catch( RaiseException e ) { if( e.getException() instanceof RubyNameError ) { String script = getFunction( method ); runtime.evalScriptlet( script ); rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } else { throw e; } } IRubyObject meRuby = JavaEmbedUtils.javaToRuby( runtime, me ); RubyClass rubyClass = meRuby.getMetaClass(); if( !rubyClass.isFrozen() ) { SetterDynamicMethod setter = new SetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); GetterDynamicMethod getter = new GetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); Method[] compositeMethods = me.getClass().getInterfaces()[ 0 ].getMethods(); for( Method compositeMethod : compositeMethods ) { if( Property.class.isAssignableFrom( compositeMethod.getReturnType() ) ) { rubyClass.addMethod( compositeMethod.getName() + "=", setter ); rubyClass.addMethod( compositeMethod.getName(), getter ); } } rubyClass.freeze( ThreadContext.newContext( runtime ) ); } RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); rubyObjectAdapter.setInstanceVariable( rubyObject, "@this", meRuby ); rubyObjects.put( declaringClass, rubyObject ); } IRubyObject rubyResult; if( args != null ) { IRubyObject[] rubyArgs = new IRubyObject[args.length]; for( int i = 0; i < args.length; i++ ) { Object arg = args[ i ]; rubyArgs[ i ] = JavaEmbedUtils.javaToRuby( runtime, arg ); } rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName(), rubyArgs ); } else { rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName() ); } Object result = JavaEmbedUtils.rubyToJava( runtime, rubyResult, method.getReturnType() ); return result; } catch( Exception e ) { e.printStackTrace(); throw e; } } Object invoke( Object proxy, Method method, Object[] args ); void reloadScripts(); }
JRubyMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { Class declaringClass = method.getDeclaringClass(); IRubyObject rubyObject = rubyObjects.get( declaringClass ); if( rubyObject == null ) { try { rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } catch( RaiseException e ) { if( e.getException() instanceof RubyNameError ) { String script = getFunction( method ); runtime.evalScriptlet( script ); rubyObject = runtime.evalScriptlet( declaringClass.getSimpleName() + ".new()" ); } else { throw e; } } IRubyObject meRuby = JavaEmbedUtils.javaToRuby( runtime, me ); RubyClass rubyClass = meRuby.getMetaClass(); if( !rubyClass.isFrozen() ) { SetterDynamicMethod setter = new SetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); GetterDynamicMethod getter = new GetterDynamicMethod( runtime.getObjectSpaceModule(), Visibility.PUBLIC, null ); Method[] compositeMethods = me.getClass().getInterfaces()[ 0 ].getMethods(); for( Method compositeMethod : compositeMethods ) { if( Property.class.isAssignableFrom( compositeMethod.getReturnType() ) ) { rubyClass.addMethod( compositeMethod.getName() + "=", setter ); rubyClass.addMethod( compositeMethod.getName(), getter ); } } rubyClass.freeze( ThreadContext.newContext( runtime ) ); } RubyObjectAdapter rubyObjectAdapter = JavaEmbedUtils.newObjectAdapter(); rubyObjectAdapter.setInstanceVariable( rubyObject, "@this", meRuby ); rubyObjects.put( declaringClass, rubyObject ); } IRubyObject rubyResult; if( args != null ) { IRubyObject[] rubyArgs = new IRubyObject[args.length]; for( int i = 0; i < args.length; i++ ) { Object arg = args[ i ]; rubyArgs[ i ] = JavaEmbedUtils.javaToRuby( runtime, arg ); } rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName(), rubyArgs ); } else { rubyResult = rubyObject.callMethod( runtime.getCurrentContext(), method.getName() ); } Object result = JavaEmbedUtils.rubyToJava( runtime, rubyResult, method.getReturnType() ); return result; } catch( Exception e ) { e.printStackTrace(); throw e; } } Object invoke( Object proxy, Method method, Object[] args ); void reloadScripts(); }
@Test public void testInvoke() { GroovyComposite domain1 = module.newTransient( GroovyComposite.class ); GroovyComposite domain2 = module.newTransient( GroovyComposite.class ); Assert.assertEquals( "do1() in Groovy:1", domain1.do1() ); Assert.assertEquals( "do1() in Groovy:2", domain1.do1() ); Assert.assertEquals( "do1() in Groovy:3", domain1.do1() ); Assert.assertEquals( "do1() in Groovy:4", domain1.do1() ); Assert.assertEquals( "do1() in Groovy:1", domain2.do1() ); Assert.assertEquals( "do1() in Groovy:2", domain2.do1() ); Assert.assertEquals( "do1() in Groovy:3", domain2.do1() ); Assert.assertEquals( "do1() in Groovy:4", domain2.do1() ); Assert.assertEquals( "do1() in Groovy:5", domain2.do1() ); Assert.assertEquals( "do1() in Groovy:6", domain2.do1() ); Assert.assertEquals( "do1() in Groovy:5", domain1.do1() ); }
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { final FunctionResource groovySource = getFunctionResource( method ); if( groovySource != null ) { if( groovySource.script ) { return invokeAsObject( method, args, groovySource.url ); } return invokeAsScript( method, args, groovySource.url ); } throw new RuntimeException( "Internal error: Mixin invoked even if it does not apply" ); }
GroovyMixin implements InvocationHandler { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { final FunctionResource groovySource = getFunctionResource( method ); if( groovySource != null ) { if( groovySource.script ) { return invokeAsObject( method, args, groovySource.url ); } return invokeAsScript( method, args, groovySource.url ); } throw new RuntimeException( "Internal error: Mixin invoked even if it does not apply" ); } }
GroovyMixin implements InvocationHandler { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { final FunctionResource groovySource = getFunctionResource( method ); if( groovySource != null ) { if( groovySource.script ) { return invokeAsObject( method, args, groovySource.url ); } return invokeAsScript( method, args, groovySource.url ); } throw new RuntimeException( "Internal error: Mixin invoked even if it does not apply" ); } GroovyMixin(); }
GroovyMixin implements InvocationHandler { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { final FunctionResource groovySource = getFunctionResource( method ); if( groovySource != null ) { if( groovySource.script ) { return invokeAsObject( method, args, groovySource.url ); } return invokeAsScript( method, args, groovySource.url ); } throw new RuntimeException( "Internal error: Mixin invoked even if it does not apply" ); } GroovyMixin(); Object invoke( Object proxy, Method method, Object[] args ); }
GroovyMixin implements InvocationHandler { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { final FunctionResource groovySource = getFunctionResource( method ); if( groovySource != null ) { if( groovySource.script ) { return invokeAsObject( method, args, groovySource.url ); } return invokeAsScript( method, args, groovySource.url ); } throw new RuntimeException( "Internal error: Mixin invoked even if it does not apply" ); } GroovyMixin(); Object invoke( Object proxy, Method method, Object[] args ); }
@Test public void testInvoke() throws Throwable { JavaScriptComposite domain = module.newTransient( JavaScriptComposite.class ); Assert.assertEquals( "do1 script \" and ' for many cases is harder.", domain.do1() ); }
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Context cx = Context.enter(); try { Scriptable proxyScope = Context.toObject( proxy, instanceScope ); proxyScope.setPrototype( instanceScope ); proxyScope.put( "compositeBuilderFactory", proxyScope, factory ); proxyScope.put( "This", proxyScope, me ); Function fn = getFunction( cx, proxyScope, method ); Object result = fn.call( cx, instanceScope, proxyScope, args ); if( result instanceof Undefined ) { return null; } else if( result instanceof Wrapper ) { return ( (Wrapper) result ).unwrap(); } else { return result; } } finally { Context.exit(); } }
JavaScriptMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Context cx = Context.enter(); try { Scriptable proxyScope = Context.toObject( proxy, instanceScope ); proxyScope.setPrototype( instanceScope ); proxyScope.put( "compositeBuilderFactory", proxyScope, factory ); proxyScope.put( "This", proxyScope, me ); Function fn = getFunction( cx, proxyScope, method ); Object result = fn.call( cx, instanceScope, proxyScope, args ); if( result instanceof Undefined ) { return null; } else if( result instanceof Wrapper ) { return ( (Wrapper) result ).unwrap(); } else { return result; } } finally { Context.exit(); } } }
JavaScriptMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Context cx = Context.enter(); try { Scriptable proxyScope = Context.toObject( proxy, instanceScope ); proxyScope.setPrototype( instanceScope ); proxyScope.put( "compositeBuilderFactory", proxyScope, factory ); proxyScope.put( "This", proxyScope, me ); Function fn = getFunction( cx, proxyScope, method ); Object result = fn.call( cx, instanceScope, proxyScope, args ); if( result instanceof Undefined ) { return null; } else if( result instanceof Wrapper ) { return ( (Wrapper) result ).unwrap(); } else { return result; } } finally { Context.exit(); } } JavaScriptMixin(); }
JavaScriptMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Context cx = Context.enter(); try { Scriptable proxyScope = Context.toObject( proxy, instanceScope ); proxyScope.setPrototype( instanceScope ); proxyScope.put( "compositeBuilderFactory", proxyScope, factory ); proxyScope.put( "This", proxyScope, me ); Function fn = getFunction( cx, proxyScope, method ); Object result = fn.call( cx, instanceScope, proxyScope, args ); if( result instanceof Undefined ) { return null; } else if( result instanceof Wrapper ) { return ( (Wrapper) result ).unwrap(); } else { return result; } } finally { Context.exit(); } } JavaScriptMixin(); Object invoke( Object proxy, Method method, Object[] args ); void reloadScripts(); }
JavaScriptMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Context cx = Context.enter(); try { Scriptable proxyScope = Context.toObject( proxy, instanceScope ); proxyScope.setPrototype( instanceScope ); proxyScope.put( "compositeBuilderFactory", proxyScope, factory ); proxyScope.put( "This", proxyScope, me ); Function fn = getFunction( cx, proxyScope, method ); Object result = fn.call( cx, instanceScope, proxyScope, args ); if( result instanceof Undefined ) { return null; } else if( result instanceof Wrapper ) { return ( (Wrapper) result ).unwrap(); } else { return result; } } finally { Context.exit(); } } JavaScriptMixin(); Object invoke( Object proxy, Method method, Object[] args ); void reloadScripts(); }
@Test public void testInvoke() throws Throwable { BeanShellComposite domain1 = module.newTransient( BeanShellComposite.class ); BeanShellComposite domain2 = module.newTransient( BeanShellComposite.class ); Assert.assertEquals( "do1() in Beanshell:1", domain1.do1() ); Assert.assertEquals( "do1() in Beanshell:2", domain1.do1() ); Assert.assertEquals( "do1() in Beanshell:3", domain1.do1() ); Assert.assertEquals( "do1() in Beanshell:4", domain1.do1() ); Assert.assertEquals( "do1() in Beanshell:1", domain2.do1() ); Assert.assertEquals( "do1() in Beanshell:2", domain2.do1() ); Assert.assertEquals( "do1() in Beanshell:3", domain2.do1() ); Assert.assertEquals( "do1() in Beanshell:4", domain2.do1() ); Assert.assertEquals( "do1() in Beanshell:5", domain2.do1() ); Assert.assertEquals( "do1() in Beanshell:6", domain2.do1() ); Assert.assertEquals( "do1() in Beanshell:5", domain1.do1() ); }
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Interpreter runtime; synchronized( BeanShellMixin.class ) { runtime = runtimes.get( module ); } if( runtime == null ) { runtime = new Interpreter(); BshClassManager.createClassManager( runtime ); Class compositeType = me.getClass().getInterfaces()[ 0 ]; NameSpace namespace = buildNamespace( compositeType, runtime ); runtime.setNameSpace( namespace ); synchronized( BeanShellMixin.class ) { runtimes.put( module, runtime ); } runtime.set( "compositeBuilderFactory", compositeBuilderFactory ); runtime.set( "unitOfWorkFactory", uowFactory ); } if( mixins == null ) { mixins = extractMixins( runtime.getClassManager() ); } Object instance = mixins.get( method.getDeclaringClass() ); return method.invoke( instance, args ); }
BeanShellMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Interpreter runtime; synchronized( BeanShellMixin.class ) { runtime = runtimes.get( module ); } if( runtime == null ) { runtime = new Interpreter(); BshClassManager.createClassManager( runtime ); Class compositeType = me.getClass().getInterfaces()[ 0 ]; NameSpace namespace = buildNamespace( compositeType, runtime ); runtime.setNameSpace( namespace ); synchronized( BeanShellMixin.class ) { runtimes.put( module, runtime ); } runtime.set( "compositeBuilderFactory", compositeBuilderFactory ); runtime.set( "unitOfWorkFactory", uowFactory ); } if( mixins == null ) { mixins = extractMixins( runtime.getClassManager() ); } Object instance = mixins.get( method.getDeclaringClass() ); return method.invoke( instance, args ); } }
BeanShellMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Interpreter runtime; synchronized( BeanShellMixin.class ) { runtime = runtimes.get( module ); } if( runtime == null ) { runtime = new Interpreter(); BshClassManager.createClassManager( runtime ); Class compositeType = me.getClass().getInterfaces()[ 0 ]; NameSpace namespace = buildNamespace( compositeType, runtime ); runtime.setNameSpace( namespace ); synchronized( BeanShellMixin.class ) { runtimes.put( module, runtime ); } runtime.set( "compositeBuilderFactory", compositeBuilderFactory ); runtime.set( "unitOfWorkFactory", uowFactory ); } if( mixins == null ) { mixins = extractMixins( runtime.getClassManager() ); } Object instance = mixins.get( method.getDeclaringClass() ); return method.invoke( instance, args ); } }
BeanShellMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Interpreter runtime; synchronized( BeanShellMixin.class ) { runtime = runtimes.get( module ); } if( runtime == null ) { runtime = new Interpreter(); BshClassManager.createClassManager( runtime ); Class compositeType = me.getClass().getInterfaces()[ 0 ]; NameSpace namespace = buildNamespace( compositeType, runtime ); runtime.setNameSpace( namespace ); synchronized( BeanShellMixin.class ) { runtimes.put( module, runtime ); } runtime.set( "compositeBuilderFactory", compositeBuilderFactory ); runtime.set( "unitOfWorkFactory", uowFactory ); } if( mixins == null ) { mixins = extractMixins( runtime.getClassManager() ); } Object instance = mixins.get( method.getDeclaringClass() ); return method.invoke( instance, args ); } Object invoke( Object proxy, Method method, Object[] args ); void reloadScripts(); }
BeanShellMixin implements InvocationHandler, ScriptReloadable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { Interpreter runtime; synchronized( BeanShellMixin.class ) { runtime = runtimes.get( module ); } if( runtime == null ) { runtime = new Interpreter(); BshClassManager.createClassManager( runtime ); Class compositeType = me.getClass().getInterfaces()[ 0 ]; NameSpace namespace = buildNamespace( compositeType, runtime ); runtime.setNameSpace( namespace ); synchronized( BeanShellMixin.class ) { runtimes.put( module, runtime ); } runtime.set( "compositeBuilderFactory", compositeBuilderFactory ); runtime.set( "unitOfWorkFactory", uowFactory ); } if( mixins == null ) { mixins = extractMixins( runtime.getClassManager() ); } Object instance = mixins.get( method.getDeclaringClass() ); return method.invoke( instance, args ); } Object invoke( Object proxy, Method method, Object[] args ); void reloadScripts(); }
@Test public void testRouter() throws IOException { final List<DomainEventValue> matched = new ArrayList<DomainEventValue>( ); EventRouter<IOException> router = new EventRouter<IOException>(); router.route( Events.withNames( "Test1", "Test2" ), new Receiver<DomainEventValue,IOException>() { @Override public void receive( DomainEventValue item ) throws IOException { matched.add(item); } }); Inputs.iterable( Events.events( list ) ).transferTo( router ); Assert.assertThat(matched.toString(), CoreMatchers.equalTo( "[{\"name\":\"Test1\",\"entityType\":\"Foo\",\"entityId\":\"123\",\"parameters\":\"{}\"}, {\"name\":\"Test2\",\"entityType\":\"Foo\",\"entityId\":\"123\",\"parameters\":\"{}\"}]" )); }
public EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ) { routeEvent.put( specification, receiver ); return this; }
EventRouter implements Output<DomainEventValue, T>, Receiver<UnitOfWorkDomainEventsValue, T> { public EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ) { routeEvent.put( specification, receiver ); return this; } }
EventRouter implements Output<DomainEventValue, T>, Receiver<UnitOfWorkDomainEventsValue, T> { public EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ) { routeEvent.put( specification, receiver ); return this; } }
EventRouter implements Output<DomainEventValue, T>, Receiver<UnitOfWorkDomainEventsValue, T> { public EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ) { routeEvent.put( specification, receiver ); return this; } EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ); EventRouter defaultReceiver( Receiver<DomainEventValue, T> defaultReceiver ); @Override void receiveFrom( Sender<? extends DomainEventValue, SenderThrowableType> sender ); @Override void receive( final UnitOfWorkDomainEventsValue item ); }
EventRouter implements Output<DomainEventValue, T>, Receiver<UnitOfWorkDomainEventsValue, T> { public EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ) { routeEvent.put( specification, receiver ); return this; } EventRouter route( Specification<DomainEventValue> specification, Receiver<DomainEventValue, T> receiver ); EventRouter defaultReceiver( Receiver<DomainEventValue, T> defaultReceiver ); @Override void receiveFrom( Sender<? extends DomainEventValue, SenderThrowableType> sender ); @Override void receive( final UnitOfWorkDomainEventsValue item ); }
@Test public void testIterablesEvents() { assertThat( count( events( list ) ), equalTo( 6L ) ); iterable( events( list ) ).transferTo( systemOut() ); }
public static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ) { return Iterables.flattenIterables( Iterables.map( new Function<UnitOfWorkDomainEventsValue, Iterable<DomainEventValue>>() { @Override public Iterable<DomainEventValue> map( UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue ) { return unitOfWorkDomainEventsValue.events().get(); } }, transactions ) ); }
Events { public static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ) { return Iterables.flattenIterables( Iterables.map( new Function<UnitOfWorkDomainEventsValue, Iterable<DomainEventValue>>() { @Override public Iterable<DomainEventValue> map( UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue ) { return unitOfWorkDomainEventsValue.events().get(); } }, transactions ) ); } }
Events { public static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ) { return Iterables.flattenIterables( Iterables.map( new Function<UnitOfWorkDomainEventsValue, Iterable<DomainEventValue>>() { @Override public Iterable<DomainEventValue> map( UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue ) { return unitOfWorkDomainEventsValue.events().get(); } }, transactions ) ); } }
Events { public static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ) { return Iterables.flattenIterables( Iterables.map( new Function<UnitOfWorkDomainEventsValue, Iterable<DomainEventValue>>() { @Override public Iterable<DomainEventValue> map( UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue ) { return unitOfWorkDomainEventsValue.events().get(); } }, transactions ) ); } static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ); static Iterable<DomainEventValue> events( UnitOfWorkDomainEventsValue... unitOfWorkDomainValues ); static Specification<UnitOfWorkDomainEventsValue> afterDate( final Date afterDate ); static Specification<UnitOfWorkDomainEventsValue> beforeDate( final Date afterDate ); static Specification<UnitOfWorkDomainEventsValue> withUsecases( final String... names ); static Specification<UnitOfWorkDomainEventsValue> byUser( final String... by ); static Specification<DomainEventValue> withNames( final Iterable<String> names ); static Specification<DomainEventValue> withNames( final String... names ); static Specification<DomainEventValue> withNames( final Class eventClass ); static Specification<DomainEventValue> onEntities( final String... entities ); static Specification<DomainEventValue> onEntityTypes( final String... entityTypes ); static Specification<DomainEventValue> paramIs( final String name, final String value ); }
Events { public static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ) { return Iterables.flattenIterables( Iterables.map( new Function<UnitOfWorkDomainEventsValue, Iterable<DomainEventValue>>() { @Override public Iterable<DomainEventValue> map( UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue ) { return unitOfWorkDomainEventsValue.events().get(); } }, transactions ) ); } static Iterable<DomainEventValue> events( Iterable<UnitOfWorkDomainEventsValue> transactions ); static Iterable<DomainEventValue> events( UnitOfWorkDomainEventsValue... unitOfWorkDomainValues ); static Specification<UnitOfWorkDomainEventsValue> afterDate( final Date afterDate ); static Specification<UnitOfWorkDomainEventsValue> beforeDate( final Date afterDate ); static Specification<UnitOfWorkDomainEventsValue> withUsecases( final String... names ); static Specification<UnitOfWorkDomainEventsValue> byUser( final String... by ); static Specification<DomainEventValue> withNames( final Iterable<String> names ); static Specification<DomainEventValue> withNames( final String... names ); static Specification<DomainEventValue> withNames( final Class eventClass ); static Specification<DomainEventValue> onEntities( final String... entities ); static Specification<DomainEventValue> onEntityTypes( final String... entityTypes ); static Specification<DomainEventValue> paramIs( final String name, final String value ); }
@Test public void testEntityTypeSerializer() throws RDFHandlerException { EntityDescriptor entityDescriptor = module.entityDescriptor(TestEntity.class.getName()); Iterable<Statement> graph = serializer.serialize( entityDescriptor ); String[] prefixes = new String[]{ "rdf", "dc", " vc", "qi4j" }; String[] namespaces = new String[]{ Rdfs.RDF, DcRdf.NAMESPACE, "http: new RdfXmlSerializer().serialize( graph, new PrintWriter( System.out ), prefixes, namespaces ); }
public EntityTypeSerializer() { dataTypes.put( String.class.getName(), XMLSchema.STRING ); dataTypes.put( Integer.class.getName(), XMLSchema.INT ); dataTypes.put( Boolean.class.getName(), XMLSchema.BOOLEAN ); dataTypes.put( Byte.class.getName(), XMLSchema.BYTE ); dataTypes.put( BigDecimal.class.getName(), XMLSchema.DECIMAL ); dataTypes.put( Double.class.getName(), XMLSchema.DOUBLE ); dataTypes.put( Long.class.getName(), XMLSchema.LONG ); dataTypes.put( Short.class.getName(), XMLSchema.SHORT ); dataTypes.put( Date.class.getName(), XMLSchema.DATETIME ); }
EntityTypeSerializer { public EntityTypeSerializer() { dataTypes.put( String.class.getName(), XMLSchema.STRING ); dataTypes.put( Integer.class.getName(), XMLSchema.INT ); dataTypes.put( Boolean.class.getName(), XMLSchema.BOOLEAN ); dataTypes.put( Byte.class.getName(), XMLSchema.BYTE ); dataTypes.put( BigDecimal.class.getName(), XMLSchema.DECIMAL ); dataTypes.put( Double.class.getName(), XMLSchema.DOUBLE ); dataTypes.put( Long.class.getName(), XMLSchema.LONG ); dataTypes.put( Short.class.getName(), XMLSchema.SHORT ); dataTypes.put( Date.class.getName(), XMLSchema.DATETIME ); } }
EntityTypeSerializer { public EntityTypeSerializer() { dataTypes.put( String.class.getName(), XMLSchema.STRING ); dataTypes.put( Integer.class.getName(), XMLSchema.INT ); dataTypes.put( Boolean.class.getName(), XMLSchema.BOOLEAN ); dataTypes.put( Byte.class.getName(), XMLSchema.BYTE ); dataTypes.put( BigDecimal.class.getName(), XMLSchema.DECIMAL ); dataTypes.put( Double.class.getName(), XMLSchema.DOUBLE ); dataTypes.put( Long.class.getName(), XMLSchema.LONG ); dataTypes.put( Short.class.getName(), XMLSchema.SHORT ); dataTypes.put( Date.class.getName(), XMLSchema.DATETIME ); } EntityTypeSerializer(); }
EntityTypeSerializer { public EntityTypeSerializer() { dataTypes.put( String.class.getName(), XMLSchema.STRING ); dataTypes.put( Integer.class.getName(), XMLSchema.INT ); dataTypes.put( Boolean.class.getName(), XMLSchema.BOOLEAN ); dataTypes.put( Byte.class.getName(), XMLSchema.BYTE ); dataTypes.put( BigDecimal.class.getName(), XMLSchema.DECIMAL ); dataTypes.put( Double.class.getName(), XMLSchema.DOUBLE ); dataTypes.put( Long.class.getName(), XMLSchema.LONG ); dataTypes.put( Short.class.getName(), XMLSchema.SHORT ); dataTypes.put( Date.class.getName(), XMLSchema.DATETIME ); } EntityTypeSerializer(); Iterable<Statement> serialize( final EntityDescriptor entityDescriptor ); }
EntityTypeSerializer { public EntityTypeSerializer() { dataTypes.put( String.class.getName(), XMLSchema.STRING ); dataTypes.put( Integer.class.getName(), XMLSchema.INT ); dataTypes.put( Boolean.class.getName(), XMLSchema.BOOLEAN ); dataTypes.put( Byte.class.getName(), XMLSchema.BYTE ); dataTypes.put( BigDecimal.class.getName(), XMLSchema.DECIMAL ); dataTypes.put( Double.class.getName(), XMLSchema.DOUBLE ); dataTypes.put( Long.class.getName(), XMLSchema.LONG ); dataTypes.put( Short.class.getName(), XMLSchema.SHORT ); dataTypes.put( Date.class.getName(), XMLSchema.DATETIME ); } EntityTypeSerializer(); Iterable<Statement> serialize( final EntityDescriptor entityDescriptor ); }
@Test public void findParameterizedType() { assertEquals( GarbageMan.class.getGenericInterfaces()[ 0 ], ParameterizedTypes.findParameterizedType( GarbageMan.class, HandlerOf.class ) ); }
public static <S, T extends S> ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( (Type) type, searchType ); }
ParameterizedTypes { public static <S, T extends S> ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( (Type) type, searchType ); } }
ParameterizedTypes { public static <S, T extends S> ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( (Type) type, searchType ); } private ParameterizedTypes(); }
ParameterizedTypes { public static <S, T extends S> ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( (Type) type, searchType ); } private ParameterizedTypes(); static Type[] findTypeVariables( Class<T> type, Class<S> searchType ); static ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ); }
ParameterizedTypes { public static <S, T extends S> ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( (Type) type, searchType ); } private ParameterizedTypes(); static Type[] findTypeVariables( Class<T> type, Class<S> searchType ); static ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ); }
@Test public void findTypeVariables() { assertArrayEquals( ((ParameterizedType) GarbageMan.class.getGenericInterfaces()[0]).getActualTypeArguments(), ParameterizedTypes.findTypeVariables( GarbageMan.class, HandlerOf.class ) ); }
public static <S, T extends S> Type[] findTypeVariables( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( type, searchType ).getActualTypeArguments(); }
ParameterizedTypes { public static <S, T extends S> Type[] findTypeVariables( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( type, searchType ).getActualTypeArguments(); } }
ParameterizedTypes { public static <S, T extends S> Type[] findTypeVariables( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( type, searchType ).getActualTypeArguments(); } private ParameterizedTypes(); }
ParameterizedTypes { public static <S, T extends S> Type[] findTypeVariables( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( type, searchType ).getActualTypeArguments(); } private ParameterizedTypes(); static Type[] findTypeVariables( Class<T> type, Class<S> searchType ); static ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ); }
ParameterizedTypes { public static <S, T extends S> Type[] findTypeVariables( Class<T> type, Class<S> searchType ) { return ParameterizedTypes.findParameterizedType( type, searchType ).getActualTypeArguments(); } private ParameterizedTypes(); static Type[] findTypeVariables( Class<T> type, Class<S> searchType ); static ParameterizedType findParameterizedType( Class<T> type, Class<S> searchType ); }
@Test @Ignore( "The entire QRM is buggered." ) public void testInitializer() throws Exception { final DBInitializerConfiguration info = derbyDatabaseHandler.createDbInitializerConfigMock(); final DBInitializer initializer = new DBInitializer(); Properties connectionProperties = info.connectionProperties().get(); String schemaUrl = info.schemaUrl().get(); String dataUrl = info.dataUrl().get(); String dbUrl = info.dbUrl().get(); initializer.initialize( schemaUrl, dataUrl, dbUrl, connectionProperties ); derbyDatabaseHandler.checkDataInitialization(); }
public final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ) throws SQLException, IOException { Connection connection1 = getSqlConnection( dbUrl, connectionProperties ); runScript( schemaUrl, connection1 ); Connection connection2 = getSqlConnection( dbUrl, connectionProperties ); runScript( dataUrl, connection2 ); }
DBInitializer implements Serializable { public final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ) throws SQLException, IOException { Connection connection1 = getSqlConnection( dbUrl, connectionProperties ); runScript( schemaUrl, connection1 ); Connection connection2 = getSqlConnection( dbUrl, connectionProperties ); runScript( dataUrl, connection2 ); } }
DBInitializer implements Serializable { public final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ) throws SQLException, IOException { Connection connection1 = getSqlConnection( dbUrl, connectionProperties ); runScript( schemaUrl, connection1 ); Connection connection2 = getSqlConnection( dbUrl, connectionProperties ); runScript( dataUrl, connection2 ); } }
DBInitializer implements Serializable { public final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ) throws SQLException, IOException { Connection connection1 = getSqlConnection( dbUrl, connectionProperties ); runScript( schemaUrl, connection1 ); Connection connection2 = getSqlConnection( dbUrl, connectionProperties ); runScript( dataUrl, connection2 ); } final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ); }
DBInitializer implements Serializable { public final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ) throws SQLException, IOException { Connection connection1 = getSqlConnection( dbUrl, connectionProperties ); runScript( schemaUrl, connection1 ); Connection connection2 = getSqlConnection( dbUrl, connectionProperties ); runScript( dataUrl, connection2 ); } final void initialize( String schemaUrl, String dataUrl, String dbUrl, Properties connectionProperties ); }
@Test public void convertToUpperCase() { assertEquals( "identity -> ID", "ID", converter.convertIdentifier( QualifiedName.fromQN( "abc:identity" ) ) ); assertEquals( "uppercase ABC", "ABC", converter.convertIdentifier( QualifiedName.fromQN( "abc:abc" ) ) ); assertEquals( "removed qualified prefix", "ABC", converter.convertIdentifier( QualifiedName.fromQN( "aaa:abc" ) ) ); assertEquals( "removed qualified prefixes", "ABC", converter.convertIdentifier( QualifiedName.fromQN( "aaa:bbb:abc" ) ) ); }
public String convertIdentifier( final QualifiedName qualifiedIdentifier ) { final String name = qualifiedIdentifier.name(); if( name.equalsIgnoreCase( "identity" ) ) { return "ID"; } return name.toUpperCase(); }
CapitalizingIdentifierConverter implements IdentifierConverter { public String convertIdentifier( final QualifiedName qualifiedIdentifier ) { final String name = qualifiedIdentifier.name(); if( name.equalsIgnoreCase( "identity" ) ) { return "ID"; } return name.toUpperCase(); } }
CapitalizingIdentifierConverter implements IdentifierConverter { public String convertIdentifier( final QualifiedName qualifiedIdentifier ) { final String name = qualifiedIdentifier.name(); if( name.equalsIgnoreCase( "identity" ) ) { return "ID"; } return name.toUpperCase(); } }
CapitalizingIdentifierConverter implements IdentifierConverter { public String convertIdentifier( final QualifiedName qualifiedIdentifier ) { final String name = qualifiedIdentifier.name(); if( name.equalsIgnoreCase( "identity" ) ) { return "ID"; } return name.toUpperCase(); } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
CapitalizingIdentifierConverter implements IdentifierConverter { public String convertIdentifier( final QualifiedName qualifiedIdentifier ) { final String name = qualifiedIdentifier.name(); if( name.equalsIgnoreCase( "identity" ) ) { return "ID"; } return name.toUpperCase(); } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
@Test public void removeFromMap() { Map<String, Object> rawData = new HashMap<String, Object>(); rawData.put( "ABC", "test" ); assertEquals( "converted key and found value", "test", converter.getValueFromData( rawData, QualifiedName.fromQN( "aaa:abc" ) ) ); assertEquals( "entry removed", 0, rawData.size() ); }
public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
@Test public void nullIfNotFound() { Map<String, Object> rawData = new HashMap<String, Object>(); assertEquals( "converted key and found value", null, converter.getValueFromData( rawData, QualifiedName.fromQN( "aaa:abc" ) ) ); }
public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
CapitalizingIdentifierConverter implements IdentifierConverter { public Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ) { String convertedIdentifier = convertIdentifier( qualifiedName ); if( rawData.containsKey( convertedIdentifier ) ) { return rawData.remove( convertedIdentifier ); } return null; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
@Test public void convertMapKeys() { Map<QualifiedName, Object> rawData = new HashMap<QualifiedName, Object>(); rawData.put( QualifiedName.fromQN( "abc:abc" ), "test1" ); rawData.put( QualifiedName.fromQN( "abc:DEF" ), "test2" ); rawData.put( QualifiedName.fromQN( "aaa:GHI" ), "test3" ); rawData.put( QualifiedName.fromQN( "aaa:bbb:JKL" ), "test4" ); final Map<String, Object> convertedData = converter.convertKeys( rawData ); assertEquals( "all entries remained", 4, convertedData.size() ); assertEquals( "converted key and found value ABC", "test1", convertedData.get( "ABC" ) ); assertEquals( "converted key and found value DEF", "test2", convertedData.get( "DEF" ) ); assertEquals( "converted key and found value GHI", "test3", convertedData.get( "GHI" ) ); assertEquals( "converted key and found value JKL", "test4", convertedData.get( "JKL" ) ); }
public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
@Test( expected = IllegalArgumentException.class ) public void failDuplicateKeys() { Map<QualifiedName, Object> rawData = new HashMap<QualifiedName, Object>(); rawData.put( QualifiedName.fromQN( "abc" ), "test1" ); rawData.put( QualifiedName.fromQN( "ABC" ), "test2" ); converter.convertKeys( rawData ); }
public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
@Test( expected = IllegalArgumentException.class ) public void failDuplicateQualfiedKeys() { Map<QualifiedName, Object> rawData = new HashMap<QualifiedName, Object>(); rawData.put( QualifiedName.fromQN( "abc" ), "test1" ); rawData.put( QualifiedName.fromQN( "aaa:abc" ), "test2" ); converter.convertKeys( rawData ); }
public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
CapitalizingIdentifierConverter implements IdentifierConverter { public Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ) { Map<String, Object> result = new HashMap<String, Object>( rawData.size() ); for( Map.Entry<QualifiedName, Object> entry : rawData.entrySet() ) { final String convertedIdentifier = convertIdentifier( entry.getKey() ); if( result.containsKey( convertedIdentifier ) ) { throw new IllegalArgumentException( format( "Duplicate Key: %s -> %s", entry.getKey(), convertedIdentifier ) ); } result.put( convertedIdentifier, entry.getValue() ); } return result; } String convertIdentifier( final QualifiedName qualifiedIdentifier ); Object getValueFromData( final Map<String, Object> rawData, final QualifiedName qualifiedName ); Map<String, Object> convertKeys( Map<QualifiedName, Object> rawData ); }
@Test void testOpenSDSInfo() { OpenSDSInfo OpenSDSInfo = new OpenSDSInfo("testId", "testHostName", "testPort"); OpenSDSInfo.hashCode(); OpenSDSInfo.getHostName(); OpenSDSInfo.getURL(); OpenSDSInfo.getProductSN(); OpenSDSInfo.toString(); }
public OpenSDSInfo() { super(); }
OpenSDSInfo extends BaseArrayInfo { public OpenSDSInfo() { super(); } }
OpenSDSInfo extends BaseArrayInfo { public OpenSDSInfo() { super(); } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); }
OpenSDSInfo extends BaseArrayInfo { public OpenSDSInfo() { super(); } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); @Override boolean equals(Object obj); @Override int hashCode(); String getProductSN(); void setProductSN(String productSN); boolean getauthEnabled(); void setauthEnabled(boolean authEnabled); void clearAll(); @Override String getURL(); @Override String toString(); }
OpenSDSInfo extends BaseArrayInfo { public OpenSDSInfo() { super(); } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); @Override boolean equals(Object obj); @Override int hashCode(); String getProductSN(); void setProductSN(String productSN); boolean getauthEnabled(); void setauthEnabled(boolean authEnabled); void clearAll(); @Override String getURL(); @Override String toString(); }
@Test void testEqualsObject() { OpenSDSInfo OpenSDSInfo = new OpenSDSInfo("testId", "testHostName", "testPort"); OpenSDSInfo obj = new OpenSDSInfo("testId", "testHostName", "testPort"); OpenSDSInfo.equals(obj); }
@Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); @Override boolean equals(Object obj); @Override int hashCode(); String getProductSN(); void setProductSN(String productSN); boolean getauthEnabled(); void setauthEnabled(boolean authEnabled); void clearAll(); @Override String getURL(); @Override String toString(); }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); @Override boolean equals(Object obj); @Override int hashCode(); String getProductSN(); void setProductSN(String productSN); boolean getauthEnabled(); void setauthEnabled(boolean authEnabled); void clearAll(); @Override String getURL(); @Override String toString(); }
@Test void testNotEqualsObject() { OpenSDSInfo OpenSDSInfo = new OpenSDSInfo(); OpenSDSInfo obj = new OpenSDSInfo("testId", "testHostName", "testPort"); OpenSDSInfo.equals(obj); }
@Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); @Override boolean equals(Object obj); @Override int hashCode(); String getProductSN(); void setProductSN(String productSN); boolean getauthEnabled(); void setauthEnabled(boolean authEnabled); void clearAll(); @Override String getURL(); @Override String toString(); }
OpenSDSInfo extends BaseArrayInfo { @Override public boolean equals(Object obj) { if (obj instanceof OpenSDSInfo) { OpenSDSInfo openSDSInfo = (OpenSDSInfo) obj; if (openSDSInfo.getId().equals(getId())) { return true; } } return false; } OpenSDSInfo(); OpenSDSInfo(String id, String hostName, String port); @Override boolean equals(Object obj); @Override int hashCode(); String getProductSN(); void setProductSN(String productSN); boolean getauthEnabled(); void setauthEnabled(boolean authEnabled); void clearAll(); @Override String getURL(); @Override String toString(); }
@Test void testCreateVolume() throws Exception { readDefaultConfig(); VolumeService volumeService = new VolumeService(); volumeService.createVolume(arrayInfo, "test_script_vol", "test_script_vol", 1, profileId); }
public void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); log.info("Volume " + volume.id + "is created"); }
VolumeService { public void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); log.info("Volume " + volume.id + "is created"); } }
VolumeService { public void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); log.info("Volume " + volume.id + "is created"); } }
VolumeService { public void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); log.info("Volume " + volume.id + "is created"); } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
VolumeService { public void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); log.info("Volume " + volume.id + "is created"); } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
@Test void testcreateAndAttachVolume() throws Exception { VolumeService volumeService = new VolumeService(); readDefaultConfig(); volumeService.createAndAttachVolume(arrayInfo, "attach_vol", "attach volume test", 1, profileId, esxIP, esxIQN); }
public String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); TimeUnit.SECONDS.sleep(10); ConnectMO connect = new ConnectMO(hostIP, HOST_OS_TYPE.ESXI, iqn, hostIP, null, ATTACH_MODE.RW, ATTACH_PROTOCOL.ISCSI); opensds.attachVolume(volume.id, connect); String volume_wwn = opensds.getVolumeWWN(volume.id); return volume_wwn; }
VolumeService { public String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); TimeUnit.SECONDS.sleep(10); ConnectMO connect = new ConnectMO(hostIP, HOST_OS_TYPE.ESXI, iqn, hostIP, null, ATTACH_MODE.RW, ATTACH_PROTOCOL.ISCSI); opensds.attachVolume(volume.id, connect); String volume_wwn = opensds.getVolumeWWN(volume.id); return volume_wwn; } }
VolumeService { public String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); TimeUnit.SECONDS.sleep(10); ConnectMO connect = new ConnectMO(hostIP, HOST_OS_TYPE.ESXI, iqn, hostIP, null, ATTACH_MODE.RW, ATTACH_PROTOCOL.ISCSI); opensds.attachVolume(volume.id, connect); String volume_wwn = opensds.getVolumeWWN(volume.id); return volume_wwn; } }
VolumeService { public String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); TimeUnit.SECONDS.sleep(10); ConnectMO connect = new ConnectMO(hostIP, HOST_OS_TYPE.ESXI, iqn, hostIP, null, ATTACH_MODE.RW, ATTACH_PROTOCOL.ISCSI); opensds.attachVolume(volume.id, connect); String volume_wwn = opensds.getVolumeWWN(volume.id); return volume_wwn; } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
VolumeService { public String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); VolumeMO volume = opensds.createVolume(name, description, capacity, profile); TimeUnit.SECONDS.sleep(10); ConnectMO connect = new ConnectMO(hostIP, HOST_OS_TYPE.ESXI, iqn, hostIP, null, ATTACH_MODE.RW, ATTACH_PROTOCOL.ISCSI); opensds.attachVolume(volume.id, connect); String volume_wwn = opensds.getVolumeWWN(volume.id); return volume_wwn; } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
@Test void testDeleteVolume() throws Exception { VolumeService volumeService = new VolumeService(); readDefaultConfig(); volumeService.deleteVolume(arrayInfo, volId); }
public void deleteVolume(OpenSDSInfo openSDSInfo, String id) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.deleteVolume(id); log.info("Volume " + id + "is deleted"); }
VolumeService { public void deleteVolume(OpenSDSInfo openSDSInfo, String id) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.deleteVolume(id); log.info("Volume " + id + "is deleted"); } }
VolumeService { public void deleteVolume(OpenSDSInfo openSDSInfo, String id) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.deleteVolume(id); log.info("Volume " + id + "is deleted"); } }
VolumeService { public void deleteVolume(OpenSDSInfo openSDSInfo, String id) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.deleteVolume(id); log.info("Volume " + id + "is deleted"); } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
VolumeService { public void deleteVolume(OpenSDSInfo openSDSInfo, String id) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.deleteVolume(id); log.info("Volume " + id + "is deleted"); } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
@Test void testexpandVolume() throws Exception { VolumeService volumeService = new VolumeService(); readDefaultConfig(); volumeService.expandVolume(arrayInfo, volId, 2); }
public void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.expandVolume(id, capacity); }
VolumeService { public void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.expandVolume(id, capacity); } }
VolumeService { public void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.expandVolume(id, capacity); } }
VolumeService { public void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.expandVolume(id, capacity); } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
VolumeService { public void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity) throws Exception { OpenSDS opensds = new OpenSDS(); opensds.login(openSDSInfo); log.info("Logged in to OpenSDS"); opensds.expandVolume(id, capacity); } void createVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile); void deleteVolume(OpenSDSInfo openSDSInfo, String id); String createAndAttachVolume(OpenSDSInfo openSDSInfo, String name, String description, long capacity, String profile, String hostIP, String iqn); void expandVolume(OpenSDSInfo openSDSInfo, String id, long capacity); }
@Test void testRegister() throws Exception { Configuration conf = new Configuration("testID", "opensds"); conf.register("OpenSDS_Test", "127.0.0.1", "50040", "admin", "opensds@123", true, "V1"); }
public void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel) throws Exception { String uniqId = hostname + "-" + port; OpenSDSInfo arrayInfo = new OpenSDSInfo(uniqId, hostname, port); arrayInfo.setArrayName(arrayName); arrayInfo.setHostName(hostname); arrayInfo.setPort(port); arrayInfo.setUsername(username); arrayInfo.setPassword(password); arrayInfo.setauthEnabled(authEnabled); arrayInfo.setProductModel(productModel); if (LOG.isInfoEnabled()) { LOG.info("register:::" + arrayInfo); } OpenSDS opensds = new OpenSDS(); opensds.login(arrayInfo); StorageMO storage = opensds.getDeviceInfo(); arrayInfo.setProductName(storage.name); arrayInfo.setProductVersion("V1"); arrayInfo.setProductSN(storage.sn); OpenSDSStorageRepository.getUniqueInstance().updateProperties(arrayInfo, OpenSDSStorageRepository.ADD); }
Configuration { public void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel) throws Exception { String uniqId = hostname + "-" + port; OpenSDSInfo arrayInfo = new OpenSDSInfo(uniqId, hostname, port); arrayInfo.setArrayName(arrayName); arrayInfo.setHostName(hostname); arrayInfo.setPort(port); arrayInfo.setUsername(username); arrayInfo.setPassword(password); arrayInfo.setauthEnabled(authEnabled); arrayInfo.setProductModel(productModel); if (LOG.isInfoEnabled()) { LOG.info("register:::" + arrayInfo); } OpenSDS opensds = new OpenSDS(); opensds.login(arrayInfo); StorageMO storage = opensds.getDeviceInfo(); arrayInfo.setProductName(storage.name); arrayInfo.setProductVersion("V1"); arrayInfo.setProductSN(storage.sn); OpenSDSStorageRepository.getUniqueInstance().updateProperties(arrayInfo, OpenSDSStorageRepository.ADD); } }
Configuration { public void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel) throws Exception { String uniqId = hostname + "-" + port; OpenSDSInfo arrayInfo = new OpenSDSInfo(uniqId, hostname, port); arrayInfo.setArrayName(arrayName); arrayInfo.setHostName(hostname); arrayInfo.setPort(port); arrayInfo.setUsername(username); arrayInfo.setPassword(password); arrayInfo.setauthEnabled(authEnabled); arrayInfo.setProductModel(productModel); if (LOG.isInfoEnabled()) { LOG.info("register:::" + arrayInfo); } OpenSDS opensds = new OpenSDS(); opensds.login(arrayInfo); StorageMO storage = opensds.getDeviceInfo(); arrayInfo.setProductName(storage.name); arrayInfo.setProductVersion("V1"); arrayInfo.setProductSN(storage.sn); OpenSDSStorageRepository.getUniqueInstance().updateProperties(arrayInfo, OpenSDSStorageRepository.ADD); } Configuration(String id, String name); }
Configuration { public void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel) throws Exception { String uniqId = hostname + "-" + port; OpenSDSInfo arrayInfo = new OpenSDSInfo(uniqId, hostname, port); arrayInfo.setArrayName(arrayName); arrayInfo.setHostName(hostname); arrayInfo.setPort(port); arrayInfo.setUsername(username); arrayInfo.setPassword(password); arrayInfo.setauthEnabled(authEnabled); arrayInfo.setProductModel(productModel); if (LOG.isInfoEnabled()) { LOG.info("register:::" + arrayInfo); } OpenSDS opensds = new OpenSDS(); opensds.login(arrayInfo); StorageMO storage = opensds.getDeviceInfo(); arrayInfo.setProductName(storage.name); arrayInfo.setProductVersion("V1"); arrayInfo.setProductSN(storage.sn); OpenSDSStorageRepository.getUniqueInstance().updateProperties(arrayInfo, OpenSDSStorageRepository.ADD); } Configuration(String id, String name); String getId(); void setId(String id); String getName(); void setName(String name); String test(); void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel); void unregister(OpenSDSInfo opensdsInfo); void debugOn(); void debugOff(); List<OpenSDSInfo> getOpenSDSInfos(); }
Configuration { public void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel) throws Exception { String uniqId = hostname + "-" + port; OpenSDSInfo arrayInfo = new OpenSDSInfo(uniqId, hostname, port); arrayInfo.setArrayName(arrayName); arrayInfo.setHostName(hostname); arrayInfo.setPort(port); arrayInfo.setUsername(username); arrayInfo.setPassword(password); arrayInfo.setauthEnabled(authEnabled); arrayInfo.setProductModel(productModel); if (LOG.isInfoEnabled()) { LOG.info("register:::" + arrayInfo); } OpenSDS opensds = new OpenSDS(); opensds.login(arrayInfo); StorageMO storage = opensds.getDeviceInfo(); arrayInfo.setProductName(storage.name); arrayInfo.setProductVersion("V1"); arrayInfo.setProductSN(storage.sn); OpenSDSStorageRepository.getUniqueInstance().updateProperties(arrayInfo, OpenSDSStorageRepository.ADD); } Configuration(String id, String name); String getId(); void setId(String id); String getName(); void setName(String name); String test(); void register(String arrayName, String hostname, String port, String username, String password, boolean authEnabled, String productModel); void unregister(OpenSDSInfo opensdsInfo); void debugOn(); void debugOff(); List<OpenSDSInfo> getOpenSDSInfos(); }