ImapElement.java revision ff0712cb1e2e1902d754ac37ab637b94b8cc8933
1/* 2 * Copyright (C) 2010 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 com.android.email.mail.store.imap; 18 19/** 20 * Class representing "element"s in IMAP responses. 21 * 22 * <p>Class hierarchy: 23 * <pre> 24 * ImapElement 25 * | 26 * |-- ImapElement.NONE (for 'index out of range') 27 * | 28 * |-- ImapList (isList() == true) 29 * | | 30 * | |-- ImapList.EMPTY 31 * | | 32 * | --- ImapResponse 33 * | 34 * --- ImapString (isString() == true) 35 * | 36 * |-- ImapString.EMPTY 37 * | 38 * |-- ImapSimpleString 39 * | 40 * |-- ImapMemoryLiteral 41 * | 42 * --- ImapTempFileLiteral 43 * </pre> 44 */ 45public abstract class ImapElement { 46 /** 47 * An element that is returned by {@link ImapList#getElementOrNone} to indicate an index 48 * is out of range. 49 */ 50 public static final ImapElement NONE = new ImapElement() { 51 @Override public boolean isList() { 52 return false; 53 } 54 55 @Override public boolean isString() { 56 return false; 57 } 58 59 @Override public String toString() { 60 return "[NO ELEMENT]"; 61 } 62 63 @Override 64 public boolean equalsForTest(ImapElement that) { 65 return super.equalsForTest(that); 66 } 67 }; 68 69 public abstract boolean isList(); 70 71 public abstract boolean isString(); 72 73 /** 74 * Clean up the resources used by the instance. 75 * It's for removing a temp file used by {@link ImapTempFileLiteral}. 76 */ 77 public void destroy() { 78 } 79 80 /** 81 * Return a string that represents this object; it's purely for the debug purpose. Don't 82 * mistake it for {@link ImapString#getString}. 83 * 84 * Abstract to force subclasses to implement it. 85 */ 86 @Override 87 public abstract String toString(); 88 89 /** 90 * The equals implementation that is intended to be used only for unit testing. 91 * (Because it may be heavy and has a special sense of "equal" for testing.) 92 */ 93 public boolean equalsForTest(ImapElement that) { 94 if (that == null) { 95 return false; 96 } 97 return this.getClass() == that.getClass(); // Has to be the same class. 98 } 99} 100