Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5820917d588a0a5077e69f93697b5b0b4ddb8c28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.jdk.core.util;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * @author Ken J. Aguilar
 */
public class EnhancedProperties implements Serializable {
   private static final long serialVersionUID = 4105281128024379352L;

   private final HashMap<String, Serializable> map;

   public EnhancedProperties() {
      map = new HashMap<>();
   }

   public EnhancedProperties(int initialCapacity) {
      map = new HashMap<>(initialCapacity);
   }

   public EnhancedProperties(EnhancedProperties props) {
      this();
      addAll(props);
   }

   public void setProperty(String key, Serializable value) {
      map.put(key, value);
   }

   public Serializable getProperty(String key) {
      return map.get(key);
   }

   public Serializable getProperty(String key, Serializable defaultValue) {
      Serializable value = map.get(key);
      return value == null ? defaultValue : value;
   }

   public Set<Map.Entry<String, Serializable>> entrySet() {
      return map.entrySet();
   }

   public void addAll(EnhancedProperties otherProps) {
      this.map.putAll(otherProps.map);
   }

   public void addAll(Map<String, Serializable> otherMap) {
      this.map.putAll(otherMap);
   }

   public void clear() {
      map.clear();
   }

   public Collection<String> differences(EnhancedProperties otherProps) {
      LinkedList<String> differences = new LinkedList<>();
      for (Entry<String, Serializable> entry : map.entrySet()) {
         Serializable value = otherProps.getProperty(entry.getKey());
         if (value == null) {
            if (entry.getValue() != null) {
               differences.add(entry.getKey());
            }
         } else {
            if (!value.equals(entry.getValue())) {
               differences.add(entry.getKey());
            }
         }
      }
      map.clear();
      map.putAll(otherProps.map);
      return differences;
   }

   public Map<String, Serializable> asMap() {
      return map;
   }
}

Back to the top