BrightSide Workbench Full Report + Source Code
AttributeSupport.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.context;
19 
20 import java.util.*;
21 import org.turro.string.Strings;
22 
27 public class AttributeSupport extends HashMap {
28 
30  public AttributeSupport() {
31  }
32 
33  public void addAttribute(AttributeItem attr) {
34  put(attr.name, attr);
35  }
36 
37  public AttributeItem get(String name) {
38  return (AttributeItem) super.get(name);
39  }
40 
41  public AttributeItem getAttribute(String name) {
42  return (AttributeItem) get(name);
43  }
44 
45  public String getAttributeValue(String name, String defaultValue) {
46  AttributeItem ai = (AttributeItem) get(name);
47  String value = null;
48  if(ai != null) {
49  value = ai.getValue();
50  }
51  if(value == null) {
52  return defaultValue;
53  }
54  return value;
55  }
56 
57  public int getAttributeIntegerValue(String name, int defaultValue) {
58  AttributeItem ai = (AttributeItem) get(name);
59  if(ai != null) {
60  return ai.getIntegerValue(defaultValue);
61  }
62  return defaultValue;
63  }
64 
65  public double getAttributeDoubleValue(String name, double defaultValue) {
66  AttributeItem ai = (AttributeItem) get(name);
67  if(ai != null) {
68  return ai.getDoubleValue(defaultValue);
69  }
70  return defaultValue;
71  }
72 
73  public boolean getAttributeBooleanValue(String name, boolean defaultValue) {
74  AttributeItem ai = (AttributeItem) get(name);
75  if(ai != null) {
76  return ai.getBooleanValue(defaultValue);
77  }
78  return defaultValue;
79  }
80 
81  public Date getAttributeDateValue(String name, Date defaultValue) {
82  AttributeItem ai = (AttributeItem) get(name);
83  if(ai != null) {
84  return ai.getDateValue(defaultValue);
85  }
86  return defaultValue;
87  }
88 
89  public List<String> getAttributeListValue(String name, String defaultValue) {
90  String value = getAttributeValue(name, defaultValue);
91  if(!Strings.isBlank(value)) {
92  return Arrays.asList(value.split(","));
93  }
94  return null;
95  }
96 
97 }
int getAttributeIntegerValue(String name, int defaultValue)
String getAttributeValue(String name, String defaultValue)
double getAttributeDoubleValue(String name, double defaultValue)
List< String > getAttributeListValue(String name, String defaultValue)
Date getAttributeDateValue(String name, Date defaultValue)
boolean getAttributeBooleanValue(String name, boolean defaultValue)