View Javadoc

1   /*
2    * Copyright 2005,2009 Ivan SZKIBA
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.ini4j.addon;
17  
18  import java.util.NoSuchElementException;
19  import java.util.prefs.Preferences;
20  
21  public class StrictPreferences extends PreferencesWrapper
22  {
23      public StrictPreferences(Preferences peer)
24      {
25          super(peer);
26      }
27  
28      public boolean getBoolean(String key) throws NoSuchElementException
29      {
30          return Boolean.valueOf(get(key));
31      }
32  
33      public byte[] getByteArray(String key) throws NoSuchElementException
34      {
35          byte[] value = getByteArray(key, null);
36  
37          if (value == null)
38          {
39              throw new NoSuchElementException();
40          }
41  
42          return value;
43      }
44  
45      public double getDouble(String key) throws NoSuchElementException
46      {
47          return Double.parseDouble(get(key));
48      }
49  
50      public float getFloat(String key) throws NoSuchElementException
51      {
52          return Float.parseFloat(get(key));
53      }
54  
55      public int getInt(String key) throws NoSuchElementException
56      {
57          return Integer.parseInt(get(key));
58      }
59  
60      public long getLong(String key) throws NoSuchElementException
61      {
62          return Long.parseLong(get(key));
63      }
64  
65      public String get(String key) throws NoSuchElementException
66      {
67          String value = get(key, null);
68  
69          if (value == null)
70          {
71              throw new NoSuchElementException();
72          }
73  
74          return value;
75      }
76  }