11/*******************************************************************************
2- * Copyright (c) 2007, 2018 Wind River Systems, Inc. and others.
2+ * Copyright (c) 2007, 2026 Wind River Systems, Inc. and others.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License 2.0
55 * which accompanies this distribution, and is available at
@@ -37,7 +37,7 @@ public TerminalTextDataFastScroll(ITerminalTextData data, int maxHeight) {
3737 fData = data ;
3838 fData .setDimensions (maxHeight , fData .getWidth ());
3939 if (maxHeight > 2 ) {
40- assert shiftOffset (-2 ) || throwRuntimeException ( );
40+ moveOffset (-2 );
4141 }
4242 }
4343
@@ -49,15 +49,6 @@ public TerminalTextDataFastScroll() {
4949 this (new TerminalTextDataStore (), 1 );
5050 }
5151
52- /**
53- * This is used in asserts to throw an {@link RuntimeException}.
54- * This is useful for tests.
55- * @return never -- throws an exception
56- */
57- private boolean throwRuntimeException () {
58- throw new RuntimeException ();
59- }
60-
6152 /**
6253 *
6354 * @param line
@@ -72,21 +63,14 @@ int getPositionOfLine(int line) {
7263 * @param delta
7364 */
7465 void moveOffset (int delta ) {
75- assert Math .abs (delta ) < fMaxHeight || throwRuntimeException ();
66+ if (Math .abs (delta ) >= fMaxHeight ) {
67+ throw new IllegalArgumentException (
68+ "Parameter 'delta' absolute value (" + delta + ") must be less than maxHeight(" + fMaxHeight + ")" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
69+ }
7670 fOffset = (fMaxHeight + fOffset + delta ) % fMaxHeight ;
7771
7872 }
7973
80- /**
81- * Test method to shift the offset for testing (if assert ==true)
82- * @param shift TODO
83- * @return true
84- */
85- private boolean shiftOffset (int shift ) {
86- moveOffset (shift );
87- return true ;
88- }
89-
9074 @ Override
9175 public void addLine () {
9276 if (getHeight () < fMaxHeight ) {
@@ -117,21 +101,25 @@ public void copyLine(ITerminalTextData source, int sourceLine, int destLine) {
117101
118102 @ Override
119103 public void copyRange (ITerminalTextData source , int sourceStartLine , int destStartLine , int length ) {
120- assert (destStartLine >= 0 && destStartLine + length <= fHeight ) || throwRuntimeException ();
104+ if (destStartLine < 0 || destStartLine + length > fHeight ) {
105+ throw new IllegalArgumentException (
106+ "Value of 'destStartLine'+'length' parameters must be valid line (range [0-" //$NON-NLS-1$
107+ + getHeight () + "). Parameter values: 'destStartLine'=" + destStartLine + ", 'size'=" //$NON-NLS-1$//$NON-NLS-2$
108+ + length );
109+ }
121110 for (int i = 0 ; i < length ; i ++) {
122111 fData .copyLine (source , i + sourceStartLine , getPositionOfLine (i + destStartLine ));
123112 }
124113 }
125114
126115 @ Override
127116 public char getChar (int line , int column ) {
128- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
117+ validateLineParameter (line );
129118 return fData .getChar (getPositionOfLine (line ), column );
130119 }
131120
132121 @ Override
133122 public char [] getChars (int line ) {
134- assert (line >= 0 && line < fHeight ) || throwRuntimeException ();
135123 return fData .getChars (getPositionOfLine (line ));
136124 }
137125
@@ -142,7 +130,7 @@ public int getHeight() {
142130
143131 @ Override
144132 public LineSegment [] getLineSegments (int line , int startCol , int numberOfCols ) {
145- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
133+ validateLineParameter (line );
146134 return fData .getLineSegments (getPositionOfLine (line ), startCol , numberOfCols );
147135 }
148136
@@ -153,13 +141,13 @@ public int getMaxHeight() {
153141
154142 @ Override
155143 public TerminalStyle getStyle (int line , int column ) {
156- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
144+ validateLineParameter (line );
157145 return fData .getStyle (getPositionOfLine (line ), column );
158146 }
159147
160148 @ Override
161149 public TerminalStyle [] getStyles (int line ) {
162- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
150+ validateLineParameter (line );
163151 return fData .getStyles (getPositionOfLine (line ));
164152 }
165153
@@ -181,7 +169,10 @@ private void cleanLines(int line, int len) {
181169
182170 @ Override
183171 public void scroll (int startLine , int size , int shift ) {
184- assert (startLine >= 0 && startLine + size <= fHeight ) || throwRuntimeException ();
172+ if (startLine + size > getHeight ()) {
173+ throw new IllegalArgumentException ("Value of 'startLine'+'size' parameters must be valid line (range [0-" //$NON-NLS-1$
174+ + getHeight () + "). Parameter values: 'startLine'=" + startLine + ", 'size'=" + size ); //$NON-NLS-1$ //$NON-NLS-2$
175+ }
185176 if (shift >= fMaxHeight || -shift >= fMaxHeight ) {
186177 cleanLines (startLine , fMaxHeight - startLine );
187178 return ;
@@ -216,26 +207,30 @@ public void scroll(int startLine, int size, int shift) {
216207
217208 @ Override
218209 public void setChar (int line , int column , char c , TerminalStyle style ) {
219- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
210+ validateLineParameter (line );
220211 fData .setChar (getPositionOfLine (line ), column , c , style );
221212 }
222213
223214 @ Override
224215 public void setChars (int line , int column , char [] chars , int start , int len , TerminalStyle style ) {
225- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
216+ validateLineParameter (line );
226217 fData .setChars (getPositionOfLine (line ), column , chars , start , len , style );
227218 }
228219
229220 @ Override
230221 public void setChars (int line , int column , char [] chars , TerminalStyle style ) {
231- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
222+ validateLineParameter (line );
232223 fData .setChars (getPositionOfLine (line ), column , chars , style );
233224 }
234225
235226 @ Override
236227 public void setDimensions (int height , int width ) {
237- assert height >= 0 || throwRuntimeException ();
238- assert width >= 0 || throwRuntimeException ();
228+ if (height < 0 ) {
229+ throw new IllegalArgumentException ("Parameter 'height' can't be negative value:" + height ); //$NON-NLS-1$
230+ }
231+ if (width < 0 ) {
232+ throw new IllegalArgumentException ("Parameter 'width' can't be negative value:" + width ); //$NON-NLS-1$
233+ }
239234 if (height > fMaxHeight ) {
240235 setMaxHeight (height );
241236 }
@@ -247,7 +242,10 @@ public void setDimensions(int height, int width) {
247242
248243 @ Override
249244 public void setMaxHeight (int maxHeight ) {
250- assert maxHeight >= fHeight || throwRuntimeException ();
245+ if (maxHeight < fHeight ) {
246+ throw new IllegalArgumentException ("Parameter 'maxHeight' (value '" + maxHeight //$NON-NLS-1$
247+ + "') must't be less than 'fHeight' (value '" + fHeight + "')" ); //$NON-NLS-1$ //$NON-NLS-2$
248+ }
251249 // move everything to offset0
252250 int start = getPositionOfLine (0 );
253251 if (start != 0 ) {
@@ -264,7 +262,7 @@ public void setMaxHeight(int maxHeight) {
264262 }
265263 // copy the buffer back to our data
266264 fData .copy (buffer );
267- shiftOffset (-start );
265+ moveOffset (-start );
268266 } else {
269267 fData .setDimensions (maxHeight , fData .getWidth ());
270268 }
@@ -293,13 +291,20 @@ public void setCursorLine(int line) {
293291
294292 @ Override
295293 public boolean isWrappedLine (int line ) {
296- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
294+ validateLineParameter (line );
297295 return fData .isWrappedLine (getPositionOfLine (line ));
298296 }
299297
298+ private void validateLineParameter (int line ) {
299+ if (line < 0 || line >= fHeight ) {
300+ throw new IllegalArgumentException (
301+ "Parameter 'line' must be >= 0 and less than 'width' (current value '" + fHeight + "')" ); //$NON-NLS-1$ //$NON-NLS-2$
302+ }
303+ }
304+
300305 @ Override
301306 public void setWrappedLine (int line ) {
302- assert (line >= 0 && line < fHeight ) || throwRuntimeException ( );
307+ validateLineParameter (line );
303308 fData .setWrappedLine (getPositionOfLine (line ));
304309 }
305310
0 commit comments