package eecs2030.test2;
import java.util.ArrayList;
import java.util.List;
public class Test2G {
/**
* The size of the list required by the method Test2G.negate2
*/
public static final int NEGATE2_LIST_SIZE = 2;
private Test2G() {
// empty by design
}
/**
* Returns true if value
is strictly less than min
* or strictly greater than max
, and false otherwise.
*
* @param min
* a minimum value
* @param max
* a maximum value
* @param value
* a value to check
* @return true if value
is strictly less than min
* or strictly greater than max
, and false otherwise
* @pre. min is greater than or equal to max
*/
public static boolean isOutside(int min, int max, int value) {
return value < min || value > max;
}
/**
* Given a list containing exactly 2 integers, negates the values of the
* integers in the list. The list t
is not modified by this method.
* For example, given a list
*
*
* [-5, 9]
*
*
* negate2
modifies the list so that it becomes
*
*
*
* Consider the list containing twelve ones:
*
*
* A run length encoded version of the list would be:
*
* Similarly, consider the list containing four tens and three fives:
*
*
* A run length encoded version of the list would be:
*
* If the list contains few or no repeated values, then the run length
* encoded version of the list is longer than the original list. For example,
* the run length encoded version of the list:
*
*
* is:
*
* [5, -9]
*
* @pre. t is not null
*
* @param t
* a list containing exactly 2 integers
* @throws IllegalArgumentException
* if the list does not contain exactly 2 integers
*/
public static void negate2(Listt
. The list t
is not modified by this method.
*
*
* [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
*
*
*
* [12, 1] (twelve 1s)
*
*
*
* [10, 10, 10, 10, 5, 5, 5]
*
*
*
* [4, 10, 3, 5] (four 10s, three 5s)
*
*
*
* [1, 2, 3, 4]
*
*
*
* [1, 1, 1, 2, 1, 3, 1, 4] (one 1, one 2, one 3, one 4)
*
*
* @param t a list of integer values
* @return a new list equal to the run length encoded version of t
* @pre t is not null
* @pre t is not empty
*/
public static List