Switch to JDT annotations for Nullable and NonNull
[netvirt.git] / aclservice / api / src / main / java / org / opendaylight / netvirt / aclservice / api / AclInterfaceCache.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies 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.netvirt.aclservice.api;
9
10 import java.util.Collection;
11 import java.util.Map.Entry;
12 import java.util.function.BiConsumer;
13 import java.util.function.BiFunction;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
17
18 /**
19  * Interface for an AclInterface cache.
20  *
21  * @author Thomas Pantelis
22  */
23 public interface AclInterfaceCache {
24
25     /**
26      * Adds a new AclInterface if not already existing, otherwise updates the existing instance. In either case,
27      * the given updateFunction is used to build a new instance.
28      *
29      * @param interfaceId the interface Id
30      * @param updateFunction the function used to build a new instance from the provided AclInterface.Builder. If an
31      *                       instance already exists in the cache, the previous instance is passed to the function and
32      *                       the Builder is initially populated from the existing instance.
33      * @return the new or updated AclInterface
34      */
35     @NonNull
36     AclInterface addOrUpdate(@NonNull String interfaceId,
37             @NonNull BiConsumer<AclInterface, AclInterface.Builder> updateFunction);
38
39     /**
40      * Updates an existing AclInterface instance in the cache. The given updateFunction is used to build a new instance.
41      *
42      * @param interfaceId the interface Id
43      * @param updateFunction the function used to build a new instance from the provided AclInterface.Builder. The
44      *                       previous instance is passed to the function and the Builder is initially populated from
45      *                       the existing instance. The function returns a boolean indicating if any updates were
46      *                       actually made.
47      * @return the updated AclInterface or null if no instance was present or no updates were made
48      */
49     @Nullable
50     AclInterface updateIfPresent(@NonNull String interfaceId,
51             @NonNull BiFunction<AclInterface, AclInterface.Builder, Boolean> updateFunction);
52
53     /**
54      * Removes an AclInterface instance from the cache.
55      *
56      * @param interfaceId the interface Id
57      * @return the AclInterface if present, null oherwise
58      */
59     AclInterface remove(@NonNull String interfaceId);
60
61     /**
62      * Gets an AclInterface instance from the cache if present.
63      *
64      * @param interfaceId the interface Id
65      * @return the AclInterface instance if found, null otherwise
66      */
67     @Nullable
68     AclInterface get(@NonNull String interfaceId);
69
70     @NonNull
71     Collection<Entry<String, AclInterface>> entries();
72 }