Exemplo n.º 1
0
 /// <summary>
 /// Finds the currency pair that is a cross between this pair and the other pair.
 /// <para>
 /// The cross is only returned if the two pairs contains three currencies in total,
 /// such as AAA/BBB and BBB/CCC and neither pair is an identity such as AAA/AAA.
 /// <ul>
 /// <li>Given two pairs AAA/BBB and BBB/CCC the result will be AAA/CCC or CCC/AAA as per the market convention.
 /// <li>Given two pairs AAA/BBB and CCC/DDD the result will be empty.
 /// <li>Given two pairs AAA/AAA and AAA/BBB the result will be empty.
 /// <li>Given two pairs AAA/BBB and AAA/BBB the result will be empty.
 /// <li>Given two pairs AAA/AAA and AAA/AAA the result will be empty.
 /// </ul>
 ///
 /// </para>
 /// </summary>
 /// <param name="other">  the other currency pair </param>
 /// <returns> the cross currency pair, or empty if no cross currency pair can be created </returns>
 public Optional <CurrencyPair> cross(CurrencyPair other)
 {
     ArgChecker.notNull(other, "other");
     if (Identity || other.Identity || this.Equals(other) || this.Equals(other.inverse()))
     {
         return(null);
     }
     // AAA/BBB cross BBB/CCC
     if (counter.Equals(other.@base))
     {
         return(of(@base, other.counter).toConventional());
     }
     // AAA/BBB cross CCC/BBB
     if (counter.Equals(other.counter))
     {
         return(of(@base, other.@base).toConventional());
     }
     // BBB/AAA cross BBB/CCC
     if (@base.Equals(other.@base))
     {
         return(of(counter, other.counter).toConventional());
     }
     // BBB/AAA cross CCC/BBB
     if (@base.Equals(other.counter))
     {
         return(of(counter, other.@base).toConventional());
     }
     return(null);
 }
        public virtual void test_inverse_same()
        {
            CurrencyPair test = CurrencyPair.of(GBP, GBP);

            assertEquals(test.inverse(), CurrencyPair.of(GBP, GBP));
        }