1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.report.util; 24 25 import com.sun.star.report.ParameterMap; 26 27 import java.util.HashMap; 28 import java.util.Map; 29 30 31 public class DefaultParameterMap implements ParameterMap 32 { 33 34 private final Map backend; 35 DefaultParameterMap()36 public DefaultParameterMap() 37 { 38 backend = new HashMap(); 39 } 40 clear()41 public void clear() 42 { 43 backend.clear(); 44 } 45 46 /** 47 * Retrieves the value stored for a key in this properties collection. 48 * 49 * @param key the property key. 50 * @return The stored value, or <code>null</code> if the key does not exist in this 51 * collection. 52 */ get(final String key)53 public Object get(final String key) 54 { 55 if (key == null) 56 { 57 throw new NullPointerException("DefaultParameterMap.get (..): Parameter 'key' must not be null"); 58 } 59 return backend.get(key); 60 } 61 62 /** 63 * Retrieves the value stored for a key in this properties collection, and returning the 64 * default value if the key was not stored in this properties collection. 65 * 66 * @param key the property key. 67 * @param defaultValue the default value to be returned when the key is not stored in 68 * this properties collection. 69 * @return The stored value, or the default value if the key does not exist in this 70 * collection. 71 */ get(final String key, final Object defaultValue)72 public Object get(final String key, final Object defaultValue) 73 { 74 if (key == null) 75 { 76 throw new NullPointerException("DefaultParameterMap.get (..): Parameter 'key' must not be null"); 77 } 78 final Object o = this.backend.get(key); 79 if (o == null) 80 { 81 return defaultValue; 82 } 83 return o; 84 } 85 keys()86 public String[] keys() 87 { 88 return (String[]) this.backend.keySet().toArray(new String[backend.size()]); 89 } 90 91 /** 92 * Adds a property to this properties collection. If a property with the given name 93 * exist, the property will be replaced with the new value. If the value is null, the 94 * property will be removed. 95 * 96 * @param key the property key. 97 * @param value the property value. 98 */ put(final String key, final Object value)99 public void put(final String key, final Object value) 100 { 101 if (key == null) 102 { 103 throw new NullPointerException("ReportProperties.put (..): Parameter 'key' must not be null"); 104 } 105 if (value == null) 106 { 107 this.backend.remove(key); 108 } 109 else 110 { 111 this.backend.put(key, value); 112 } 113 } 114 size()115 public int size() 116 { 117 return this.backend.size(); 118 } 119 } 120