001package react4j;
002
003import javax.annotation.Nonnull;
004import javax.annotation.Nullable;
005import react4j.annotations.Input;
006
007/**
008 * Interface implemented by objects so that they can be marked as {@link Input#immutable()}
009 */
010public interface Keyed
011{
012  /**
013   * Return a string that will be the key or contribute to the key of a view.
014   *
015   * @return the value used to form key.
016   */
017  @Nonnull
018  String getKey();
019
020  /**
021   * Invoked {@link #getKey()} on specified parameter if the parameter implements {@link Keyed} otherwise return null.
022   *
023   * @param object the object on which to call {@link #getKey()}.
024   * @return the value used to form key, else null.
025   */
026  @Nullable
027  static String getKey( @Nullable final Object object )
028  {
029    if ( object instanceof Keyed )
030    {
031      return ( (Keyed) object ).getKey();
032    }
033    else
034    {
035      return null;
036    }
037  }
038}