SyncAdapterType.java revision 718d8a2d7ff3e864a73879eb646f46c14ab74d07
1/* 2 * Copyright (C) 2009 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 17package android.content; 18 19import android.text.TextUtils; 20 21/** 22 * Value type that represents a SyncAdapterType. This object overrides {@link #equals} and 23 * {@link #hashCode}, making it suitable for use as the key of a {@link java.util.Map} 24 */ 25public class SyncAdapterType { 26 public final String authority; 27 public final String accountType; 28 29 public SyncAdapterType(String authority, String accountType) { 30 if (TextUtils.isEmpty(authority)) { 31 throw new IllegalArgumentException("the authority must not be empty: " + authority); 32 } 33 if (TextUtils.isEmpty(accountType)) { 34 throw new IllegalArgumentException("the accountType must not be empty: " + accountType); 35 } 36 this.authority = authority; 37 this.accountType = accountType; 38 } 39 40 public boolean equals(Object o) { 41 if (o == this) return true; 42 if (!(o instanceof SyncAdapterType)) return false; 43 final SyncAdapterType other = (SyncAdapterType)o; 44 return authority.equals(other.authority) && accountType.equals(other.accountType); 45 } 46 47 public int hashCode() { 48 int result = 17; 49 result = 31 * result + authority.hashCode(); 50 result = 31 * result + accountType.hashCode(); 51 return result; 52 } 53 54 public String toString() { 55 return "SyncAdapterType {name=" + authority + ", type=" + accountType + "}"; 56 } 57}