Represents map-like data-flow facts. @param type of keys @param type of values
| 37 | * @param <V> type of values |
| 38 | */ |
| 39 | public class MapFact<K, V> implements Copyable<MapFact<K, V>> { |
| 40 | |
| 41 | /** |
| 42 | * The map holding the mappings of this MapFact. |
| 43 | */ |
| 44 | protected final Map<K, V> map; |
| 45 | |
| 46 | /** |
| 47 | * Constructs a new MapFact with the same mappings as specified Map. |
| 48 | * |
| 49 | * @param map the map whose mappings are to be placed in this map. |
| 50 | */ |
| 51 | public MapFact(Map<K, V> map) { |
| 52 | this.map = Maps.newHybridMap(map); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return the value to which the specified key is mapped, |
| 57 | * or null if this map contains no mapping for the key. |
| 58 | */ |
| 59 | public V get(K key) { |
| 60 | return map.get(key); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Updates the key-value mapping in this fact. |
| 65 | * |
| 66 | * @return if the update changes this fact. |
| 67 | */ |
| 68 | public boolean update(K key, V value) { |
| 69 | return !Objects.equals(map.put(key, value), value); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Removes the key-value mapping for given key. |
| 74 | * |
| 75 | * @return the previous value associated with key, |
| 76 | * or null if there was no mapping for key. |
| 77 | */ |
| 78 | public V remove(K key) { |
| 79 | return map.remove(key); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Copies the content from given fact to this fact. |
| 84 | * |
| 85 | * @return true if this fact changed as a result of the call, otherwise false. |
| 86 | */ |
| 87 | public boolean copyFrom(MapFact<K, V> fact) { |
| 88 | boolean changed = false; |
| 89 | for (Map.Entry<K, V> entry : fact.map.entrySet()) { |
| 90 | changed |= update(entry.getKey(), entry.getValue()); |
| 91 | } |
| 92 | return changed; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Creates and returns a copy of this fact. |
nothing calls this directly
no outgoing calls
no test coverage detected