List of usage examples for java.lang Byte MAX_VALUE
byte MAX_VALUE
To view the source code for java.lang Byte MAX_VALUE.
Click Source Link
From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCacheTest.java
private byte[] containerTooLarge() { byte[] container = new byte[TOO_LARGE_CONTAINER_SIZE]; for (int i = 0; i < TOO_LARGE_CONTAINER_SIZE; i++) { container[i] = (byte) (i % Byte.MAX_VALUE); }// w w w. j a va 2 s. c o m return container; }
From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjectorTest.java
@Test public void injectorConfigByteArrayTest() { injectMembersTest("testConfigByteArray", false); Assertions.assertThat(testConfigByteArray).isNull(); injectMembersTest("testConfigByteArray", true); Assertions.assertThat(testConfigByteArray).isNotNull(); Assertions.assertThat(testConfigByteArray.length).isEqualTo(1); Assertions.assertThat(testConfigByteArray[0]).isEqualTo(Byte.MAX_VALUE); }
From source file:com.basho.riak.presto.CoverageRecordCursor.java
private OtpErlangTuple buildQuery() //List<RiakColumnHandle> columnHandles, //TupleDomain tupleDom) { // case where a='b' Map<ConnectorColumnHandle, Comparable<?>> fixedValues = tupleDomain.extractFixedValues(); for (Map.Entry<ConnectorColumnHandle, Comparable<?>> fixedValue : fixedValues.entrySet()) { log.debug("> %s (%s)", fixedValue, fixedValue.getClass()); log.debug(">> %s", fixedValue.getKey()); checkNotNull(fixedValue.getKey()); checkArgument(fixedValue.getKey() instanceof ConnectorColumnHandle); checkArgument(fixedValue.getKey() instanceof RiakColumnHandle); RiakColumnHandle c = (RiakColumnHandle) fixedValue.getKey(); for (RiakColumnHandle columnHandle : columnHandles) { if (c.getColumn().getName().equals(columnHandle.getColumn().getName()) && c.getColumn().getType().equals(columnHandle.getColumn().getType()) && columnHandle.getColumn().getIndex()) { String field = null; OtpErlangObject value;// w w w.ja v a2 s .co m if (columnHandle.getColumn().getType() == BigintType.BIGINT) { field = columnHandle.getColumn().getName() + "_int"; Long l = (Long) fixedValue.getValue(); value = new OtpErlangLong(l); } else if (columnHandle.getColumn().getType() == VarcharType.VARCHAR) { field = columnHandle.getColumn().getName() + "_bin"; Slice s = (Slice) fixedValue.getValue(); value = new OtpErlangBinary(s.getBytes()); } else { continue; } OtpErlangObject[] t = { new OtpErlangAtom("eq"), new OtpErlangBinary(field.getBytes()), value }; return new OtpErlangTuple(t); } } } //case where a < b and ... blah Map<RiakColumnHandle, Domain> map = tupleDomain.getDomains(); for (Map.Entry<RiakColumnHandle, Domain> entry : map.entrySet()) { RiakColumnHandle c = entry.getKey(); for (RiakColumnHandle columnHandle : columnHandles) { if (c.getColumn().getName().equals(columnHandle.getColumn().getName()) && c.getColumn().getType().equals(columnHandle.getColumn().getType()) && columnHandle.getColumn().getIndex()) { String field = null; OtpErlangObject lhs, rhs; Range span = entry.getValue().getRanges().getSpan(); //log.debug("value:%s, range:%s, span:%s", // entry.getValue(), entry.getValue().getRanges(),span); //log.debug("min: %s max:%s", span.getLow(), span.getHigh()); if (columnHandle.getColumn().getType() == BigintType.BIGINT) { field = columnHandle.getColumn().getName() + "_int"; // NOTE: Both Erlang and JSON can express smaller integer than Long.MIN_VALUE Long l = Long.MIN_VALUE; if (!span.getLow().isLowerUnbounded()) { l = (Long) span.getLow().getValue(); } // NOTE: Both Erlang and JSON can express greater integer lang Long.MAX_VALUE Long r = Long.MAX_VALUE; if (!span.getHigh().isUpperUnbounded()) { r = (Long) span.getHigh().getValue(); } lhs = new OtpErlangLong(l); rhs = new OtpErlangLong(r); } else if (columnHandle.getColumn().getType() == VarcharType.VARCHAR) { field = columnHandle.getColumn().getName() + "_bin"; //Byte m = Byte.MIN_VALUE; byte[] l = { 0 }; if (!span.getLow().isLowerUnbounded()) { l = ((String) span.getLow().getValue()).getBytes(); } Byte m2 = Byte.MAX_VALUE; byte[] r = { m2 }; if (!span.getHigh().isUpperUnbounded()) { r = ((String) span.getHigh().getValue()).getBytes(); } lhs = new OtpErlangBinary(l); rhs = new OtpErlangBinary(r); } else { continue; } OtpErlangObject[] t = { new OtpErlangAtom("range"), new OtpErlangBinary(field.getBytes()), lhs, rhs }; return new OtpErlangTuple(t); } } } return null; }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Convert any Number object to the specified type for this * <i>Converter</i>.//from w w w. j a v a2 s . c om * <p> * This method handles conversion to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The Number to convert. * * @return The converted value. */ private Number toNumber(Class sourceType, Class targetType, Number value) { // Correct Number type already if (targetType.equals(value.getClass())) { return value; } // Byte if (targetType.equals(Byte.class)) { long longValue = value.longValue(); if (longValue > Byte.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Byte.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Byte(value.byteValue()); } // Short if (targetType.equals(Short.class)) { long longValue = value.longValue(); if (longValue > Short.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Short.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Short(value.shortValue()); } // Integer if (targetType.equals(Integer.class)) { long longValue = value.longValue(); if (longValue > Integer.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Integer.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Integer(value.intValue()); } // Long if (targetType.equals(Long.class)) { return new Long(value.longValue()); } // Float if (targetType.equals(Float.class)) { if (value.doubleValue() > Float.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } return new Float(value.floatValue()); } // Double if (targetType.equals(Double.class)) { return new Double(value.doubleValue()); } // BigDecimal if (targetType.equals(BigDecimal.class)) { if (value instanceof Float || value instanceof Double) { return new BigDecimal(value.toString()); } else if (value instanceof BigInteger) { return new BigDecimal((BigInteger) value); } else { return BigDecimal.valueOf(value.longValue()); } } // BigInteger if (targetType.equals(BigInteger.class)) { if (value instanceof BigDecimal) { return ((BigDecimal) value).toBigInteger(); } else { return BigInteger.valueOf(value.longValue()); } } String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'"; throw new ConversionException(msg); }
From source file:net.spfbl.core.User.java
public boolean isValidOTP(Integer code) { if (code == null) { return false; } else if (code.equals(otp_sucess)) { return false; } else if (Core.isValidOTP(otp_transition, code)) { otp_secret = otp_transition;// ww w .ja v a 2 s .c om otp_transition = null; otp_fail = 0; otp_sucess = code; otp_last = System.currentTimeMillis(); CHANGED = true; return true; } else if (Core.isValidOTP(otp_secret, code)) { otp_transition = null; otp_fail = 0; otp_sucess = code; otp_last = System.currentTimeMillis(); CHANGED = true; return true; } else if (otp_fail < Byte.MAX_VALUE) { otp_fail++; otp_last = System.currentTimeMillis(); CHANGED = true; return false; } else { otp_last = System.currentTimeMillis(); CHANGED = true; return false; } }
From source file:javadz.beanutils.converters.NumberConverter.java
/** * Convert any Number object to the specified type for this * <i>Converter</i>./*from ww w . java 2 s . c o m*/ * <p> * This method handles conversion to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The Number to convert. * * @return The converted value. */ private Number toNumber(Class sourceType, Class targetType, Number value) { // Correct Number type already if (targetType.equals(value.getClass())) { return value; } // Byte if (targetType.equals(Byte.class)) { long longValue = value.longValue(); if (longValue > Byte.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Byte.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Byte(value.byteValue()); } // Short if (targetType.equals(Short.class)) { long longValue = value.longValue(); if (longValue > Short.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Short.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Short(value.shortValue()); } // Integer if (targetType.equals(Integer.class)) { long longValue = value.longValue(); if (longValue > Integer.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Integer.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Integer(value.intValue()); } // Long if (targetType.equals(Long.class)) { return new Long(value.longValue()); } // Float if (targetType.equals(Float.class)) { if (value.doubleValue() > Float.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } return new Float(value.floatValue()); } // Double if (targetType.equals(Double.class)) { return new Double(value.doubleValue()); } // BigDecimal if (targetType.equals(BigDecimal.class)) { if (value instanceof Float || value instanceof Double) { return new BigDecimal(value.toString()); } else if (value instanceof BigInteger) { return new BigDecimal((BigInteger) value); } else { return BigDecimal.valueOf(value.longValue()); } } // BigInteger if (targetType.equals(BigInteger.class)) { if (value instanceof BigDecimal) { return ((BigDecimal) value).toBigInteger(); } else { return BigInteger.valueOf(value.longValue()); } } String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'"; if (log().isWarnEnabled()) { log().warn(" " + msg); } throw new ConversionException(msg); }
From source file:gridool.dht.impl.TcBtreeLocalDirectory.java
private static final byte[] calculateRightEdgeValue(final byte[] v) { final int vlen = v.length; final byte[] b = new byte[vlen + 1]; System.arraycopy(v, 0, b, 0, vlen); b[vlen] = Byte.MAX_VALUE; return b;//w w w. j a v a2 s . c om }
From source file:me.j360.idgen.impl.test.TableIdGenServiceJdbcTest.java
/** * [Flow #-6] Positive, Negative Case : try to get next byte id * /*from w w w . j a v a 2s .co m*/ * @throws Exception * fail to test */ @Test public void testMaxByteIds() throws Exception { IdGenService idGenerator = (IdGenService) applicationContext.getBean("Ids-TestMaxByteIds"); int testCount = 100; // max = 127 long max = Byte.MAX_VALUE; long initial = max - testCount; // 1. Initialize the counter in the database. initializeNextLongId("test", initial); // 2. get next byte id until limitation of Byte for (int i = 0; i <= testCount; i++) { byte id = idGenerator.getNextByteId(); assertEquals("The returned id was not what was expected.", i + initial, id); } // 3. in case it reached a max value data type // allows, get next byte // id. try { byte id = idGenerator.getNextByteId(); fail("Should not have gotten an id: " + id); } catch (Exception e) { assertTrue(e instanceof IdCreationException); } }
From source file:com.peterphi.std.crypto.keygen.CaHelper.java
static private X509V3CertificateGenerator addCaExtensions(X509V3CertificateGenerator gen, PublicKey pubKey) throws Exception { gen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(true)); gen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment | KeyUsage.dataEncipherment | KeyUsage.keyCertSign | KeyUsage.cRLSign)); gen.addExtension(X509Extensions.ExtendedKeyUsage, getExtendedKeyUsageCriticality(), new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth)); // gen.addExtension(X509Extensions.SubjectAlternativeName, false, // new GeneralNames(new GeneralName(GeneralName.rfc822Name, // "test@test.test"))); // netscape-cert-type "2.16.840.1.113730.1.1" // * bit-0 SSL client - 128 // * bit-1 SSL server - 64 // * bit-2 S/MIME - 32 // * bit-3 Object Signing - 16 // * bit-4 Reserved - 8 // * bit-5 SSL CA - 4 // * bit-6 S/MIME CA - 2 // * bit-7 Object Signing CA - 1 gen.addExtension(netscapeCertType, false, new DERBitString(new byte[] { Byte.MAX_VALUE })); // was 4 addSubjectKeyIdentifier(gen, pubKey); addAuthorityKeyIdentifier(gen, pubKey); return gen;//from ww w . ja v a2 s. c om }
From source file:com.jcwhatever.nucleus.internal.managed.commands.Arguments.java
@Override public byte getByte(String parameterName) throws InvalidArgumentException { return getByte(parameterName, Byte.MIN_VALUE, Byte.MAX_VALUE); }