@@ -0,0 +1,3081 @@
+/*%0A * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.%0A *%0A * This program and the accompanying materials are made available under the%0A * terms of the Eclipse Public License v1.0 which accompanies this distribution,%0A * and is available at http://www.eclipse.org/legal/epl-v10.html%0A */%0Apackage org.opendaylight.yangtools.util;%0A%0Aimport static java.util.Objects.requireNonNull;%0A%0Aimport com.google.common.annotations.Beta;%0Aimport com.google.common.base.MoreObjects;%0Aimport java.util.Collections;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0Aimport java.util.concurrent.ConcurrentHashMap;%0Aimport java.util.function.Consumer;%0Aimport java.util.stream.Stream;%0Aimport org.eclipse.jdt.annotation.NonNullByDefault;%0Aimport org.eclipse.jdt.annotation.Nullable;%0Aimport org.opendaylight.yangtools.concepts.AbstractObjectRegistration;%0Aimport org.opendaylight.yangtools.concepts.ObjectRegistration;%0A%0A@Beta%0A@NonNullByDefault%0Apublic final class ObjectRegistry%3CT%3E %7B%0A    private final Set%3CObjectRegistration%3C? extends T%3E%3E objects;%0A    private final Set%3CObjectRegistration%3C? extends T%3E%3E unmodifiableView;%0A    private final String name;%0A%0A    private ObjectRegistry(final String name, Set%3CObjectRegistration%3C? extends T%3E%3E objects) %7B%0A        this.name = requireNonNull(name);%0A        this.objects = requireNonNull(objects);%0A        this.unmodifiableView = Collections.unmodifiableSet(objects);%0A    %7D%0A%0A    public static %3CT%3E ObjectRegistry%3CT%3E createConcurrent(final String name) %7B%0A        return new ObjectRegistry%3C%3E(name, ConcurrentHashMap.newKeySet());%0A    %7D%0A%0A    public static %3CT%3E ObjectRegistry%3CT%3E createSimple(final String name) %7B%0A        return new ObjectRegistry%3C%3E(name, new HashSet%3C%3E(1));%0A    %7D%0A%0A    public boolean isEmpty() %7B%0A        return objects.isEmpty();%0A    %7D%0A%0A    public Stream%3C? extends T%3E streamObjects() %7B%0A        return streamRegistrations().map(ObjectRegistration::getInstance);%0A    %7D%0A%0A    public Set%3CObjectRegistration%3C? extends T%3E%3E getRegistrations() %7B%0A        return unmodifiableView;%0A    %7D%0A%0A    public Stream%3CObjectRegistration%3C? extends T%3E%3E streamRegistrations() %7B%0A        return objects.stream();%0A    %7D%0A%0A    public %3CO extends T%3E ObjectRegistration%3CO%3E register(final O object) %7B%0A        final ObjectRegistration%3CO%3E ret = new Reg%3C%3E(object, objects::remove);%0A        objects.add(ret);%0A        return ret;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return MoreObjects.toStringHelper(this).add(%22name%22, name).add(%22objects%22, objects.size()).toString();%0A    %7D%0A%0A    private static final class Reg%3CT%3E extends AbstractObjectRegistration%3CT%3E %7B%0A        private @Nullable @javax.annotation.Nullable Consumer%3CObjectRegistration%3C? super T%3E%3E removeCall;%0A%0A        Reg(final T instance, final Consumer%3CObjectRegistration%3C? super T%3E%3E removeCall) %7B%0A            super(instance);%0A            this.removeCall = requireNonNull(removeCall);%0A        %7D%0A%0A        @Override%0A        protected void removeRegistration() %7B%0A            removeCall.accept(this);%0A            // Do not retail reference to that state%0A            removeCall = null;%0A        %7D%0A    %7D%0A%7D%0A

Add ObjectRegistry