Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit b39329f5 authored by Noric Couderc's avatar Noric Couderc

Removed useless code

Code was not used.
parent e775bffb
package se.lth.cs.Random;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
import java.util.*;
public class RandomList<T> implements List<T> {
List<T> implementation;
public RandomList(List impl) {
implementation = impl;
}
@Override
public int size() {
return implementation.size();
}
@Override
public boolean isEmpty() {
return implementation.isEmpty();
}
@Override
public boolean contains(Object o) {
return implementation.contains(o);
}
@NotNull
@Override
public Iterator<T> iterator() {
return implementation.iterator();
}
@NotNull
@Override
public Object[] toArray() {
return implementation.toArray();
}
@NotNull
@Override
public <T1> T1[] toArray(@NotNull T1[] t1s) {
return implementation.toArray(t1s);
}
@Override
public boolean add(T t) {
return implementation.add(t);
}
@Override
public boolean remove(Object o) { return implementation.remove(o); }
@Override
public boolean containsAll(@NotNull Collection<?> collection) {
return implementation.containsAll(collection);
}
@Override
public boolean addAll(@NotNull Collection<? extends T> collection) {
return implementation.addAll(collection);
}
@Override
public boolean addAll(int i, @NotNull Collection<? extends T> collection) {
return implementation.addAll(i, collection);
}
@Override
public boolean removeAll(@NotNull Collection<?> collection) {
return removeAll(collection);
}
@Override
public boolean retainAll(@NotNull Collection<?> collection) {
return retainAll(collection);
}
@Override
public void clear() {
implementation.clear();
}
@Override
public T get(int i) {
return implementation.get(i);
}
@Override
public T set(int i, T t) {
return implementation.set(i, t);
}
@Override
public void add(int i, T t) {
implementation.add(i, t);
}
@Override
public T remove(int i) {
return implementation.remove(i);
}
@Override
public int indexOf(Object o) {
return implementation.indexOf(o);
}
@Override
public int lastIndexOf(Object o) {
return implementation.lastIndexOf(o);
}
@NotNull
@Override
public ListIterator<T> listIterator() {
return implementation.listIterator();
}
@NotNull
@Override
public ListIterator<T> listIterator(int i) {
return implementation.listIterator(i);
}
@NotNull
@Override
public List<T> subList(int i, int i1) {
return implementation.subList(i, i1);
}
}
package se.lth.cs.Random;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
public class RandomListMethodSequence extends RandomMethodSequence<List<Integer>>{
public RandomListMethodSequence(Long seed, Integer applicationSize, List targetObject) {
super(seed, applicationSize, targetObject);
}
@Override
public Object generateArgument(Class expectedClass) {
if (expectedClass == java.lang.Integer.class) {
return generateIndex();
}
if (expectedClass == java.util.Comparator.class) {
return Comparator.comparingInt(x -> (int) x);
}
if (expectedClass == java.util.Collection.class) {
return generateCollection();
}
return generateValue();
}
@Override
public int generateIndex() {
return generator.nextInt(targetObject.size());
}
@Override
public Collection<Integer> generateCollection() {
ArrayList l = new ArrayList();
generator.ints(targetObject.size() / 2).forEach(
x -> l.add(x)
);
return l;
}
}
package se.lth.cs.Random;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class RandomMap<K, V> implements Map<K, V> {
Map<K, V> implemetation;
@Override
public int size() {
return implemetation.size();
}
@Override
public boolean isEmpty() {
return implemetation.isEmpty();
}
@Override
public boolean containsKey(Object o) {
return implemetation.containsKey(o);
}
@Override
public boolean containsValue(Object o) {
return implemetation.containsValue(o);
}
@Override
public V get(Object o) {
return get(o);
}
@Nullable
@Override
public V put(K k, V v) {
return implemetation.put(k, v);
}
@Override
public V remove(Object o) {
return implemetation.remove(o);
}
@Override
public void putAll(@NotNull Map<? extends K, ? extends V> map) {
implemetation.putAll(map);
}
@Override
public void clear() {
implemetation.clear();
}
@NotNull
@Override
public Set<K> keySet() {
return implemetation.keySet();
}
@NotNull
@Override
public Collection<V> values() {
return implemetation.values();
}
@NotNull
@Override
public Set<Entry<K, V>> entrySet() {
return implemetation.entrySet();
}
}
package se.lth.cs.Random;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
public abstract class RandomMethodSequence<T> {
Random generator;
Method[] methodSequence;
int currentMethodIndex = 0;
Object[][] arguments;
T targetObject;
boolean methodMatch(Method m, Method m1) {
return m.getName() == m1.getName()
&& m.getParameterTypes().equals(m.getParameterTypes())
&& m.getReturnType().equals(m.getReturnType());
}
RandomMethodSequence(Long seed, Integer applicationSize, T targetObject) {
generator = new Random(seed);
methodSequence = new Method[applicationSize];
arguments = new Object[applicationSize][0];
this.targetObject = targetObject;
// We get the methods to run on our object
List<Method> methodsSelected = Arrays.stream(targetObject.getClass().getMethods())
.sorted(Comparator.comparing(Method::getName))
.filter(m -> !m.isDefault()) // No Default methods!
.collect(Collectors.toList());
for (int i = 0; i < applicationSize; i++) {
int index = generator.nextInt(methodsSelected.size());
methodSequence[i] = methodsSelected.get(index);
arguments[i] = generateArguments(methodSequence[i]);
}
}
public Object generateArgument(Class toGenerate) {
if (toGenerate.equals(java.lang.Integer.class)) {
return generateIndex();
} else {
return generateValue();
}
}
public Object[] generateArguments(Method m) {
Object[] args = new Object[m.getParameterCount()];
Class[] argTypes = m.getParameterTypes();
for (int i = 0; i < m.getParameterCount(); ++i) {
Class toGenerate = argTypes[i];
args[i] = generateArgument(toGenerate);
}
return args;
}
public abstract int generateIndex();
public Integer generateValue() {
return generator.nextInt();
}
public abstract Collection<Integer> generateCollection();
public Object runCurrentMethod() throws InvocationTargetException, IllegalAccessException {
return methodSequence[currentMethodIndex].invoke(targetObject,
arguments[currentMethodIndex]);
}
public void tick() {
currentMethodIndex++;
}
public boolean isFinished() {
return currentMethodIndex == methodSequence.length - 1;
}
}
package se.lth.cs.Random;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
public class RandomSet<T> implements Set<T> {
Set<T> implementation;
@Override
public int size() {
return implementation.size();
}
@Override
public boolean isEmpty() {
return implementation.isEmpty();
}
@Override
public boolean contains(Object o) {
return implementation.contains(o);
}
@NotNull
@Override
public Iterator<T> iterator() {
return implementation.iterator();
}
@NotNull
@Override
public Object[] toArray() {
return implementation.toArray();
}
@NotNull
@Override
public <T1> T1[] toArray(@NotNull T1[] t1s) {
return implementation.toArray(t1s);
}
@Override
public boolean add(T t) {
return implementation.add(t);
}
@Override
public boolean remove(Object o) {
return implementation.remove(o);
}
@Override
public boolean containsAll(@NotNull Collection<?> collection) {
return implementation.containsAll(collection);
}
@Override
public boolean addAll(@NotNull Collection<? extends T> collection) {
return implementation.addAll(collection);
}
@Override
public boolean retainAll(@NotNull Collection<?> collection) {
return implementation.retainAll(collection);
}
@Override
public boolean removeAll(@NotNull Collection<?> collection) {
return implementation.removeAll(collection);
}
@Override
public void clear() {
implementation.clear();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment