Committed by
Ray Milkey
Remove unused class: BatchWrite
Change-Id: I334bf328213881dc44e94524d5a54151f1cba8d4
Showing
1 changed file
with
0 additions
and
129 deletions
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 final 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 | - private BatchWrite() {} | ||
40 | - | ||
41 | - /** | ||
42 | - * Returns a new empty batch write operation builder. | ||
43 | - * | ||
44 | - * @return BatchWrite | ||
45 | - */ | ||
46 | - public static BatchWrite newInstance() { | ||
47 | - return new BatchWrite(); | ||
48 | - } | ||
49 | - | ||
50 | - public List<Operation> operations() { | ||
51 | - return Collections.unmodifiableList(operations); | ||
52 | - } | ||
53 | - | ||
54 | - public boolean isEmpty() { | ||
55 | - return operations.isEmpty(); | ||
56 | - } | ||
57 | - | ||
58 | - public BatchWrite createIntent(Intent intent) { | ||
59 | - operations.add(Operation.of(OpType.CREATE_INTENT, | ||
60 | - ImmutableList.of(intent))); | ||
61 | - return this; | ||
62 | - } | ||
63 | - | ||
64 | - public BatchWrite removeIntent(IntentId intentId) { | ||
65 | - operations.add(Operation.of(OpType.REMOVE_INTENT, | ||
66 | - ImmutableList.of(intentId))); | ||
67 | - return this; | ||
68 | - } | ||
69 | - | ||
70 | - public BatchWrite setState(Intent intent, IntentState newState) { | ||
71 | - operations.add(Operation.of(OpType.SET_STATE, | ||
72 | - ImmutableList.of(intent, newState))); | ||
73 | - return this; | ||
74 | - } | ||
75 | - | ||
76 | - public BatchWrite setInstallableIntents(IntentId intentId, List<Intent> installableIntents) { | ||
77 | - operations.add(Operation.of(OpType.SET_INSTALLABLE, | ||
78 | - ImmutableList.of(intentId, installableIntents))); | ||
79 | - return this; | ||
80 | - } | ||
81 | - | ||
82 | - public BatchWrite removeInstalledIntents(IntentId intentId) { | ||
83 | - operations.add(Operation.of(OpType.REMOVE_INSTALLED, | ||
84 | - ImmutableList.of(intentId))); | ||
85 | - return this; | ||
86 | - } | ||
87 | - | ||
88 | - @Override | ||
89 | - public String toString() { | ||
90 | - return MoreObjects.toStringHelper(getClass()) | ||
91 | - .add("operations", operations) | ||
92 | - .toString(); | ||
93 | - } | ||
94 | - | ||
95 | - public static final class Operation { | ||
96 | - final OpType type; | ||
97 | - final ImmutableList<Object> args; | ||
98 | - | ||
99 | - public static Operation of(OpType type, List<Object> args) { | ||
100 | - return new Operation(type, args); | ||
101 | - } | ||
102 | - | ||
103 | - private Operation(OpType type, List<Object> args) { | ||
104 | - this.type = checkNotNull(type); | ||
105 | - this.args = ImmutableList.copyOf(args); | ||
106 | - } | ||
107 | - | ||
108 | - public OpType type() { | ||
109 | - return type; | ||
110 | - } | ||
111 | - | ||
112 | - public ImmutableList<Object> args() { | ||
113 | - return args; | ||
114 | - } | ||
115 | - | ||
116 | - @SuppressWarnings("unchecked") | ||
117 | - public <T> T arg(int i) { | ||
118 | - return (T) args.get(i); | ||
119 | - } | ||
120 | - | ||
121 | - @Override | ||
122 | - public String toString() { | ||
123 | - return MoreObjects.toStringHelper(getClass()) | ||
124 | - .add("type", type) | ||
125 | - .add("args", args) | ||
126 | - .toString(); | ||
127 | - } | ||
128 | - } | ||
129 | -} |
-
Please register or login to post a comment