Example usage for java.lang Long MAX_VALUE

List of usage examples for java.lang Long MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Long MAX_VALUE.

Prototype

long MAX_VALUE

To view the source code for java.lang Long MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value a long can have, 263-1.

Usage

From source file:Main.java

/**
 * Convert the bytes within the specified range of the given byte 
 * array into a signed long in the given radix . The range extends 
 * from <code>start</code> till, but not including <code>end</code>. <p>
 *
 * Based on java.lang.Long.parseLong()//  ww w.j a v a  2  s  .co m
 */
public static long parseLong(byte[] b, int start, int end, int radix) throws NumberFormatException {
    if (b == null)
        throw new NumberFormatException("null");

    long result = 0;
    boolean negative = false;
    int i = start;
    long limit;
    long multmin;
    int digit;

    if (end > start) {
        if (b[i] == '-') {
            negative = true;
            limit = Long.MIN_VALUE;
            i++;
        } else {
            limit = -Long.MAX_VALUE;
        }
        multmin = limit / radix;
        if (i < end) {
            digit = Character.digit((char) b[i++], radix);
            if (digit < 0) {
                throw new NumberFormatException("illegal number: " + toString(b, start, end));
            } else {
                result = -digit;
            }
        }
        while (i < end) {
            // Accumulating negatively avoids surprises near MAX_VALUE
            digit = Character.digit((char) b[i++], radix);
            if (digit < 0) {
                throw new NumberFormatException("illegal number");
            }
            if (result < multmin) {
                throw new NumberFormatException("illegal number");
            }
            result *= radix;
            if (result < limit + digit) {
                throw new NumberFormatException("illegal number");
            }
            result -= digit;
        }
    } else {
        throw new NumberFormatException("illegal number");
    }
    if (negative) {
        if (i > start + 1) {
            return result;
        } else { /* Only got "-" */
            throw new NumberFormatException("illegal number");
        }
    } else {
        return -result;
    }
}

From source file:com.offbynull.portmapper.MappedPort.java

/**
 * Constructs a {@link MappedPort} object.
 * @param internalPort internal port/*from ww  w . j ava  2 s.c  om*/
 * @param externalPort external port
 * @param externalAddress external address
 * @param portType port type
 * @param duration mapping lifetime
 * @throws NullPointerException if any argument is {@code null}
 * @throws IllegalArgumentException if any numeric argument is non-positive, or if {@code internalPort > 65535 || externalPort > 65535}
 */
public MappedPort(int internalPort, int externalPort, InetAddress externalAddress, PortType portType,
        long duration) {
    Validate.inclusiveBetween(1, 65535, internalPort);
    Validate.inclusiveBetween(1, 65535, externalPort);
    Validate.notNull(externalAddress);
    Validate.notNull(portType);
    Validate.inclusiveBetween(0L, Long.MAX_VALUE, duration);

    this.internalPort = internalPort;
    this.externalPort = externalPort;
    this.externalAddress = externalAddress;
    this.portType = portType;
    this.lifetime = duration;
}

From source file:com.cloudera.cdk.morphline.metrics.servlets.HttpMetricsMorphlineTest.java

@Test
public void testBasic() throws Exception {
    morphline = createMorphline("test-morphlines/startReportingMetricsToHTTP");

    Record record = new Record();
    String msg = "foo";
    record.put(Fields.MESSAGE, msg);//from   www  . j  a v a 2  s.  c  o m
    Record expected = new Record();
    expected.put(Fields.MESSAGE, msg);
    processAndVerifySuccess(record, expected);

    if ("true".equals(System.getProperty("HttpMetricsMorphlineTest.isDemo"))) {
        // wait forever so user can browse to http://localhost:8080/ and interactively explore the features
        Thread.sleep(Long.MAX_VALUE);
    }

    verifyServing(8080);
    verifyServing(8081);
    verifyShutdown(8080);
    verifyShutdown(8081);
}

From source file:Main.java

/**
 * Adds two positive longs and caps the result at Long.MAX_VALUE.
 * @param a the first value/*from w  w  w .j  a  v a2 s  . c  om*/
 * @param b the second value
 * @return the capped sum of a and b
 */
public static long addCap(long a, long b) {
    long u = a + b;
    if (u < 0L) {
        u = Long.MAX_VALUE;
    }
    return u;
}

From source file:net.sf.jasperreports.data.cache.BigIntegerStore.java

private void reset() {
    this.rawStore.resetValues();

    this.min = BigInteger.valueOf(Long.MAX_VALUE);
    this.max = BigInteger.valueOf(Long.MIN_VALUE);
}

From source file:com.twitter.hraven.TestTaskKey.java

@Test
public void testSerialization() {
    TaskKeyConverter conv = new TaskKeyConverter();

    TaskKey key1 = new TaskKey(new JobKey("test@local", "testuser", "app", 1234L, "job_20120101000000_1111"),
            "m_001");
    assertEquals("test@local", key1.getCluster());
    assertEquals("testuser", key1.getUserName());
    assertEquals("app", key1.getAppId());
    assertEquals(1234L, key1.getRunId());
    assertEquals("job_20120101000000_1111", key1.getJobId().getJobIdString());
    assertEquals("m_001", key1.getTaskId());

    byte[] key1Bytes = conv.toBytes(key1);
    TaskKey key2 = conv.fromBytes(key1Bytes);
    assertKey(key1, key2);//ww  w  . ja v a 2 s  .  c  o  m

    TaskKey key3 = conv.fromBytes(conv.toBytes(key2));
    assertKey(key1, key3);

    // test with a run ID containing the separator
    long now = System.currentTimeMillis();
    byte[] encoded = Bytes.toBytes(Long.MAX_VALUE - now);
    // replace last byte with separator and reconvert to long
    Bytes.putBytes(encoded, encoded.length - Constants.SEP_BYTES.length, Constants.SEP_BYTES, 0,
            Constants.SEP_BYTES.length);
    long badId = Long.MAX_VALUE - Bytes.toLong(encoded);
    LOG.info("Bad run ID is " + badId);

    TaskKey badKey1 = new TaskKey(
            new JobKey(key1.getQualifiedJobId(), key1.getUserName(), key1.getAppId(), badId), key1.getTaskId());
    byte[] badKeyBytes = conv.toBytes(badKey1);
    TaskKey badKey2 = conv.fromBytes(badKeyBytes);
    assertKey(badKey1, badKey2);
}

From source file:info.archinnov.achilles.test.integration.tests.CacheSizeIT.java

@Test
public void should_re_prepare_statements_when_cache_size_exceeded() throws Exception {
    //Given/*from   ww  w.  ja v a2  s.co m*/
    CompleteBean bean = builder().id(RandomUtils.nextLong(0, Long.MAX_VALUE)).name("name").buid();

    CompleteBean managed = pm.insert(bean);

    //When
    managed.setAge(10L);
    pm.update(managed);

    managed.setFriends(Arrays.asList("foo", "bar"));
    pm.update(managed);

    managed.setFollowers(Sets.newHashSet("George", "Paul"));
    pm.update(managed);

    managed.setAge(11L);
    pm.update(managed);

    //Then
    CompleteBean found = pm.find(CompleteBean.class, bean.getId());

    assertThat(found.getAge()).isEqualTo(11L);
    assertThat(found.getName()).isEqualTo("name");
    assertThat(found.getFriends()).containsExactly("foo", "bar");
    assertThat(found.getFollowers()).containsOnly("George", "Paul");
}

From source file:com.adito.ldap.GroupContainer.java

synchronized String storeGroup(LdapGroup group) {
    String principalName = storePrincipal(group);
    final String dn = group.getDn().toLowerCase();
    dnToRoleCache.store(dn, group, Long.MAX_VALUE, null, GROUPS_CACHE_PREFIX);
    return principalName;
}

From source file:com.basetechnology.s0.agentserver.field.IntField.java

public IntField(SymbolTable symbolTable, String name, String label) {
    this.symbol = new Symbol(symbolTable, name, IntegerTypeNode.one);
    this.label = label;
    minValue = Long.MIN_VALUE;/*  ww  w . ja  v  a2 s.co  m*/
    maxValue = Long.MAX_VALUE;
}

From source file:com.eviware.loadui.util.statistics.ValueStatistics.java

public synchronized Map<String, Number> getData(long timestamp) {
    long max = 0;
    long min = Long.MAX_VALUE;
    long sum = 0;

    for (Iterator<DataPoint> it = dataPoints.iterator(); it.hasNext();) {
        DataPoint dataPoint = it.next();
        if (dataPoint.timestamp < timestamp - period && period > 0)
            it.remove();//from ww  w . j  a  v  a2 s .  c  om
        else {
            sum += dataPoint.value;
            max = Math.max(max, dataPoint.value);
            min = Math.min(min, dataPoint.value);
        }
    }

    int count = dataPoints.size();
    double avg = count > 0 ? (double) sum / count : 0;

    double stdDev = 0;
    double[] dataSet = new double[count];
    if (count > 0) {
        int i = 0;
        for (DataPoint dataPoint : dataPoints) {
            dataSet[i] = dataPoint.value;
            i++;
            stdDev += Math.pow(dataPoint.value - avg, 2);
        }
        stdDev = Math.sqrt(stdDev / count);
    }

    double tps = 0;
    long vps = 0;
    long duration = 0;
    if (count >= 2) {
        int samples = 0;
        long earliest = timestamp - snapshotLength;
        DataPoint point = null;
        while (++samples < count) {
            point = dataPoints.get(count - samples);
            vps += point.value;
            if (point.timestamp < earliest)
                break;
        }

        long timeDelta = timestamp - Preconditions.checkNotNull(point).timestamp;

        timeDelta = timeDelta == 0 ? 1000 : timeDelta;

        vps = vps * 1000 / timeDelta;
        tps = (samples - 1) * 1000.0 / timeDelta;
        duration = dataPoints.get(count - 1).timestamp - dataPoints.get(0).timestamp;
    }

    Percentile perc = new Percentile(90);

    double percentile = perc.evaluate(dataSet, 90);

    return new ImmutableMap.Builder<String, Number>() //
            .put("Max", max) //
            .put("Min", min == Long.MAX_VALUE ? 0L : min) //
            .put("Avg", avg) //
            .put("Sum", sum) //
            .put("Std-Dev", stdDev) //
            .put("Tps", tps) //
            .put("Avg-Tps", duration > 0L ? 1000L * count / duration : 0) //
            .put("Vps", vps) //
            .put("Avg-Vps", duration > 0L ? 1000L * sum / duration : 0) //
            .put("Percentile", percentile) //
            .put("AvgResponseSize", 1000L * sum / (dataPoints.size() == 0 ? 1 : dataPoints.size())) //
            .build();
}