com.softicar.platform.common.container.map.index.IIndexMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
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));
}
}