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 org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.eclipse.jdt.annotation.Nullable;
15 * A opportunistically-caching {@link DerivedString}. Canonical name is cached at first encounter.
17 * @param <T> derived string type
18 * @author Robert Varga
21 public abstract class CachingDerivedString<T extends CachingDerivedString<T>> extends DerivedString<T> {
22 private static final long serialVersionUID = 1L;
24 private transient volatile @Nullable String str;
26 protected CachingDerivedString() {
30 protected CachingDerivedString(final String str) {
31 this.str = requireNonNull(str);
35 public final String toCanonicalString() {
37 return (local = this.str) != null ? local : (str = computeCanonicalString());
41 * Return the canonical string representation of this object's value.
43 * @return Canonical string
45 protected abstract String computeCanonicalString();