Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/StringCPEntry.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/StringCPEntry.java,v 1.1.1.1 2003/08/07 13:40:30 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/08/07 13:40:30 $, by $Author: toggm $            *
9    * Version: $Revision: 1.1.1.1 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  /**
25   * this class represent a String constant pool entry
26   * @author Mike Toggweiler
27   **/
28  public final class StringCPEntry extends ShortValueCPEntry {
29      /**
30       * The tag identifying a String cp entry
31       **/
32      public static final byte TAG = 8;
33  
34      private String string;
35      private short stringIndex;
36  
37      /**
38       * Create a string cp entry with a steing
39       * @param string the string value
40       **/
41      public StringCPEntry(String string) {
42    super(TAG);
43    this.string = string;
44      }
45  
46      /**
47       * Creates a StringCPEntry and initializes it from a DataInputStream
48       * @param dis the DataInputStream to read from
49       * @param cp the constant pool to resolve indices
50       **/
51      protected StringCPEntry(DataInputStream dis) 
52    throws IOException {
53    super(TAG);  
54    stringIndex = (short)dis.readUnsignedShort();  
55      }
56  
57      /**
58       * Resolve the internal stored indices thorugh the Constantpool
59       * @param cp the constantpool to resolve indices
60       **/
61      protected void resolve(ConstantPool cp) {
62    UTF8CPEntry utf = (UTF8CPEntry)cp.getCPEntryAt(stringIndex);
63    string = utf.getString();
64      }
65  
66      /**
67       * Write the type specific constant pool entry information onto a 
68       * DataOutputStream
69       * @param dos the DataOutputStream to write on     
70       * @param cp the constantpool entry used to register names
71       **/
72      protected void writeCPEntry(DataOutputStream dos, ConstantPool cp) 
73    throws IOException {
74    dos.writeShort(cp.addCPEntry(new UTF8CPEntry(string)));
75      }
76  
77      /**
78       * @return the string value 
79       **/
80      public String getString() {
81    return string;
82      }
83  
84      /**
85       * Set the new string value
86       * @param string the string value to set
87       **/
88      public void setString(String string) {
89    this.string = string;
90      }
91  
92      /**
93       * Checks if another stringCPEntry is equal to this. 
94       **/
95      public boolean equals(Object obj) {
96    if (!(obj instanceof StringCPEntry)) {
97        return false;
98    }
99    StringCPEntry other = (StringCPEntry)obj;
100   String otherStr = other.string;
101   return (this.string == null && otherStr == null || 
102     this.string  != null && this.string.equals(otherStr));
103     }
104 
105     /**
106      * print in a readable way
107      **/
108     public String toString() {
109   return getClass().getName()+":"+hashCode()+":"+string;
110     }
111 }