2 * Copyright (c) 2018 Pantheon Technologies, 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.common;
9 import static java.util.Objects.requireNonNull;
11 import com.google.common.annotations.Beta;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.io.Serial;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.eclipse.jdt.annotation.Nullable;
18 * A opportunistically-caching {@link DerivedString}. Canonical name is cached at first encounter.
20 * @param <T> derived string type
21 * @author Robert Varga
25 public abstract class CachingDerivedString<T extends CachingDerivedString<T>> extends DerivedString<T> {
27 private static final long serialVersionUID = 1L;
29 private transient volatile @Nullable String str;
31 @SuppressFBWarnings("NP_STORE_INTO_NONNULL_FIELD")
32 protected CachingDerivedString() {
36 protected CachingDerivedString(final String str) {
37 this.str = requireNonNull(str);
41 public final String toCanonicalString() {
43 return (local = this.str) != null ? local : (str = computeCanonicalString());
47 * Return the canonical string representation of this object's value.
49 * @return Canonical string
51 protected abstract String computeCanonicalString();