Debian Codegraph @

telephony/common/com/google/android/mms/pdu/PduBody.java

raw symbols SCIP
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.google.android.mms.pdu;
19
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.os.Build;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.Vector;
26
27 public class PduBody {
28 private Vector<PduPart> mParts = null;
29
30 private Map<String, PduPart> mPartMapByContentId = null;
31 private Map<String, PduPart> mPartMapByContentLocation = null;
32 private Map<String, PduPart> mPartMapByName = null;
33 private Map<String, PduPart> mPartMapByFileName = null;
34
35 /**
36 * Constructor.
37 */
38 @UnsupportedAppUsage
39 public PduBody() {
40 mParts = new Vector<PduPart>();
41
42 mPartMapByContentId = new HashMap<String, PduPart>();
43 mPartMapByContentLocation = new HashMap<String, PduPart>();
44 mPartMapByName = new HashMap<String, PduPart>();
45 mPartMapByFileName = new HashMap<String, PduPart>();
46 }
47
48 private void putPartToMaps(PduPart part) {
49 // Put part to mPartMapByContentId.
50 byte[] contentId = part.getContentId();
51 if(null != contentId) {
52 mPartMapByContentId.put(new String(contentId), part);
53 }
54
55 // Put part to mPartMapByContentLocation.
56 byte[] contentLocation = part.getContentLocation();
57 if(null != contentLocation) {
58 String clc = new String(contentLocation);
59 mPartMapByContentLocation.put(clc, part);
60 }
61
62 // Put part to mPartMapByName.
63 byte[] name = part.getName();
64 if(null != name) {
65 String clc = new String(name);
66 mPartMapByName.put(clc, part);
67 }
68
69 // Put part to mPartMapByFileName.
70 byte[] fileName = part.getFilename();
71 if(null != fileName) {
72 String clc = new String(fileName);
73 mPartMapByFileName.put(clc, part);
74 }
75 }
76
77 /**
78 * Appends the specified part to the end of this body.
79 *
80 * @param part part to be appended
81 * @return true when success, false when fail
82 * @throws NullPointerException when part is null
83 */
84 @UnsupportedAppUsage
85 public boolean addPart(PduPart part) {
86 if(null == part) {
87 throw new NullPointerException();
88 }
89
90 putPartToMaps(part);
91 return mParts.add(part);
92 }
93
94 /**
95 * Inserts the specified part at the specified position.
96 *
97 * @param index index at which the specified part is to be inserted
98 * @param part part to be inserted
99 * @throws NullPointerException when part is null
100 */
101 @UnsupportedAppUsage
102 public void addPart(int index, PduPart part) {
103 if(null == part) {
104 throw new NullPointerException();
105 }
106
107 putPartToMaps(part);
108 mParts.add(index, part);
109 }
110
111 /**
112 * Removes the part at the specified position.
113 *
114 * @param index index of the part to return
115 * @return part at the specified index
116 */
117 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
118 public PduPart removePart(int index) {
119 return mParts.remove(index);
120 }
121
122 /**
123 * Remove all of the parts.
124 */
125 public void removeAll() {
126 mParts.clear();
127 }
128
129 /**
130 * Get the part at the specified position.
131 *
132 * @param index index of the part to return
133 * @return part at the specified index
134 */
135 @UnsupportedAppUsage
136 public PduPart getPart(int index) {
137 return mParts.get(index);
138 }
139
140 /**
141 * Get the index of the specified part.
142 *
143 * @param part the part object
144 * @return index the index of the first occurrence of the part in this body
145 */
146 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
147 public int getPartIndex(PduPart part) {
148 return mParts.indexOf(part);
149 }
150
151 /**
152 * Get the number of parts.
153 *
154 * @return the number of parts
155 */
156 @UnsupportedAppUsage
157 public int getPartsNum() {
158 return mParts.size();
159 }
160
161 /**
162 * Get pdu part by content id.
163 *
164 * @param cid the value of content id.
165 * @return the pdu part.
166 */
167 @UnsupportedAppUsage
168 public PduPart getPartByContentId(String cid) {
169 return mPartMapByContentId.get(cid);
170 }
171
172 /**
173 * Get pdu part by Content-Location. Content-Location of part is
174 * the same as filename and name(param of content-type).
175 *
176 * @param fileName the value of filename.
177 * @return the pdu part.
178 */
179 @UnsupportedAppUsage
180 public PduPart getPartByContentLocation(String contentLocation) {
181 return mPartMapByContentLocation.get(contentLocation);
182 }
183
184 /**
185 * Get pdu part by name.
186 *
187 * @param fileName the value of filename.
188 * @return the pdu part.
189 */
190 @UnsupportedAppUsage
191 public PduPart getPartByName(String name) {
192 return mPartMapByName.get(name);
193 }
194
195 /**
196 * Get pdu part by filename.
197 *
198 * @param fileName the value of filename.
199 * @return the pdu part.
200 */
201 @UnsupportedAppUsage
202 public PduPart getPartByFileName(String filename) {
203 return mPartMapByFileName.get(filename);
204 }
205 }