Skip to content

Commit

Permalink
cleaning up some type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mtf90 committed Mar 15, 2024
1 parent 7c09476 commit 398e863
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public interface GuardExpression {

GuardExpression relabel(VarMapping relabelling);
GuardExpression relabel(VarMapping<?, ?> relabelling);

boolean isSatisfied(Mapping<SymbolicDataValue, DataValue<?>> val);

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/net/automatalib/data/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
*
* @author falk
*/
public class Constants extends Mapping<SymbolicDataValue.Constant, DataValue<?>> {
public class Constants extends Valuation<SymbolicDataValue.Constant, DataValue<?>> {

}
19 changes: 7 additions & 12 deletions api/src/main/java/net/automatalib/data/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author falk
*/
public final class DataType {
public final class DataType<T> {

/**
* name of type (defining member)
Expand All @@ -33,18 +33,16 @@ public final class DataType {
/**
* base type
*/
final Class base;
final Class<T> base;

public DataType(String name, Class base) {
public DataType(String name, Class<T> base) {
this.name = name;
this.base = base;
}

@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + Objects.hashCode(this.name);
return hash;
return this.name.hashCode();
}

@Override
Expand All @@ -55,18 +53,15 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
final DataType other = (DataType) obj;
if (!Objects.equals(this.name, other.name)) {
return false;
}
return true;
final DataType<?> other = (DataType<?>) obj;
return Objects.equals(this.name, other.name);
}

public String getName() {
return name;
}

public Class getBase() {
public Class<?> getBase() {
return base;
}
}
21 changes: 7 additions & 14 deletions api/src/main/java/net/automatalib/data/DataValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
import java.util.Objects;

/**
* @param <T>
*
* @author falk
* @param <T>
*/
public class DataValue<T> {

protected final DataType type;
protected final DataType<T> type;

protected final T id;

public DataValue(DataType type, T id) {
public DataValue(DataType<T> type, T id) {
this.type = type;
this.id = id;
}


@Override
public String toString() {
return id.toString() + "[" + this.type.getName() + "]";
Expand All @@ -56,23 +55,17 @@ public boolean equals(Object obj) {
if (!(obj instanceof DataValue)) {
return false;
}
final DataValue other = (DataValue) obj;
if (!Objects.equals(this.type, other.type)) {
return false;
}
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
final DataValue<?> other = (DataValue<?>) obj;

return Objects.equals(this.type, other.type) && Objects.equals(this.id, other.id);
}

public T getId() {
return id;
}

public DataType getType() {
public DataType<?> getType() {
return type;
}


}
26 changes: 3 additions & 23 deletions api/src/main/java/net/automatalib/data/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
*/
package net.automatalib.data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -31,26 +28,9 @@
* @param <K>
* @param <V>
*/
public class Mapping<K, V extends DataValue<?>> extends LinkedHashMap<K, V>
public class Mapping<K, V> extends LinkedHashMap<K, V>
implements Iterable<Map.Entry<K, V>> {

/**
* returns the contained values of some type.
*
* @param <T>
* @param type the type
* @return
*/
public <T> Collection<DataValue<T>> values(DataType type) {
List<DataValue<T>> list = new ArrayList<>();
for (DataValue<?> v : values()) {
if (v.type.equals(type)) {
list.add((DataValue<T>) v);
}
}
return list;
}

@Override
public Iterator<Map.Entry<K, V>> iterator() {
return this.entrySet().iterator();
Expand Down Expand Up @@ -94,7 +74,7 @@ public String toString(String map) {
}

public Set<K> getAllKeys(V value) {
Set<K> retKeySet = new LinkedHashSet();
Set<K> retKeySet = new HashSet<>();
for (Map.Entry<K,V> entry : this.entrySet()) {
//log.trace("key = " + K);
//log.trace("value = " + entry.getKey().toString());
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/net/automatalib/data/ParValuation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
*
* @author falk
*/
public class ParValuation extends Mapping<Parameter, DataValue<?>> {
public class ParValuation extends Valuation<Parameter, DataValue<?>> {

public ParValuation() {

}

public ParValuation(PSymbolInstance psi) {
ParameterGenerator pgen = new ParameterGenerator();
for (DataValue dv : psi.getParameterValues()) {
for (DataValue<?> dv : psi.getParameterValues()) {
this.put(pgen.next(dv.getType()), dv);
}
}
Expand All @@ -46,7 +46,7 @@ public ParValuation(Word<PSymbolInstance> dw) {
Iterator<PSymbolInstance> it = dw.iterator();
while (it.hasNext()) {
PSymbolInstance psi = it.next();
for (DataValue dv : psi.getParameterValues()) {
for (DataValue<?> dv : psi.getParameterValues()) {
put(pgen.next(dv.getType()), dv);
}
}
Expand Down
83 changes: 44 additions & 39 deletions api/src/main/java/net/automatalib/data/SymbolicDataValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,85 +23,94 @@
*
* @author falk
*/
public abstract class SymbolicDataValue extends DataValue<Integer> {
public abstract class SymbolicDataValue {

protected final DataType<?> type;
protected final int id;

private SymbolicDataValue(DataType<?> dataType, int id) {
this.type = dataType;
this.id = id;
}

public DataType<?> getType() {
return type;
}

public int getId() {
return id;
}

public static final class Parameter extends SymbolicDataValue {

public Parameter(DataType dataType, int id) {
public Parameter(DataType<?> dataType, int id) {
super(dataType, id);
}

public boolean equals(Parameter other) {
return (this.getType().equals(other.getType()) && this.getId().equals(other.getId()));
}

@Override
public SymbolicDataValue.Parameter copy() {
return new SymbolicDataValue.Parameter(type, id);
}

@Override
public String toString() {
return "p" + this.id;
}
};

public static final class Register extends SymbolicDataValue {

public Register(DataType dataType, int id) {
public Register(DataType<?> dataType, int id) {
super(dataType, id);
}

@Override
public SymbolicDataValue.Register copy() {
return new SymbolicDataValue.Register(type, id);
}

@Override
public String toString() {
return "r" + this.id;
}
};

public static final class Constant extends SymbolicDataValue {

public Constant(DataType dataType, int id) {
public Constant(DataType<?> dataType, int id) {
super(dataType, id);
}

@Override
public SymbolicDataValue.Constant copy() {
return new SymbolicDataValue.Constant(type, id);
}

@Override
public String toString() {
return "c" + this.id;
}
};

public static final class SuffixValue extends SymbolicDataValue {

public SuffixValue(DataType dataType, int id) {
public SuffixValue(DataType<?> dataType, int id) {
super(dataType, id);
}

@Override
public SymbolicDataValue.SuffixValue copy() {
return new SymbolicDataValue.SuffixValue(type, id);
}
};

private SymbolicDataValue(DataType dataType, int id) {
super(dataType, id);
}

public String toStringWithType() {
return this.toString() + ":" + this.type.getName();
}
@Override
public String toString() {
return "s" + this.id;
}
};

public abstract SymbolicDataValue copy();

@Override
public String toString() {
String s = "";
if (this.isParameter()) {
s += "p";
} else if (this.isRegister()) {
s += "r";
} else if (this.isSuffixValue()) {
s += "s";
} else if (this.isConstant()) {
s += "c";
}
return s + this.id;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
Expand All @@ -110,14 +119,10 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}

final SymbolicDataValue other = (SymbolicDataValue) obj;
if (!Objects.equals(this.type, other.type)) {
return false;
}
if (this.id != other.id) {
return false;
}
return true;

return this.id == other.id && Objects.equals(this.type, other.type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@ public void set(SymbolicDataValueGenerator g) {
id = g.id;
}

public abstract SymbolicDataValue next(DataType type);
public abstract SymbolicDataValue next(DataType<?> type);

public static final class ParameterGenerator extends SymbolicDataValueGenerator {
@Override
public SymbolicDataValue.Parameter next(DataType type) {
public SymbolicDataValue.Parameter next(DataType<?> type) {
return new SymbolicDataValue.Parameter(type, id++);
}
};

public static final class RegisterGenerator extends SymbolicDataValueGenerator {
@Override
public SymbolicDataValue.Register next(DataType type) {
public SymbolicDataValue.Register next(DataType<?> type) {
return new SymbolicDataValue.Register(type, id++);
}
};

public static final class SuffixValueGenerator extends SymbolicDataValueGenerator {
@Override
public SymbolicDataValue.SuffixValue next(DataType type) {
public SymbolicDataValue.SuffixValue next(DataType<?> type) {
return new SymbolicDataValue.SuffixValue(type, id++);
}
};

public static final class ConstantGenerator extends SymbolicDataValueGenerator {
@Override
public SymbolicDataValue.Constant next(DataType type) {
public SymbolicDataValue.Constant next(DataType<?> type) {
return new SymbolicDataValue.Constant(type, id++);
}
};
Expand Down
Loading

0 comments on commit 398e863

Please sign in to comment.