Sho SHIMIZU
Committed by Gerrit Code Review

Move nested class to top-level class

Because BatchWrite is public and no need to place it as an inner class in
IntentStore interface

Change-Id: I17e87e06baa4f0af55fa30b09a891bc23932a6fd
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.intent;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.collect.ImmutableList;
20 +
21 +import java.util.ArrayList;
22 +import java.util.Collections;
23 +import java.util.List;
24 +
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +public class BatchWrite {
28 +
29 + public enum OpType {
30 + CREATE_INTENT,
31 + REMOVE_INTENT,
32 + SET_STATE,
33 + SET_INSTALLABLE,
34 + REMOVE_INSTALLED
35 + }
36 +
37 + List<Operation> operations = new ArrayList<>();
38 +
39 + public List<Operation> operations() {
40 + return Collections.unmodifiableList(operations);
41 + }
42 +
43 + public boolean isEmpty() {
44 + return operations.isEmpty();
45 + }
46 +
47 + public BatchWrite createIntent(Intent intent) {
48 + operations.add(Operation.of(OpType.CREATE_INTENT,
49 + ImmutableList.of(intent)));
50 + return this;
51 + }
52 +
53 + public BatchWrite removeIntent(IntentId intentId) {
54 + operations.add(Operation.of(OpType.REMOVE_INTENT,
55 + ImmutableList.of(intentId)));
56 + return this;
57 + }
58 +
59 + public BatchWrite setState(Intent intent, IntentState newState) {
60 + operations.add(Operation.of(OpType.SET_STATE,
61 + ImmutableList.of(intent, newState)));
62 + return this;
63 + }
64 +
65 + public BatchWrite setInstallableIntents(IntentId intentId, List<Intent> installableIntents) {
66 + operations.add(Operation.of(OpType.SET_INSTALLABLE,
67 + ImmutableList.of(intentId, installableIntents)));
68 + return this;
69 + }
70 +
71 + public BatchWrite removeInstalledIntents(IntentId intentId) {
72 + operations.add(Operation.of(OpType.REMOVE_INSTALLED,
73 + ImmutableList.of(intentId)));
74 + return this;
75 + }
76 +
77 + @Override
78 + public String toString() {
79 + return MoreObjects.toStringHelper(getClass())
80 + .add("operations", operations)
81 + .toString();
82 + }
83 +
84 + public static class Operation {
85 + final OpType type;
86 + final ImmutableList<Object> args;
87 +
88 + public static Operation of(OpType type, List<Object> args) {
89 + return new Operation(type, args);
90 + }
91 +
92 + // TODO: consider make it private
93 + public Operation(OpType type, List<Object> args) {
94 + this.type = checkNotNull(type);
95 + this.args = ImmutableList.copyOf(args);
96 + }
97 +
98 + public OpType type() {
99 + return type;
100 + }
101 +
102 + public ImmutableList<Object> args() {
103 + return args;
104 + }
105 +
106 + @SuppressWarnings("unchecked")
107 + public <T> T arg(int i) {
108 + return (T) args.get(i);
109 + }
110 +
111 + @Override
112 + public String toString() {
113 + return MoreObjects.toStringHelper(getClass())
114 + .add("type", type)
115 + .add("args", args)
116 + .toString();
117 + }
118 + }
119 +}
...@@ -15,16 +15,9 @@ ...@@ -15,16 +15,9 @@
15 */ 15 */
16 package org.onosproject.net.intent; 16 package org.onosproject.net.intent;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import org.onosproject.net.intent.BatchWrite.Operation;
19 -
20 -import org.onosproject.net.intent.IntentStore.BatchWrite.Operation;
21 import org.onosproject.store.Store; 19 import org.onosproject.store.Store;
22 20
23 -import com.google.common.base.MoreObjects;
24 -import com.google.common.collect.ImmutableList;
25 -
26 -import java.util.ArrayList;
27 -import java.util.Collections;
28 import java.util.List; 21 import java.util.List;
29 22
30 /** 23 /**
...@@ -135,96 +128,4 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { ...@@ -135,96 +128,4 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
135 */ 128 */
136 List<Operation> batchWrite(BatchWrite batch); 129 List<Operation> batchWrite(BatchWrite batch);
137 130
138 - public static class BatchWrite {
139 -
140 - public enum OpType {
141 - CREATE_INTENT,
142 - REMOVE_INTENT,
143 - SET_STATE,
144 - SET_INSTALLABLE,
145 - REMOVE_INSTALLED
146 - }
147 -
148 - List<Operation> operations = new ArrayList<>();
149 -
150 - public List<Operation> operations() {
151 - return Collections.unmodifiableList(operations);
152 - }
153 -
154 - public boolean isEmpty() {
155 - return operations.isEmpty();
156 - }
157 -
158 - public BatchWrite createIntent(Intent intent) {
159 - operations.add(Operation.of(OpType.CREATE_INTENT,
160 - ImmutableList.of(intent)));
161 - return this;
162 - }
163 -
164 - public BatchWrite removeIntent(IntentId intentId) {
165 - operations.add(Operation.of(OpType.REMOVE_INTENT,
166 - ImmutableList.of(intentId)));
167 - return this;
168 - }
169 -
170 - public BatchWrite setState(Intent intent, IntentState newState) {
171 - operations.add(Operation.of(OpType.SET_STATE,
172 - ImmutableList.of(intent, newState)));
173 - return this;
174 - }
175 -
176 - public BatchWrite setInstallableIntents(IntentId intentId, List<Intent> installableIntents) {
177 - operations.add(Operation.of(OpType.SET_INSTALLABLE,
178 - ImmutableList.of(intentId, installableIntents)));
179 - return this;
180 - }
181 -
182 - public BatchWrite removeInstalledIntents(IntentId intentId) {
183 - operations.add(Operation.of(OpType.REMOVE_INSTALLED,
184 - ImmutableList.of(intentId)));
185 - return this;
186 - }
187 -
188 - @Override
189 - public String toString() {
190 - return MoreObjects.toStringHelper(getClass())
191 - .add("operations", operations)
192 - .toString();
193 - }
194 -
195 - public static class Operation {
196 - final OpType type;
197 - final ImmutableList<Object> args;
198 -
199 - public static Operation of(OpType type, List<Object> args) {
200 - return new Operation(type, args);
201 - }
202 -
203 - public Operation(OpType type, List<Object> args) {
204 - this.type = checkNotNull(type);
205 - this.args = ImmutableList.copyOf(args);
206 - }
207 -
208 - public OpType type() {
209 - return type;
210 - }
211 -
212 - public ImmutableList<Object> args() {
213 - return args;
214 - }
215 -
216 - @SuppressWarnings("unchecked")
217 - public <T> T arg(int i) {
218 - return (T) args.get(i);
219 - }
220 -
221 - @Override
222 - public String toString() {
223 - return MoreObjects.toStringHelper(getClass())
224 - .add("type", type)
225 - .add("args", args)
226 - .toString();
227 - }
228 - }
229 - }
230 } 131 }
......
...@@ -48,7 +48,7 @@ import org.onosproject.net.intent.IntentOperations; ...@@ -48,7 +48,7 @@ import org.onosproject.net.intent.IntentOperations;
48 import org.onosproject.net.intent.IntentService; 48 import org.onosproject.net.intent.IntentService;
49 import org.onosproject.net.intent.IntentState; 49 import org.onosproject.net.intent.IntentState;
50 import org.onosproject.net.intent.IntentStore; 50 import org.onosproject.net.intent.IntentStore;
51 -import org.onosproject.net.intent.IntentStore.BatchWrite; 51 +import org.onosproject.net.intent.BatchWrite;
52 import org.onosproject.net.intent.IntentStoreDelegate; 52 import org.onosproject.net.intent.IntentStoreDelegate;
53 import org.slf4j.Logger; 53 import org.slf4j.Logger;
54 54
......
...@@ -32,13 +32,14 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -32,13 +32,14 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
32 import org.apache.felix.scr.annotations.Service; 32 import org.apache.felix.scr.annotations.Service;
33 import org.onlab.metrics.MetricsService; 33 import org.onlab.metrics.MetricsService;
34 import org.onosproject.core.MetricsHelper; 34 import org.onosproject.core.MetricsHelper;
35 +import org.onosproject.net.intent.BatchWrite;
35 import org.onosproject.net.intent.Intent; 36 import org.onosproject.net.intent.Intent;
36 import org.onosproject.net.intent.IntentEvent; 37 import org.onosproject.net.intent.IntentEvent;
37 import org.onosproject.net.intent.IntentId; 38 import org.onosproject.net.intent.IntentId;
38 import org.onosproject.net.intent.IntentState; 39 import org.onosproject.net.intent.IntentState;
39 import org.onosproject.net.intent.IntentStore; 40 import org.onosproject.net.intent.IntentStore;
40 import org.onosproject.net.intent.IntentStoreDelegate; 41 import org.onosproject.net.intent.IntentStoreDelegate;
41 -import org.onosproject.net.intent.IntentStore.BatchWrite.Operation; 42 +import org.onosproject.net.intent.BatchWrite.Operation;
42 import org.onosproject.store.AbstractStore; 43 import org.onosproject.store.AbstractStore;
43 import org.onosproject.store.serializers.KryoNamespaces; 44 import org.onosproject.store.serializers.KryoNamespaces;
44 import org.onosproject.store.serializers.KryoSerializer; 45 import org.onosproject.store.serializers.KryoSerializer;
......
...@@ -38,12 +38,13 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -38,12 +38,13 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
38 import org.apache.felix.scr.annotations.Service; 38 import org.apache.felix.scr.annotations.Service;
39 import org.onlab.metrics.MetricsService; 39 import org.onlab.metrics.MetricsService;
40 import org.onosproject.core.MetricsHelper; 40 import org.onosproject.core.MetricsHelper;
41 +import org.onosproject.net.intent.BatchWrite;
41 import org.onosproject.net.intent.Intent; 42 import org.onosproject.net.intent.Intent;
42 import org.onosproject.net.intent.IntentEvent; 43 import org.onosproject.net.intent.IntentEvent;
43 import org.onosproject.net.intent.IntentId; 44 import org.onosproject.net.intent.IntentId;
44 import org.onosproject.net.intent.IntentState; 45 import org.onosproject.net.intent.IntentState;
45 import org.onosproject.net.intent.IntentStore; 46 import org.onosproject.net.intent.IntentStore;
46 -import org.onosproject.net.intent.IntentStore.BatchWrite.Operation; 47 +import org.onosproject.net.intent.BatchWrite.Operation;
47 import org.onosproject.net.intent.IntentStoreDelegate; 48 import org.onosproject.net.intent.IntentStoreDelegate;
48 import org.onosproject.store.hz.AbstractHazelcastStore; 49 import org.onosproject.store.hz.AbstractHazelcastStore;
49 import org.onosproject.store.hz.SMap; 50 import org.onosproject.store.hz.SMap;
......
...@@ -22,13 +22,14 @@ import org.apache.felix.scr.annotations.Activate; ...@@ -22,13 +22,14 @@ import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 23 import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
25 +import org.onosproject.net.intent.BatchWrite;
25 import org.onosproject.net.intent.Intent; 26 import org.onosproject.net.intent.Intent;
26 import org.onosproject.net.intent.IntentEvent; 27 import org.onosproject.net.intent.IntentEvent;
27 import org.onosproject.net.intent.IntentId; 28 import org.onosproject.net.intent.IntentId;
28 import org.onosproject.net.intent.IntentState; 29 import org.onosproject.net.intent.IntentState;
29 import org.onosproject.net.intent.IntentStore; 30 import org.onosproject.net.intent.IntentStore;
30 import org.onosproject.net.intent.IntentStoreDelegate; 31 import org.onosproject.net.intent.IntentStoreDelegate;
31 -import org.onosproject.net.intent.IntentStore.BatchWrite.Operation; 32 +import org.onosproject.net.intent.BatchWrite.Operation;
32 import org.onosproject.store.AbstractStore; 33 import org.onosproject.store.AbstractStore;
33 import org.slf4j.Logger; 34 import org.slf4j.Logger;
34 35
......