@Override public int executeUpdate(String sql) throws SQLException { checkClosed(); if (execute(sql) && sqlResponse.rowCount() > 0) { resultSet = null; throw new SQLException("Execution of statement returned a ResultSet"); } else { // return 0 if no affected Rows are given return (int) Math.max(0L, sqlResponse.rowCount()); } }
protected List<DatabaseObject> mergeDatabaseObjects(List<DatabaseObject> objects) { int maxIdx = -1; for (DatabaseObject object : objects) { maxIdx = Math.max(maxIdx, object.getOrder()); } final List<DatabaseObject> orderedObjects = createListAndFillNull(maxIdx); final List<DatabaseObject> unorderedObjects = new ArrayList<>(); final List<DatabaseObject> mergedObjects = new ArrayList<>(); for (DatabaseObject object : objects) { if (object.getOrder() > -1) { int objIdx = object.getOrder(); if (objIdx < orderedObjects.size() && orderedObjects.get(objIdx) != null) { throw new TajoInternalError( "This catalog configuration contains duplicated order of DatabaseObject"); } orderedObjects.add(objIdx, object); } else { unorderedObjects.add(object); } } for (DatabaseObject object : orderedObjects) { if (object != null) { mergedObjects.add(object); } } for (DatabaseObject object : unorderedObjects) { if (object != null) { mergedObjects.add(object); } } return mergedObjects; }
/** Tests the computation of line length histogram descriptors. */ public void testHistogramDescriptors() { DRQA drqa = new DRQA(trajectory, eps); drqa.computeRQA(10, 10, 10); // should not change the result. drqa.computeRQA(2, 2, 2); Map<DRQA.HistogramStatistic, Double> expected_diagonal_rqa = new HashMap<DRQA.HistogramStatistic, Double>(), expected_vertical_rqa = new HashMap<DRQA.HistogramStatistic, Double>(), expected_white_vertical_rqa = new HashMap<DRQA.HistogramStatistic, Double>(), expected_orthogonal_rqa = new HashMap<DRQA.HistogramStatistic, Double>(), expected_diagonal_rqa_definite = new HashMap<DRQA.HistogramStatistic, Double>(), expected_vertical_rqa_definite = new HashMap<DRQA.HistogramStatistic, Double>(), expected_white_vertical_rqa_definite = new HashMap<DRQA.HistogramStatistic, Double>(), expected_orthogonal_rqa_definite = new HashMap<DRQA.HistogramStatistic, Double>(); expected_diagonal_rqa.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 0.6365141682948128); expected_diagonal_rqa.put(DRQA.HistogramStatistic.SORTEDNESS, 0.6666666666666666); expected_diagonal_rqa.put(DRQA.HistogramStatistic.MAX, 14.0); expected_diagonal_rqa.put(DRQA.HistogramStatistic.DEFINITENESS, 0.2727272727272727); expected_diagonal_rqa.put(DRQA.HistogramStatistic.ENTROPY, 1.0986122886681096); expected_diagonal_rqa.put(DRQA.HistogramStatistic.FILTER_RATIO, 0.6060606060606061); expected_diagonal_rqa.put(DRQA.HistogramStatistic.SPARSENESS, 0.8333333333333334); expected_diagonal_rqa.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.07142857142857142); expected_diagonal_rqa.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 3.0 / 7.0); expected_diagonal_rqa.put(DRQA.HistogramStatistic.AVERAGE, 6.666666666666666); expected_diagonal_rqa.put(DRQA.HistogramStatistic.MEDIAN, 4.); expected_vertical_rqa.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 0.0); expected_vertical_rqa.put(DRQA.HistogramStatistic.SORTEDNESS, 1.0); expected_vertical_rqa.put(DRQA.HistogramStatistic.MAX, 3.0); expected_vertical_rqa.put(DRQA.HistogramStatistic.DEFINITENESS, 0.7115384615384616); expected_vertical_rqa.put(DRQA.HistogramStatistic.ENTROPY, 0.5402041423888608); expected_vertical_rqa.put(DRQA.HistogramStatistic.FILTER_RATIO, 0.5576923076923077); expected_vertical_rqa.put(DRQA.HistogramStatistic.SPARSENESS, 0.0); expected_vertical_rqa.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.3333333333333333); expected_vertical_rqa.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 1.0); expected_vertical_rqa.put(DRQA.HistogramStatistic.AVERAGE, 2.230769230769231); expected_vertical_rqa.put(DRQA.HistogramStatistic.MEDIAN, 2.); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 1.3296613488547582); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.SORTEDNESS, 0.65); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.MAX, 7.0); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.DEFINITENESS, 0.6041666666666666); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.ENTROPY, 1.6470013963439956); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.FILTER_RATIO, 1.0); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.SPARSENESS, 0.16666666666666666); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.14285714285714285); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 2.0 / 4.0); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.AVERAGE, 3.5999999999999996); expected_white_vertical_rqa.put(DRQA.HistogramStatistic.MEDIAN, 3.); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 0.0); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.SORTEDNESS, 0.5); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.MAX, 5.0); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.DEFINITENESS, 0.42105263157894735); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.ENTROPY, 0.6931471805599453); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.FILTER_RATIO, 0.42105263157894735); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.SPARSENESS, 0.6666666666666666); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.2); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 1.0); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.AVERAGE, 4.0); expected_orthogonal_rqa.put(DRQA.HistogramStatistic.MEDIAN, 3.); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 0.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.SORTEDNESS, 1.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.MAX, 2.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.DEFINITENESS, 0.2727272727272727); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.ENTROPY, 0.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.FILTER_RATIO, 0.6060606060606061); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.SPARSENESS, 0.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.5); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 1.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.AVERAGE, 2.0); expected_diagonal_rqa_definite.put(DRQA.HistogramStatistic.MEDIAN, 2.); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 0.0); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.SORTEDNESS, 1.0); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.MAX, 3.0); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.DEFINITENESS, 0.7115384615384616); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.ENTROPY, 0.6615632381579821); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.FILTER_RATIO, 0.5576923076923077); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.SPARSENESS, 0.0); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.3333333333333333); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 1.0); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.AVERAGE, 2.375); expected_vertical_rqa_definite.put(DRQA.HistogramStatistic.MEDIAN, 2.); expected_white_vertical_rqa_definite.put( DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 1.3296613488547582); expected_white_vertical_rqa_definite.put( DRQA.HistogramStatistic.SORTEDNESS, 0.6363636363636364); expected_white_vertical_rqa_definite.put(DRQA.HistogramStatistic.MAX, 7.0); expected_white_vertical_rqa_definite.put( DRQA.HistogramStatistic.DEFINITENESS, 0.6041666666666666); expected_white_vertical_rqa_definite.put(DRQA.HistogramStatistic.ENTROPY, 1.5196682491027627); expected_white_vertical_rqa_definite.put(DRQA.HistogramStatistic.FILTER_RATIO, 1.0); expected_white_vertical_rqa_definite.put( DRQA.HistogramStatistic.SPARSENESS, 0.3333333333333333); expected_white_vertical_rqa_definite.put( DRQA.HistogramStatistic.INVERSE_MAX, 0.14285714285714285); expected_white_vertical_rqa_definite.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 0.5); expected_white_vertical_rqa_definite.put(DRQA.HistogramStatistic.AVERAGE, 3.954545454545454); expected_white_vertical_rqa_definite.put(DRQA.HistogramStatistic.MEDIAN, 3.); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.DIFFERENCE_ENTROPY, 0.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.SORTEDNESS, 0.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.MAX, 3.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.DEFINITENESS, 0.42105263157894735); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.ENTROPY, 0.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.FILTER_RATIO, 0.42105263157894735); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.SPARSENESS, 1.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.INVERSE_MAX, 0.3333333333333333); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.LOCAL_MAXIMA, 1.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.AVERAGE, 3.0); expected_orthogonal_rqa_definite.put(DRQA.HistogramStatistic.MEDIAN, 3.); assertEquals(expected_diagonal_rqa, drqa.diagonal_rqa); assertEquals(expected_vertical_rqa, drqa.vertical_rqa); assertEquals(expected_white_vertical_rqa, drqa.white_vertical_rqa); assertEquals(expected_orthogonal_rqa, drqa.orthogonal_rqa); assertEquals(expected_diagonal_rqa_definite, drqa.diagonal_rqa_definite); assertEquals(expected_vertical_rqa_definite, drqa.vertical_rqa_definite); assertEquals(expected_white_vertical_rqa_definite, drqa.white_vertical_rqa_definite); assertEquals(expected_orthogonal_rqa_definite, drqa.orthogonal_rqa_definite); assertEquals(Math.max(2, Math.round(37.0 / 26.)), drqa.estimate_l_min(), 1e-10); }