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

com.mmnaseri.utils.tuples.impl.KeyValue Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.mmnaseri.utils.tuples.impl;

import java.util.Map;

/**
 * Represents a key-value pair of items. This is in essence just a {@link TwoTuple} with with some
 * facade methods.
 *
 * @author Milad Naseri ([email protected])
 */
public class KeyValue extends TwoTuple {

  public KeyValue(final K key, final V value) {
    super(key, value);
  }

  /**
   * Returns the key (the first item in the pair).
   *
   * @see #first()
   */
  public K key() {
    return first();
  }

  /**
   * Returns the value (the second item in the pair).
   *
   * @see #second()
   */
  public V value() {
    return second();
  }

  /** Creates a new {@link KeyValue} instance. */
  public static  KeyValue create(K key, V value) {
    return new KeyValue<>(key, value);
  }

  /**
   * Creates a new {@link KeyValue} instance from the given map entry.
   *
   * 

This can be used to create a stream of tuples from a map: * *

   * map.entrySet().stream().map(KeyValue::create);
   * 
*/ public static KeyValue create(Map.Entry entry) { return new KeyValue<>(entry.getKey(), entry.getValue()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy