001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hdfs.server.namenode;
019
020import com.google.common.base.Objects;
021import org.apache.hadoop.fs.StorageType;
022import org.apache.hadoop.util.StringUtils;
023
024 public class QuotaByStorageTypeEntry {
025   private StorageType type;
026   private long quota;
027
028   public StorageType getStorageType() {
029     return type;
030   }
031
032   public long getQuota() {
033     return quota;
034   }
035
036   @Override
037   public boolean equals(Object o){
038     if (o == null) {
039       return false;
040     }
041     if (getClass() != o.getClass()) {
042       return false;
043     }
044     QuotaByStorageTypeEntry other = (QuotaByStorageTypeEntry)o;
045     return Objects.equal(type, other.type) && Objects.equal(quota, other.quota);
046   }
047
048   @Override
049   public int hashCode() {
050     return Objects.hashCode(type, quota);
051   }
052
053   @Override
054   public String toString() {
055     StringBuilder sb = new StringBuilder();
056     assert (type != null);
057     sb.append(StringUtils.toLowerCase(type.toString()));
058     sb.append(':');
059     sb.append(quota);
060     return sb.toString();
061   }
062
063   public static class Builder {
064     private StorageType type;
065     private long quota;
066
067     public Builder setStorageType(StorageType type) {
068       this.type = type;
069       return this;
070     }
071
072     public Builder setQuota(long quota) {
073       this.quota = quota;
074       return this;
075     }
076
077     public QuotaByStorageTypeEntry build() {
078       return new QuotaByStorageTypeEntry(type, quota);
079     }
080   }
081
082   private QuotaByStorageTypeEntry(StorageType type, long quota) {
083     this.type = type;
084     this.quota = quota;
085   }
086 }