-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReduction.java
More file actions
31 lines (25 loc) · 828 Bytes
/
Reduction.java
File metadata and controls
31 lines (25 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
final class Reduction {
private final List<Type> pattern;
private final Function<List<Symbol>, TreeSymbol> reduction;
private Reduction(List<Type> pattern, Function<List<Symbol>, TreeSymbol> reduction) {
this.pattern = pattern;
this.reduction = reduction;
}
static final Reduction build(List<Type> pattern, Function<List<Symbol>, TreeSymbol> reduction){
Objects.requireNonNull(pattern);
Objects.requireNonNull(reduction);
return new Reduction(pattern, reduction);
}
final int size(){
return pattern.size();
}
final boolean matches(List<Type> typeList){
return pattern.equals(typeList);
}
final Symbol apply(List<Symbol> symbolList){
return reduction.apply(symbolList);
}
}