1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.messaging.mmslib.pdu; 19 20 import java.util.Vector; 21 22 public class PduBody { 23 private Vector<PduPart> mParts = null; 24 25 /** 26 * Constructor. 27 */ PduBody()28 public PduBody() { 29 mParts = new Vector<PduPart>(); 30 } 31 32 /** 33 * Appends the specified part to the end of this body. 34 * 35 * @param part part to be appended 36 * @return true when success, false when fail 37 * @throws NullPointerException when part is null 38 */ addPart(PduPart part)39 public boolean addPart(PduPart part) { 40 if (null == part) { 41 throw new NullPointerException(); 42 } 43 44 return mParts.add(part); 45 } 46 47 /** 48 * Inserts the specified part at the specified position. 49 * 50 * @param index index at which the specified part is to be inserted 51 * @param part part to be inserted 52 * @throws NullPointerException when part is null 53 */ addPart(int index, PduPart part)54 public void addPart(int index, PduPart part) { 55 if (null == part) { 56 throw new NullPointerException(); 57 } 58 59 mParts.add(index, part); 60 } 61 62 /** 63 * Remove all of the parts. 64 */ removeAll()65 public void removeAll() { 66 mParts.clear(); 67 } 68 69 /** 70 * Get the part at the specified position. 71 * 72 * @param index index of the part to return 73 * @return part at the specified index 74 */ getPart(int index)75 public PduPart getPart(int index) { 76 return mParts.get(index); 77 } 78 79 /** 80 * Get the number of parts. 81 * 82 * @return the number of parts 83 */ getPartsNum()84 public int getPartsNum() { 85 return mParts.size(); 86 } 87 } 88