com.jwebmp.guicedinjection.pairing.OptionalPair Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-injection Show documentation
Show all versions of guiced-injection Show documentation
Guice Injection allows you to access multiple Guice Binders and Modules across separate archives.
Allowing you to configure your applications with injection from multiple dependancies. Servlets, EJB's, and
Stand-Alone is supported. Requires JDK 8 or 10.
package com.jwebmp.guicedinjection.pairing;
import javax.validation.constraints.NotNull;
import java.util.Optional;
/**
* Specifies a generic pair
*
* @param
* Key
* @param
* Value
*/
public class OptionalPair
extends Pair
{
/**
* Constructs a new blank pair
*/
public OptionalPair()
{
//No config required
}
/**
* Constructs a new key value pair
*
* @param key
* The key to use
* @param value
* the value to use
*/
public OptionalPair(K key, V value)
{
super(key, value);
}
@Override
public String toString()
{
return "Key[" + getKey() + "];Value[" + getValue() + "]";
}
/**
* Sets the value for the given pair
*
* @param value
* The value to set
*
* @return Optional nullable of the value
*/
@Override
public OptionalPair setValue(V value)
{
super.setValue(value);
return this;
}
/**
* Sets the key for the given pair
*
* @param key
* The key to return
*
* @return The optional pair
*/
@Override
public OptionalPair setKey(@NotNull K key)
{
super.setKey(key);
return this;
}
public Optional getKeyOptional()
{
return Optional.ofNullable(getKey());
}
/**
* Returns the optional object of the value
*
* @return Optional nullable of the value
*/
public Optional getValueOptional()
{
return Optional.ofNullable(getValue());
}
}