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

com.softicar.platform.common.container.map.index.IIndexMap Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.container.map.index;

import java.util.Comparator;
import java.util.Set;

/**
 * A simple map that assigns an index to every key element.
 *
 * @author Oliver Richers
 */
public interface IIndexMap extends Comparator {

	/**
	 * Returns the index for the given key.
	 *
	 * @param key
	 *            the key element (never null)
	 * @return the index (may be null)
	 */
	Integer getIndex(T key);

	/**
	 * Adds the given key to this map and returns its index.
	 *
	 * @param key
	 *            the key to add (never null)
	 * @return the index of the given key; if the key is already contained, the
	 *         existing index is returned, otherwise a new index is generated
	 *         and returned
	 */
	int add(T key);

	/**
	 * Returns all keys contained in the map.
	 *
	 * @return all keys (never null)
	 */
	Set keySet();

	@Override
	default int compare(T left, T right) {

		return getIndex(left).compareTo(getIndex(right));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy