702d11b86a5d0052e47607562c85067f5e148940
[yangtools.git] / yang / 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 javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
14 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
15
16 /**
17  * Abstract cache for codecs.
18  *
19  * @author Robert Varga
20  *
21  * @param <T> Codec type
22  */
23 @Beta
24 public abstract class CodecCache<T> {
25     /**
26      * Lookup a complex codec for schema node.
27      *
28      * @param schema Schema node
29      * @return Cached codec, or null if no codec is cached.
30      */
31     @Nullable abstract T lookupComplex(TypedDataSchemaNode schema);
32
33     /**
34      * Lookup a simple codec for a type definition.
35      *
36      * @param type Type definition
37      * @return Cached codec, or null if no codec is cached.
38      */
39     @Nullable abstract T lookupSimple(TypeDefinition<?> type);
40
41     /**
42      * Lookup-or-store a complex codec for a particular schema node.
43      *
44      * @param schema Schema node
45      * @param codec Codec to cache
46      * @return Codec instance, either already-cached, or the codec presented as argument.
47      */
48     @Nonnull abstract T getComplex(TypedDataSchemaNode schema, T codec);
49
50     /**
51      * Lookup-or-store a simple codec for a particular schema node.
52      *
53      * @param type Type definition
54      * @param codec Codec to cache
55      * @return Codec instance, either already-cached, or the codec presented as argument.
56      */
57     @Nonnull abstract T getSimple(TypeDefinition<?> type, T codec);
58 }