
com.cedarsoft.utils.CachingChildDetector Maven / Gradle / Ivy
The newest version!
package com.cedarsoft.utils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.WeakHashMap;
/**
* Special implementation of a child detector that always returns the same list for a given parent.
*/
public abstract class CachingChildDetector extends AbstractChildDetector
{
@NotNull
private final Cache
> childrenCache = new HashedCache
>( new WeakHashMap
>(), new Cache.Factory
>() {
@NotNull
public List extends C> create( @NotNull P key ) {
return createChildren( key );
}
} );
@NotNull
protected abstract List extends C> createChildren( @NotNull P parent );
@NotNull
public final List extends C> findChildren( @NotNull P parent ) {
return childrenCache.get( parent );
}
public void handleModified( @NotNull P parent ) {
invalidateCache( parent );
}
public void invalidateCache( @NotNull P parent ) {
childrenCache.remove( parent );
notifyChildrenChangedFor( parent );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy