001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: DxString.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
008:
009: package org.ozoneDB.DxLib;
010:
011: import java.io.*;
012:
013: public class DxString extends DxObject implements Externalizable {
014:
015: final static long serialVersionUID = 1L;
016:
017: String value = new String();
018:
019: public DxString() {
020: super ();
021: }
022:
023: public DxString(DxString s) {
024: super ();
025: value = new String(s.value);
026: }
027:
028: public DxString(String v) {
029: super ();
030: value = new String(v);
031: }
032:
033: public Object clone() {
034: return new DxString(value);
035: }
036:
037: public boolean equals(String obj) {
038: return value.equals(obj);
039: }
040:
041: public boolean equals(Object obj) {
042: if (this == obj) {
043: return true;
044: }
045: if (obj instanceof DxString && obj != null) {
046: return value.equals(((DxString) obj).value);
047: } else {
048: return false;
049: }
050: }
051:
052: public boolean isLess(DxCompatible obj) {
053: if (this == obj) {
054: return false;
055: }
056: return value.compareTo(((DxString) obj).value) < 0;
057: }
058:
059: public String toString() {
060: return value;
061: }
062:
063: public int hashCode() {
064: //die fehlenden bits dann mit equals()
065: return value.hashCode();
066: }
067:
068: public DxString append(DxString s) {
069: value += s;
070: return this ;
071: }
072:
073: public DxString append(String s) {
074: return append(new DxString(s));
075: }
076:
077: public DxString prepend(DxString s) {
078: value = s + value;
079: return this ;
080: }
081:
082: public DxString prepend(String s) {
083: return prepend(new DxString(s));
084: }
085:
086: public void insertAt(DxString s, int a) {
087: insertAt(s, a, s.length());
088: }
089:
090: public void insertAt(String s, int a) {
091: insertAt(new DxString(s), a, s.length());
092: }
093:
094: public void insertAt(DxString s, int a, int len) {
095: String pre = value.substring(0, a);
096: String app = value.substring(a, value.length());
097: value = pre + s.value.substring(0, len) + app;
098: }
099:
100: public void insertAt(String s, int a, int len) {
101: insertAt(new DxString(s), a, len);
102: }
103:
104: public void deleteAt(int a) {
105: deleteAt(a, value.length() - a);
106: }
107:
108: public void deleteAt(int a, int len) {
109: String pre = value.substring(0, a);
110: String app = value.substring(a + len, value.length());
111: value = pre + app;
112: }
113:
114: public DxString at(int a, int len) {
115: return new DxString(value.substring(a, a + len));
116: }
117:
118: public int length() {
119: return value.length();
120: }
121:
122: public void writeExternal(ObjectOutput out) throws IOException {
123: out.writeUTF(value);
124: }
125:
126: public void readExternal(ObjectInput in) throws IOException,
127: ClassNotFoundException {
128: value = in.readUTF();
129: }
130:
131: }
|