Populate data/ hierarchy
[yangtools.git] / data / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / codec / CodecCache.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.util.codec;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.TypeAware;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16
17 /**
18  * Abstract cache for codecs.
19  *
20  * @author Robert Varga
21  *
22  * @param <T> Codec type
23  */
24 @Beta
25 public abstract class CodecCache<T> {
26     /**
27      * Lookup a complex codec for schema node.
28      *
29      * @param schema Schema node
30      * @param <S> schema node type
31      * @return Cached codec, or null if no codec is cached.
32      */
33     abstract <S extends SchemaNode & TypeAware> @Nullable T lookupComplex(S schema);
34
35     /**
36      * Lookup a simple codec for a type definition.
37      *
38      * @param type Type definition
39      * @return Cached codec, or null if no codec is cached.
40      */
41     abstract @Nullable T lookupSimple(TypeDefinition<?> type);
42
43     /**
44      * Lookup-or-store a complex codec for a particular schema node.
45      *
46      * @param schema Schema node
47      * @param codec Codec to cache
48      * @param <S> schema node type
49      * @return Codec instance, either already-cached, or the codec presented as argument.
50      */
51     abstract <S extends SchemaNode & TypeAware> @NonNull T getComplex(S schema, T codec);
52
53     /**
54      * Lookup-or-store a simple codec for a particular schema node.
55      *
56      * @param type Type definition
57      * @param codec Codec to cache
58      * @return Codec instance, either already-cached, or the codec presented as argument.
59      */
60     abstract @NonNull T getSimple(TypeDefinition<?> type, T codec);
61 }