List of usage examples for java.lang Short MIN_VALUE
short MIN_VALUE
To view the source code for java.lang Short MIN_VALUE.
Click Source Link
From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java
@Test public void test_convertAnySequences() throws Exception { // Test Strings Object obj = null;// w w w.j av a 2 s.co 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:com.glaf.core.util.GetterUtils.java
public static short getShortStrict(String value) { int i = getIntegerStrict(value); if ((i < Short.MIN_VALUE) || (i > Short.MAX_VALUE)) { throw new NumberFormatException("Out of range value " + value); }// w ww .j a v a 2s . c o m return (short) i; }
From source file:org.vertx.java.http.eventbusbridge.integration.MessagePublishTest.java
@Test public void testPublishingShortXml() throws IOException { final EventBusMessageType messageType = EventBusMessageType.Short; final Short sentShort = Short.MIN_VALUE; Map<String, String> expectations = createExpectations(generateUniqueAddress(), Base64.encodeAsString(sentShort.toString()), messageType); final AtomicInteger completedCount = new AtomicInteger(0); Handler<Message> messagePublishHandler = new MessagePublishHandler(sentShort, expectations, completedCount); registerListenersAndCheckForResponses(messagePublishHandler, expectations, NUMBER_OF_PUBLISH_HANDLERS, completedCount);/*w w w . ja v a2s. c o m*/ String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_XML, expectations); HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(), MediaType.APPLICATION_XML); }
From source file:juicebox.tools.utils.original.Preprocessor.java
/** * Note -- compressed//from ww w. ja v a 2 s . co m * * @param zd Matrix zoom data * @param block Block to write * @param sampledData Array to hold a sample of the data (to compute statistics) * @throws IOException */ private void writeBlock(MatrixZoomDataPP zd, BlockPP block, DownsampledDoubleArrayList sampledData) throws IOException { final Map<Point, ContactCount> records = block.getContactRecordMap();// getContactRecords(); // System.out.println("Write contact records : records count = " + records.size()); // Count records first int nRecords; if (countThreshold > 0) { nRecords = 0; for (ContactCount rec : records.values()) { if (rec.getCounts() >= countThreshold) { nRecords++; } } } else { nRecords = records.size(); } BufferedByteWriter buffer = new BufferedByteWriter(nRecords * 12); buffer.putInt(nRecords); zd.cellCount += nRecords; // Find extents of occupied cells int binXOffset = Integer.MAX_VALUE; int binYOffset = Integer.MAX_VALUE; int binXMax = 0; int binYMax = 0; for (Map.Entry<Point, ContactCount> entry : records.entrySet()) { Point point = entry.getKey(); binXOffset = Math.min(binXOffset, point.x); binYOffset = Math.min(binYOffset, point.y); binXMax = Math.max(binXMax, point.x); binYMax = Math.max(binYMax, point.y); } buffer.putInt(binXOffset); buffer.putInt(binYOffset); // Sort keys in row-major order List<Point> keys = new ArrayList<Point>(records.keySet()); Collections.sort(keys, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { if (o1.y != o2.y) { return o1.y - o2.y; } else { return o1.x - o2.x; } } }); Point lastPoint = keys.get(keys.size() - 1); final short w = (short) (binXMax - binXOffset + 1); boolean isInteger = true; float maxCounts = 0; LinkedHashMap<Integer, List<ContactRecord>> rows = new LinkedHashMap<Integer, List<ContactRecord>>(); for (Point point : keys) { final ContactCount contactCount = records.get(point); float counts = contactCount.getCounts(); if (counts >= countThreshold) { isInteger = isInteger && (Math.floor(counts) == counts); maxCounts = Math.max(counts, maxCounts); final int px = point.x - binXOffset; final int py = point.y - binYOffset; List<ContactRecord> row = rows.get(py); if (row == null) { row = new ArrayList<ContactRecord>(10); rows.put(py, row); } row.add(new ContactRecord(px, py, counts)); } } // Compute size for each representation and choose smallest boolean useShort = isInteger && (maxCounts < Short.MAX_VALUE); int valueSize = useShort ? 2 : 4; int lorSize = 0; int nDensePts = (lastPoint.y - binYOffset) * w + (lastPoint.x - binXOffset) + 1; int denseSize = nDensePts * valueSize; for (List<ContactRecord> row : rows.values()) { lorSize += 4 + row.size() * valueSize; } buffer.put((byte) (useShort ? 0 : 1)); if (lorSize < denseSize) { buffer.put((byte) 1); // List of rows representation buffer.putShort((short) rows.size()); // # of rows for (Map.Entry<Integer, List<ContactRecord>> entry : rows.entrySet()) { int py = entry.getKey(); List<ContactRecord> row = entry.getValue(); buffer.putShort((short) py); // Row number buffer.putShort((short) row.size()); // size of row for (ContactRecord contactRecord : row) { buffer.putShort((short) (contactRecord.getBinX())); final float counts = contactRecord.getCounts(); if (useShort) { buffer.putShort((short) counts); } else { buffer.putFloat(counts); } sampledData.add(counts); zd.sum += counts; } } } else { buffer.put((byte) 2); // Dense matrix buffer.putInt(nDensePts); buffer.putShort(w); int lastIdx = 0; for (Point p : keys) { int idx = (p.y - binYOffset) * w + (p.x - binXOffset); for (int i = lastIdx; i < idx; i++) { // Filler value if (useShort) { buffer.putShort(Short.MIN_VALUE); } else { buffer.putFloat(Float.NaN); } } float counts = records.get(p).getCounts(); if (useShort) { buffer.putShort((short) counts); } else { buffer.putFloat(counts); } lastIdx = idx + 1; sampledData.add(counts); zd.sum += counts; } } byte[] bytes = buffer.getBytes(); byte[] compressedBytes = compress(bytes); los.write(compressedBytes); }
From source file:org.lwes.util.NumberCodec.java
/** * Output a short in unsigned hexadecimal form, padding with zeroes. * * @param s the String representing the short * @return the parsed short/*from w ww .j av a 2s. co m*/ */ public static short shortFromHexString(String s) { return (short) fromHexString(s, Short.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 .ja va 2s . c o m*/ 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; }
From source file:com.glaf.core.util.GetterUtils.java
private static short _parseShort(String value, short defaultValue) { int i = _parseInt(value, defaultValue); if ((i < Short.MIN_VALUE) || (i > Short.MAX_VALUE)) { return defaultValue; }//from w w w . j av a2 s .c o m return (short) i; }
From source file:net.sf.json.TestJSONObject.java
public void testFromObject_use_wrappers() { JSONObject json = JSONObject.fromObject(Boolean.TRUE); assertTrue(json.isEmpty());//from www.ja va 2s.c om json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Short(Short.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Long(Long.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Float(Float.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Double(Double.MIN_VALUE)); assertTrue(json.isEmpty()); json = JSONObject.fromObject(new Character('A')); assertTrue(json.isEmpty()); }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
/** * @param baseArrayClass// w w w .j a v a 2s .c o m * @param objectList -> for primitive type array conversion we assume the content to be * strings! * @return Returns Object. */ public static Object convertToArray(Class baseArrayClass, List objectList) { int listSize = objectList.size(); Object returnArray = null; if (int.class.equals(baseArrayClass)) { int[] array = new int[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = Integer.parseInt(o.toString()); } else { array[i] = Integer.MIN_VALUE; } } returnArray = array; } else if (float.class.equals(baseArrayClass)) { float[] array = new float[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = Float.parseFloat(o.toString()); } else { array[i] = Float.NaN; } } returnArray = array; } else if (short.class.equals(baseArrayClass)) { short[] array = new short[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = Short.parseShort(o.toString()); } else { array[i] = Short.MIN_VALUE; } } returnArray = array; } else if (byte.class.equals(baseArrayClass)) { byte[] array = new byte[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = Byte.parseByte(o.toString()); } else { array[i] = Byte.MIN_VALUE; } } returnArray = array; } else if (long.class.equals(baseArrayClass)) { long[] array = new long[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = Long.parseLong(o.toString()); } else { array[i] = Long.MIN_VALUE; } } returnArray = array; } else if (boolean.class.equals(baseArrayClass)) { boolean[] array = new boolean[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = o.toString().equalsIgnoreCase("true"); } } returnArray = array; } else if (char.class.equals(baseArrayClass)) { char[] array = new char[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = o.toString().toCharArray()[0]; } } returnArray = array; } else if (double.class.equals(baseArrayClass)) { double[] array = new double[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { array[i] = Double.parseDouble(o.toString()); } else { array[i] = Double.NaN; } } returnArray = array; } else if (Calendar.class.equals(baseArrayClass)) { Calendar[] array = new Calendar[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { if (o instanceof String) { array[i] = ConverterUtil.convertToDateTime(o.toString()); } else if (o instanceof Calendar) { array[i] = (Calendar) o; } } } returnArray = array; } else if (Date.class.equals(baseArrayClass)) { Date[] array = new Date[listSize]; for (int i = 0; i < listSize; i++) { Object o = objectList.get(i); if (o != null) { if (o instanceof String) { array[i] = ConverterUtil.convertToDate(o.toString()); } else if (o instanceof Date) { array[i] = (Date) o; } } } returnArray = array; } else { returnArray = Array.newInstance(baseArrayClass, listSize); ConvertToArbitraryObjectArray(returnArray, baseArrayClass, objectList); } return returnArray; }
From source file:com.tasktop.c2c.server.tasks.tests.service.TaskServiceTest.java
License:asdf
@Test public void testTaskSummary() { setupTestData(1000);/*from w w w. j a v a 2s .c o m*/ TaskSummary taskSummary = taskService.getTaskSummary(); assertNotNull(taskSummary); assertEquals(severities.size(), taskSummary.getItems().size()); // it all has to add up. long sum = 0; short previousSortKey = Short.MIN_VALUE; for (TaskSummaryItem item : taskSummary.getItems()) { System.out.println(String.format("%s open=%s closed=%s", item.getSeverity().getValue(), item.getOpenCount(), item.getClosedCount())); assertNotNull(item.getSeverity()); assertNotNull(item.getSeverity().getValue()); assertTrue(item.getSeverity().getSortkey() > previousSortKey); previousSortKey = item.getSeverity().getSortkey(); assertTrue(item.getOpenCount() > 40); assertTrue(item.getClosedCount() > 40); sum += item.getOpenCount(); sum += item.getClosedCount(); } assertEquals(sum, tasks.size()); }