Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Event |
|
| 1.25;1.25 | ||||
Event$ID |
|
| 1.25;1.25 |
1 | /** | |
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.yaml.snakeyaml.events; | |
17 | ||
18 | import org.yaml.snakeyaml.error.Mark; | |
19 | ||
20 | /** | |
21 | * Basic unit of output from a {@link org.yaml.snakeyaml.parser.Parser} or input | |
22 | * of a {@link org.yaml.snakeyaml.emitter.Emitter}. | |
23 | */ | |
24 | public abstract class Event { | |
25 | 11 | public enum ID { |
26 | 1 | Alias, DocumentEnd, DocumentStart, MappingEnd, MappingStart, Scalar, SequenceEnd, SequenceStart, StreamEnd, StreamStart |
27 | } | |
28 | ||
29 | private final Mark startMark; | |
30 | private final Mark endMark; | |
31 | ||
32 | 2244355 | public Event(Mark startMark, Mark endMark) { |
33 | 2244355 | this.startMark = startMark; |
34 | 2244355 | this.endMark = endMark; |
35 | 2244355 | } |
36 | ||
37 | public String toString() { | |
38 | 30 | return "<" + this.getClass().getName() + "(" + getArguments() + ")>"; |
39 | } | |
40 | ||
41 | public Mark getStartMark() { | |
42 | 524928 | return startMark; |
43 | } | |
44 | ||
45 | public Mark getEndMark() { | |
46 | 524861 | return endMark; |
47 | } | |
48 | ||
49 | /** | |
50 | * @see "__repr__ for Event in PyYAML" | |
51 | */ | |
52 | protected String getArguments() { | |
53 | 16 | return ""; |
54 | } | |
55 | ||
56 | public abstract boolean is(Event.ID id); | |
57 | ||
58 | /* | |
59 | * for tests only | |
60 | */ | |
61 | @Override | |
62 | public boolean equals(Object obj) { | |
63 | 11 | if (obj instanceof Event) { |
64 | 10 | return toString().equals(obj.toString()); |
65 | } else { | |
66 | 1 | return false; |
67 | } | |
68 | } | |
69 | ||
70 | /* | |
71 | * for tests only | |
72 | */ | |
73 | @Override | |
74 | public int hashCode() { | |
75 | 0 | return toString().hashCode(); |
76 | } | |
77 | } |