List of usage examples for java.lang Byte MIN_VALUE
byte MIN_VALUE
To view the source code for java.lang Byte MIN_VALUE.
Click Source Link
From source file:org.sakaiproject.content.impl.DbContentService.java
/** * Runs tests of the getResourcesOfType() method. Steps are:<br/> * 1) Add 26 site-level resource collections ("/group/site_A/" through "/group/site_Z/") * and 676 resources of type "org.sakaiproject.content.mock.resource-type". * 2) Invoke the getResourcesOfType() method with page-size 64 and compare * the resource-id's with the resource-id's that would be returned if the * method works correctly.//from w w w . ja v a 2s .co m * 3) Remove the mock resources and collections created in step 1. * A list of the resource-id's is created in step 1 and used in steps 2 and 3. * Verbose logging in step 2 is intended to help with troubleshooting. It would * help to reduce the amount of logging and target it better. Verbose logging also * occurs in step 3 because the no realms are created for the collections in step 1, * resulting in informational messages when an attempt is made to remove the realms. */ protected void testResourceByTypePaging() { // test List<String> collectionIdList = new ArrayList<String>(); List<String> resourceIdList = new ArrayList<String>(); String collectionId = "/group/"; String siteid = "site_"; String fileid = "image_"; String extension = "jpg"; String resourceType = "org.sakaiproject.content.mock.resource-type"; String contentType = "image/jpeg"; byte[] content = new byte[(Byte.MAX_VALUE - Byte.MIN_VALUE) * 4]; int index = 0; for (int i = 0; i < 4 && index < content.length; i++) { for (byte b = Byte.MIN_VALUE; b <= Byte.MAX_VALUE && index < content.length; b++) { content[index] = b; index++; } } try { //enableSecurityAdvisor(); Session s = sessionManager.getCurrentSession(); s.setUserId(UserDirectoryService.ADMIN_ID); for (char ch = 'A'; ch <= 'Z'; ch++) { try { String name = siteid + ch; ContentCollectionEdit collection = this.addCollection(collectionId, name); ResourcePropertiesEdit props = collection.getPropertiesEdit(); props.addProperty(ResourceProperties.PROP_DISPLAY_NAME, name); this.commitCollection(collection); collectionIdList.add(collection.getId()); for (char ch1 = 'a'; ch1 <= 'z'; ch1++) { try { String resourceName = fileid + ch1; ContentResourceEdit resource = this.addResource(collection.getId(), resourceName, extension, MAXIMUM_ATTEMPTS_FOR_UNIQUENESS); ResourcePropertiesEdit properties = resource.getPropertiesEdit(); properties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, resourceName); resource.setContent(content); resource.setContentType(contentType); resource.setResourceType(resourceType); this.commitResource(resource); resourceIdList.add(resource.getId()); } catch (Exception e) { M_log.error( "TEMPORARY LOG MESSAGE WITH STACK TRACE: Failed to create all resources; ch1 = " + ch1, e); } } } catch (Exception e) { M_log.error( "TEMPORARY LOG MESSAGE WITH STACK TRACE: Failed to create all collections; ch = " + ch, e); } } int successCount = 0; int failCount = 0; int pageSize = 64; for (int p = 0; p * pageSize < resourceIdList.size(); p++) { Collection<ContentResource> page = this.getResourcesOfType(resourceType, pageSize, p); int r = 0; for (ContentResource cr : page) { if (p * pageSize + r >= resourceIdList.size()) { M_log.info("TEMPORARY LOG MESSAGE: test failed ====> p = " + p + " r = " + r + " index out of range: p * pageSize + r = " + (p * pageSize + r) + " resourceIdList.size() = " + resourceIdList.size()); failCount++; } else if (cr.getId().equals(resourceIdList.get(p * pageSize + r))) { successCount++; } else { M_log.info("TEMPORARY LOG MESSAGE: test failed ====> p = " + p + " r = " + r + " resource-id doesn't match: cr.getId() = " + cr.getId() + " resourceIdList.get(p * pageSize + r) = resourceIdList.get(" + (p * pageSize + r) + ") = " + resourceIdList.get(p * pageSize + r)); failCount++; } r++; } M_log.info("TEMPORARY LOG MESSAGE: Testing getResourcesOfType() completed page " + p + " of " + (resourceIdList.size() / pageSize)); } M_log.info("TEMPORARY LOG MESSAGE: Testing getResourcesOfType() SUCCEEDED: " + successCount + " FAILED: " + failCount); for (String resourceId : resourceIdList) { ContentResourceEdit edit = this.editResource(resourceId); this.removeResource(edit); } M_log.info( "TEMPORARY LOG MESSAGE: Will delete 26 collections and 676 resources. Some log messages will appear. This block of code will be removed in trunk within a few days and the log messages will disappear."); for (String collId : collectionIdList) { ContentCollectionEdit edit = this.editCollection(collId); this.removeCollection(edit); } } catch (Exception e) { M_log.debug("TEMPORARY LOG MESSAGE WITH STACK TRACE: TEST FAILED ", e); } }
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 v a2 s .c om 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:TypeConversionHelper.java
/** * Utility to convert an int into a byte-generated String * @param val The int/*from ww w. j a va 2 s . c o m*/ * @return The String form of the bytes */ public static String getStringFromInt(int val) { byte[] arr = new byte[4]; for (int i = 3; i >= 0; i--) { arr[i] = (byte) ((0xFFl & val) + Byte.MIN_VALUE); val >>>= 8; } return new String(arr); }
From source file:TypeConversionHelper.java
/** * Utility to convert a short into a byte-generated String * @param val The short/* w ww .j av a 2 s . c om*/ * @return The String form of the bytes */ public static String getStringFromShort(short val) { byte[] arr = new byte[2]; for (int i = 1; i >= 0; i--) { arr[i] = (byte) ((0xFFl & val) + Byte.MIN_VALUE); val >>>= 8; } return new String(arr); }
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())); }// ww w .j av a 2 s . co 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:org.apache.axis2.databinding.utils.ConverterUtil.java
public static byte convertToByte(String s) { if ((s == null) || s.equals("")) { return Byte.MIN_VALUE; }//from ww w .j a v a 2 s . co m return Byte.parseByte(s); }
From source file:TypeConversionHelper.java
/** * Utility to convert a byte array to an int. * @param bytes The byte array/*w w w. j av a 2s . c o m*/ * @return The int */ public static int getIntFromByteArray(byte[] bytes) { int val = 0; for (int i = 0; i < 4; i++) { val = (val << 8) - Byte.MIN_VALUE + bytes[i]; } return val; }
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.lwes.util.NumberCodec.java
/** * Output a byte in unsigned hexadecimal form, padding with zeroes. * * @param s the String representing the byte. * @return the parsed byte/*from www. ja va2s . c o m*/ */ public static byte byteFromHexString(String s) { return (byte) fromHexString(s, Byte.MIN_VALUE); }
From source file:com.sun.faces.util.Util.java
/** * @return true if and only if the argument * <code>attributeVal</code> is an instance of a wrapper for a * primitive type and its value is equal to the default value for * that type as given in the spec. *///from www.j ava 2 s. com private static boolean shouldRenderAttribute(Object attributeVal) { if (attributeVal instanceof Boolean && ((Boolean) attributeVal).booleanValue() == Boolean.FALSE.booleanValue()) { return false; } else if (attributeVal instanceof Integer && ((Integer) attributeVal).intValue() == Integer.MIN_VALUE) { return false; } else if (attributeVal instanceof Double && ((Double) attributeVal).doubleValue() == Double.MIN_VALUE) { return false; } else if (attributeVal instanceof Character && ((Character) attributeVal).charValue() == Character.MIN_VALUE) { return false; } else if (attributeVal instanceof Float && ((Float) attributeVal).floatValue() == Float.MIN_VALUE) { return false; } else if (attributeVal instanceof Short && ((Short) attributeVal).shortValue() == Short.MIN_VALUE) { return false; } else if (attributeVal instanceof Byte && ((Byte) attributeVal).byteValue() == Byte.MIN_VALUE) { return false; } else if (attributeVal instanceof Long && ((Long) attributeVal).longValue() == Long.MIN_VALUE) { return false; } return true; }