Example usage for java.util OptionalInt of

List of usage examples for java.util OptionalInt of

Introduction

In this page you can find the example usage for java.util OptionalInt of.

Prototype

public static OptionalInt of(int value) 

Source Link

Document

Returns an OptionalInt describing the given value.

Usage

From source file:org.apache.zeppelin.sap.universe.UniverseUtil.java

public static OptionalInt parseInt(String toParse) {
    try {//w  w w .ja v  a 2s.com
        return OptionalInt.of(Integer.parseInt(toParse));
    } catch (NumberFormatException e) {
        return OptionalInt.empty();
    }
}

From source file:org.broadinstitute.gatk.tools.walkers.cancer.ClusteredReadPosition.java

/**
 * The function assumes that read contains the variant allele.
 *
 * @param read//w  w w. j  av  a2  s .  c o m
 * @param variantStartPosition the location of the variant in the reference
 * @return
 */

protected Pair<OptionalInt, OptionalInt> getVariantPositionInRead(final GATKSAMRecord read,
        final int variantStartPosition) {
    final Pair<Integer, Boolean> refPositionAndDeletionFlag = ReadUtils.getReadCoordinateForReferenceCoordinate(
            read.getSoftStart(), read.getCigar(), variantStartPosition, true);
    // the +1 is needed there because getReadCoordinateForReferenceCoordinate() returns the number of read bases from the left end to the variant - 1
    int numReadBasesFromLeftEndToVariant = refPositionAndDeletionFlag.getFirst() + 1;

    // we don't take advantage of fallsInsideOrJustBeforeDeletionOrSkippedRegion flag now, but we might want to, so I will leave it here in comments.
    // boolean fallsInsideOrJustBeforeDeletionOrSkippedRegion = refPositionAndDeletionFlag.getSecond();

    if (numReadBasesFromLeftEndToVariant == ReadUtils.CLIPPING_GOAL_NOT_REACHED) {
        return new Pair(OptionalInt.empty(), OptionalInt.empty());
    } else {
        int leftOffset = numReadBasesFromLeftEndToVariant - 1;
        int rightOffset = read.getReadLength() - numReadBasesFromLeftEndToVariant;
        return new Pair(OptionalInt.of(leftOffset), OptionalInt.of(rightOffset));
    }
}

From source file:org.kie.workbench.common.dmn.backend.DMNMarshallerTest.java

@Test
public void testConnectorRightToLeft() throws Exception {
    final org.kie.workbench.common.stunner.core.graph.content.Bounds bounds = org.kie.workbench.common.stunner.core.graph.content.Bounds
            .create(0, 0, 100, 50);/*w  w  w.j ava 2s.  c om*/
    final String decisionNode1UUID = org.kie.workbench.common.stunner.core.util.UUID.uuid();
    final String decisionNode2UUID = org.kie.workbench.common.stunner.core.util.UUID.uuid();
    final String edgeUUID = org.kie.workbench.common.stunner.core.util.UUID.uuid();

    final ViewConnector edgeView = marshallAndUnMarshallConnectors(bounds, decisionNode1UUID, decisionNode2UUID,
            edgeUUID, (sc) -> {
                when(sc.getMagnetIndex()).thenReturn(OptionalInt.of(MagnetConnection.MAGNET_RIGHT));
                when(sc.getLocation()).thenReturn(new Point2D(bounds.getWidth(), bounds.getHeight() / 2));
            }, (tc) -> {
                when(tc.getMagnetIndex()).thenReturn(OptionalInt.of(MagnetConnection.MAGNET_LEFT));
                when(tc.getLocation()).thenReturn(new Point2D(0, bounds.getHeight() / 2));
            });

    final MagnetConnection sourceConnection = (MagnetConnection) edgeView.getSourceConnection().get();
    assertEquals(bounds.getWidth(), sourceConnection.getLocation().getX(), 0.0);
    assertEquals(bounds.getHeight() / 2, sourceConnection.getLocation().getY(), 0.0);
    assertFalse(sourceConnection.getMagnetIndex().isPresent());
    assertTrue(sourceConnection.isAuto());

    final MagnetConnection targetConnection = (MagnetConnection) edgeView.getTargetConnection().get();
    assertEquals(0, targetConnection.getLocation().getX(), 0.0);
    assertEquals(bounds.getHeight() / 2, targetConnection.getLocation().getY(), 0.0);
    assertFalse(targetConnection.getMagnetIndex().isPresent());
    assertTrue(targetConnection.isAuto());
}

From source file:org.onosproject.netconf.config.NetconfDeviceConfig.java

/**
 * Gets the connect timeout of the SSH connection.
 *
 * @return connectTimeout/*w  ww  . jav  a  2 s .  c o m*/
 */
public OptionalInt connectTimeout() {
    int connectTimeout = get(CONNECT_TIMEOUT, 0);
    return (connectTimeout == 0) ? OptionalInt.empty() : OptionalInt.of(connectTimeout);
}

From source file:org.onosproject.netconf.config.NetconfDeviceConfig.java

/**
 * Gets the reply timeout of the SSH connection.
 *
 * @return replyTimeout//ww  w  . ja  v  a2  s. co m
 */
public OptionalInt replyTimeout() {
    int replyTimeout = get(REPLY_TIMEOUT, 0);
    return (replyTimeout == 0) ? OptionalInt.empty() : OptionalInt.of(replyTimeout);
}

From source file:org.onosproject.netconf.config.NetconfDeviceConfig.java

/**
 * Gets the idle timeout of the SSH connection.
 *
 * @return idleTimeout//from  w ww . j  ava  2s.  co m
 */
public OptionalInt idleTimeout() {
    int idleTimeout = get(IDLE_TIMEOUT, 0);
    return (idleTimeout == 0) ? OptionalInt.empty() : OptionalInt.of(idleTimeout);
}