Skip to content

Commit ff4b3b3

Browse files
committed
VisitorLambda simplification
1 parent 05783fb commit ff4b3b3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/visitor/VisitorLambda.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class VisitorLambda {
1010

1111
public static class LambdaVisitor<A> implements Function<Object, A> {
12-
private Map<Class<?>, Function<Object, A>> fMap = new HashMap<>();
12+
private final Map<Class<?>, Function<Object, A>> fMap = new HashMap<>();
1313

1414
@SuppressWarnings(value = "unchecked")
1515
public <B> LambdaVisitor<A> addHandler(Class<B> clazz, Function<B, A> handler) {
@@ -41,24 +41,24 @@ public Circle(double radius) {
4141
}
4242

4343
public static class Rectangle {
44-
final double weidht;
44+
final double width;
4545
final double height;
4646

47-
public Rectangle( double weidht, double height ) {
48-
this.weidht = weidht;
47+
public Rectangle(double width, double height ) {
48+
this.width = width;
4949
this.height = height;
5050
}
5151
}
5252

5353
static Function<Object, Double> areaVisitor = new LambdaVisitor<Double>()
5454
.addHandler(Square.class, (Square s) -> s.side * s.side )
5555
.addHandler(Circle.class, c -> Math.PI * c.radius * c.radius )
56-
.addHandler(Rectangle.class, r -> r.height * r.weidht );
56+
.addHandler(Rectangle.class, r -> r.height * r.width);
5757

5858
static Function<Object, Double> perimeterVisitor = new LambdaVisitor<Double>()
5959
.addHandler(Square.class, s -> 4 * s.side )
6060
.addHandler(Circle.class, c -> 2 * Math.PI * c.radius )
61-
.addHandler(Rectangle.class, r -> 2 * r.height + 2 * r.weidht );
61+
.addHandler(Rectangle.class, r -> 2 * r.height + 2 * r.width);
6262

6363
public static void main( String[] args ) {
6464
List<Object> figures = Arrays.asList( new Circle( 4 ), new Square( 5 ), new Rectangle( 6, 7 ) );

0 commit comments

Comments
 (0)