1
2 /*
3 * Copyright 2011 The Kuali Foundation
4 *
5 * Licensed under the Educational Community License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.opensource.org/licenses/ecl1.php
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.kuali.student.r2.common.util;
18
19 import java.util.List;
20 import java.util.Map;
21 import org.kuali.student.r2.common.dto.AttributeInfo;
22
23 /**
24 * Utility to convert text between plain and formatted
25 *
26 * @author nwright
27 */
28 public class AttributeHelper {
29
30 private List<AttributeInfo> attrs;
31
32 public AttributeHelper(List<AttributeInfo> attrs) {
33 this.attrs = attrs;
34 }
35
36 public void putAll(Map<String, String> map) {
37 //Code Changed for JIRA-8997 - SONAR Critical issues - Performance - Inefficient use of keySet iterator instead of entrySet iterator
38 for(Map.Entry<String, String> entry: map.entrySet()) {
39 this.put(entry.getKey(), entry.getValue());
40 }
41 }
42
43 public String get(String key) {
44 for (AttributeInfo attr : attrs) {
45 if (attr.getKey().equals(key)) {
46 return attr.getValue();
47 }
48 }
49 return null;
50 }
51
52 public void put(String key, String value) {
53 for (AttributeInfo attr : attrs) {
54 if (attr.getKey().equals(key)) {
55 attr.setValue(value);
56 return;
57 }
58 }
59 AttributeInfo info = new AttributeInfo(key, value);
60 attrs.add(info);
61 }
62 }