• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, 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     public enum ID {
26         Alias, DocumentEnd, DocumentStart, MappingEnd, MappingStart, Scalar, SequenceEnd, SequenceStart, StreamEnd, StreamStart
27     }
28 
29     private final Mark startMark;
30     private final Mark endMark;
31 
Event(Mark startMark, Mark endMark)32     public Event(Mark startMark, Mark endMark) {
33         this.startMark = startMark;
34         this.endMark = endMark;
35     }
36 
toString()37     public String toString() {
38         return "<" + this.getClass().getName() + "(" + getArguments() + ")>";
39     }
40 
getStartMark()41     public Mark getStartMark() {
42         return startMark;
43     }
44 
getEndMark()45     public Mark getEndMark() {
46         return endMark;
47     }
48 
49     /**
50      * @see "__repr__ for Event in PyYAML"
51      */
getArguments()52     protected String getArguments() {
53         return "";
54     }
55 
is(Event.ID id)56     public abstract boolean is(Event.ID id);
57 
58     /*
59      * for tests only
60      */
61     @Override
equals(Object obj)62     public boolean equals(Object obj) {
63         if (obj instanceof Event) {
64             return toString().equals(obj.toString());
65         } else {
66             return false;
67         }
68     }
69 
70     /*
71      * for tests only
72      */
73     @Override
hashCode()74     public int hashCode() {
75         return toString().hashCode();
76     }
77 }
78