JavaPatternMatching/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/GenericsRegistry.java

49 lines
1.5 KiB
Java
Raw Normal View History

2017-03-22 15:05:59 +00:00
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
2017-09-20 21:41:06 +00:00
import java.util.ArrayList;
2017-03-29 15:28:29 +00:00
import java.util.HashMap;
2017-09-20 21:41:06 +00:00
import java.util.List;
import java.util.Optional;
2017-03-22 15:05:59 +00:00
2017-09-20 21:41:06 +00:00
public class GenericsRegistry {
private final List<GenericVariable> registry = new ArrayList<>();
public final GenericsRegistry globalRegistry;
2017-03-22 15:05:59 +00:00
2017-09-20 21:41:06 +00:00
public GenericsRegistry(GenericsRegistry globalRegistry){
this.globalRegistry = globalRegistry;
}
public void put(String name, GenericContext genericContext){
registry.add(new GenericVariable(genericContext,name));
if(globalRegistry != null)globalRegistry.put(name, genericContext);
}
public boolean contains(String name) {
Optional<Boolean> ret = registry.stream().<Boolean>map(((GenericVariable genericVariable) -> genericVariable.name.equals(name)))
.reduce(((a, b) -> a || b));
if(ret.isPresent())
return ret.get();
return false;
}
public GenericContext get(String name) {
return registry.stream()
.filter((genericVariable -> genericVariable.name.equals(name))).findAny().get().context;
}
public void putAll(GenericsRegistry generics) {
for(GenericVariable generic : generics.registry){
this.put(generic.name, generic.context);
}
}
}
class GenericVariable{
final GenericContext context;
final String name;
GenericVariable(GenericContext context, String name){
this.context = context;
this.name = name;
}
2017-03-29 15:28:29 +00:00
}