Add INFO.yaml for GBP
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / statistics / flowcache / FlowCacheKeys.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.groupbasedpolicy.renderer.ofoverlay.statistics.flowcache;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import com.google.common.base.Joiner;
14 import com.google.common.base.Preconditions;
15
16 public final class FlowCacheKeys {
17
18     private static final String SEPARATOR = ",";
19
20     private String value;
21
22     private FlowCacheKeys(FlowCacheKeysBuilder builder) {
23         this.value = Joiner.on(SEPARATOR).join(builder.getValues());
24     }
25
26     public String getValue() {
27         return value;
28     }
29
30     public static FlowCacheKeysBuilder builder(){
31         return new FlowCacheKeysBuilder();
32     }
33
34     public static class FlowCacheKeysBuilder {
35
36         private List<String> values = new ArrayList<>();
37
38         public List<String> getValues() {
39             return values;
40         }
41
42         /**
43          * Sets FlowCache's "key" values by copying {@code String}s from {@code values},
44          * to avoid immutable list put as a parameter.
45          * {@code null}s are omitted.
46          *
47          * @param values List of String
48          * @return FlowCacheKeysBuilder
49          */
50         public FlowCacheKeysBuilder setValues(List<String> values) {
51             Preconditions.checkNotNull(values);
52             for (String value : values) {
53                 if (value != null) {
54                     this.values.add(value);
55                 }
56             }
57             return this;
58         }
59
60         public FlowCacheKeysBuilder addValue(String value) {
61             values.add(Preconditions.checkNotNull(value));
62             return this;
63         }
64
65         public FlowCacheKeys build() {
66             return new FlowCacheKeys(this);
67         }
68     }
69 }