1 /**
2 * Copyright (c) 2008-2011, 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
17 package org.yaml.snakeyaml.events;
18
19 import org.yaml.snakeyaml.error.Mark;
20
21 /**
22 * Basic unit of output from a {@link org.yaml.snakeyaml.parser.Parser} or input
23 * of a {@link org.yaml.snakeyaml.emitter.Emitter}.
24 */
25 public abstract class Event {
26 public enum ID {
27 Alias, DocumentEnd, DocumentStart, MappingEnd, MappingStart, Scalar, SequenceEnd, SequenceStart, StreamEnd, StreamStart
28 }
29
30 private final Mark startMark;
31 private final Mark endMark;
32
33 public Event(Mark startMark, Mark endMark) {
34 this.startMark = startMark;
35 this.endMark = endMark;
36 }
37
38 public String toString() {
39 return "<" + this.getClass().getName() + "(" + getArguments() + ")>";
40 }
41
42 public Mark getStartMark() {
43 return startMark;
44 }
45
46 public Mark getEndMark() {
47 return endMark;
48 }
49
50 /**
51 * @see __repr__ for Event in PyYAML
52 */
53 protected String getArguments() {
54 return "";
55 }
56
57 public abstract boolean is(Event.ID id);
58
59 /*
60 * for tests only
61 */
62 @Override
63 public boolean equals(Object obj) {
64 if (obj instanceof Event) {
65 return toString().equals(obj.toString());
66 } else {
67 return false;
68 }
69 }
70 }