001 /*
002 * Copyright 2005 [ini4j] Development Team
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.ini4j.addon;
018
019 import java.util.NoSuchElementException;
020 import java.util.prefs.Preferences;
021
022 public class StrictPreferences extends PreferencesWrapper
023 {
024 public StrictPreferences(Preferences peer)
025 {
026 super(peer);
027 }
028
029 public String get(String key) throws NoSuchElementException
030 {
031 String value = get(key, null);
032
033 if ( value == null )
034 {
035 throw new NoSuchElementException();
036 }
037
038 return value;
039 }
040
041 public int getInt(String key) throws NoSuchElementException
042 {
043 return Integer.parseInt(get(key));
044 }
045
046 public long getLong(String key) throws NoSuchElementException
047 {
048 return Long.parseLong(get(key));
049 }
050
051 public boolean getBoolean(String key) throws NoSuchElementException
052 {
053 return Boolean.valueOf(get(key));
054 }
055
056 public float getFloat(String key) throws NoSuchElementException
057 {
058 return Float.parseFloat(get(key));
059 }
060
061 public double getDouble(String key) throws NoSuchElementException
062 {
063 return Double.parseDouble(get(key));
064 }
065
066 public byte[] getByteArray(String key) throws NoSuchElementException
067 {
068 byte[] value = getByteArray(key, null);
069
070 if ( value == null )
071 {
072 throw new NoSuchElementException();
073 }
074
075 return value;
076 }
077 }