List of usage examples for java.lang Long MAX_VALUE
long MAX_VALUE
To view the source code for java.lang Long MAX_VALUE.
Click Source Link
From source file:jp.primecloud.auto.api.ApiValidate.java
public static void validateComponentNo(String componentNo) { ValidateUtil.required(componentNo, "EAPI-000001", new Object[] { PARAM_NAME_COMPONENT_NO }); ValidateUtil.longInRange(componentNo, new Long(1), Long.MAX_VALUE, "EAPI-000002", new Object[] { PARAM_NAME_COMPONENT_NO, new Long(1), Long.MAX_VALUE }); }
From source file:MathUtils.java
public static long multiplyAndCheck(long a, long b) { long ret;/*www .j av a 2 s . c o m*/ String msg = "overflow: multiply"; if (a > b) { // use symmetry to reduce boundry cases ret = multiplyAndCheck(b, a); } else { if (a < 0) { if (b < 0) { // check for positive overflow with negative a, negative b if (a >= Long.MAX_VALUE / b) { ret = a * b; } else { throw new ArithmeticException(msg); } } else if (b > 0) { // check for negative overflow with negative a, positive b if (Long.MIN_VALUE / b <= a) { ret = a * b; } else { throw new ArithmeticException(msg); } } else { // assert b == 0 ret = 0; } } else if (a > 0) { // assert a > 0 // assert b > 0 // check for positive overflow with positive a, positive b if (a <= Long.MAX_VALUE / b) { ret = a * b; } else { throw new ArithmeticException(msg); } } else { // assert a == 0 ret = 0; } } return ret; }
From source file:Main.java
/** * Compute e^x to a given scale. Break x into its whole and fraction parts * and compute (e^(1 + fraction/whole))^whole using Taylor's formula. * // www. j av a 2 s .c o m * @param x * the value of x * @param scale * the desired scale of the result * @return the result value */ public static BigDecimal exp(BigDecimal x, int scale) { // e^0 = 1 if (x.signum() == 0) { return BigDecimal.valueOf(1); } // If x is negative, return 1/(e^-x). else if (x.signum() == -1) { return BigDecimal.valueOf(1).divide(exp(x.negate(), scale), scale, BigDecimal.ROUND_HALF_EVEN); } // Compute the whole part of x. BigDecimal xWhole = x.setScale(0, BigDecimal.ROUND_DOWN); // If there isn't a whole part, compute and return e^x. if (xWhole.signum() == 0) { return expTaylor(x, scale); } // Compute the fraction part of x. BigDecimal xFraction = x.subtract(xWhole); // z = 1 + fraction/whole BigDecimal z = BigDecimal.valueOf(1).add(xFraction.divide(xWhole, scale, BigDecimal.ROUND_HALF_EVEN)); // t = e^z BigDecimal t = expTaylor(z, scale); BigDecimal maxLong = BigDecimal.valueOf(Long.MAX_VALUE); BigDecimal result = BigDecimal.valueOf(1); // Compute and return t^whole using intPower(). // If whole > Long.MAX_VALUE, then first compute products // of e^Long.MAX_VALUE. while (xWhole.compareTo(maxLong) >= 0) { result = result.multiply(intPower(t, Long.MAX_VALUE, scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN); xWhole = xWhole.subtract(maxLong); Thread.yield(); } return result.multiply(intPower(t, xWhole.longValue(), scale)).setScale(scale, BigDecimal.ROUND_HALF_EVEN); }
From source file:examples.utils.CifarReader.java
public static void downloadAndExtract() { if (new File("data", TEST_DATA_FILE).exists() == false) { try {/* w ww . ja va 2s.c om*/ if (new File("data", ARCHIVE_BINARY_FILE).exists() == false) { URL website = new URL("http://www.cs.toronto.edu/~kriz/" + ARCHIVE_BINARY_FILE); FileOutputStream fos = new FileOutputStream("data/" + ARCHIVE_BINARY_FILE); fos.getChannel().transferFrom(Channels.newChannel(website.openStream()), 0, Long.MAX_VALUE); fos.close(); } TarArchiveInputStream tar = new TarArchiveInputStream( new GZIPInputStream(new FileInputStream("data/" + ARCHIVE_BINARY_FILE))); TarArchiveEntry entry = null; while ((entry = tar.getNextTarEntry()) != null) { if (entry.isDirectory()) { new File("data", entry.getName()).mkdirs(); } else { byte data[] = new byte[2048]; int count; BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(new File("data/", entry.getName())), 2048); while ((count = tar.read(data, 0, 2048)) != -1) { bos.write(data, 0, count); } bos.close(); } } tar.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:ch.cyberduck.core.sftp.SFTPQuotaFeature.java
@Override public Space get() throws BackgroundException { final ThreadLocal<Space> quota = new ThreadLocal<Space>() { @Override//from w w w . j av a 2s.c o m protected Space initialValue() { return new Space(0L, Long.MAX_VALUE); } }; final Path home = new SFTPHomeDirectoryService(session).find(); new SFTPCommandFeature(session).send(String.format("df -Pk %s | awk '{print $3, $4}'", home.getAbsolute()), new DisabledProgressListener(), new TranscriptListener() { @Override public void log(final Type request, final String output) { switch (request) { case response: final String[] numbers = StringUtils.split(output, ' '); if (numbers.length == 2) { try { quota.set(new Space(Long.valueOf(numbers[0]) * 1000L, Long.valueOf(numbers[1]) * 1000L)); } catch (NumberFormatException e) { log.warn(String.format("Ignore line %s", output)); } } else { log.warn(String.format("Ignore line %s", output)); } } } }); return quota.get(); }
From source file:livhuwani.rambuda.test.repository.PersonRepositoryTest.java
@Test public void CreateUser() { //Save Intermediary userRepo = ctx.getBean(IntermediaryRepository.class); Intermediary user = new Intermediary(); user.setId(Long.MAX_VALUE + 1); user.setIntermediaryCode("E939964"); intermediary = user;// w ww . j a v a2s .co m userRepo.saveAndFlush(intermediary); id = intermediary.getId(); Assert.notNull(id); }
From source file:cz.cvut.kbss.wpa.dto.test.AbstractObjectCloneTest.java
@Test public void testUserClone() throws CloneNotSupportedException { PlayerDTO p = new PlayerDTO(); p.setName("Test_name"); p.setSurname("Test_surname"); p.setHeight(200);//from w w w . ja v a 2 s. c o m p.setUsername("Test_Username"); p.setPassword("Test_pass"); p.setId(Long.MIN_VALUE); PlayerDTO clone = (PlayerDTO) p.clone(); assertEquals(clone.getName(), p.getName()); assertThat(clone.getId(), sameInstance(p.getId())); assertThat(p.getName(), sameInstance(clone.getName())); clone.setName("Clone_name"); clone.setId(Long.MAX_VALUE); assertThat(p.getName(), not(sameInstance(clone.getName()))); assertThat(p.getId(), not(sameInstance(clone.getId()))); assertThat(clone.getName(), not(p.getName())); assertThat(clone.getId(), not(p.getId())); }
From source file:com.clearspring.analytics.stream.frequency.CountMinSketchTest.java
@Test(expected = IllegalStateException.class) public void sizeOverflow() { CountMinSketch sketch = new CountMinSketch(0.0001, 0.99999, 1); sketch.add(3, Long.MAX_VALUE); sketch.add(4, 1);//from w ww . j a v a 2s . com }
From source file:ch.cyberduck.core.io.SegmentingOutputStream.java
public SegmentingOutputStream(final OutputStream proxy, final Long threshold, final OutputStream buffer) { super(proxy); this.buffer = buffer; this.proxy = proxy; this.threshold = -1L == threshold ? Long.MAX_VALUE : threshold; }
From source file:com.notonthehighstreet.ratel.internal.model.Memory.java
Memory() { final long max = Runtime.getRuntime().maxMemory(); if (max == Long.MAX_VALUE) { free = toMB(Runtime.getRuntime().freeMemory()); } else {/* w ww .j a va 2s.c o m*/ free = toMB(max - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory()); } freeTotal = null; total = toMB(Runtime.getRuntime().maxMemory()); }