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

org.abego.commons.stringpool.StringPool Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
/*
 * MIT License
 *
 * Copyright (c) 2020 Udo Borkowski, ([email protected])
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package org.abego.commons.stringpool;

import org.eclipse.jdt.annotation.Nullable;

/**
 * A StringPool contains a set of {@link String}s that are accessible through
 * an ID, stored in an int.
 *
 * 

Create a StringPool using a {@link StringPoolBuilder}.

* *

The default implementation of a StringPool stores the strings in a * compact form only. E.g. a String of ASCII characters and length * n <= 127 only requires n + 1 bytes. Especially * for short strings this is significantly less that used for a native Java * {@link String} object. Also equal strings are only stored once in the poll. * So a StringPool fits well into an application that has memory constraints * and uses a lot of short (and/or duplicated) strings.

* *

A side effect of StringPool strings: as the StringPool holds unique * strings the equal check of string can be reduced to a an int check of the IDs. *

* *

A {@code null} String has the ID {@code 0}.

*/ @SuppressWarnings("EmptyMethod") public interface StringPool { /** * Return the {@link String} with the given id or * null when id == 0. */ @Nullable String getStringOrNull(int id); /** * Return an {@link Iterable} with all strings in the StringPool. */ Iterable allStrings(); /** * Return an {@link Iterable} with all strings in the StringPool, together with the string's ID in this StringPool. */ Iterable allStringAndIDs(); /** * Holds a {@link String} and its ID in this StringPool. */ interface StringAndID { String getString(); int getID(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy