Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit f42deb1

Browse files
committed
Updates FrozenList/Map to use AbstractList/Map
1 parent 1a7800b commit f42deb1

4 files changed

Lines changed: 44 additions & 194 deletions

File tree

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,29 @@
11
package org.openapijsonschematools.client.schemas.validation;
22

3+
import java.util.AbstractList;
34
import java.util.ArrayList;
45
import java.util.Collection;
6+
import java.util.List;
57

6-
public class FrozenList<E> extends ArrayList<E> {
8+
public class FrozenList<E> extends AbstractList<E> {
79
/*
810
A frozen List
911
Once schema validation has been run, indexed access returns values of the correct type
1012
If values were mutable, the types in those methods would not agree with returned values
1113
*/
14+
private final List<E> list;
1215
public FrozenList(Collection<? extends E> m) {
13-
super(m);
16+
super();
17+
list = new ArrayList<>(m);
1418
}
1519

16-
public boolean add(E e) {
17-
throw new UnsupportedOperationException();
20+
@Override
21+
public E get(int index) {
22+
return list.get(index);
1823
}
1924

20-
public void add(int index, E element) {
21-
throw new UnsupportedOperationException();
22-
}
23-
24-
public E remove(int index) {
25-
throw new UnsupportedOperationException();
26-
}
27-
28-
public boolean remove(Object o) {
29-
throw new UnsupportedOperationException();
30-
}
31-
32-
public void clear() {
33-
throw new UnsupportedOperationException();
34-
}
35-
36-
public boolean addAll(Collection<? extends E> c) {
37-
throw new UnsupportedOperationException();
38-
}
39-
40-
public boolean addAll(int index, Collection<? extends E> c) {
41-
throw new UnsupportedOperationException();
42-
}
43-
44-
public boolean removeAll(Collection<?> c) {
45-
throw new UnsupportedOperationException();
46-
}
47-
48-
public boolean retainAll(Collection<?> c) {
49-
throw new UnsupportedOperationException();
25+
@Override
26+
public int size() {
27+
return list.size();
5028
}
5129
}

samples/client/3_0_3_unit_test/java/src/main/java/org/openapijsonschematools/client/schemas/validation/FrozenMap.java

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
44
import org.openapijsonschematools.client.exceptions.InvalidAdditionalPropertyException;
55

6-
import java.util.LinkedHashMap;
6+
import java.util.AbstractMap;
7+
import java.util.HashMap;
78
import java.util.Map;
89
import java.util.Set;
9-
import java.util.function.BiFunction;
10-
import java.util.function.Function;
1110

12-
public class FrozenMap<V> extends LinkedHashMap<String, V> {
11+
public class FrozenMap<V> extends AbstractMap<String, V> {
1312
/*
1413
A frozen Map
1514
Once schema validation has been run, written accessor methods return values of the correct type
1615
If values were mutable, the types in those methods would not agree with returned values
1716
*/
17+
private final Map<String, V> map;
1818
public FrozenMap(Map<String, ? extends V> m) {
19-
super(m);
19+
20+
super();
21+
map = new HashMap<>(m);
2022
}
2123

2224
protected void throwIfKeyNotPresent(String key) throws UnsetPropertyException {
@@ -31,64 +33,8 @@ protected void throwIfKeyKnown(String key, Set<String> requiredKeys, Set<String>
3133
}
3234
}
3335

34-
public V put(String key, V value) {
35-
throw new UnsupportedOperationException();
36-
}
37-
public V remove(Object key) {
38-
throw new UnsupportedOperationException();
39-
}
40-
public void putAll(Map<? extends String, ? extends V> m) {
41-
throw new UnsupportedOperationException();
42-
}
43-
public void clear() {
44-
throw new UnsupportedOperationException();
45-
}
46-
47-
@Override
48-
public void replaceAll(BiFunction<? super String, ? super V, ? extends V> function) {
49-
throw new UnsupportedOperationException();
50-
}
51-
52-
@Override
53-
public V putIfAbsent(String key, V value) {
54-
throw new UnsupportedOperationException();
55-
}
56-
57-
@Override
58-
public boolean remove(Object key, Object value) {
59-
throw new UnsupportedOperationException();
60-
}
61-
62-
@Override
63-
public boolean replace(String key, V oldValue, V newValue) {
64-
throw new UnsupportedOperationException();
65-
}
66-
67-
@Override
68-
public V replace(String key, V value) {
69-
throw new UnsupportedOperationException();
70-
}
71-
72-
@Override
73-
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
74-
throw new UnsupportedOperationException();
75-
}
76-
77-
@Override
78-
public V computeIfPresent(String key,
79-
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
80-
throw new UnsupportedOperationException();
81-
}
82-
83-
@Override
84-
public V compute(String key,
85-
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
86-
throw new UnsupportedOperationException();
87-
}
88-
8936
@Override
90-
public V merge(String key, V value,
91-
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
92-
throw new UnsupportedOperationException();
37+
public Set<Entry<String, V>> entrySet() {
38+
return map.entrySet();
9339
}
9440
}
Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
11
package {{{packageName}}}.schemas.validation;
22

3+
import java.util.AbstractList;
34
import java.util.ArrayList;
45
import java.util.Collection;
6+
import java.util.List;
57

6-
public class FrozenList<E> extends ArrayList<E> {
8+
public class FrozenList<E> extends AbstractList<E> {
79
/*
810
A frozen List
911
Once schema validation has been run, indexed access returns values of the correct type
1012
If values were mutable, the types in those methods would not agree with returned values
1113
*/
14+
private final List<E> list;
1215
public FrozenList(Collection<? extends E> m) {
13-
super(m);
16+
super();
17+
list = new ArrayList<>(m);
1418
}
1519

16-
public boolean add(E e) {
17-
throw new UnsupportedOperationException();
20+
@Override
21+
public E get(int index) {
22+
return list.get(index);
1823
}
1924

20-
public void add(int index, E element) {
21-
throw new UnsupportedOperationException();
22-
}
23-
24-
public E remove(int index) {
25-
throw new UnsupportedOperationException();
26-
}
27-
28-
public boolean remove(Object o) {
29-
throw new UnsupportedOperationException();
30-
}
31-
32-
public void clear() {
33-
throw new UnsupportedOperationException();
34-
}
35-
36-
public boolean addAll(Collection<? extends E> c) {
37-
throw new UnsupportedOperationException();
38-
}
39-
40-
public boolean addAll(int index, Collection<? extends E> c) {
41-
throw new UnsupportedOperationException();
42-
}
43-
44-
public boolean removeAll(Collection<?> c) {
45-
throw new UnsupportedOperationException();
46-
}
47-
48-
public boolean retainAll(Collection<?> c) {
49-
throw new UnsupportedOperationException();
25+
@Override
26+
public int size() {
27+
return list.size();
5028
}
5129
}
30+

src/main/resources/java/src/main/java/packagename/schemas/validation/FrozenMap.hbs

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ package {{{packageName}}}.schemas.validation;
33
import {{{packageName}}}.exceptions.UnsetPropertyException;
44
import {{{packageName}}}.exceptions.InvalidAdditionalPropertyException;
55

6-
import java.util.LinkedHashMap;
6+
import java.util.AbstractMap;
7+
import java.util.HashMap;
78
import java.util.Map;
89
import java.util.Set;
9-
import java.util.function.BiFunction;
10-
import java.util.function.Function;
1110

12-
public class FrozenMap<V> extends LinkedHashMap<String, V> {
11+
public class FrozenMap<V> extends AbstractMap<String, V> {
1312
/*
1413
A frozen Map
1514
Once schema validation has been run, written accessor methods return values of the correct type
1615
If values were mutable, the types in those methods would not agree with returned values
1716
*/
17+
private final Map<String, V> map;
1818
public FrozenMap(Map<String, ? extends V> m) {
19-
super(m);
19+
20+
super();
21+
map = new HashMap<>(m);
2022
}
2123

2224
protected void throwIfKeyNotPresent(String key) throws UnsetPropertyException {
@@ -31,64 +33,9 @@ public class FrozenMap<V> extends LinkedHashMap<String, V> {
3133
}
3234
}
3335

34-
public V put(String key, V value) {
35-
throw new UnsupportedOperationException();
36-
}
37-
public V remove(Object key) {
38-
throw new UnsupportedOperationException();
39-
}
40-
public void putAll(Map<? extends String, ? extends V> m) {
41-
throw new UnsupportedOperationException();
42-
}
43-
public void clear() {
44-
throw new UnsupportedOperationException();
45-
}
46-
47-
@Override
48-
public void replaceAll(BiFunction<? super String, ? super V, ? extends V> function) {
49-
throw new UnsupportedOperationException();
50-
}
51-
52-
@Override
53-
public V putIfAbsent(String key, V value) {
54-
throw new UnsupportedOperationException();
55-
}
56-
5736
@Override
58-
public boolean remove(Object key, Object value) {
59-
throw new UnsupportedOperationException();
60-
}
61-
62-
@Override
63-
public boolean replace(String key, V oldValue, V newValue) {
64-
throw new UnsupportedOperationException();
65-
}
66-
67-
@Override
68-
public V replace(String key, V value) {
69-
throw new UnsupportedOperationException();
70-
}
71-
72-
@Override
73-
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
74-
throw new UnsupportedOperationException();
75-
}
76-
77-
@Override
78-
public V computeIfPresent(String key,
79-
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
80-
throw new UnsupportedOperationException();
81-
}
82-
83-
@Override
84-
public V compute(String key,
85-
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
86-
throw new UnsupportedOperationException();
87-
}
88-
89-
@Override
90-
public V merge(String key, V value,
91-
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
92-
throw new UnsupportedOperationException();
37+
public Set<Entry<String, V>> entrySet() {
38+
return map.entrySet();
9339
}
9440
}
41+

0 commit comments

Comments
 (0)