L3: Add eth to br-ex
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / message / MonitorRequestBuilder.java
1 /*
2  * Copyright (c) 2013, 2015 EBay Software Foundation 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
9 package org.opendaylight.ovsdb.lib.message;
10
11 import java.util.List;
12 import java.util.Set;
13
14 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
15 import org.opendaylight.ovsdb.lib.schema.TableSchema;
16
17 public class MonitorRequestBuilder<E extends TableSchema<E>> {
18
19     E tableSchema;
20     MonitorRequest<E> monitorRequest;
21
22     MonitorRequestBuilder(E tableSchema) {
23         this.tableSchema = tableSchema;
24     }
25
26     public static <T extends TableSchema<T>> MonitorRequestBuilder<T> builder(T tableSchema) {
27         return new MonitorRequestBuilder<>(tableSchema);
28     }
29
30     MonitorRequest<E> getMonitorRequest() {
31         if (monitorRequest == null) {
32             monitorRequest = new MonitorRequest<>();
33         }
34         return monitorRequest;
35     }
36
37     public MonitorRequestBuilder<E> addColumn(String column) {
38         getMonitorRequest().addColumn(column);
39         return this;
40     }
41
42     public MonitorRequestBuilder<E> addColumn(ColumnSchema<?, ?> column) {
43         this.addColumn(column.getName());
44         return this;
45     }
46
47     public MonitorRequestBuilder<E> addColumns(List<ColumnSchema<E, ?>> columns) {
48         for (ColumnSchema<E, ?> schema : columns) {
49             this.addColumn(schema);
50         }
51         return this;
52     }
53
54     public Set<String> getColumns() {
55         return getMonitorRequest().getColumns();
56     }
57
58     public MonitorRequestBuilder<E> with(MonitorSelect select) {
59         getMonitorRequest().setSelect(select);
60         return this;
61     }
62
63     public MonitorRequest<E> build() {
64         MonitorRequest<E> monitorRequest = getMonitorRequest();
65         if (monitorRequest.getSelect() == null) {
66             monitorRequest.setSelect(new MonitorSelect());
67         }
68         monitorRequest.setTableName(tableSchema.getName());
69         return monitorRequest;
70     }
71 }