2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.schema;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.Interner;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
16 final class InterningLeafNodeBuilder<T> implements LeafNode.Builder<T> {
17 private final Interner<LeafNode<T>> interner;
18 private final LeafNode.Builder<T> delegate;
20 InterningLeafNodeBuilder(final LeafNode.Builder<T> delegate, final Interner<LeafNode<T>> interner) {
21 this.delegate = requireNonNull(delegate);
22 this.interner = requireNonNull(interner);
26 public LeafNode.Builder<T> withValue(final T value) {
27 delegate.withValue(value);
32 public LeafNode.Builder<T> withNodeIdentifier(final NodeIdentifier nodeIdentifier) {
33 delegate.withNodeIdentifier(nodeIdentifier);
38 public LeafNode<T> build() {
39 return interner.intern(delegate.build());