Ejemplo n.º 1
0
 /**
  * Returns whether the given {@link IntArrayND} equals the given object
  *
  * @param array The array
  * @param object The object
  * @return Whether the array equals the object
  */
 static boolean equals(IntArrayND array, Object object) {
   if (array == object) {
     return true;
   }
   if (object == null) {
     return false;
   }
   if (!(object instanceof IntArrayND)) {
     return false;
   }
   IntArrayND other = (IntArrayND) object;
   if (!array.getSize().equals(other.getSize())) {
     return false;
   }
   Stream<MutableIntTuple> coordinates =
       Coordinates.coordinates(array.getPreferredIterationOrder(), array.getSize());
   Iterable<MutableIntTuple> iterable = () -> coordinates.iterator();
   for (IntTuple coordinate : iterable) {
     int arrayValue = array.get(coordinate);
     int otherValue = other.get(coordinate);
     if (arrayValue != otherValue) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 2
0
 /**
  * Creates a formatted representation of the given array. After each dimension, a newline
  * character will be inserted.
  *
  * @param array The array
  * @param format The format for the array entries
  * @return The hash code
  */
 public static String toFormattedString(IntArrayND array, String format) {
   if (array == null) {
     return "null";
   }
   StringBuilder sb = new StringBuilder();
   Iterable<MutableIntTuple> iterable = IntTupleIterables.lexicographicalIterable(array.getSize());
   IntTuple previous = null;
   for (IntTuple coordinates : iterable) {
     if (previous != null) {
       int c = Utils.countDifferences(previous, coordinates);
       for (int i = 0; i < c - 1; i++) {
         sb.append("\n");
       }
     }
     int value = array.get(coordinates);
     sb.append(String.format(format + ", ", value));
     previous = coordinates;
   }
   return sb.toString();
 }