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:com.cyberway.issue.crawler.frontier.BdbMultipleWorkQueuesTest.java

/**
 * Basic sanity checks for calculateInsertKey() -- ensure ordinal, cost,
 * and schedulingDirective have the intended effects, for ordinal values
 * up through 1/4th of the maximum (about 2^61).
 * /*w  w w.j  a  v  a  2  s .c  om*/
 * @throws URIException
 */
public void testCalculateInsertKey() throws URIException {
    for (long ordinalOrigin = 1; ordinalOrigin < Long.MAX_VALUE / 4; ordinalOrigin <<= 1) {
        CandidateURI cauri1 = new CandidateURI(UURIFactory.getInstance("http://archive.org/foo"));
        CrawlURI curi1 = new CrawlURI(cauri1, ordinalOrigin);
        curi1.setClassKey("foo");
        byte[] key1 = BdbMultipleWorkQueues.calculateInsertKey(curi1).getData();
        CandidateURI cauri2 = new CandidateURI(UURIFactory.getInstance("http://archive.org/bar"));
        CrawlURI curi2 = new CrawlURI(cauri2, ordinalOrigin + 1);
        curi2.setClassKey("foo");
        byte[] key2 = BdbMultipleWorkQueues.calculateInsertKey(curi2).getData();
        CandidateURI cauri3 = new CandidateURI(UURIFactory.getInstance("http://archive.org/baz"));
        CrawlURI curi3 = new CrawlURI(cauri3, ordinalOrigin + 2);
        curi3.setClassKey("foo");
        curi3.setSchedulingDirective(CandidateURI.HIGH);
        byte[] key3 = BdbMultipleWorkQueues.calculateInsertKey(curi3).getData();
        CandidateURI cauri4 = new CandidateURI(UURIFactory.getInstance("http://archive.org/zle"));
        CrawlURI curi4 = new CrawlURI(cauri4, ordinalOrigin + 3);
        curi4.setClassKey("foo");
        curi4.setHolderCost(2);
        byte[] key4 = BdbMultipleWorkQueues.calculateInsertKey(curi4).getData();
        CandidateURI cauri5 = new CandidateURI(UURIFactory.getInstance("http://archive.org/gru"));
        CrawlURI curi5 = new CrawlURI(cauri5, ordinalOrigin + 4);
        curi5.setClassKey("foo");
        curi5.setHolderCost(1);
        byte[] key5 = BdbMultipleWorkQueues.calculateInsertKey(curi5).getData();
        // ensure that key1 (with lower ordinal) sorts before key2 (higher
        // ordinal)
        assertTrue("lower ordinal sorting first (" + ordinalOrigin + ")",
                Key.compareKeys(key1, key2, null) < 0);
        // ensure that key3 (with HIGH scheduling) sorts before key2 (even
        // though
        // it has lower ordinal)
        assertTrue("lower directive sorting first (" + ordinalOrigin + ")",
                Key.compareKeys(key3, key2, null) < 0);
        // ensure that key5 (with lower cost) sorts before key4 (even though 
        // key4  has lower ordinal and same default NORMAL scheduling directive)
        assertTrue("lower cost sorting first (" + ordinalOrigin + ")", Key.compareKeys(key5, key4, null) < 0);
    }
}

From source file:io.github.benas.jpopulator.randomizers.validation.MinValueRandomizer.java

/**
 * Generate a random value for the given type.
 *
 * @param type the type for which a random value will be generated
 * @param minValue the minimum threshold for the generated value
 * @return a random value (greater than maxValue) for the given type or null if the type is not supported
 *///from w  w  w.j  av a2  s. c  o  m
public static Object getRandomValue(final Class type, final long minValue) {

    if (type.equals(Byte.TYPE) || type.equals(Byte.class)) {
        return (byte) randomDataGenerator.nextLong(minValue, Byte.MAX_VALUE);
    }
    if (type.equals(Short.TYPE) || type.equals(Short.class)) {
        return (short) randomDataGenerator.nextLong(minValue, Short.MAX_VALUE);
    }
    if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
        return (int) randomDataGenerator.nextLong(minValue, Integer.MAX_VALUE);
    }
    if (type.equals(Long.TYPE) || type.equals(Long.class)) {
        return randomDataGenerator.nextLong(minValue, Long.MAX_VALUE);
    }
    if (type.equals(BigInteger.class)) {
        return new BigInteger(String.valueOf(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE)));
    }
    if (type.equals(BigDecimal.class)) {
        return new BigDecimal(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE));
    }
    return null;
}

From source file:com.proofpoint.units.DataSize.java

public long toBytes() {
    double bytes = getValue(Unit.BYTE);
    Preconditions.checkState(bytes <= Long.MAX_VALUE, "size is too large to be represented in bytes as a long");
    return (long) bytes;
}

From source file:Main.java

/**
 * Add two long integers, checking for overflow.
 * //from  w w  w  .jav  a 2 s . c om
 * @param a an addend
 * @param b an addend
 * @param msg the message to use for any thrown exception.
 * @return the sum <code>a+b</code>
 * @throws ArithmeticException if the result can not be represented as an
 *         long
 * @since 1.2
 */
private static long addAndCheck(long a, long b, String msg) {
    long ret;
    if (a > b) {
        // use symmetry to reduce boundry cases
        ret = addAndCheck(b, a, msg);
    } else {
        // assert a <= b

        if (a < 0) {
            if (b < 0) {
                // check for negative overflow
                if (Long.MIN_VALUE - b <= a) {
                    ret = a + b;
                } else {
                    throw new ArithmeticException(msg);
                }
            } else {
                // oppisite sign addition is always safe
                ret = a + b;
            }
        } else {
            // assert a >= 0
            // assert b >= 0

            // check for positive overflow
            if (a <= Long.MAX_VALUE - b) {
                ret = a + b;
            } else {
                throw new ArithmeticException(msg);
            }
        }
    }
    return ret;
}

From source file:math.tools.Browse.java

/**
 * Creates new form jsontable// ww w .  j  a v a2 s . com
 */
public Browse() {
    BufferedReader in;
    FileOutputStream fos;
    new File(System.getProperty("user.home") + "//MathHelper//tools//").mkdirs();
    try {
        URL website = new URL("https://dl.dropboxusercontent.com/u/67622419/mathTools/toolInfo.json");
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        fos = new FileOutputStream(System.getProperty("user.home") + "//MathHelper//toolInfo.json");
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    } catch (IOException ex) {
        Logger.getLogger(Browse.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        in = new BufferedReader(
                new FileReader(System.getProperty("user.home") + "//MathHelper//toolInfo.json"));
        String inputLine;
        int i = -1;
        JSONObject json;
        while ((inputLine = in.readLine()) != null) {
            i++;
            json = (JSONObject) new JSONParser().parse(inputLine);
            table[i][0] = json.get("name");
            table[i][1] = json.get("author");
            table[i][2] = json.get("rating");
            File f = new File(
                    System.getProperty("user.home") + "//MathHelper//tools//" + json.get("name") + ".jar");
            if (!f.exists()) {
                table[i][3] = "Not Downloaded Yet";
            } else {
                table[i][3] = "Downloaded";
            }
            table[i][4] = json.get("adress");
        }
        in.close();
    } catch (IOException | ParseException ex) {
        Logger.getLogger(Browse.class.getName()).log(Level.SEVERE, null, ex);
    }
    initComponents();
}

From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.StopEpoch.java

/**
 * @param initiator/* w w w. ja v  a 2 s  . co m*/
 * @param name
 * @param epochNumber
 * @param getFinalState
 * @param executeStop 
 */
public StopEpoch(NodeIDType initiator, String name, int epochNumber, boolean getFinalState,
        boolean executeStop) {
    super(initiator, ReconfigurationPacket.PacketType.STOP_EPOCH, name, epochNumber);
    this.getFinalState = getFinalState;
    this.requestID = (long) (Math.random() * Long.MAX_VALUE);
    this.executeStop = executeStop;
}

From source file:info.archinnov.achilles.it.bugs.TestEntityWithByteBufferTypeIT.java

@Test
public void should_support_bytebuffer_type() throws Exception {
    //Given/* w ww .  j a va  2 s . c om*/
    final Cluster cluster = CassandraEmbeddedServerBuilder.builder().useUnsafeCassandraDeamon()
            .withScript("functions/createFunctions.cql").buildNativeCluster();

    final Long id = RandomUtils.nextLong(0, Long.MAX_VALUE);
    final byte[] bytes = RandomUtils.nextBytes(100);
    final ByteBuffer value = ByteBuffer.wrap(bytes);

    //When
    final ManagerFactory managerFactory = ManagerFactoryBuilder.builder(cluster)
            .withManagedEntityClasses(EntityWithByteBufferType.class).doForceSchemaCreation(true)
            .withDefaultKeyspaceName(DEFAULT_CASSANDRA_EMBEDDED_KEYSPACE_NAME).build();

    final EntityWithByteBufferType_Manager manager = managerFactory.forEntityWithByteBufferType();

    final EntityWithByteBufferType entity = new EntityWithByteBufferType(id, value);

    manager.crud().insert(entity).execute();

    final Row one = manager.getNativeSession()
            .execute("SELECT * FROM " + EntityWithByteBufferType.TABLE + " WHERE id = " + id).one();

    assertThat(one).isNotNull();
    assertThat(one.getBytes("value")).isEqualTo(value);
}

From source file:com.navercorp.pinpoint.common.server.bo.RandomTSpan.java

public TSpan randomTSpan() {
    final TSpan tSpan = new TSpan();
    tSpan.setAgentId("agentId");
    tSpan.setApplicationName("appName");
    tSpan.setAgentStartTime(System.currentTimeMillis());

    tSpan.setTransactionId(TransactionIdUtils.formatByteBuffer("agent", System.currentTimeMillis(),
            RandomUtils.nextLong(0, Long.MAX_VALUE)));
    tSpan.setSpanId(random.nextLong());//from  w  ww  .  j  a  va  2  s. co  m
    tSpan.setParentSpanId(RandomUtils.nextInt(0, 100000));
    tSpan.setStartTime(System.currentTimeMillis() + RandomUtils.nextInt(0, 1000));
    tSpan.setElapsed(RandomUtils.nextInt(0, 2000));
    tSpan.setRpc(RandomStringUtils.random(10));

    tSpan.setServiceType(randomServerServiceType());
    tSpan.setEndPoint(RandomStringUtils.random(20));
    tSpan.setRemoteAddr(RandomStringUtils.random(20));

    List<TAnnotation> tAnnotationList = randomTAnnotationList();
    if (CollectionUtils.isNotEmpty(tAnnotationList)) {
        tSpan.setAnnotations(tAnnotationList);
    }
    tSpan.setFlag((short) RandomUtils.nextInt(0, 4));
    tSpan.setErr((short) RandomUtils.nextInt(0, 2));
    //        tSpan.setSpanEventList()
    tSpan.setParentApplicationName("parentApp");
    tSpan.setParentApplicationType(randomServerServiceType());
    tSpan.setAcceptorHost("acceptHost");
    tSpan.setApiId(RandomUtils.nextInt(0, 5000));
    if (random.nextBoolean()) {
        tSpan.setApplicationServiceType(randomServerServiceType());
    } else {
        tSpan.setApplicationServiceType(tSpan.getServiceType());
    }
    if (random.nextBoolean()) {
        TIntStringValue exceptionInfo = new TIntStringValue();
        exceptionInfo.setIntValue(RandomUtils.nextInt(0, 5000));
        exceptionInfo.setStringValue(RandomStringUtils.random(100));
        tSpan.setExceptionInfo(exceptionInfo);
    }
    tSpan.setLoggingTransactionInfo((byte) RandomUtils.nextInt(0, 256));
    return tSpan;
}

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

@Test
public void should_insert_and_find_entity_with_transformed_types() throws Exception {
    //Given/*from w  w w  . j  a v a  2  s .c  o m*/
    Long id = RandomUtils.nextLong(0, Long.MAX_VALUE);
    Long longValue = RandomUtils.nextLong(0, Long.MAX_VALUE);

    final EntityWithTypeTransformer entity = new EntityWithTypeTransformer(id, longValue,
            Arrays.asList(longValue), Sets.newSet(longValue), ImmutableMap.of(longValue, "longValue"),
            ImmutableMap.of(1, longValue), ImmutableMap.of(longValue, NamingStrategy.CASE_SENSITIVE));

    manager.insert(entity);

    //When
    final EntityWithTypeTransformer found = manager.find(EntityWithTypeTransformer.class, id);

    //Then
    assertThat(found.getLongToString()).isEqualTo(longValue);
    assertThat(found.getMyList()).contains(longValue);
    assertThat(found.getMySet()).contains(longValue);
    assertThat(found.getKeyMap()).hasSize(1).containsKey(longValue).containsValue("longValue");
    assertThat(found.getValueMap()).hasSize(1).containsKey(1).containsValue(longValue);
    assertThat(found.getKeyValueMap()).hasSize(1).containsKey(longValue)
            .containsValue(NamingStrategy.CASE_SENSITIVE);
}

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

@Test
public void should_slice_query_with_class_consistency_level() throws Exception {
    //Given//w w  w. ja v a 2  s . co  m
    Long id = RandomUtils.nextLong(0, Long.MAX_VALUE);
    Date date1 = new Date(1);
    Date date2 = new Date(2);
    Date date3 = new Date(3);

    final ClusteredEntityWithConsistencyLevel entity1 = new ClusteredEntityWithConsistencyLevel(id, date1, "1");
    final ClusteredEntityWithConsistencyLevel entity2 = new ClusteredEntityWithConsistencyLevel(id, date2, "2");
    final ClusteredEntityWithConsistencyLevel entity3 = new ClusteredEntityWithConsistencyLevel(id, date3, "3");

    manager.insert(entity1);
    manager.insert(entity2);
    manager.insert(entity3);

    //When
    logAsserter.prepareLogLevelForDriverConnection();

    final ClusteredEntityWithConsistencyLevel found = manager
            .sliceQuery(ClusteredEntityWithConsistencyLevel.class).forSelect().withPartitionComponents(id)
            .fromClusterings(date1).getOne();

    //Then
    assertThat(found.getId().getDate()).isEqualTo(date1);
    logAsserter.assertConsistencyLevels(ConsistencyLevel.LOCAL_ONE);
}