| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.deltacloud.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * |
| 25 | * @author Adrian Cole |
| 26 | */ |
| 27 | public class RangeHardwareProperty extends ParameterizedHardwareProperty { |
| 28 | |
| 29 | private final Number first; |
| 30 | private final Number last; |
| 31 | |
| 32 | public RangeHardwareProperty(String name, String unit, Number value, HardwareParameter param, Number first, |
| 33 | Number last) { |
| 34 | super(Kind.FIXED, name, unit, value, param); |
| 35 | this.first = checkNotNull(first, "first"); |
| 36 | this.last = checkNotNull(last, "last"); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * |
| 41 | * @return minimum value |
| 42 | */ |
| 43 | public Number getFirst() { |
| 44 | return first; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * |
| 49 | * @return maximum value |
| 50 | */ |
| 51 | public Number getLast() { |
| 52 | return last; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String toString() { |
| 57 | return "[kind=" + getKind() + ", name=" + getName() + ", unit=" + getUnit() + ", value=" + getValue() |
| 58 | + ", param=" + getParam() + ", first=" + first + ", last=" + last + "]"; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public int hashCode() { |
| 63 | final int prime = 31; |
| 64 | int result = super.hashCode(); |
| 65 | result = prime * result + ((first == null) ? 0 : first.hashCode()); |
| 66 | result = prime * result + ((last == null) ? 0 : last.hashCode()); |
| 67 | return result; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean equals(Object obj) { |
| 72 | if (this == obj) |
| 73 | return true; |
| 74 | if (!super.equals(obj)) |
| 75 | return false; |
| 76 | if (getClass() != obj.getClass()) |
| 77 | return false; |
| 78 | RangeHardwareProperty other = (RangeHardwareProperty) obj; |
| 79 | if (first == null) { |
| 80 | if (other.first != null) |
| 81 | return false; |
| 82 | } else if (!first.equals(other.first)) |
| 83 | return false; |
| 84 | if (last == null) { |
| 85 | if (other.last != null) |
| 86 | return false; |
| 87 | } else if (!last.equals(other.last)) |
| 88 | return false; |
| 89 | return true; |
| 90 | } |
| 91 | } |