lishuai | 2ddc469 | 2015-07-31 15:15:16 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.ovsdb.rfc.utils; |
| 17 | |
| 18 | import org.onosproject.ovsdb.rfc.notation.Condition; |
| 19 | import org.onosproject.ovsdb.rfc.notation.Condition.Function; |
| 20 | |
| 21 | /** |
| 22 | * Condition utility class. |
| 23 | */ |
| 24 | public final class ConditionUtil { |
| 25 | |
| 26 | /** |
| 27 | * Constructs a ConditionUtil object. Utility classes should not have a |
| 28 | * public or default constructor, otherwise IDE will compile unsuccessfully. This |
| 29 | * class should not be instantiated. |
| 30 | */ |
| 31 | private ConditionUtil() { |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Returns a Condition that means Function.EQUALS . |
| 36 | * @param columnName column name |
| 37 | * @param data column value |
| 38 | * @return Condition |
| 39 | */ |
Ray Milkey | 676249c | 2015-12-18 09:27:03 -0800 | [diff] [blame] | 40 | public static Condition isEqual(String columnName, Object data) { |
lishuai | 2ddc469 | 2015-07-31 15:15:16 +0800 | [diff] [blame] | 41 | Object value = TransValueUtil.getFormatData(data); |
| 42 | return new Condition(columnName, Function.EQUALS, value); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns a Condition that means Function.NOT_EQUALS . |
| 47 | * @param columnName column name |
| 48 | * @param data column value |
| 49 | * @return Condition |
| 50 | */ |
| 51 | public static Condition unEquals(String columnName, Object data) { |
| 52 | Object value = TransValueUtil.getFormatData(data); |
| 53 | return new Condition(columnName, Function.NOT_EQUALS, value); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns a Condition that means Function.GREATER_THAN . |
| 58 | * @param columnName column name |
| 59 | * @param data column value |
| 60 | * @return Condition |
| 61 | */ |
| 62 | public static Condition greaterThan(String columnName, Object data) { |
| 63 | Object value = TransValueUtil.getFormatData(data); |
| 64 | return new Condition(columnName, Function.GREATER_THAN, value); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns a Condition that means Function.GREATER_THAN_OR_EQUALS . |
| 69 | * @param columnName column name |
| 70 | * @param data column value |
| 71 | * @return Condition |
| 72 | */ |
| 73 | public static Condition greaterThanOrEquals(String columnName, Object data) { |
| 74 | Object value = TransValueUtil.getFormatData(data); |
| 75 | return new Condition(columnName, Function.GREATER_THAN_OR_EQUALS, value); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns a Condition that means Function.LESS_THAN . |
| 80 | * @param columnName column name |
| 81 | * @param data column value |
| 82 | * @return Condition |
| 83 | */ |
| 84 | public static Condition lesserThan(String columnName, Object data) { |
| 85 | Object value = TransValueUtil.getFormatData(data); |
| 86 | return new Condition(columnName, Function.LESS_THAN, value); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns a Condition that means Function.LESS_THAN_OR_EQUALS . |
| 91 | * @param columnName column name |
| 92 | * @param data column value |
| 93 | * @return Condition |
| 94 | */ |
| 95 | public static Condition lesserThanOrEquals(String columnName, Object data) { |
| 96 | Object value = TransValueUtil.getFormatData(data); |
| 97 | return new Condition(columnName, Function.LESS_THAN_OR_EQUALS, value); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns a Condition that means Function.INCLUDES . |
| 102 | * @param columnName column name |
| 103 | * @param data column value |
| 104 | * @return Condition |
| 105 | */ |
| 106 | public static Condition includes(String columnName, Object data) { |
| 107 | Object value = TransValueUtil.getFormatData(data); |
| 108 | return new Condition(columnName, Function.INCLUDES, value); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns a Condition that means Function.EXCLUDES . |
| 113 | * @param columnName column name |
| 114 | * @param data column value |
| 115 | * @return Condition |
| 116 | */ |
| 117 | public static Condition excludes(String columnName, Object data) { |
| 118 | Object value = TransValueUtil.getFormatData(data); |
| 119 | return new Condition(columnName, Function.EXCLUDES, value); |
| 120 | } |
| 121 | |
| 122 | } |