content: /*
   * CDDL HEADER START
   *
   * The contents of this file are subject to the terms of the Common Development
   * and Distribution License (the "License").
   * You may not use this file except in compliance with the License.
   *
   * You can obtain a copy of the license at
   * src/com/vodafone360/people/VODAFONE.LICENSE.txt or
   * http://github.com/360/360-Engine-for-Android
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   * When distributing Covered Code, include this CDDL HEADER in each file and
   * include the License file at src/com/vodafone360/people/VODAFONE.LICENSE.txt.
   * If applicable, add the following below this CDDL HEADER, with the fields
   * enclosed by brackets "[]" replaced with your own identifying information:
   * Portions Copyright [yyyy] [name of copyright owner]
   *
   * CDDL HEADER END
   *
   * Copyright 2010 Vodafone Sales & Services Ltd.  All rights reserved.
   * Use is subject to license terms.
   */
  
  package com.vodafone360.people.datatypes;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.List;
  
  import com.vodafone360.people.utils.LogUtils;
  
  /**
   * BaseDataType representing Contact detail deletion information retrieved from
   * server
   */
  public class ContactDetailDeletion extends BaseDataType {
  
      /**
       * Tags associated with ContactDetailDeletion item.
       */
      private enum Tags {
          CONTACT_ID("contactid"),
          SERVER_REVISION_BEFORE("serverrevisionbefore"),
          SERVER_REVISION_AFTER("serverrevisionafter");
  
          private final String tag;
  
          /**
           * Construct Tags item from supplied String
           * 
           * @param s String value for Tags item.
           */
          private Tags(String s) {
              tag = s;
          }
  
          /**
           * String value for Tags item.
           * 
           * @return String value for Tags item.
           */
          private String tag() {
              return tag;
          }
      }
  
      /**
       * Find Tags item for specified String
       * 
       * @param tag String value to find Tags item for
       * @return Tags item for specified String, null otherwise
       */
      private Tags findTag(String tag) {
          for (Tags tags : Tags.values()) {
              if (tag.compareTo(tags.tag()) == 0) {
                  return tags;
              }
          }
          return null;
      }
  
      public Integer mServerVersionBefore = null;
  
      public Integer mServerVersionAfter = null;
  
      public Integer mContactId = null;
  
      public List<ContactDetail> mDetails = null;
  
      /** {@inheritDoc} */
      @Override
      public int getType() {
          return CONTACT_DETAIL_DELETION_DATA_TYPE;
      }
  
      /** {@inheritDoc} */
      @Override
      public String toString() {
          final StringBuffer sb = 
              new StringBuffer("Contact Detail Deletion: ");
          if (mServerVersionBefore != null) {
              sb.append("\n Server version before: "); 
              sb.append(mServerVersionBefore);
          }
          if (mServerVersionAfter != null) {
              sb.append("\n Server version after: "); 
              sb.append(mServerVersionAfter);
          }
          if (mContactId != null) {
              sb.append("\n Contact ID: " + mContactId);
          }
          if (mDetails != null) {
              sb.append("\n Details ("); sb.append(mDetails.size()); sb.append("):\n");
              for (int i = 0; i < mDetails.size(); i++) {
                  sb.append(mDetails.get(i).toString());
              }
          } else {
              sb.append("\n Contacts (0).");
          }
  
          return sb.toString();
      }
  
      /**
       * Create ContactDetailDeletion from Hashtable generated by Hessian-decoder
       * 
       * @param hash Hashtable containing Contact detail deletion parameters
       * @return ContactDetailDeletion instance generated from hashtable
       */
      public ContactDetailDeletion createFromHashtable(Hashtable<String, Object> hash) {
          Enumeration<String> e = hash.keys();
          while (e.hasMoreElements()) {
              String key = e.nextElement();
              Object value = hash.get(key);
              Tags tag = findTag(key);
              setValue(tag, value);
          }
  
          return this;
      }
  
      /**
       * Sets the value of the member data item associated with the specified tag.
       * 
       * @param tag Current tag
       * @param obj Value associated with the tag
       */
      private void setValue(Tags tag, Object obj) {
          if (tag == null) {
              LogUtils.logW("ContactDetailDeletion.setValue - tag was NULL");
              return;
          }
          switch (tag) {
              case CONTACT_ID:
                  if (mContactId == null) {
                      mContactId = ((Long)(obj)).intValue();
                  }
                  break;
              case SERVER_REVISION_AFTER:
                  if (mServerVersionAfter == null) {
                      mServerVersionAfter = ((Long)(obj)).intValue();
                  }
                  break;
              case SERVER_REVISION_BEFORE:
                  if (mServerVersionBefore == null) {
                      mServerVersionBefore = ((Long)(obj)).intValue();
                  }
                  break;
              default:
                  // Do nothing.
                  break;
          }
      }
  }
  