OSDN Git Service

84199ef8a3904fee54a39ace0cd6490be2f2e636
[dvibrowser/dvi2epub.git] / src / main / java / jp / sourceforge / dvibrowser / dvi2epub / cmd / ParserState.java
1 /*
2  * Copyright (c) 2012, Takeyuki Nagao
3  * All rights reserved.
4  * 
5  * Redistribution and use in source and binary forms, with or
6  * without modification, are permitted provided that the
7  * following conditions are met:
8  * 
9  *  * Redistributions of source code must retain the above
10  *    copyright notice, this list of conditions and the
11  *    following disclaimer.
12  *  * Redistributions in binary form must reproduce the above
13  *    copyright notice, this list of conditions and the
14  *    following disclaimer in the documentation and/or other
15  *    materials provided with the distribution.
16  *    
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
29  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  */
32
33 package jp.sourceforge.dvibrowser.dvi2epub.cmd;
34
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.List;
38
39 public class ParserState {
40         private final String[] args;
41         private List<String> list = new ArrayList<String>();
42         private Throwable throwable;
43         private boolean stop = false;
44         private String optionName;
45         private String optionParameter;
46
47         public ParserState(String [] args) {
48                 this.args = args;
49                 this.list.addAll(Arrays.asList(args));
50         }
51
52         public String[] getOriginalArgs() {
53                 return args;
54         }
55
56         public List<String> getList() {
57                 return list;
58         }
59
60         public String shift() {
61                 String ret = null;
62                 if (list.size() > 0) {
63                         ret = list.remove(0);
64                 }
65                 return ret;
66         }
67         
68         public void unshift(String value) {
69                 list.add(0, value);
70         }
71
72         public boolean wantStop() {
73                 return stop;
74         }
75
76         public void wantStop(boolean stop) {
77                 this.stop = stop;
78         }
79         
80         public void setError(Throwable ex) {
81                 this.throwable = ex;
82         }
83         
84         public void stopWithError(Throwable ex) {
85                 setError(ex);
86                 wantStop(true);
87         }
88
89         public Throwable getThrowable() {
90                 return this.throwable;
91         }
92         
93         public boolean hasError() {
94                 return getThrowable() != null;
95         }
96
97         public String getOptionParameter() {
98                 return optionParameter;
99         }
100
101         public void setOptionParameter(String optionParameter) {
102                 this.optionParameter = optionParameter;
103         }
104
105         public String getOptionName() {
106                 return optionName;
107         }
108
109         public void setOptionName(String optionName) {
110                 this.optionName = optionName;
111         }
112 }