Fix findbugs violations in library
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / operations / Mutate.java
1 /*
2  * Copyright © 2014, 2017 Matt Oswalt 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.ovsdb.lib.operations;
9
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.ovsdb.lib.notation.Condition;
14 import org.opendaylight.ovsdb.lib.notation.Mutation;
15 import org.opendaylight.ovsdb.lib.notation.Mutator;
16 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
17 import org.opendaylight.ovsdb.lib.schema.TableSchema;
18
19 public class Mutate<E extends TableSchema<E>> extends Operation<E> implements ConditionalOperation {
20
21     public static final String MUTATE = "mutate";
22     List<Condition> where = new ArrayList<>();
23     private List<Mutation> mutations = new ArrayList<>();
24
25     public Mutate on(TableSchema schema) {
26         this.setTableSchema(schema);
27         return this;
28     }
29
30     public Mutate(TableSchema<E> schema) {
31         super(schema, MUTATE);
32     }
33
34     @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT") // validate call below
35     public <T extends TableSchema<T>, D> Mutate<E> addMutation(ColumnSchema<T, D> columnSchema,
36                                                                Mutator mutator, D value) {
37         columnSchema.validate(value);
38         Object untypedValue = columnSchema.getNormalizeData(value);
39         mutations.add(new Mutation(columnSchema.getName(), mutator, untypedValue));
40         return this;
41     }
42
43     public List<Mutation> getMutations() {
44         return mutations;
45     }
46
47     public void setMutations(List<Mutation> mutations) {
48         this.mutations = mutations;
49     }
50
51     @Override
52     public void addCondition(Condition condition) {
53         this.where.add(condition);
54     }
55
56     public Where where(Condition condition) {
57         this.where.add(condition);
58         return new Where(this);
59     }
60
61     public List<Condition> getWhere() {
62         return where;
63     }
64
65     public void setWhere(List<Condition> where) {
66         this.where = where;
67     }
68 }