OSDN Git Service

412dfc3f79db0431b4e15aceef2f346bee9be2dc
[android-x86/dalvik.git] / dx / src / com / android / dx / cf / code / ByteBlockList.java
1 /*
2  * Copyright (C) 2007 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
17 package com.android.dx.cf.code;
18
19 import com.android.dx.util.FixedSizeList;
20 import com.android.dx.util.Hex;
21 import com.android.dx.util.LabeledList;
22
23 /**
24  * List of {@link ByteBlock} instances.
25  */
26 public final class ByteBlockList extends LabeledList {
27
28     /**
29      * Constructs an instance.
30      *
31      * @param size {@code >= 0;} the number of elements to be in the list
32      */
33     public ByteBlockList(int size) {
34         super(size);
35     }
36
37     /**
38      * Gets the indicated element. It is an error to call this with the
39      * index for an element which was never set; if you do that, this
40      * will throw {@code NullPointerException}.
41      *
42      * @param n {@code >= 0, < size();} which element
43      * @return {@code non-null;} the indicated element
44      */
45     public ByteBlock get(int n) {
46         return (ByteBlock) get0(n);
47     }
48
49     /**
50      * Gets the block with the given label.
51      *
52      * @param label the label to look for
53      * @return {@code non-null;} the block with the given label
54      */
55     public ByteBlock labelToBlock(int label) {
56         int idx = indexOfLabel(label);
57
58         if (idx < 0) {
59             throw new IllegalArgumentException("no such label: "
60                     + Hex.u2(label));
61         }
62
63         return get(idx);
64     }
65
66     /**
67      * Sets the element at the given index.
68      *
69      * @param n {@code >= 0, < size();} which element
70      * @param bb {@code null-ok;} the value to store
71      */
72     public void set(int n, ByteBlock bb) {
73         super.set(n, bb);
74     }
75 }