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