1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.supercsv.benchmark.cellprocessor;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.supercsv.benchmark.model.StopTypeAndName;
22 import org.supercsv.cellprocessor.HashMapper;
23 import org.supercsv.cellprocessor.ift.CellProcessor;
24 import org.supercsv.exception.SuperCsvCellProcessorException;
25 import org.supercsv.util.CsvContext;
26
27
28
29
30
31
32 public class ParseStopTypeAndName extends HashMapper {
33
34 private static final Map<Object, Object> MAP = new HashMap<Object, Object>();
35 static {
36 MAP.put("Airport, airport stop", StopTypeAndName.AIRPORT_STOP);
37 MAP.put("Bus/coach stop", StopTypeAndName.BUS_COACH_STOP);
38 MAP.put("Ferry", StopTypeAndName.FERRY);
39 MAP.put("Metro/tram", StopTypeAndName.METRO_TRAM);
40 MAP.put("Rail", StopTypeAndName.RAIL);
41 MAP.put("Taxi rank", StopTypeAndName.TAXI_RANK);
42 }
43
44
45
46
47 public ParseStopTypeAndName() {
48 super(MAP);
49 }
50
51
52
53
54 public ParseStopTypeAndName(CellProcessor next) {
55 super(MAP, next);
56 }
57
58
59
60
61 @Override
62 public Object execute(Object value, CsvContext context) {
63
64 validateInputNotNull(value, context);
65
66 Object stopTypeAndName = MAP.get(value);
67 if (stopTypeAndName == null) {
68 throw new SuperCsvCellProcessorException(String.format(
69 "Unknown StopTypeAndName: %s", value), context, this);
70 }
71 return next.execute(stopTypeAndName, context);
72 }
73
74 }