Example usage for com.google.common.collect Iterables getOnlyElement

List of usage examples for com.google.common.collect Iterables getOnlyElement

Introduction

In this page you can find the example usage for com.google.common.collect Iterables getOnlyElement.

Prototype

public static <T> T getOnlyElement(Iterable<T> iterable) 

Source Link

Document

Returns the single element contained in iterable .

Usage

From source file:com.opengamma.financial.analytics.model.black.BlackDiscountingImpliedVolatilityIRFutureOptionFunction.java

@Override
public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
    return new BlackDiscountingCompiledFunction(getTargetToDefinitionConverter(context),
            getDefinitionToDerivativeConverter(context), false) {

        @Override/*  w ww  . ja v  a 2 s . c  om*/
        protected Set<ComputedValue> getValues(final FunctionExecutionContext executionContext,
                final FunctionInputs inputs, final ComputationTarget target,
                final Set<ValueRequirement> desiredValues, final InstrumentDerivative derivative,
                final FXMatrix fxMatrix) {
            final BlackSTIRFuturesSmileProviderInterface blackData = getBlackSurface(executionContext, inputs,
                    target, fxMatrix);
            final double impliedVolatility = derivative.accept(CALCULATOR, blackData);
            final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
            final ValueProperties properties = desiredValue.getConstraints().copy().get();
            final ValueSpecification spec = new ValueSpecification(SECURITY_IMPLIED_VOLATILITY,
                    target.toSpecification(), properties);
            return Collections.singleton(new ComputedValue(spec, impliedVolatility));
        }

    };
}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventStripeNode.java

/**
 * Constructor/*from ww w . j a v a2  s.com*/
 *
 * @param chartLane   the DetailsChartLane this node belongs to
 * @param eventStripe the EventStripe represented by this node
 * @param parentNode  the EventClusterNode that is the parent of this node.
 */
EventStripeNode(DetailsChartLane<?> chartLane, EventStripe eventStripe, EventClusterNode parentNode) {
    super(chartLane, eventStripe, parentNode);

    //setup description label
    descrLabel.setTextOverrun(OverrunStyle.CENTER_ELLIPSIS);
    descrLabel.setPrefWidth(USE_COMPUTED_SIZE);

    setMinHeight(24);
    setAlignment(subNodePane, Pos.BOTTOM_LEFT);

    if (eventStripe.getClusters().size() > 1) {
        for (EventCluster cluster : eventStripe.getClusters()) {
            subNodes.add(createChildNode(cluster.withParent(eventStripe)));
        }
        //stack componenets vertically
        getChildren().addAll(new VBox(infoHBox, subNodePane));
    } else {
        //if the stripe only has one cluster, use alternate simpler layout
        EventNodeBase<?> childNode;
        EventCluster cluster = Iterables.getOnlyElement(eventStripe.getClusters()).withParent(eventStripe);
        if (cluster.getEventIDs().size() == 1) {
            childNode = createChildNode(cluster);
        } else {
            //if the cluster has more than one event, add the clusters controls to this stripe node directly.
            EventClusterNode eventClusterNode = (EventClusterNode) createChildNode(cluster);
            eventClusterNode.installActionButtons();
            controlsHBox.getChildren().addAll(eventClusterNode.getNewCollapseButton(),
                    eventClusterNode.getNewExpandButton());
            eventClusterNode.infoHBox.getChildren().remove(eventClusterNode.countLabel);
            childNode = eventClusterNode;
        }

        //hide the cluster description
        childNode.setDescriptionVisibility(DescriptionVisibility.HIDDEN);

        subNodes.add(childNode);
        //stack componenet in z rather than vertically
        getChildren().addAll(infoHBox, subNodePane);
    }
}