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