
com.opengamma.strata.product.PositionInfoBuilder Maven / Gradle / Ivy
/*
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product;
import java.util.HashMap;
import java.util.Map;
import com.opengamma.strata.basics.StandardId;
import com.opengamma.strata.collect.ArgChecker;
/**
* Builder to create {@code PositionInfo}.
*
* This builder allows a {@link PositionInfo} to be created.
*/
public final class PositionInfoBuilder implements PortfolioItemInfoBuilder {
/**
* The primary identifier for the position.
*
* The identifier is used to identify the position.
*/
private StandardId id;
/**
* The position attributes.
*
* Position attributes, provide the ability to associate arbitrary information
* with a position in a key-value map.
*/
private final Map, Object> attributes = new HashMap<>();
// creates an empty instance
PositionInfoBuilder() {
}
// creates a populated instance
PositionInfoBuilder(
StandardId id,
Map, Object> attributes) {
this.id = id;
this.attributes.putAll(attributes);
}
//-----------------------------------------------------------------------
/**
* Sets the primary identifier for the position, optional.
*
* The identifier is used to identify the position.
*
* @param id the identifier
* @return this, for chaining
*/
@Override
public PositionInfoBuilder id(StandardId id) {
this.id = id;
return this;
}
/**
* Adds a position attribute to the map of attributes.
*
* The attribute is added using {@code Map.put(type, value)} semantics.
*
* @param the type of the value
* @param attributeType the type providing meaning to the value
* @param attributeValue the value
* @return this, for chaining
*/
@Override
@SuppressWarnings("unchecked")
public PositionInfoBuilder addAttribute(AttributeType attributeType, T attributeValue) {
ArgChecker.notNull(attributeType, "attributeType");
ArgChecker.notNull(attributeValue, "attributeValue");
attributes.put(attributeType, attributeType.toStoredForm(attributeValue));
return this;
}
/**
* Builds the position information.
*
* @return the position information
*/
@Override
public PositionInfo build() {
return new PositionInfo(id, attributes);
}
}