@Test public void getRepository() { final LocalDhisResourceRepository<?> r1 = container.getRepository( TrackedEntityInstance.class, teiLocalDhisRepositoryPersistCallback ); final LocalDhisResourceRepository<?> r2 = container.getRepository( TrackedEntityInstance.class, teiLocalDhisRepositoryPersistCallback ); final LocalDhisResourceRepository<?> r3 = container.getRepository( Enrollment.class, enrollmentLocalDhisRepositoryPersistCallback ); Assert.assertSame( r1, r2 ); Assert.assertNotSame( r1, r3 ); }
@Nonnull @Override @SuppressWarnings( "unchecked" ) public <T extends DhisResource> LocalDhisResourceRepository<T> getRepository( @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ) { if ( !supportedResourceClasses.contains( resourceClass ) ) { throw new IllegalArgumentException( "Resource class is not supported: " + resourceClass ); } final RepositoryItem<? extends DhisResource> repositoryItem = repositoryItems.computeIfAbsent( resourceClass, rc -> new RepositoryItem<>( new LocalDhisResourceRepositoryImpl<>( resourceClass ), persistCallback ) ); return (LocalDhisResourceRepository<T>) repositoryItem.getResourceRepository(); }
LocalDhisResourceRepositoryContainerImpl implements LocalDhisResourceRepositoryContainer { @Nonnull @Override @SuppressWarnings( "unchecked" ) public <T extends DhisResource> LocalDhisResourceRepository<T> getRepository( @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ) { if ( !supportedResourceClasses.contains( resourceClass ) ) { throw new IllegalArgumentException( "Resource class is not supported: " + resourceClass ); } final RepositoryItem<? extends DhisResource> repositoryItem = repositoryItems.computeIfAbsent( resourceClass, rc -> new RepositoryItem<>( new LocalDhisResourceRepositoryImpl<>( resourceClass ), persistCallback ) ); return (LocalDhisResourceRepository<T>) repositoryItem.getResourceRepository(); } }
LocalDhisResourceRepositoryContainerImpl implements LocalDhisResourceRepositoryContainer { @Nonnull @Override @SuppressWarnings( "unchecked" ) public <T extends DhisResource> LocalDhisResourceRepository<T> getRepository( @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ) { if ( !supportedResourceClasses.contains( resourceClass ) ) { throw new IllegalArgumentException( "Resource class is not supported: " + resourceClass ); } final RepositoryItem<? extends DhisResource> repositoryItem = repositoryItems.computeIfAbsent( resourceClass, rc -> new RepositoryItem<>( new LocalDhisResourceRepositoryImpl<>( resourceClass ), persistCallback ) ); return (LocalDhisResourceRepository<T>) repositoryItem.getResourceRepository(); } LocalDhisResourceRepositoryContainerImpl( @Nonnull Set<Class<? extends DhisResource>> supportedResourceClasses ); }
LocalDhisResourceRepositoryContainerImpl implements LocalDhisResourceRepositoryContainer { @Nonnull @Override @SuppressWarnings( "unchecked" ) public <T extends DhisResource> LocalDhisResourceRepository<T> getRepository( @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ) { if ( !supportedResourceClasses.contains( resourceClass ) ) { throw new IllegalArgumentException( "Resource class is not supported: " + resourceClass ); } final RepositoryItem<? extends DhisResource> repositoryItem = repositoryItems.computeIfAbsent( resourceClass, rc -> new RepositoryItem<>( new LocalDhisResourceRepositoryImpl<>( resourceClass ), persistCallback ) ); return (LocalDhisResourceRepository<T>) repositoryItem.getResourceRepository(); } LocalDhisResourceRepositoryContainerImpl( @Nonnull Set<Class<? extends DhisResource>> supportedResourceClasses ); @Nonnull @Override @SuppressWarnings( "unchecked" ) LocalDhisResourceRepository<T> getRepository(
        @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ); @Override void apply( @Nonnull LocalDhisRepositoryResultCallback resultCallback ); }
LocalDhisResourceRepositoryContainerImpl implements LocalDhisResourceRepositoryContainer { @Nonnull @Override @SuppressWarnings( "unchecked" ) public <T extends DhisResource> LocalDhisResourceRepository<T> getRepository( @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ) { if ( !supportedResourceClasses.contains( resourceClass ) ) { throw new IllegalArgumentException( "Resource class is not supported: " + resourceClass ); } final RepositoryItem<? extends DhisResource> repositoryItem = repositoryItems.computeIfAbsent( resourceClass, rc -> new RepositoryItem<>( new LocalDhisResourceRepositoryImpl<>( resourceClass ), persistCallback ) ); return (LocalDhisResourceRepository<T>) repositoryItem.getResourceRepository(); } LocalDhisResourceRepositoryContainerImpl( @Nonnull Set<Class<? extends DhisResource>> supportedResourceClasses ); @Nonnull @Override @SuppressWarnings( "unchecked" ) LocalDhisResourceRepository<T> getRepository(
        @Nonnull Class<T> resourceClass, @Nonnull LocalDhisRepositoryPersistCallback<T> persistCallback ); @Override void apply( @Nonnull LocalDhisRepositoryResultCallback resultCallback );  }