当前位置: 首页>>代码示例>>Java>>正文


Java Option.some方法代码示例

本文整理汇总了Java中fj.data.Option.some方法的典型用法代码示例。如果您正苦于以下问题:Java Option.some方法的具体用法?Java Option.some怎么用?Java Option.some使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fj.data.Option的用法示例。


在下文中一共展示了Option.some方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sumBatchResult

import fj.data.Option; //导入方法依赖的package包/类
private static Option<Integer> sumBatchResult(int[] xs)
{
    int result = 0;
    for (int x: xs)
    {
        if (x >= 0)
        {
            result += x;
        }
        else if (x == Statement.SUCCESS_NO_INFO)
        {
            return Option.none();
        }
        else if (x == Statement.EXECUTE_FAILED)
        {
            throw new IllegalStateException("a batch command failed but an sql exception was not raised by the driver!");
        }
        else
        {
            throw new IllegalStateException("unrecognized batch return code " + x);
        }
    }
    return Option.some(result);
}
 
开发者ID:novarto-oss,项目名称:sane-dbc,代码行数:25,代码来源:Binders.java

示例2: getAttachNode

import fj.data.Option; //导入方法依赖的package包/类
private Option<KnotNode> getAttachNode( final PullerNode pullerNode ) {
    List<KnotNode> knots = pullerNode.color == BLUE ? blueKnots : redKnots;
    List<KnotNode> free = knots.filter( _free ).filter( new F<KnotNode, Boolean>() {
        @Override public Boolean f( final KnotNode knotNode ) {
            return knotPullerDistance( knotNode, pullerNode ) < 80;
        }
    } );
    if ( free.length() > 0 ) {
        KnotNode closest = free.minimum( FJUtils.ord( new F<KnotNode, Double>() {
            @Override public Double f( final KnotNode k ) {
                return knotPullerDistance( k, pullerNode );
            }
        } ) );
        return Option.some( closest );
    }
    else { return Option.none(); }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:TugOfWarCanvas.java

示例3: animateSliceToBucket

import fj.data.Option; //导入方法依赖的package包/类
public PieSet animateSliceToBucket( CellPointer cell, long randomSeed ) {

        //Cell that should be moved
        //May choose a slice that is on its way to a pie
        final Slice prototype = sliceFactory.createPieCell( pies.length(), cell.container, cell.cell, denominator );
        final Option<Slice> sliceOption = slices.find( new F<Slice, Boolean>() {
            @Override public Boolean f( Slice m ) {
                return ( m.position.equals( prototype.position ) && m.angle == prototype.angle ) || m.movingToward( prototype );
            }
        } );

        final Slice slice = sliceOption.isSome() ? sliceOption.some() : slices.find( new F<Slice, Boolean>() {
            @Override public Boolean f( Slice s ) {
                return s.position.getY() == prototype.position.getY();
            }
        } ).some();

        //Could be none if still animating
        return animateSliceToBucket( slice, randomSeed );
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:21,代码来源:PieSet.java

示例4: testIt

import fj.data.Option; //导入方法依赖的package包/类
@Test
public void testIt()
{
    SyncDbInterpreter dbi = new SyncDbInterpreter(
            // provide a piece of code which knows how to spawn connections
            // in this case we are just using the DriverManager
            () -> DriverManager.getConnection("jdbc:hsqldb:mem:test", "sa", ""
    ));
    dbi.submit(StuffDb.createStuffTable());

    Integer updateCount = dbi.submit(StuffDb.insertStuff("stuff 1"));
    assertThat(updateCount, is(1));

    Integer generatedKey = dbi.submit(StuffDb.insertStuffGetKey("stuff 2"));

    List<Stuff> stuffs = dbi.submit(StuffDb.selectByDescription("no such"));
    assertThat(stuffs.isEmpty(), is(true));

    stuffs = dbi.submit(StuffDb.selectByDescription("stuff 1"));
    //with head() we select the first element of the immutable list
    assertThat(stuffs.head().description, is("stuff 1"));
    //with tail() we select the rest of the list. it should be the empty list: nil()
    assertThat(stuffs.tail(), is(nil()));

    Option<Stuff> stuff2Option = dbi.submit(StuffDb.selectByKey(generatedKey));
    assertThat(stuff2Option.isSome(), is(true));
    Stuff stuff2 = stuff2Option.some();
    assertThat(stuff2, is(new Stuff(generatedKey, "stuff 2")));

    Option<Integer> batchCountOpt = dbi.submit(StuffDb.insertMany(asList("a", "b", "c")));
    Integer batchCount = batchCountOpt.some();
    assertThat(batchCount, is(3));

    Long stuCount = dbi.submit(StuffDb.count("StU"));
    //stuff 1 and stuff 2 match StU, so count should be 2
    assertThat(stuCount, is(2L));

}
 
开发者ID:novarto-oss,项目名称:sane-dbc,代码行数:39,代码来源:BasicUsage.java

示例5: getFrontCardInStack

import fj.data.Option; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") private Option<T> getFrontCardInStack() {
    List<T> sorted = cards.sort( FJUtils.ord( new F<T, Double>() {
        @Override public Double f( final T n ) {
            final Option<Integer> positionInStack = n.getPositionInStack(); //unchecked warning
            return positionInStack.orSome( -1 ).doubleValue();
        }
    } ) );
    return sorted.isEmpty() ? Option.<T>none() : Option.some( sorted.last() );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:10,代码来源:Stack.java

示例6: undo

import fj.data.Option; //导入方法依赖的package包/类
void undo() {
    setDragRegionPickable( true );
    Option<Fraction> value = isComplete() ? Option.some( getValue() ) : Option.<Fraction>none();

    Point2D topCardLocation = numerator.cardNode != null ? numerator.cardNode.getGlobalTranslation() : null;
    Point2D bottomCardLocation = denominator.cardNode != null ? denominator.cardNode.getGlobalTranslation() : null;
    Point2D wholeCardLocation = whole.cardNode != null ? whole.cardNode.getGlobalTranslation() : null;

    if ( cardNode != null ) {
        cardNode.undo();
        cardNode = null;
    }

    //Undo whichever happened last
    if ( dropListHistory.length() > 0 ) {
        FractionNodePosition element = dropListHistory.last();
        if ( element == FractionNodePosition.WHOLE ) { undo( whole, wholeCardLocation ); }
        else if ( element == FractionNodePosition.NUMERATOR ) { undo( numerator, topCardLocation ); }
        else if ( element == FractionNodePosition.DENOMINATOR ) { undo( denominator, bottomCardLocation ); }

        //Drop the last item
        dropListHistory = dropListHistory.reverse().drop( 1 ).reverse();
    }
    undoButton.setVisible( numerator.cardNode != null || denominator.cardNode != null || whole.cardNode != null );
    for ( VoidFunction1<Option<Fraction>> undoListener : undoListeners ) {
        undoListener.apply( value );
    }

    context.updateStacks();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:FractionNode.java

示例7: toUserInput

import fj.data.Option; //导入方法依赖的package包/类
private UserInput toUserInput() {
    if ( mousePressed.size() > 0 ) {
        return new UserInput( Option.some( mousePressed.get( mousePressed.size() - 1 ) ) );
    }
    else {
        return new UserInput( Option.<Vector2D>none() );
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:9,代码来源:EventRecorder.java

示例8: add

import fj.data.Option; //导入方法依赖的package包/类
public <T extends A> SkinnyMux<A> add(Class<T> c, String name, JsonEncoder<T> encoder) {
    F<A, Option<JsonValue>> f =
      a ->
        c.isInstance(a) ?
        Option.some(jObj(p(name, encoder.encode(c.cast(a))))) :
        Option.none();

    return new SkinnyMux<>(a -> encoders.f(a).orElse(f.f(a)));
}
 
开发者ID:kantega,项目名称:kson,代码行数:10,代码来源:SkinnyMux.java

示例9: pick

import fj.data.Option; //导入方法依赖的package包/类
@Override protected Option<PickResult> pick( final Vector2D vector2D, final MockState mockState ) {
    return shape.contains( vector2D.x, vector2D.y ) ? Option.some( new PickResult( this, mockState.getDragHandler() ) ) : Option.<PickResult>none();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:4,代码来源:FillShape.java

示例10: pick

import fj.data.Option; //导入方法依赖的package包/类
@Override protected Option<PickResult> pick( final Vector2D vector2D, final MockState mockState ) {
    return toTextLayout.f( new Args( mockState.getFont(), text, mockState.getFontRenderContext() ) ).
            getOutline( new AffineTransform() ).contains( vector2D.toPoint2D() ) ? Option.some( new PickResult( this, mockState.getDragHandler() ) ) : Option.<PickResult>none();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:5,代码来源:DrawText.java

示例11: getSingleContainerNode

import fj.data.Option; //导入方法依赖的package包/类
private Option<SingleContainerNode> getSingleContainerNode( final int container ) {
    return getSingleContainerNodes().length() <= container ? Option.<SingleContainerNode>none() : Option.some( getSingleContainerNodes().index( container ) );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:4,代码来源:ContainerNode.java

示例12: ShapeSceneNode

import fj.data.Option; //导入方法依赖的package包/类
public ShapeSceneNode( final int levelIndex, final BuildAFractionModel model, final SceneContext context, BooleanProperty soundEnabled, boolean fractionLab, final boolean showContainerNodeOnStartup ) {
    this( levelIndex, model, context, soundEnabled, Option.some( getToolbarOffset( levelIndex, model, context, soundEnabled, fractionLab, showContainerNodeOnStartup ) ), fractionLab, showContainerNodeOnStartup );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:4,代码来源:ShapeSceneNode.java

示例13: onArray

import fj.data.Option; //导入方法依赖的package包/类
public <T> Option<T> onArray(F<List<JsonValue>, T> f) {
  return Option.some(f.f(values));
}
 
开发者ID:kantega,项目名称:kson,代码行数:4,代码来源:JsonArray.java

示例14: onObject

import fj.data.Option; //导入方法依赖的package包/类
public <T> Option<T> onObject(F<TreeMap<String, JsonValue>, T> f) {
    return Option.some(f.f(pairs));
}
 
开发者ID:kantega,项目名称:kson,代码行数:4,代码来源:JsonObject.java

示例15: onBool

import fj.data.Option; //导入方法依赖的package包/类
public <T> Option<T> onBool(F<Boolean, T> f) {
  return Option.some(f.f(value));
}
 
开发者ID:kantega,项目名称:kson,代码行数:4,代码来源:JsonBool.java


注:本文中的fj.data.Option.some方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。