Skip to content

Commit

Permalink
Updates FrozenList/Map to use AbstractList/Map
Browse files Browse the repository at this point in the history
  • Loading branch information
spacether committed Dec 15, 2023
1 parent 1a7800b commit f42deb1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 194 deletions.
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
package org.openapijsonschematools.client.schemas.validation;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class FrozenList<E> extends ArrayList<E> {
public class FrozenList<E> extends AbstractList<E> {
/*
A frozen List
Once schema validation has been run, indexed access returns values of the correct type
If values were mutable, the types in those methods would not agree with returned values
*/
private final List<E> list;
public FrozenList(Collection<? extends E> m) {
super(m);
super();
list = new ArrayList<>(m);
}

public boolean add(E e) {
throw new UnsupportedOperationException();
@Override
public E get(int index) {
return list.get(index);
}

public void add(int index, E element) {
throw new UnsupportedOperationException();
}

public E remove(int index) {
throw new UnsupportedOperationException();
}

public boolean remove(Object o) {
throw new UnsupportedOperationException();
}

public void clear() {
throw new UnsupportedOperationException();
}

public boolean addAll(Collection<? extends E> c) {
throw new UnsupportedOperationException();
}

public boolean addAll(int index, Collection<? extends E> c) {
throw new UnsupportedOperationException();
}

public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}

public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
@Override
public int size() {
return list.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import org.openapijsonschematools.client.exceptions.UnsetPropertyException;
import org.openapijsonschematools.client.exceptions.InvalidAdditionalPropertyException;

import java.util.LinkedHashMap;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;

public class FrozenMap<V> extends LinkedHashMap<String, V> {
public class FrozenMap<V> extends AbstractMap<String, V> {
/*
A frozen Map
Once schema validation has been run, written accessor methods return values of the correct type
If values were mutable, the types in those methods would not agree with returned values
*/
private final Map<String, V> map;
public FrozenMap(Map<String, ? extends V> m) {
super(m);

super();
map = new HashMap<>(m);
}

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

public V put(String key, V value) {
throw new UnsupportedOperationException();
}
public V remove(Object key) {
throw new UnsupportedOperationException();
}
public void putAll(Map<? extends String, ? extends V> m) {
throw new UnsupportedOperationException();
}
public void clear() {
throw new UnsupportedOperationException();
}

@Override
public void replaceAll(BiFunction<? super String, ? super V, ? extends V> function) {
throw new UnsupportedOperationException();
}

@Override
public V putIfAbsent(String key, V value) {
throw new UnsupportedOperationException();
}

@Override
public boolean remove(Object key, Object value) {
throw new UnsupportedOperationException();
}

@Override
public boolean replace(String key, V oldValue, V newValue) {
throw new UnsupportedOperationException();
}

@Override
public V replace(String key, V value) {
throw new UnsupportedOperationException();
}

@Override
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
throw new UnsupportedOperationException();
}

@Override
public V computeIfPresent(String key,
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
}

@Override
public V compute(String key,
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
}

@Override
public V merge(String key, V value,
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
public Set<Entry<String, V>> entrySet() {
return map.entrySet();
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
package {{{packageName}}}.schemas.validation;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class FrozenList<E> extends ArrayList<E> {
public class FrozenList<E> extends AbstractList<E> {
/*
A frozen List
Once schema validation has been run, indexed access returns values of the correct type
If values were mutable, the types in those methods would not agree with returned values
*/
private final List<E> list;
public FrozenList(Collection<? extends E> m) {
super(m);
super();
list = new ArrayList<>(m);
}

public boolean add(E e) {
throw new UnsupportedOperationException();
@Override
public E get(int index) {
return list.get(index);
}

public void add(int index, E element) {
throw new UnsupportedOperationException();
}

public E remove(int index) {
throw new UnsupportedOperationException();
}

public boolean remove(Object o) {
throw new UnsupportedOperationException();
}

public void clear() {
throw new UnsupportedOperationException();
}

public boolean addAll(Collection<? extends E> c) {
throw new UnsupportedOperationException();
}

public boolean addAll(int index, Collection<? extends E> c) {
throw new UnsupportedOperationException();
}

public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}

public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
@Override
public int size() {
return list.size();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ package {{{packageName}}}.schemas.validation;
import {{{packageName}}}.exceptions.UnsetPropertyException;
import {{{packageName}}}.exceptions.InvalidAdditionalPropertyException;

import java.util.LinkedHashMap;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;

public class FrozenMap<V> extends LinkedHashMap<String, V> {
public class FrozenMap<V> extends AbstractMap<String, V> {
/*
A frozen Map
Once schema validation has been run, written accessor methods return values of the correct type
If values were mutable, the types in those methods would not agree with returned values
*/
private final Map<String, V> map;
public FrozenMap(Map<String, ? extends V> m) {
super(m);

super();
map = new HashMap<>(m);
}

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

public V put(String key, V value) {
throw new UnsupportedOperationException();
}
public V remove(Object key) {
throw new UnsupportedOperationException();
}
public void putAll(Map<? extends String, ? extends V> m) {
throw new UnsupportedOperationException();
}
public void clear() {
throw new UnsupportedOperationException();
}

@Override
public void replaceAll(BiFunction<? super String, ? super V, ? extends V> function) {
throw new UnsupportedOperationException();
}

@Override
public V putIfAbsent(String key, V value) {
throw new UnsupportedOperationException();
}

@Override
public boolean remove(Object key, Object value) {
throw new UnsupportedOperationException();
}

@Override
public boolean replace(String key, V oldValue, V newValue) {
throw new UnsupportedOperationException();
}

@Override
public V replace(String key, V value) {
throw new UnsupportedOperationException();
}

@Override
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
throw new UnsupportedOperationException();
}

@Override
public V computeIfPresent(String key,
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
}

@Override
public V compute(String key,
BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
}

@Override
public V merge(String key, V value,
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
throw new UnsupportedOperationException();
public Set<Entry<String, V>> entrySet() {
return map.entrySet();
}
}

0 comments on commit f42deb1

Please sign in to comment.