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

com.opengamma.strata.loader.fpml.FpmlPartySelector Maven / Gradle / Ivy

There is a newer version: 2.12.46
Show newest version
/*
 * Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.strata.loader.fpml;

import static com.opengamma.strata.collect.Guavate.toImmutableList;

import java.util.List;
import java.util.regex.Pattern;

import com.google.common.collect.ListMultimap;

/**
 * Finds the party representing "us" in FpML.
 * 

* The FpML data structure is neutral as to the direction of a trade, choosing to * represent the two parties throughout the structure. The Strata data model takes * the opposite view, with each trade stored with Pay/Receive or Buy/Sell concepts * expressed from "our" point of view. This selector is used to bridge the gap, * picking the party that represents "us" in the FpML data. */ @FunctionalInterface public interface FpmlPartySelector { /** * Returns a selector that will choose any party from the trade. *

* The party chosen varies by trade type and will be consistent for a given input file. * For example, in a FRA the 'Buy' party will be chosen, whereas in a swap * the 'Pay' party of the first leg will be chosen. * In general, it is not recommended to rely on this implementation. * * @return the selector that will choose the party from the first leg */ public static FpmlPartySelector any() { return FpmlDocument.ANY_SELECTOR; } /** * Returns a selector that matches the specified party ID. *

* This examines the party IDs included in the FpML document and returns the * href ID for the party that exactly matches the specified party ID. * * @param partyId the party ID to match * @return the selector that will choose the party based on the specified party ID */ public static FpmlPartySelector matching(String partyId) { return allParties -> allParties.entries().stream() .filter(e -> e.getValue().equals(partyId)) .map(e -> e.getKey()) .distinct() .collect(toImmutableList()); } /** * Returns a selector that matches the specified party ID regular expression. *

* This examines the party IDs included in the FpML document and returns the * href ID for the party that matches the specified party ID regular expression. * * @param partyIdRegex the party ID regular expression to match * @return the selector that will choose the party based on the specified party ID */ public static FpmlPartySelector matchingRegex(Pattern partyIdRegex) { return allParties -> allParties.entries().stream() .filter(e -> partyIdRegex.matcher(e.getValue()).matches()) .map(e -> e.getKey()) .distinct() .collect(toImmutableList()); } //------------------------------------------------------------------------- /** * Given a map of all parties in the FpML document, extract those that * represent "our" side of the trade. * * @param allParties the multimap of party href id to associated partyId * @return the party href ids to use, empty if unable to find "our" party */ public abstract List selectParties(ListMultimap allParties); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy