View Javadoc

1   package net.sf.jack4j;
2   
3   /*
4   Copyright (C) 2008 Ondrej Par
5   
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU Lesser General Public License as published by
8   the Free Software Foundation; either version 2.1 of the License, or
9   (at your option) any later version.
10  
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU Lesser General Public License for more details.
15  
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  
20  */
21  
22  
23  /**
24   * Java version of Jack enum <code>jack_transport_state_t</code>.
25   * 
26   * @author repa
27   * 
28   */
29  public enum JackTransportState {
30  	STOPPED {
31  
32  		@Override
33  		protected int nativeIntValue() {
34  			return JackConstants.JackTransportStopped();
35  		}
36  	},
37  	ROLLING {
38  
39  		@Override
40  		protected int nativeIntValue() {
41  			return JackConstants.JackTransportRolling();
42  		}
43  	},
44  	LOOPING {
45  
46  		@Override
47  		protected int nativeIntValue() {
48  			return JackConstants.JackTransportLooping();
49  		}
50  	},
51  	STARTING {
52  
53  		@Override
54  		protected int nativeIntValue() {
55  			return JackConstants.JackTransportStarting();
56  		}
57  	},
58  	;
59  
60  	private Integer cachedIntValue = null;
61  
62  	protected abstract int nativeIntValue();
63  
64  	/**
65  	 * Returns integer value of native constant corresponding to this enum
66  	 * value.
67  	 */
68  	public int intValue() {
69  		if (cachedIntValue == null) {
70  			cachedIntValue = nativeIntValue();
71  		}
72  		return cachedIntValue;
73  	}
74  
75  	/**
76  	 * Returns the enum constant with given integer value.
77  	 */
78  	public static JackTransportState byIntValue(int intValue) {
79  		for (JackTransportState state : values()) {
80  			if (state.intValue() == intValue) {
81  				return state;
82  			}
83  		}
84  		throw new IllegalArgumentException();
85  	}
86  }