Example usage for java.lang Long MIN_VALUE

List of usage examples for java.lang Long MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Long MIN_VALUE.

Prototype

long MIN_VALUE

To view the source code for java.lang Long MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value a long can have, -263.

Usage

From source file:org.alfresco.repo.domain.node.AbstractNodeDAOImpl.java

/**
 * Invalidate cache entries for all children of a give node.  This usually applies
 * where the child associations or nodes are modified en-masse.
 * //  w w w .j  a v  a  2s . c  o m
 * @param parentNodeId          the parent node of all child nodes to be invalidated (may be <tt>null</tt>)
 * @param touchNodes            <tt>true<tt> to also touch the nodes
 * @return                      the number of child associations found (might be capped)
 */
private int invalidateNodeChildrenCaches(Long parentNodeId, boolean primary, boolean touchNodes) {
    Long txnId = getCurrentTransaction().getId();

    int count = 0;
    List<Long> childNodeIds = new ArrayList<Long>(256);
    Long minChildNodeIdInclusive = Long.MIN_VALUE;
    while (minChildNodeIdInclusive != null) {
        childNodeIds.clear();
        List<ChildAssocEntity> childAssocs = selectChildNodeIds(parentNodeId, Boolean.valueOf(primary),
                minChildNodeIdInclusive, 256);
        // Remove the cache entries as we go
        for (ChildAssocEntity childAssoc : childAssocs) {
            Long childNodeId = childAssoc.getChildNode().getId();
            if (childNodeId.compareTo(minChildNodeIdInclusive) < 0) {
                throw new RuntimeException("Query results did not increase for child node id ID");
            } else {
                minChildNodeIdInclusive = new Long(childNodeId.longValue() + 1L);
            }
            // Invalidate the node cache
            childNodeIds.add(childNodeId);
            invalidateNodeCaches(childNodeId);
            count++;
        }
        // Bring all the nodes into the transaction, if required
        if (touchNodes) {
            updateNodes(txnId, childNodeIds);
        }
        // Now break out if we didn't have the full set of results
        if (childAssocs.size() < 256) {
            break;
        }
    }
    // Done
    return count;
}

From source file:com.gemstone.gemfire.cache.hdfs.internal.hoplog.HdfsSortedOplogOrganizer.java

@Override
public void close() throws IOException {
    super.close();

    synchronized (changePrimarylockObject) {
        organizerClosed = true;/*  w  w w .  j a  va  2  s  .c  om*/
    }
    //Suspend compaction
    getCompactor().suspend();

    //Close the readers controller.
    hoplogReadersController.close();

    previousCleanupTimestamp.set(Long.MIN_VALUE);

}

From source file:net.aksingh.java.api.owm.AbstractWeatherData.java

/**
 * Parameterized constructor//from w  ww .j av  a2  s.  co  m
 * <p>
 * Initializes variables from values from the given JSON object.
 * <p>
 * @param jsonObj JSON object containing weather data
 */
public AbstractWeatherData(JSONObject jsonObj) {
    // getting seconds from the data
    long sec = (jsonObj != null) ? jsonObj.optLong(this.JSON_DATE_TIME, Long.MIN_VALUE) : Long.MIN_VALUE;

    // converting seconds to Date object
    if (sec != Long.MIN_VALUE) {
        /*
         @bugfix It always return "Sat Jan 17 04:10:42 CET 1970"
         Issue: #3 given at http://code.aksingh.net/owm-japis/issue/3/problem-with-datetime
         Incorrect: this.dateTime = new Date(sec);
         Correct: this.dateTime = new Date(sec * 1000);
         Reason: Date requires milliseconds but previously, seconds were provided.
         */
        this.dateTime = new Date(sec * 1000);
    } else {
        this.dateTime = null;
    }
}

From source file:com.android.launcher3.ItemTouchHelper.java

/**
 * Starts dragging or swiping the given View. Call with null if you want to clear it.
 *
 * @param selected    The ViewHolder to drag or swipe. Can be null if you want to cancel the
 *                    current action//from  w  w  w.ja  va  2 s.  c o  m
 * @param actionState The type of action
 */
void select(android.support.v7.widget.RecyclerView.ViewHolder selected, int actionState) {
    if (selected == mSelected && actionState == mActionState) {
        return;
    }
    mDragScrollStartTimeInMs = Long.MIN_VALUE;
    final int prevActionState = mActionState;
    // prevent duplicate animations
    endRecoverAnimation(selected, true);
    mActionState = actionState;
    if (actionState == ACTION_STATE_DRAG) {
        // we remove after animation is complete. this means we only elevate the last drag
        // child but that should perform good enough as it is very hard to start dragging a
        // new child before the previous one settles.
        mOverdrawChild = selected.itemView;
        addChildDrawingOrderCallback();
    }
    int actionStateMask = (1 << (DIRECTION_FLAG_COUNT + DIRECTION_FLAG_COUNT * actionState)) - 1;
    boolean preventLayout = false;

    if (mSelected != null) {
        final android.support.v7.widget.RecyclerView.ViewHolder prevSelected = mSelected;
        if (prevSelected.itemView.getParent() != null) {
            final int swipeDir = prevActionState == ACTION_STATE_DRAG ? 0 : swipeIfNecessary(prevSelected);
            releaseVelocityTracker();
            // find where we should animate to
            final float targetTranslateX, targetTranslateY;
            int animationType;
            switch (swipeDir) {
            case LEFT:
            case RIGHT:
            case START:
            case END:
                targetTranslateY = 0;
                targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth();
                break;
            case UP:
            case DOWN:
                targetTranslateX = 0;
                targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight();
                break;
            default:
                targetTranslateX = 0;
                targetTranslateY = 0;
            }
            if (prevActionState == ACTION_STATE_DRAG) {
                animationType = ANIMATION_TYPE_DRAG;
            } else if (swipeDir > 0) {
                animationType = ANIMATION_TYPE_SWIPE_SUCCESS;
            } else {
                animationType = ANIMATION_TYPE_SWIPE_CANCEL;
            }
            getSelectedDxDy(mTmpPosition);
            final float currentTranslateX = mTmpPosition[0];
            final float currentTranslateY = mTmpPosition[1];
            final RecoverAnimation rv = new RecoverAnimation(prevSelected, animationType, prevActionState,
                    currentTranslateX, currentTranslateY, targetTranslateX, targetTranslateY) {
                @Override
                public void onAnimationEnd(ValueAnimatorCompat animation) {
                    super.onAnimationEnd(animation);
                    if (this.mOverridden) {
                        return;
                    }
                    if (swipeDir <= 0) {
                        // this is a drag or failed swipe. recover immediately
                        mCallback.clearView(mRecyclerView, prevSelected);
                        // full cleanup will happen on onDrawOver
                    } else {
                        // wait until remove animation is complete.
                        mPendingCleanup.add(prevSelected.itemView);
                        mIsPendingCleanup = true;
                        if (swipeDir > 0) {
                            // Animation might be ended by other animators during a layout.
                            // We defer callback to avoid editing adapter during a layout.
                            postDispatchSwipe(this, swipeDir);
                        }
                    }
                    // removed from the list after it is drawn for the last time
                    if (mOverdrawChild == prevSelected.itemView) {
                        removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
                    }
                }
            };
            final long duration = mCallback.getAnimationDuration(mRecyclerView, animationType,
                    targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY);
            rv.setDuration(duration);
            mRecoverAnimations.add(rv);
            rv.start();
            preventLayout = true;
        } else {
            removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
            mCallback.clearView(mRecyclerView, prevSelected);
        }
        mSelected = null;
    }
    if (selected != null) {
        mSelectedFlags = (mCallback.getAbsoluteMovementFlags(mRecyclerView, selected)
                & actionStateMask) >> (mActionState * DIRECTION_FLAG_COUNT);
        mSelectedStartX = selected.itemView.getLeft();
        mSelectedStartY = selected.itemView.getTop();
        mSelected = selected;

        if (actionState == ACTION_STATE_DRAG) {
            mSelected.itemView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        }
    }
    final ViewParent rvParent = mRecyclerView.getParent();
    if (rvParent != null) {
        rvParent.requestDisallowInterceptTouchEvent(mSelected != null);
    }
    if (!preventLayout) {
        mRecyclerView.getLayoutManager().requestSimpleAnimationsInNextLayout();
    }
    mCallback.onSelectedChanged(mSelected, mActionState);
    mRecyclerView.invalidate();
}

From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java

@Test
public void test_convertAnySequences() throws Exception {
    // Test Strings
    Object obj = null;//from   ww w. j  a  va2s . com
    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:org.ramadda.geodata.cdmdata.PointDatabaseTypeHandler.java

/**
 * _more_//from   w w  w .  ja v  a2  s . co m
 *
 *
 * @param request _more_
 * @param entry _more_
 * @param metadata _more_
 * @param fdp _more_
 * @param connection _more_
 * @param newEntry _more_
 *
 * @throws Exception _more_
 */
private void insertData(Request request, Entry entry, List<PointDataMetadata> metadata, FeatureDatasetPoint fdp,
        Connection connection, boolean newEntry) throws Exception {

    String tableName = getTableName(entry);
    String[] ARRAY = new String[metadata.size()];
    for (PointDataMetadata pdm : metadata) {
        ARRAY[pdm.getColumnNumber()] = pdm.getColumnName();
    }
    String insertString = SqlUtil.makeInsert(tableName, SqlUtil.commaNoDot(ARRAY),
            SqlUtil.getQuestionMarks(ARRAY.length));

    double north = 0, south = 0, east = 0, west = 0;

    long minTime = (newEntry ? Long.MAX_VALUE : entry.getStartDate());
    long maxTime = (newEntry ? Long.MIN_VALUE : entry.getEndDate());
    PreparedStatement insertStmt = connection.prepareStatement(insertString);
    Object[] values = new Object[metadata.size()];
    int cnt = 0;
    int batchCnt = 0;
    GregorianCalendar calendar = new GregorianCalendar(RepositoryUtil.TIMEZONE_DEFAULT);
    boolean didone = false;

    Hashtable properties = getProperties(entry);
    int baseId = Misc.getProperty(properties, PROP_ID, 0);
    int totalCnt = Misc.getProperty(properties, PROP_CNT, 0);
    long t1 = System.currentTimeMillis();

    long tt1 = System.currentTimeMillis();
    //        for(int i=0;i<200;i++) {

    PointFeatureIterator pfi = CdmDataOutputHandler.getPointIterator(fdp);
    while (pfi.hasNext()) {
        PointFeature po = (PointFeature) pfi.next();
        ucar.unidata.geoloc.EarthLocation el = po.getLocation();
        if (el == null) {
            continue;
        }

        double lat = el.getLatitude();
        double lon = el.getLongitude();
        double alt = el.getAltitude();
        Date time = po.getNominalTimeAsDate();

        long tmpTime = time.getTime();
        if (tmpTime < minTime) {
            minTime = tmpTime;
        }
        if (tmpTime > maxTime) {
            maxTime = tmpTime;
        }

        if (didone) {
            north = Math.max(north, lat);
            south = Math.min(south, lat);
            west = Math.min(west, lon);
            east = Math.max(east, lon);
        } else {
            north = (newEntry ? lat : entry.hasNorth() ? entry.getNorth() : lat);
            south = (newEntry ? lat : entry.hasSouth() ? entry.getSouth() : lat);
            east = (newEntry ? lon : entry.hasEast() ? entry.getEast() : lon);
            west = (newEntry ? lon : entry.hasWest() ? entry.getWest() : lon);
        }
        didone = true;

        calendar.setTime(time);
        StructureData structure = po.getData();
        boolean hadAnyNumericValues = false;
        boolean hadGoodNumericValue = false;
        /*
        if(totalCnt<5) {
        StructureMembers.Member member =
            structure.findMember("altitude");
        if(member!=null) {
            double d = structure.convertScalarFloat(member);
        } else {
            System.err.println("no member");
                
        }
        }
        */

        for (PointDataMetadata pdm : metadata) {
            Object value;
            if (COL_ID.equals(pdm.getColumnName())) {
                value = new Integer(baseId);
                baseId++;
            } else if (COL_LATITUDE.equals(pdm.getColumnName())) {
                value = new Double(checkWriteValue(lat));
            } else if (COL_LONGITUDE.equals(pdm.getColumnName())) {
                value = new Double(checkWriteValue(lon));
            } else if (COL_ALTITUDE.equals(pdm.getColumnName())) {
                value = new Double(checkWriteValue(alt));
            } else if (COL_DATE.equals(pdm.getColumnName())) {
                value = time;
            } else if (COL_HOUR.equals(pdm.getColumnName())) {
                value = new Integer(calendar.get(GregorianCalendar.HOUR));
            } else if (COL_MONTH.equals(pdm.getColumnName())) {
                value = new Integer(calendar.get(GregorianCalendar.MONTH));
            } else {
                StructureMembers.Member member = structure.findMember((String) pdm.shortName);
                if (pdm.isString()) {
                    value = structure.getScalarString(member);
                    if (value == null) {
                        value = "";
                    }
                    value = value.toString().trim();
                } else {
                    double d = structure.convertScalarFloat(member);
                    hadAnyNumericValues = true;
                    if (d == d) {
                        hadGoodNumericValue = true;
                    }
                    value = new Double(checkWriteValue(d));
                }
            }
            values[pdm.getColumnNumber()] = value;
        }
        if (hadAnyNumericValues && !hadGoodNumericValue) {
            continue;
        }
        totalCnt++;
        getDatabaseManager().setValues(insertStmt, values);
        insertStmt.addBatch();
        batchCnt++;
        if (batchCnt > 100) {
            insertStmt.executeBatch();
            batchCnt = 0;
        }
        if (((++cnt) % 5000) == 0) {
            System.err.println("added " + cnt + " observations " + (System.currentTimeMillis() - tt1));
        }
    }

    //        }

    if (batchCnt > 0) {
        insertStmt.executeBatch();
    }
    insertStmt.close();

    long t2 = System.currentTimeMillis();
    System.err.println("inserted " + cnt + " observations in " + (t2 - t1) + "ms");

    properties.put(PROP_CNT, totalCnt + "");
    properties.put(PROP_ID, baseId + "");
    setProperties(entry, properties);

    if (didone) {
        entry.setWest(west);
        entry.setEast(east);
        entry.setNorth(north);
        entry.setSouth(south);
    }

    if (minTime != Long.MAX_VALUE) {
        entry.setStartDate(minTime);
        entry.setEndDate(maxTime);
    }

}

From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java

/**
 * @param series Plot series.//from   w w w  .  j  ava2  s.co m
 * @param mode Generation mode.
 * @return Graph info.
 */
private static JFreeChartPlotInfo info(PlotSeries series, JFreeChartGenerationMode mode) {
    double sum = 0;
    double min = Long.MAX_VALUE;
    double max = Long.MIN_VALUE;

    int len = series.data[1].length;

    if (len == 1) {
        double val = series.data[1][0];

        return new JFreeChartPlotInfo(series.seriesName, series.configuration(), val, val, val, 0, mode);
    }

    for (int i = 0; i < len; i++) {
        double val = series.data[1][i];

        min = Math.min(min, val);

        max = Math.max(max, val);

        sum += val;
    }

    double avg = sum / len;

    double s = 0;

    for (int i = 0; i < len; i++) {
        double val = series.data[1][i];

        s += Math.pow((val - avg), 2);
    }

    double stdDiv = Math.sqrt(s / (len - 1));

    return new JFreeChartPlotInfo(series.seriesName, series.configuration(), avg, min, max, stdDiv, mode);
}

From source file:at.alladin.rmbt.statisticServer.OpenTestSearchResource.java

/**
 * Gets the JSON-Response for the histograms
 * @param whereClause/*from   www. ja  va  2 s .  c  o  m*/
 * @param searchValues
 * @return Json as String
 */
private String getHistogram(String whereClause, Queue<Map.Entry<String, FieldType>> searchValues) {
    JSONObject ret = new JSONObject();
    try {
        if (searchValues.isEmpty()) {
            //try getting from cache
            String cacheString = (String) cache.get("opentest-histogram");
            if (cacheString != null) {
                System.out.println("cache hit for histogram");
                return cacheString;
            }
        }

        //Download
        // logarithmic if without filters
        boolean logarithmic = false;
        if (histogramInfo.max_download == Long.MIN_VALUE && histogramInfo.min_download == Long.MIN_VALUE) {

            histogramInfo.max_download = 1;
            histogramInfo.min_download = 0;
            logarithmic = true;
        }
        if (!logarithmic && histogramInfo.max_download == Long.MIN_VALUE) {
            histogramInfo.max_download = HISTOGRAMDOWNLOADDEFAULTMAX;
        }
        if (!logarithmic && histogramInfo.min_download == Long.MIN_VALUE) {
            histogramInfo.min_download = HISTOGRAMDOWNLOADDEFAULTMIN;
        }
        double min = this.histogramInfo.min_download;
        double max = this.histogramInfo.max_download;
        JSONArray downArray = getJSONForHistogram(min, max,
                (logarithmic) ? "speed_download_log" : "speed_download", logarithmic, whereClause,
                searchValues);

        ret.put("download_kbit", downArray);

        // Upload
        logarithmic = false;
        if (histogramInfo.max_upload == Long.MIN_VALUE && histogramInfo.min_upload == Long.MIN_VALUE) {
            histogramInfo.max_upload = 1;
            histogramInfo.min_upload = 0;
            logarithmic = true;
        }
        if (!logarithmic && histogramInfo.max_upload == Long.MIN_VALUE) {
            histogramInfo.max_upload = HISTOGRAMUPLOADDEFAULTMAX;
        }
        if (!logarithmic && histogramInfo.min_upload == Long.MIN_VALUE) {
            histogramInfo.min_upload = HISTOGRAMUPLOADDEFAULTMIN;
        }
        min = this.histogramInfo.min_upload;
        max = this.histogramInfo.max_upload;
        JSONArray upArray = getJSONForHistogram(min, max, (logarithmic) ? "speed_upload_log" : "speed_upload",
                logarithmic, whereClause, searchValues);

        ret.put("upload_kbit", upArray);

        //Ping
        if (histogramInfo.max_ping == Long.MIN_VALUE) {
            histogramInfo.max_ping = HISTOGRAMPINGDEFAULTMAX;
        }
        if (histogramInfo.min_ping == Long.MIN_VALUE) {
            histogramInfo.min_ping = HISTOGRAMPINGDEFAULTMIN;
        }
        min = this.histogramInfo.min_ping;
        max = this.histogramInfo.max_ping;
        JSONArray pingArray = getJSONForHistogram(min, max, "(t.ping_median::float / 1000000)", false,
                whereClause, searchValues);

        ret.put("ping_ms", pingArray);

        if (searchValues.isEmpty()) {
            //if it was the default -> save it to the cache for later
            cache.set("opentest-histogram", CACHE_EXP, ret.toString());
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ret.toString();
}

From source file:net.java.sip.communicator.impl.history.HistoryReaderImpl.java

/**
 * Used to limit the files if any starting or ending date exist
 * So only few files to be searched./*  w w  w .jav  a 2s.c o m*/
 *
 * @param filelist Iterator
 * @param startDate Date
 * @param endDate Date
 * @param reverseOrder reverse order of files
 * @return Vector
 */
static Vector<String> filterFilesByDate(Iterator<String> filelist, Date startDate, Date endDate,
        final boolean reverseOrder) {
    if (startDate == null && endDate == null) {
        // no filtering needed then just return the same list
        Vector<String> result = new Vector<String>();
        while (filelist.hasNext()) {
            result.add(filelist.next());
        }

        Collections.sort(result, new Comparator<String>() {

            public int compare(String o1, String o2) {
                if (reverseOrder)
                    return o2.compareTo(o1);
                else
                    return o1.compareTo(o2);
            }
        });

        return result;
    }
    // first convert all files to long
    TreeSet<Long> files = new TreeSet<Long>();
    while (filelist.hasNext()) {
        String filename = filelist.next();

        files.add(Long.parseLong(filename.substring(0, filename.length() - 4)));
    }

    TreeSet<Long> resultAsLong = new TreeSet<Long>();

    // Temporary fix of a NoSuchElementException
    if (files.size() == 0) {
        return new Vector<String>();
    }

    Long startLong;
    Long endLong;

    if (startDate == null)
        startLong = Long.MIN_VALUE;
    else
        startLong = startDate.getTime();

    if (endDate == null)
        endLong = Long.MAX_VALUE;
    else
        endLong = endDate.getTime();

    // get all records inclusive the one before the startdate
    for (Long f : files) {
        if (startLong <= f && f <= endLong) {
            resultAsLong.add(f);
        }
    }

    // get the subset before the start date, to get its last element
    // if exists
    if (!files.isEmpty() && files.first() <= startLong) {
        SortedSet<Long> setBeforeTheInterval = files.subSet(files.first(), true, startLong, true);
        if (!setBeforeTheInterval.isEmpty())
            resultAsLong.add(setBeforeTheInterval.last());
    }

    Vector<String> result = new Vector<String>();

    Iterator<Long> iter = resultAsLong.iterator();
    while (iter.hasNext()) {
        Long item = iter.next();
        result.add(item.toString() + ".xml");
    }

    Collections.sort(result, new Comparator<String>() {

        public int compare(String o1, String o2) {
            if (reverseOrder)
                return o2.compareTo(o1);
            else
                return o1.compareTo(o2);
        }
    });

    return result;
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testDataTypes() throws SQLException {
    conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    Statement stat = conn.createStatement();
    PreparedStatement prep;/*w  w  w.ja va2 s  . c o  m*/
    ResultSet rs;
    trace("Create tables");
    stat.execute("CREATE TABLE T_INT(ID INT PRIMARY KEY,VALUE INT)");
    stat.execute("CREATE TABLE T_VARCHAR(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
    stat.execute("CREATE TABLE T_DECIMAL_0(ID INT PRIMARY KEY,VALUE DECIMAL(30,0))");
    stat.execute("CREATE TABLE T_DECIMAL_10(ID INT PRIMARY KEY,VALUE DECIMAL(20,10))");
    stat.execute("CREATE TABLE T_DATETIME(ID INT PRIMARY KEY,VALUE DATETIME)");
    prep = conn.prepareStatement("INSERT INTO T_INT VALUES(?,?)", ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    prep.setInt(1, 1);
    prep.setInt(2, 0);
    prep.executeUpdate();
    prep.setInt(1, 2);
    prep.setInt(2, -1);
    prep.executeUpdate();
    prep.setInt(1, 3);
    prep.setInt(2, 3);
    prep.executeUpdate();
    prep.setInt(1, 4);
    prep.setNull(2, Types.INTEGER);
    prep.executeUpdate();
    prep.setInt(1, 5);
    prep.setBigDecimal(2, new BigDecimal("0"));
    prep.executeUpdate();
    prep.setInt(1, 6);
    prep.setString(2, "-1");
    prep.executeUpdate();
    prep.setInt(1, 7);
    prep.setObject(2, new Integer(3));
    prep.executeUpdate();
    prep.setObject(1, "8");
    // should throw an exception
    prep.setObject(2, null);
    // some databases don't allow calling setObject with null (no data type)
    prep.executeUpdate();
    prep.setInt(1, 9);
    prep.setObject(2, -4, Types.VARCHAR);
    prep.executeUpdate();
    prep.setInt(1, 10);
    prep.setObject(2, "5", Types.INTEGER);
    prep.executeUpdate();
    prep.setInt(1, 11);
    prep.setObject(2, null, Types.INTEGER);
    prep.executeUpdate();
    prep.setInt(1, 12);
    prep.setBoolean(2, true);
    prep.executeUpdate();
    prep.setInt(1, 13);
    prep.setBoolean(2, false);
    prep.executeUpdate();
    prep.setInt(1, 14);
    prep.setByte(2, (byte) -20);
    prep.executeUpdate();
    prep.setInt(1, 15);
    prep.setByte(2, (byte) 100);
    prep.executeUpdate();
    prep.setInt(1, 16);
    prep.setShort(2, (short) 30000);
    prep.executeUpdate();
    prep.setInt(1, 17);
    prep.setShort(2, (short) (-30000));
    prep.executeUpdate();
    prep.setInt(1, 18);
    prep.setLong(2, Integer.MAX_VALUE);
    prep.executeUpdate();
    prep.setInt(1, 19);
    prep.setLong(2, Integer.MIN_VALUE);
    prep.executeUpdate();

    assertTrue(stat.execute("SELECT * FROM T_INT ORDER BY ID"));
    rs = stat.getResultSet();
    assertResultSetOrdered(rs,
            new String[][] { { "1", "0" }, { "2", "-1" }, { "3", "3" }, { "4", null }, { "5", "0" },
                    { "6", "-1" }, { "7", "3" }, { "8", null }, { "9", "-4" }, { "10", "5" }, { "11", null },
                    { "12", "1" }, { "13", "0" }, { "14", "-20" }, { "15", "100" }, { "16", "30000" },
                    { "17", "-30000" }, { "18", "" + Integer.MAX_VALUE }, { "19", "" + Integer.MIN_VALUE }, });

    prep = conn.prepareStatement("INSERT INTO T_DECIMAL_0 VALUES(?,?)");
    prep.setInt(1, 1);
    prep.setLong(2, Long.MAX_VALUE);
    prep.executeUpdate();
    prep.setInt(1, 2);
    prep.setLong(2, Long.MIN_VALUE);
    prep.executeUpdate();
    prep.setInt(1, 3);
    prep.setFloat(2, 10);
    prep.executeUpdate();
    prep.setInt(1, 4);
    prep.setFloat(2, -20);
    prep.executeUpdate();
    prep.setInt(1, 5);
    prep.setFloat(2, 30);
    prep.executeUpdate();
    prep.setInt(1, 6);
    prep.setFloat(2, -40);
    prep.executeUpdate();

    rs = stat.executeQuery("SELECT VALUE FROM T_DECIMAL_0 ORDER BY ID");
    checkBigDecimal(rs, new String[] { "" + Long.MAX_VALUE, "" + Long.MIN_VALUE, "10", "-20", "30", "-40" });
}