@ -31,88 +31,62 @@ import org.springframework.util.Assert;
@@ -31,88 +31,62 @@ import org.springframework.util.Assert;
* /
public abstract class CacheOperation implements BasicOperation {
private String name = "" ;
private final String name ;
private Set < String > cacheNames = Collections . emptySet ( ) ;
private final Set < String > cacheNames ;
private String key = "" ;
private final String key ;
private String keyGenerator = "" ;
private final String keyGenerator ;
private String cacheManager = "" ;
private final String cacheManager ;
private String cacheResolver = "" ;
private final String cacheResolver ;
private String condition = "" ;
private final String condition ;
private final String toString ;
public void setName ( String name ) {
Assert . hasText ( name ) ;
this . name = name ;
protected CacheOperation ( Builder b ) {
this . name = b . name ;
this . cacheNames = b . cacheNames ;
this . key = b . key ;
this . keyGenerator = b . keyGenerator ;
this . cacheManager = b . cacheManager ;
this . cacheResolver = b . cacheResolver ;
this . condition = b . condition ;
this . toString = b . getOperationDescription ( ) . toString ( ) ;
}
public String getName ( ) {
return this . name ;
}
public void setCacheName ( String cacheName ) {
Assert . hasText ( cacheName ) ;
this . cacheNames = Collections . singleton ( cacheName ) ;
}
public void setCacheNames ( String . . . cacheNames ) {
this . cacheNames = new LinkedHashSet < String > ( cacheNames . length ) ;
for ( String cacheName : cacheNames ) {
Assert . hasText ( cacheName , "Cache name must be non-null if specified" ) ;
this . cacheNames . add ( cacheName ) ;
}
}
@Override
public Set < String > getCacheNames ( ) {
return this . cacheNames ;
}
public void setKey ( String key ) {
Assert . notNull ( key ) ;
this . key = key ;
}
public String getKey ( ) {
return this . key ;
}
public void setKeyGenerator ( String keyGenerator ) {
Assert . notNull ( keyGenerator ) ;
this . keyGenerator = keyGenerator ;
}
public String getKeyGenerator ( ) {
return this . keyGenerator ;
}
public void setCacheManager ( String cacheManager ) {
Assert . notNull ( cacheManager ) ;
this . cacheManager = cacheManager ;
}
public String getCacheManager ( ) {
return this . cacheManager ;
}
public void setCacheResolver ( String cacheResolver ) {
Assert . notNull ( this . cacheManager ) ;
this . cacheResolver = cacheResolver ;
}
public String getCacheResolver ( ) {
return this . cacheResolver ;
}
public void setCondition ( String condition ) {
Assert . notNull ( condition ) ;
this . condition = condition ;
}
public String getCondition ( ) {
return this . condition ;
@ -121,6 +95,7 @@ public abstract class CacheOperation implements BasicOperation {
@@ -121,6 +95,7 @@ public abstract class CacheOperation implements BasicOperation {
/ * *
* This implementation compares the { @code toString ( ) } results .
*
* @see # toString ( )
* /
@Override
@ -130,6 +105,7 @@ public abstract class CacheOperation implements BasicOperation {
@@ -130,6 +105,7 @@ public abstract class CacheOperation implements BasicOperation {
/ * *
* This implementation returns { @code toString ( ) } ' s hash code .
*
* @see # toString ( )
* /
@Override
@ -139,29 +115,112 @@ public abstract class CacheOperation implements BasicOperation {
@@ -139,29 +115,112 @@ public abstract class CacheOperation implements BasicOperation {
/ * *
* Return an identifying description for this cache operation .
* < p > Has to be overridden in subclasses for correct { @code equals }
* and { @code hashCode } behavior . Alternatively , { @link # equals }
* and { @link # hashCode } can be overridden themselves .
* < p > Returned value is produced by calling { @link Builder # getOperationDescription ( ) }
* during object construction . This method is used in { # hashCode } and { # equals } .
*
* @see Builder # getOperationDescription ( )
* /
@Override
public String toString ( ) {
return getOperationDescription ( ) . toString ( ) ;
public final String toString ( ) {
return this . toString ;
}
/ * *
* Return an identifying description for this caching operation .
* < p > Available to subclasses , for inclusion in their { @code toString ( ) } result .
* /
protected StringBuilder getOperationDescription ( ) {
StringBuilder result = new StringBuilder ( getClass ( ) . getSimpleName ( ) ) ;
result . append ( "[" ) . append ( this . name ) ;
result . append ( "] caches=" ) . append ( this . cacheNames ) ;
result . append ( " | key='" ) . append ( this . key ) ;
result . append ( "' | keyGenerator='" ) . append ( this . keyGenerator ) ;
result . append ( "' | cacheManager='" ) . append ( this . cacheManager ) ;
result . append ( "' | cacheResolver='" ) . append ( this . cacheResolver ) ;
result . append ( "' | condition='" ) . append ( this . condition ) . append ( "'" ) ;
return result ;
public abstract static class Builder {
private String name = "" ;
private Set < String > cacheNames = Collections . emptySet ( ) ;
private String key = "" ;
private String keyGenerator = "" ;
private String cacheManager = "" ;
private String cacheResolver = "" ;
private String condition = "" ;
public void setName ( String name ) {
Assert . hasText ( name ) ;
this . name = name ;
}
public void setCacheName ( String cacheName ) {
Assert . hasText ( cacheName ) ;
this . cacheNames = Collections . singleton ( cacheName ) ;
}
public void setCacheNames ( String . . . cacheNames ) {
this . cacheNames = new LinkedHashSet < String > ( cacheNames . length ) ;
for ( String cacheName : cacheNames ) {
Assert . hasText ( cacheName , "Cache name must be non-null if specified" ) ;
this . cacheNames . add ( cacheName ) ;
}
}
public Set < String > getCacheNames ( ) {
return this . cacheNames ;
}
public void setKey ( String key ) {
Assert . notNull ( key ) ;
this . key = key ;
}
public String getKey ( ) {
return this . key ;
}
public String getKeyGenerator ( ) {
return this . keyGenerator ;
}
public String getCacheManager ( ) {
return this . cacheManager ;
}
public String getCacheResolver ( ) {
return this . cacheResolver ;
}
public void setKeyGenerator ( String keyGenerator ) {
Assert . notNull ( keyGenerator ) ;
this . keyGenerator = keyGenerator ;
}
public void setCacheManager ( String cacheManager ) {
Assert . notNull ( cacheManager ) ;
this . cacheManager = cacheManager ;
}
public void setCacheResolver ( String cacheResolver ) {
Assert . notNull ( this . cacheManager ) ;
this . cacheResolver = cacheResolver ;
}
public void setCondition ( String condition ) {
Assert . notNull ( condition ) ;
this . condition = condition ;
}
/ * *
* Return an identifying description for this caching operation .
* < p > Available to subclasses , for inclusion in their { @code toString ( ) } result .
* /
protected StringBuilder getOperationDescription ( ) {
StringBuilder result = new StringBuilder ( getClass ( ) . getSimpleName ( ) ) ;
result . append ( "[" ) . append ( this . name ) ;
result . append ( "] caches=" ) . append ( this . cacheNames ) ;
result . append ( " | key='" ) . append ( this . key ) ;
result . append ( "' | keyGenerator='" ) . append ( this . keyGenerator ) ;
result . append ( "' | cacheManager='" ) . append ( this . cacheManager ) ;
result . append ( "' | cacheResolver='" ) . append ( this . cacheResolver ) ;
result . append ( "' | condition='" ) . append ( this . condition ) . append ( "'" ) ;
return result ;
}
public abstract CacheOperation build ( ) ;
}
}