+ /**
+ * Cut and move the specified section
+ * @param inSectionStart start index of section
+ * @param inSectionEnd end index of section
+ * @param inMoveTo index of move to point
+ * @return true if move successful
+ */
+ public boolean cutAndMoveSection(int inSectionStart, int inSectionEnd, int inMoveTo)
+ {
+ // TODO: Move cut/move into separate function?
+ // Check that indices make sense
+ if (inSectionStart > 0 && inSectionEnd > inSectionStart && inMoveTo >= 0
+ && (inMoveTo < inSectionStart || inMoveTo > (inSectionEnd+1)))
+ {
+ // do the cut and move
+ DataPoint[] newPointArray = new DataPoint[_numPoints];
+ // System.out.println("Cut/move section (" + inSectionStart + " - " + inSectionEnd + ") to before point " + inMoveTo);
+ // Is it a forward copy or a backward copy?
+ if (inSectionStart > inMoveTo)
+ {
+ int sectionLength = inSectionEnd - inSectionStart + 1;
+ // move section to earlier point
+ if (inMoveTo > 0) {
+ System.arraycopy(_dataPoints, 0, newPointArray, 0, inMoveTo); // unchanged points before
+ }
+ System.arraycopy(_dataPoints, inSectionStart, newPointArray, inMoveTo, sectionLength); // moved bit
+ // after insertion point, before moved bit
+ System.arraycopy(_dataPoints, inMoveTo, newPointArray, inMoveTo + sectionLength, inSectionStart - inMoveTo);
+ // after moved bit
+ if (inSectionEnd < (_numPoints - 1)) {
+ System.arraycopy(_dataPoints, inSectionEnd+1, newPointArray, inSectionEnd+1, _numPoints - inSectionEnd - 1);
+ }
+ }
+ else
+ {
+ // Move section to later point
+ if (inSectionStart > 0) {
+ System.arraycopy(_dataPoints, 0, newPointArray, 0, inSectionStart); // unchanged points before
+ }
+ // from end of section to move to point
+ if (inMoveTo > (inSectionEnd + 1)) {
+ System.arraycopy(_dataPoints, inSectionEnd+1, newPointArray, inSectionStart, inMoveTo - inSectionEnd - 1);
+ }
+ // moved bit
+ System.arraycopy(_dataPoints, inSectionStart, newPointArray, inSectionStart + inMoveTo - inSectionEnd - 1,
+ inSectionEnd - inSectionStart + 1);
+ // unchanged bit after
+ if (inSectionEnd < (_numPoints - 1)) {
+ System.arraycopy(_dataPoints, inMoveTo, newPointArray, inMoveTo, _numPoints - inMoveTo);
+ }
+ }
+ // Copy array references
+ _dataPoints = newPointArray;
+ _scaled = false;
+ return true;
+ }
+ return false;
+ }
+
+