1   package org.apache.commons.jcs3.engine;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import java.util.Arrays;
23  import java.util.Objects;
24  
25  import org.apache.commons.jcs3.engine.behavior.ICacheElementSerialized;
26  import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
27  
28  
29  public class CacheElementSerialized<K, V>
30      extends CacheElement<K, V>
31      implements ICacheElementSerialized<K, V>
32  {
33      
34      private static final long serialVersionUID = -7265084818647601874L;
35  
36      
37      private final byte[] serializedValue;
38  
39      
40  
41  
42  
43  
44  
45  
46  
47      public CacheElementSerialized( final String cacheNameArg, final K keyArg, final byte[] serializedValueArg,
48                                     final IElementAttributes elementAttributesArg )
49      {
50          super(cacheNameArg, keyArg, null, elementAttributesArg);
51          this.serializedValue = serializedValueArg;
52      }
53  
54      
55      @Override
56      public byte[] getSerializedValue()
57      {
58          return this.serializedValue;
59      }
60  
61      
62  
63  
64  
65      @Override
66      public boolean equals(final Object obj)
67      {
68          if (this == obj)
69          {
70              return true;
71          }
72          if (!(obj instanceof CacheElementSerialized))
73          {
74              return false;
75          }
76          final CacheElementSerialized<?,?> other = (CacheElementSerialized<?,?>) obj;
77          return Objects.equals(getKey(), other.getKey());
78      }
79  
80      
81  
82  
83  
84  
85      @Override
86      public String toString()
87      {
88          final StringBuilder buf = new StringBuilder();
89          buf.append( "\n CacheElementSerialized: " );
90          buf.append( "\n CacheName = [" + getCacheName() + "]" );
91          buf.append( "\n Key = [" + getKey() + "]" );
92          buf.append( "\n SerializedValue = " + Arrays.toString(getSerializedValue()) );
93          buf.append( "\n ElementAttributes = " + getElementAttributes() );
94          return buf.toString();
95      }
96  
97  }