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:net.spfbl.dnsbl.QueryDNSBL.java
public static void setConnectionLimit(int limit) { if (limit < 1 || limit > Byte.MAX_VALUE) { Server.logError("invalid DNSBL connection limit '" + limit + "'."); } else {//from w w w .j a va 2 s . c o m CONNECTION_LIMIT = (byte) limit; } }
From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java
@Test public void test_convertAnySequences() throws Exception { // Test Strings Object obj = null;/*from w w w .j a va 2 s. c o m*/ Any theAny = JacorbUtil.init().create_any(); final String[] stringInitialValue = new String[] { "a", "b", "c" }; StringSeqHelper.insert(theAny, stringInitialValue); final String[] stringExtractedValue = StringSeqHelper.extract(theAny); // Sanity Check Assert.assertTrue(Arrays.equals(stringInitialValue, stringExtractedValue)); // The real test obj = AnyUtils.convertAny(theAny); Assert.assertTrue(obj instanceof String[]); Assert.assertTrue(Arrays.equals(stringInitialValue, (String[]) obj)); // Test Doubles obj = null; theAny = JacorbUtil.init().create_any(); final double[] doubleInitialValue = new double[] { 0.1, 0.2, 0.3 }; DoubleSeqHelper.insert(theAny, doubleInitialValue); final double[] doubleExtractedValue = DoubleSeqHelper.extract(theAny); // Sanity Check Assert.assertTrue(Arrays.equals(doubleInitialValue, doubleExtractedValue)); // The real test obj = AnyUtils.convertAny(theAny); Assert.assertTrue(obj instanceof Double[]); Assert.assertTrue(Arrays.equals(ArrayUtils.toObject(doubleInitialValue), (Double[]) obj)); // Test Integers obj = null; theAny = JacorbUtil.init().create_any(); final int[] intInitialValue = new int[] { 1, 2, 3 }; LongSeqHelper.insert(theAny, intInitialValue); final int[] intExtractedValue = LongSeqHelper.extract(theAny); // Sanity Check Assert.assertTrue(Arrays.equals(intInitialValue, intExtractedValue)); // The real test obj = AnyUtils.convertAny(theAny); Assert.assertTrue(obj instanceof Integer[]); Assert.assertTrue(Arrays.equals(ArrayUtils.toObject(intInitialValue), (Integer[]) obj)); // Test Recursive Sequence obj = null; final Any[] theAnys = new Any[2]; theAnys[0] = JacorbUtil.init().create_any(); theAnys[1] = JacorbUtil.init().create_any(); LongSeqHelper.insert(theAnys[0], intInitialValue); LongSeqHelper.insert(theAnys[1], intInitialValue); AnySeqHelper.insert(theAny, theAnys); // The real test obj = AnyUtils.convertAny(theAny); Assert.assertTrue(obj instanceof Object[]); int[] extractedIntArray = ArrayUtils.toPrimitive((Integer[]) ((Object[]) obj)[0]); Assert.assertTrue(Arrays.equals(intInitialValue, extractedIntArray)); extractedIntArray = ArrayUtils.toPrimitive((Integer[]) ((Object[]) obj)[1]); Assert.assertTrue(Arrays.equals(intInitialValue, extractedIntArray)); String[] str = (String[]) AnyUtils .convertAny(AnyUtils.toAnySequence(new String[] { "2", "3" }, TCKind.tk_string)); Assert.assertEquals("2", str[0]); str = (String[]) AnyUtils.convertAny(AnyUtils.toAnySequence(new String[] { "3", "4" }, TCKind.tk_wstring)); Assert.assertEquals("3", str[0]); final Boolean[] bool = (Boolean[]) AnyUtils .convertAny(AnyUtils.toAnySequence(new boolean[] { false, true }, TCKind.tk_boolean)); Assert.assertTrue(bool[1].booleanValue()); final Short[] b = (Short[]) AnyUtils .convertAny(AnyUtils.toAnySequence(new byte[] { Byte.MIN_VALUE, Byte.MAX_VALUE }, TCKind.tk_octet)); Assert.assertEquals(Byte.MAX_VALUE, b[1].byteValue()); Character[] c = (Character[]) AnyUtils .convertAny(AnyUtils.toAnySequence(new char[] { 'r', 'h' }, TCKind.tk_char)); Assert.assertEquals('h', c[1].charValue()); c = (Character[]) AnyUtils .convertAny(AnyUtils.toAnySequence(new Character[] { '2', '3' }, TCKind.tk_wchar)); Assert.assertEquals('2', c[0].charValue()); final Short[] s = (Short[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new short[] { Short.MIN_VALUE, Short.MAX_VALUE }, TCKind.tk_short)); Assert.assertEquals(Short.MAX_VALUE, s[1].shortValue()); final Integer[] i = (Integer[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE }, TCKind.tk_long)); Assert.assertEquals(Integer.MAX_VALUE, i[1].intValue()); final Long[] l = (Long[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new long[] { Long.MIN_VALUE, Long.MAX_VALUE }, TCKind.tk_longlong)); Assert.assertEquals(Long.MAX_VALUE, l[1].longValue()); final Float[] f = (Float[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new float[] { Float.MIN_VALUE, Float.MAX_VALUE }, TCKind.tk_float)); Assert.assertEquals(Float.MAX_VALUE, f[1].floatValue(), 0.00001); final Double[] d = (Double[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new double[] { Double.MIN_VALUE, Double.MAX_VALUE }, TCKind.tk_double)); Assert.assertEquals(Double.MAX_VALUE, d[1].doubleValue(), 0.00001); final Integer[] us = (Integer[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new short[] { Short.MIN_VALUE, Short.MAX_VALUE }, TCKind.tk_ushort)); Assert.assertEquals(Short.MAX_VALUE, us[1].intValue()); final Long[] ui = (Long[]) AnyUtils.convertAny( AnyUtils.toAnySequence(new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE }, TCKind.tk_ulong)); Assert.assertEquals(Integer.MAX_VALUE, ui[1].longValue()); final BigInteger[] ul = (BigInteger[]) AnyUtils.convertAny(AnyUtils .toAnySequence(new BigInteger[] { new BigInteger("2"), new BigInteger("3") }, TCKind.tk_ulonglong)); Assert.assertEquals(3L, ul[1].longValue()); }
From source file:voldemort.VoldemortClientShell.java
@SuppressWarnings("unchecked") protected static Object tightenNumericTypes(Object o) { if (o == null) { return null; } else if (o instanceof List) { List l = (List) o; for (int i = 0; i < l.size(); i++) l.set(i, tightenNumericTypes(l.get(i))); return l; } else if (o instanceof Map) { Map m = (Map) o;//from w w w .j a v a 2 s . c o m for (Map.Entry entry : (Set<Map.Entry>) m.entrySet()) m.put(entry.getKey(), tightenNumericTypes(entry.getValue())); return m; } else if (o instanceof Number) { Number n = (Number) o; if (o instanceof Integer) { if (n.intValue() < Byte.MAX_VALUE) return n.byteValue(); else if (n.intValue() < Short.MAX_VALUE) return n.shortValue(); else return n; } else if (o instanceof Double) { if (n.doubleValue() < Float.MAX_VALUE) return n.floatValue(); else return n; } else { throw new RuntimeException("Unsupported numeric type: " + o.getClass()); } } else { return o; } }
From source file:org.solbase.lucenehbase.IndexWriter.java
@SuppressWarnings("unchecked") public ParsedDoc parseDoc(Document doc, Analyzer analyzer, String indexName, int docNumber, List<String> sortFieldNames) throws CorruptIndexException, IOException { // given doc, what are all of terms we indexed List<Term> allIndexedTerms = new ArrayList<Term>(); Map<String, byte[]> fieldCache = new HashMap<String, byte[]>(1024); // need to hold onto TermDocMetaData, so it can return this array List<TermDocMetadata> metadatas = new ArrayList<TermDocMetadata>(); byte[] docId = Bytes.toBytes(docNumber); int position = 0; for (Fieldable field : (List<Fieldable>) doc.getFields()) { // Indexed field if (field.isIndexed() && field.isTokenized()) { TokenStream tokens = field.tokenStreamValue(); if (tokens == null) { tokens = analyzer.tokenStream(field.name(), new StringReader(field.stringValue())); }// w w w. ja v a 2 s .c o m // collect term information per field Map<Term, Map<ByteBuffer, List<Number>>> allTermInformation = new ConcurrentSkipListMap<Term, Map<ByteBuffer, List<Number>>>(); int lastOffset = 0; if (position > 0) { position += analyzer.getPositionIncrementGap(field.name()); } tokens.reset(); // reset the TokenStream to the first token // offsets OffsetAttribute offsetAttribute = null; if (field.isStoreOffsetWithTermVector()) offsetAttribute = (OffsetAttribute) tokens.addAttribute(OffsetAttribute.class); // positions PositionIncrementAttribute posIncrAttribute = null; if (field.isStorePositionWithTermVector()) posIncrAttribute = (PositionIncrementAttribute) tokens .addAttribute(PositionIncrementAttribute.class); TermAttribute termAttribute = (TermAttribute) tokens.addAttribute(TermAttribute.class); // store normalizations of field per term per document // rather // than per field. // this adds more to write but less to read on other side Integer tokensInField = new Integer(0); while (tokens.incrementToken()) { tokensInField++; Term term = new Term(field.name(), termAttribute.term()); allIndexedTerms.add(term); // fetch all collected information for this term Map<ByteBuffer, List<Number>> termInfo = allTermInformation.get(term); if (termInfo == null) { termInfo = new ConcurrentSkipListMap<ByteBuffer, List<Number>>(); allTermInformation.put(term, termInfo); } // term frequency List<Number> termFrequency = termInfo.get(TermDocMetadata.termFrequencyKeyBytes); if (termFrequency == null) { termFrequency = new ArrayList<Number>(); termFrequency.add(new Integer(0)); termInfo.put(TermDocMetadata.termFrequencyKeyBytes, termFrequency); } // increment termFrequency.set(0, termFrequency.get(0).intValue() + 1); // position vector if (field.isStorePositionWithTermVector()) { position += (posIncrAttribute.getPositionIncrement() - 1); List<Number> positionVector = termInfo.get(TermDocMetadata.positionVectorKeyBytes); if (positionVector == null) { positionVector = new ArrayList<Number>(); termInfo.put(TermDocMetadata.positionVectorKeyBytes, positionVector); } positionVector.add(++position); } // term offsets if (field.isStoreOffsetWithTermVector()) { List<Number> offsetVector = termInfo.get(TermDocMetadata.offsetVectorKeyBytes); if (offsetVector == null) { offsetVector = new ArrayList<Number>(); termInfo.put(TermDocMetadata.offsetVectorKeyBytes, offsetVector); } offsetVector.add(lastOffset + offsetAttribute.startOffset()); offsetVector.add(lastOffset + offsetAttribute.endOffset()); } List<Number> sortValues = new ArrayList<Number>(); // init sortValues for (int i = 0; i < Scorer.numSort; i++) { sortValues.add(new Integer(-1)); } int order = 0; // extract sort field value and store it in term doc metadata obj for (String fieldName : sortFieldNames) { Fieldable fieldable = doc.getFieldable(fieldName); if (fieldable instanceof EmbeddedSortField) { EmbeddedSortField sortField = (EmbeddedSortField) fieldable; int value = -1; if (sortField.stringValue() != null) { value = Integer.parseInt(sortField.stringValue()); } int sortSlot = sortField.getSortSlot(); sortValues.set(sortSlot - 1, new Integer(value)); } else { // TODO: this logic is used for real time indexing. // hacky. depending on order of sort field names in array int value = -1; if (fieldable.stringValue() != null) { value = Integer.parseInt(fieldable.stringValue()); } sortValues.set(order++, new Integer(value)); } } termInfo.put(TermDocMetadata.sortFieldKeyBytes, sortValues); } List<Number> bnorm = null; if (!field.getOmitNorms()) { bnorm = new ArrayList<Number>(); float norm = doc.getBoost(); norm *= field.getBoost(); norm *= similarity.lengthNorm(field.name(), tokensInField); bnorm.add(Similarity.encodeNorm(norm)); } for (Map.Entry<Term, Map<ByteBuffer, List<Number>>> term : allTermInformation.entrySet()) { Term tempTerm = term.getKey(); byte[] fieldTermKeyBytes = SolbaseUtil.generateTermKey(tempTerm); // Mix in the norm for this field alongside each term // more writes but faster on read side. if (!field.getOmitNorms()) { term.getValue().put(TermDocMetadata.normsKeyBytes, bnorm); } TermDocMetadata data = new TermDocMetadata(docNumber, term.getValue(), fieldTermKeyBytes, tempTerm); metadatas.add(data); } } // Untokenized fields go in without a termPosition if (field.isIndexed() && !field.isTokenized()) { Term term = new Term(field.name(), field.stringValue()); allIndexedTerms.add(term); byte[] fieldTermKeyBytes = SolbaseUtil.generateTermKey(term); Map<ByteBuffer, List<Number>> termMap = new ConcurrentSkipListMap<ByteBuffer, List<Number>>(); termMap.put(TermDocMetadata.termFrequencyKeyBytes, Arrays.asList(new Number[] {})); termMap.put(TermDocMetadata.positionVectorKeyBytes, Arrays.asList(new Number[] {})); TermDocMetadata data = new TermDocMetadata(docNumber, termMap, fieldTermKeyBytes, term); metadatas.add(data); } // Stores each field as a column under this doc key if (field.isStored()) { byte[] _value = field.isBinary() ? field.getBinaryValue() : Bytes.toBytes(field.stringValue()); // first byte flags if binary or not byte[] value = new byte[_value.length + 1]; System.arraycopy(_value, 0, value, 0, _value.length); value[value.length - 1] = (byte) (field.isBinary() ? Byte.MAX_VALUE : Byte.MIN_VALUE); // logic to handle multiple fields w/ same name byte[] currentValue = fieldCache.get(field.name()); if (currentValue == null) { fieldCache.put(field.name(), value); } else { // append new data byte[] newValue = new byte[currentValue.length + SolbaseUtil.delimiter.length + value.length - 1]; System.arraycopy(currentValue, 0, newValue, 0, currentValue.length - 1); System.arraycopy(SolbaseUtil.delimiter, 0, newValue, currentValue.length - 1, SolbaseUtil.delimiter.length); System.arraycopy(value, 0, newValue, currentValue.length + SolbaseUtil.delimiter.length - 1, value.length); fieldCache.put(field.name(), newValue); } } } Put documentPut = new Put(SolbaseUtil.randomize(docNumber)); // Store each field as a column under this docId for (Map.Entry<String, byte[]> field : fieldCache.entrySet()) { documentPut.add(Bytes.toBytes("field"), Bytes.toBytes(field.getKey()), field.getValue()); } // in case of real time update, we need to add back docId field if (!documentPut.has(Bytes.toBytes("field"), Bytes.toBytes("docId"))) { byte[] docIdStr = Bytes.toBytes(new Integer(docNumber).toString()); // first byte flags if binary or not byte[] value = new byte[docIdStr.length + 1]; System.arraycopy(docIdStr, 0, value, 0, docIdStr.length); value[value.length - 1] = (byte) (Byte.MIN_VALUE); documentPut.add(Bytes.toBytes("field"), Bytes.toBytes("docId"), value); } // Finally, Store meta-data so we can delete this document documentPut.add(Bytes.toBytes("allTerms"), Bytes.toBytes("allTerms"), SolbaseUtil.toBytes(allIndexedTerms).array()); ParsedDoc parsedDoc = new ParsedDoc(metadatas, doc, documentPut, fieldCache.entrySet(), allIndexedTerms); return parsedDoc; }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testInvalidWhenExhaustedAction() throws Exception { try {//w w w . j a va2 s.c om pool.setWhenExhaustedAction(Byte.MAX_VALUE); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected } try { ObjectPool pool = new GenericObjectPool(new SimpleFactory(), GenericObjectPool.DEFAULT_MAX_ACTIVE, Byte.MAX_VALUE, GenericObjectPool.DEFAULT_MAX_WAIT, GenericObjectPool.DEFAULT_MAX_IDLE, false, false, GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, false); assertNotNull(pool); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { // expected } }
From source file:adalid.core.AbstractDataArtifact.java
/** * @return the data max//from ww w . java 2 s.c o m */ // @Override public Object getDataGenMax() { if (_dataGenMax == null && isNumericPrimitive()) { if (isByteData()) { return Byte.MAX_VALUE; } if (isShortData()) { return Short.MAX_VALUE; } return 1000000000; } return _dataGenMax; }
From source file:com.epam.catgenome.manager.reference.io.NibDataReader.java
private double encodingGCContent(final double gcCode) { return (gcCode - Byte.MIN_VALUE) / (Byte.MAX_VALUE - Byte.MIN_VALUE); }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that a// ww w. j a v a2s . co m * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)} * can return a different object based on the media type argument. * * @throws HttpException * @throws IOException */ public void testReaderReadFromMediaType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlybytemediatype"); postMethod.setRequestEntity(new StringRequestEntity("empty", "custom/int", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); String response = postMethod.getResponseBodyAsString(); assertEquals("null", response); } finally { postMethod.releaseConnection(); } postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/readdifferentlybytemediatype"); postMethod.setRequestEntity(new StringRequestEntity("empty", "custom/byte", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); String response = postMethod.getResponseBodyAsString(); assertEquals("" + Byte.MAX_VALUE, response); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.hadoop.hbase.KeyValue.java
/** * Create an empty byte[] representing a KeyValue * All lengths are preset and can be filled in later. * @param rlength/*from ww w .jav a 2 s . c o m*/ * @param flength * @param qlength * @param timestamp * @param type * @param vlength * @return The newly created byte array. */ private static byte[] createEmptyByteArray(final int rlength, int flength, int qlength, final long timestamp, final Type type, int vlength, int tagsLength) { if (rlength > Short.MAX_VALUE) { throw new IllegalArgumentException("Row > " + Short.MAX_VALUE); } if (flength > Byte.MAX_VALUE) { throw new IllegalArgumentException("Family > " + Byte.MAX_VALUE); } // Qualifier length if (qlength > Integer.MAX_VALUE - rlength - flength) { throw new IllegalArgumentException("Qualifier > " + Integer.MAX_VALUE); } checkForTagsLength(tagsLength); // Key length long longkeylength = getKeyDataStructureSize(rlength, flength, qlength); if (longkeylength > Integer.MAX_VALUE) { throw new IllegalArgumentException("keylength " + longkeylength + " > " + Integer.MAX_VALUE); } int keylength = (int) longkeylength; // Value length if (vlength > HConstants.MAXIMUM_VALUE_LENGTH) { // FindBugs INT_VACUOUS_COMPARISON throw new IllegalArgumentException("Valuer > " + HConstants.MAXIMUM_VALUE_LENGTH); } // Allocate right-sized byte array. byte[] bytes = new byte[(int) getKeyValueDataStructureSize(rlength, flength, qlength, vlength, tagsLength)]; // Write the correct size markers int pos = 0; pos = Bytes.putInt(bytes, pos, keylength); pos = Bytes.putInt(bytes, pos, vlength); pos = Bytes.putShort(bytes, pos, (short) (rlength & 0x0000ffff)); pos += rlength; pos = Bytes.putByte(bytes, pos, (byte) (flength & 0x0000ff)); pos += flength + qlength; pos = Bytes.putLong(bytes, pos, timestamp); pos = Bytes.putByte(bytes, pos, type.getCode()); pos += vlength; if (tagsLength > 0) { pos = Bytes.putShort(bytes, pos, (short) (tagsLength & 0x0000ffff)); } return bytes; }
From source file:org.springframework.beans.AbstractPropertyAccessorTests.java
@Test public void setPrimitiveProperties() { NumberPropertyBean target = new NumberPropertyBean(); AbstractPropertyAccessor accessor = createAccessor(target); String byteValue = " " + Byte.MAX_VALUE + " "; String shortValue = " " + Short.MAX_VALUE + " "; String intValue = " " + Integer.MAX_VALUE + " "; String longValue = " " + Long.MAX_VALUE + " "; String floatValue = " " + Float.MAX_VALUE + " "; String doubleValue = " " + Double.MAX_VALUE + " "; accessor.setPropertyValue("myPrimitiveByte", byteValue); accessor.setPropertyValue("myByte", byteValue); accessor.setPropertyValue("myPrimitiveShort", shortValue); accessor.setPropertyValue("myShort", shortValue); accessor.setPropertyValue("myPrimitiveInt", intValue); accessor.setPropertyValue("myInteger", intValue); accessor.setPropertyValue("myPrimitiveLong", longValue); accessor.setPropertyValue("myLong", longValue); accessor.setPropertyValue("myPrimitiveFloat", floatValue); accessor.setPropertyValue("myFloat", floatValue); accessor.setPropertyValue("myPrimitiveDouble", doubleValue); accessor.setPropertyValue("myDouble", doubleValue); assertEquals(Byte.MAX_VALUE, target.getMyPrimitiveByte()); assertEquals(Byte.MAX_VALUE, target.getMyByte().byteValue()); assertEquals(Short.MAX_VALUE, target.getMyPrimitiveShort()); assertEquals(Short.MAX_VALUE, target.getMyShort().shortValue()); assertEquals(Integer.MAX_VALUE, target.getMyPrimitiveInt()); assertEquals(Integer.MAX_VALUE, target.getMyInteger().intValue()); assertEquals(Long.MAX_VALUE, target.getMyPrimitiveLong()); assertEquals(Long.MAX_VALUE, target.getMyLong().longValue()); assertEquals(Float.MAX_VALUE, target.getMyPrimitiveFloat(), 0.001); assertEquals(Float.MAX_VALUE, target.getMyFloat().floatValue(), 0.001); assertEquals(Double.MAX_VALUE, target.getMyPrimitiveDouble(), 0.001); assertEquals(Double.MAX_VALUE, target.getMyDouble().doubleValue(), 0.001); }