1 package org.andromda.taglibs.breadcrumbs;
2
3 import java.util.Collection;
4 import java.util.LinkedList;
5
6
7
8
9 public class BreadCrumbs extends LinkedList
10 {
11 private static final long serialVersionUID = 34L;
12
13 public static final String SESSION_KEY = "org.andromda.bpm4struts.breadcrumbs";
14
15 public static final int DEFAULT_SIZE = 6;
16
17 private int maxSize = -1;
18
19
20
21
22 public BreadCrumbs()
23 {
24 this(DEFAULT_SIZE);
25 }
26
27
28
29
30 public BreadCrumbs(int maxSize)
31 {
32 this.maxSize = maxSize;
33 }
34
35
36
37
38 public int getMaxSize()
39 {
40 return maxSize;
41 }
42
43
44
45
46 public void setMaxSize(int maxSize)
47 {
48 this.maxSize = maxSize;
49 }
50
51
52
53
54 public BreadCrumbs(Collection<Object> collection)
55 {
56 super(collection);
57 maxSize = collection.size();
58 }
59
60 private boolean isOverflowed()
61 {
62 return size() > maxSize;
63 }
64
65 private void trimToSize()
66 {
67 if (isOverflowed() && !isEmpty())
68 {
69 int difference = size() - maxSize;
70 this.removeRange(0, difference);
71 }
72 }
73
74
75
76
77 public void add(int index, Object element)
78 {
79 super.add(index, element);
80 trimToSize();
81 }
82
83
84
85
86 public boolean add(Object element)
87 {
88 boolean added = super.add(element);
89 trimToSize();
90 return added;
91 }
92
93
94
95
96 public void addFirst(Object element)
97 {
98 super.addFirst(element);
99 trimToSize();
100 }
101
102
103
104
105 public void addLast(Object element)
106 {
107 super.addLast(element);
108 trimToSize();
109 }
110
111
112
113
114 public boolean addAll(int index, Collection collection)
115 {
116 boolean added = super.addAll(index, collection);
117 trimToSize();
118 return added;
119 }
120
121
122
123
124 public boolean addAll(Collection collection)
125 {
126 boolean added = super.addAll(collection);
127 trimToSize();
128 return added;
129 }
130 }