1
22
23 package com.liferay.portal.kernel.util;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.List;
28
29
34 public abstract class TranslatedList<E, F> extends ListWrapper<E> {
35
36 public TranslatedList(List<E> newList, List<F> oldList) {
37 super(newList);
38
39 _oldList = oldList;
40 }
41
42 public boolean add(E o) {
43 _oldList.add(toOldObject(o));
44
45 return super.add(o);
46 }
47
48 public void add(int index, E element) {
49 _oldList.add(index, toOldObject(element));
50
51 super.add(index, element);
52 }
53
54 public boolean addAll(Collection<? extends E> c) {
55 for (E o : c) {
56 _oldList.add(toOldObject(o));
57 }
58
59 return super.addAll(c);
60 }
61
62 public boolean addAll(int index, Collection<? extends E> c) {
63 for (E o : c) {
64 _oldList.add(index++, toOldObject(o));
65 }
66
67 return super.addAll(c);
68 }
69
70 public boolean remove(Object o) {
71 _oldList.remove(toOldObject((E)o));
72
73 return super.remove(o);
74 }
75
76 public E remove(int index) {
77 _oldList.remove(index);
78
79 return super.remove(index);
80 }
81
82 public boolean removeAll(Collection<?> c) {
83 List<F> tempList = new ArrayList<F>();
84
85 for (Object o : c) {
86 tempList.add(toOldObject((E)o));
87 }
88
89 _oldList.removeAll(tempList);
90
91 return super.removeAll(c);
92 }
93
94 public boolean retainAll(Collection<?> c) {
95 List<F> tempList = new ArrayList<F>();
96
97 for (Object o : c) {
98 tempList.add(toOldObject((E)o));
99 }
100
101 _oldList.retainAll(tempList);
102
103 return super.retainAll(c);
104 }
105
106 public E set(int index, E element) {
107 _oldList.set(index, toOldObject(element));
108
109 return super.set(index, element);
110 }
111
112 public List<E> subList(int fromIndex, int toIndex) {
113 List<E> newList = super.subList(fromIndex, toIndex);
114 List<F> oldList = _oldList.subList(fromIndex, toIndex);
115
116 return newInstance(newList, oldList);
117 }
118
119 protected abstract TranslatedList<E, F> newInstance(
120 List<E> newList, List<F> oldList);
121
122 protected abstract F toOldObject(E o);
123
124 private List<F> _oldList;
125
126 }