All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.mirkosertic.bytecoder.classlib.java.lang.TString Maven / Gradle / Ivy

There is a newer version: 2024-05-10
Show newest version
/*
 * Copyright 2018 Mirko Sertic
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.mirkosertic.bytecoder.classlib.java.lang;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;

import de.mirkosertic.bytecoder.api.SubstitutesInClass;

@SubstitutesInClass(completeReplace = true)
public class TString implements java.io.Serializable, Comparable {

    static void checkBoundsOffCount(final int offset, final int count, final int length) {
        if (offset < 0 || count < 0 || offset > length - count) {
            throw new StringIndexOutOfBoundsException(
                    "offset " + offset + ", count " + count + ", length " + length);
        }
    }

    static final byte LATIN1 = 0;
    static final byte UTF16  = 1;

    static final boolean COMPACT_STRINGS = false;

    private int computedHash;
    private final char[] data;

    public TString(final int aSize) {
        data = new char[aSize];
        for (int i=0;i 0) {
            for (int i = 0; i < data.length; i++) {
                h = 31 * h + (data[i] & 0xff);
            }
            computedHash = h;
        }
        return h;
    }

    public int indexOf(final int aChar) {
        for (int i=0;i 0 || len < data.length) {
            final char[] newData = new char[len - st];
            for (int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy