/* * 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.ArrayList; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; /** * BaseDataType representing ContactListResponse information retrieved from * server. */ public class ContactListResponse extends BaseDataType { /** * Tags associated with ContactListResponse item. */ private enum Tags { SERVER_REVISION_BEFORE("serverrevisionbefore"), SERVER_REVISION_AFTER("serverrevisionafter"), CONTACT_ID_LIST("contactidlist"), CONTACT_ID("contactid"); 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 mServerRevisionBefore = null; public Integer mServerRevisionAfter = null; public List<Integer> mContactIdList = null; /** {@inheritDoc} */ @Override public int getType() { return CONTACT_LIST_RESPONSE_DATA_TYPE; } /** {@inheritDoc} */ @Override public String toString() { final StringBuffer sb = new StringBuffer("ContactListResponse: "); if (mServerRevisionBefore != null) { sb.append("\n Server revision before: "); sb.append(mServerRevisionBefore); } if (mServerRevisionAfter != null) { sb.append("\n Server revision after: "); sb.append(mServerRevisionAfter); } if (mContactIdList != null) { sb.append("\n Contact IDs: ["); for (int i = 0; i < mContactIdList.size(); i++) { sb.append(" " + mContactIdList.get(i)); if (i < mContactIdList.size() - 1) { sb.append(","); } } sb.append("]"); } return sb.toString(); } /** * Create ContactListResponse from Hashtable generated by Hessian-decoder * * @param hash Hashtable containing ContactListResponse parameters * @return ContactListResponse created from hashtable */ public ContactListResponse createFromHashTable(Hashtable<String, Object> hash) { Enumeration<String> e = hash.keys(); while (e.hasMoreElements()) { String key = e.nextElement(); Tags tag = findTag(key); setValue(tag, hash.get(key)); } return this; } /** * Sets the value of the member data item associated with the specified tag. * * @param tag Current tag * @param value Value associated with the tag */ private void setValue(Tags tag, Object value) { switch (tag) { case CONTACT_ID: Integer idVal = (Integer)value; if (idVal > 0) { if (mContactIdList == null) { mContactIdList = new ArrayList<Integer>(); } mContactIdList.add(idVal); } break; case CONTACT_ID_LIST: if (mContactIdList == null) { mContactIdList = new ArrayList<Integer>(); } break; case SERVER_REVISION_AFTER: if (mServerRevisionAfter == null) { mServerRevisionAfter = ((Long)value).intValue(); } break; case SERVER_REVISION_BEFORE: if (mServerRevisionBefore == null) { mServerRevisionBefore = ((Long)value).intValue(); } break; default: break; } } }