1
2
3
4
5
6
7
8
9
10 package ch.panter.li.bi.asn.api;
11
12 import ch.panter.li.bi.util.ShieldableArrayList;
13 import ch.panter.li.bi.util.ReadOnlyCollection;
14 import ch.panter.li.bi.util.CompareTool;
15 import ch.panter.li.bi.util.HashCodeTool;
16
17 import java.util.Stack;
18
19
20 public final class ValidationInfoImpl implements ValidationInfo
21 {
22
23 public ValidationInfoImpl()
24 {
25 }
26
27 public final ReadOnlyCollection<ValidationItem> getItems()
28 {
29 return items;
30 }
31
32 public final void pushContext( final String context )
33 {
34 contextStack.push( context );
35 }
36
37 public final String getContext()
38 {
39 final StringBuffer ctx = new StringBuffer();
40 for ( final String subContext : contextStack ) {
41 if ( ctx.length() > 0 ) {
42 ctx.append( ": " );
43 }
44 ctx.append( subContext );
45 }
46 return ctx.toString();
47 }
48
49 public final void popContext()
50 {
51 if ( !contextStack.isEmpty() ) {
52 contextStack.pop();
53 }
54 }
55
56 public final void add( final String item )
57 {
58 items.add( new ValidationItemImpl( getContext() + ": " + item ) );
59 }
60
61 public boolean equals( final Object compare )
62 {
63 if ( this == compare ) {
64 return true;
65 } else if ( compare == null || getClass() != compare.getClass() ) {
66 return false;
67 }
68 final ValidationInfoImpl comp = (ValidationInfoImpl)compare;
69 return CompareTool.areEqual( this.items, comp.items );
70 }
71
72 public int hashCode()
73 {
74 int hash = getClass().hashCode();
75 hash = HashCodeTool.addHashCode( hash, items );
76 return hash;
77 }
78
79 public String toString()
80 {
81 return items.toString();
82 }
83
84
85 private final Stack<String> contextStack = new Stack<String>();
86 private final ShieldableArrayList<ValidationItem> items = new ShieldableArrayList<ValidationItem>();
87
88 }
89
90