
com.redhat.lightblue.util.DefaultRegistry Maven / Gradle / Ivy
/*
Copyright 2013 Red Hat, Inc. and/or its affiliates.
This file is part of lightblue.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
package com.redhat.lightblue.util;
import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Default implementation of the registry interface
*/
public class DefaultRegistry implements Registry, Serializable {
private final List> resolvers = new ArrayList<>();
private final Map items = new HashMap<>();
@Override
public void add(K key, V value) {
items.put(key, value);
}
@Override
public void add(Resolver resolver) {
resolvers.add(resolver);
}
public void mergeWith(DefaultRegistry parser) {
for (Object o : parser.resolvers) {
Resolver r = (Resolver) o;
if (!this.resolvers.contains(r)) {
this.resolvers.add(r);
}
}
Iterator it = parser.items.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
if (!items.containsKey(pair.getKey())) {
items.put((K) pair.getKey(), (V) pair.getValue());
}
}
}
@Override
public V find(K name) {
V value = items.get(name);
if (value == null) {
for (Resolver x : resolvers) {
value = x.find(name);
if (value != null) {
break;
}
}
}
return value;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy