Home | History | Annotate | Download | only in sdkman2
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      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 
     17 package com.android.sdkuilib.internal.repository.sdkman2;
     18 
     19 import java.util.ArrayList;
     20 import java.util.List;
     21 
     22 abstract class PkgCategory {
     23     private final Object mKey;
     24     private final Object mIconRef;
     25     private final List<PkgItem> mItems = new ArrayList<PkgItem>();
     26     private String mLabel;
     27 
     28     public PkgCategory(Object key, String label, Object iconRef) {
     29         mKey = key;
     30         mLabel = label;
     31         mIconRef = iconRef;
     32     }
     33 
     34     public Object getKey() {
     35         return mKey;
     36     }
     37 
     38     public String getLabel() {
     39         return mLabel;
     40     }
     41 
     42     public void setLabel(String label) {
     43         mLabel = label;
     44     }
     45 
     46     public Object getIconRef() {
     47         return mIconRef;
     48     }
     49 
     50     public List<PkgItem> getItems() {
     51         return mItems;
     52     }
     53 
     54     @Override
     55     public String toString() {
     56         return String.format("%s <key=%s, label=%s, #items=%d>",
     57                 this.getClass().getSimpleName(),
     58                 mKey == null ? "null" : mKey.toString(),
     59                 mLabel,
     60                 mItems.size());
     61     }
     62 
     63     /** {@link PkgCategory}s are equal if their internal keys are equal. */
     64     @Override
     65     public int hashCode() {
     66         final int prime = 31;
     67         int result = 1;
     68         result = prime * result + ((mKey == null) ? 0 : mKey.hashCode());
     69         return result;
     70     }
     71 
     72     /** {@link PkgCategory}s are equal if their internal keys are equal. */
     73     @Override
     74     public boolean equals(Object obj) {
     75         if (this == obj) return true;
     76         if (obj == null) return false;
     77         if (getClass() != obj.getClass()) return false;
     78         PkgCategory other = (PkgCategory) obj;
     79         if (mKey == null) {
     80             if (other.mKey != null) return false;
     81         } else if (!mKey.equals(other.mKey)) return false;
     82         return true;
     83     }
     84 }
     85