/** * Creates a future position key. Note that account and traderId are converted to <code>null</code> if they only contain whitespace. * * @param inSymbol a <code>String</code> value * @param inExpiry a <code>String</code> value * @param inAccount a <code>String</code> value * @param inTraderId a <code>String</code> value * @throws IllegalArgumentException if one of the given parameters are invalid */ public static PositionKey<Future> createFutureKey(String inSymbol, @Nullable String inExpiry, @Nullable String inAccount, @Nullable String inTraderId) { return createKey(new Future(inSymbol, inExpiry), inAccount, inTraderId); } /**
/** * Parses the given <code>String</code> to create a <code>Future</code> instrument. * * @param inFullSymbol a <code>String</code> value in the form <code>SYMBOL-YYYYMM</code> or <code>SYMBOL-YYYYMDD</code> * @return a <code>Future</code> value * @throws IllegalArgumentException if the given <code>String</code> cannot be parsed */ public static Future fromString(String inFullSymbol) { inFullSymbol = StringUtils.trimToNull(inFullSymbol); Validate.notNull(inFullSymbol, Messages.NULL_SYMBOL.getText()); if(!inFullSymbol.contains("-")) { throw new IllegalArgumentException(Messages.INVALID_SYMBOL.getText(inFullSymbol)); } int dashIndex = inFullSymbol.lastIndexOf('-'); assert(dashIndex != -1); String symbol = inFullSymbol.substring(0, dashIndex); String expiry = inFullSymbol.substring(dashIndex+1); return new Future(symbol, expiry); } /**
@Override public Instrument extract(FieldMap inMessage) { // if the symbol already contains the expiry information, go ahead and create it // if it doesn't, piece the expiry onto the symbol and use that String symbol = getSymbol(inMessage); if(symbol == null) { return null; } try { return Future.fromString(symbol); } catch (IllegalArgumentException ignored) {} // assume the symbol is the underlying, not the full symbol (this is the common case, it seems) // therefore, use the multi-argument constructor instead String expiry = OptionFromMessage.getExpiry(inMessage); if(expiry == null) { return null; } Future future = new Future(symbol, expiry); return future; } /* (non-Javadoc)
new Future(inUnderlyingSymbol, inExpirationMonth, inExpirationYear));