File: DeclaredExceptionTable.java

package info (click to toggle)
emma-coverage 2.0.5312%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 2,000 kB
  • ctags: 3,667
  • sloc: java: 23,109; xml: 414; makefile: 22
file content (108 lines) | stat: -rw-r--r-- 3,075 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
 * 
 * This program and the accompanying materials are made available under
 * the terms of the Common Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v10.html
 * 
 * $Id: DeclaredExceptionTable.java,v 1.1.1.1 2004/05/09 16:57:47 vlad_r Exp $
 */
package com.vladium.jcd.cls.attribute;

import java.io.IOException;

import com.vladium.jcd.lib.UDataOutputStream;
import com.vladium.util.IntVector;

// ----------------------------------------------------------------------------
/**
 * @author (C) 2001, Vlad Roubtsov
 */
final class DeclaredExceptionTable implements IDeclaredExceptionTable
{
    // public: ................................................................

    // ACCESSORS:

    public int get (final int offset)
    {
        return m_exceptions.get (offset);
    }
    
    public int size ()
    {
        return m_exceptions.size ();
    }
    
    public long length ()
    {
        return (1 + m_exceptions.size ()) << 1; // use size() if class becomes non-final
    }
        
    // Cloneable:
    
    /**
     * Performs a deep copy.
     */
    public Object clone ()
    {
        try
        {
            final DeclaredExceptionTable _clone = (DeclaredExceptionTable) super.clone ();
            
            // deep clone:
            _clone.m_exceptions = (IntVector) m_exceptions.clone ();
            
            return _clone;
        }
        catch (CloneNotSupportedException e)
        {
            throw new InternalError (e.toString ());
        }        
    }
    
    // IClassFormatOutput:
    
    public void writeInClassFormat (final UDataOutputStream out) throws IOException
    {
        int number_of_exceptions = m_exceptions.size (); // use size() if class becomes non-final
        out.writeU2 (number_of_exceptions);
        
        for (int i = 0; i < number_of_exceptions; i++)
        {
            out.writeU2 (get (i));
        }
    }


    // MUTATORS:
        
    public int add (final int exception_index)
    {
        final int newoffset = m_exceptions.size (); // use size() if class becomes non-final
        m_exceptions.add (exception_index);
        
        return newoffset;
    }
    
    public int set (final int offset, final int exception_index)
    {
        return m_exceptions.set (offset, exception_index);
    }
    
    // protected: .............................................................

    // package: ...............................................................


    DeclaredExceptionTable (final int capacity)
    {
         m_exceptions = capacity < 0 ? new IntVector () : new IntVector (capacity);
    }

    // private: ...............................................................

    
    private IntVector m_exceptions;
    
} // end of class
// ----------------------------------------------------------------------------