Package monq.jfa.util

Class ArrayUtil

java.lang.Object
monq.jfa.util.ArrayUtil

public final class ArrayUtil extends Object

is a collection of static methods to manipulate arrays. The idea is that the currently used area in the array is stored somewhere else. The functions in here, except resize(), pretend the whole array is in use.

This will hopefully be mostly obsoleted as soon as we have generics. The set of methods is not in any way complete, because I only add what I just needed.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    delete(byte[] ary, int pos, int count)
    deletes count elements from ary starting at index pos by copying the elements at indices greater than or equal to pos+count to index pos.
    static void
    delete(int[] ary, int pos, int count)
    deletes count elements from ary starting at index pos by copying the elements at indices greater than or equal to pos+count to index pos.
    static void
    delete(Object[] ary, int pos, int count)
     
    static void
    insert(byte[] ary, int pos, byte elem)
     
    static void
    insert(char[] ary, int pos, char elem)
     
    static void
    insert(int[] ary, int pos, int elem)
    inserts elem at index pos in ary by shifting all elements at indices greater pos to a one larger index position.
    static void
    insert(Object[] ary, int pos, Object o)
     
    static byte[]
    resize(byte[] old, int newSize)
     
    static char[]
    resize(char[] old, int newSize)
     
    static int[]
    resize(int[] old, int newSize)
    allocates a new array with the given newSize and copies the content of old into the new array up to the maximum of newSize or old.length.
    static Object[]
    resize(Object[] old, int newSize)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • resize

      public static int[] resize(int[] old, int newSize)

      allocates a new array with the given newSize and copies the content of old into the new array up to the maximum of newSize or old.length.

      Returns:
      the newly allocate array
    • insert

      public static void insert(int[] ary, int pos, int elem)
      inserts elem at index pos in ary by shifting all elements at indices greater pos to a one larger index position. The very last element of the array is lost.
    • delete

      public static void delete(int[] ary, int pos, int count)

      deletes count elements from ary starting at index pos by copying the elements at indices greater than or equal to pos+count to index pos. The elements which become "free" at the end of the array are not touched and the array is not resized. Call resize() afterwards to reallocate the array.

    • delete

      public static void delete(byte[] ary, int pos, int count)

      deletes count elements from ary starting at index pos by copying the elements at indices greater than or equal to pos+count to index pos.

      See Also:
    • resize

      public static char[] resize(char[] old, int newSize)
      See Also:
    • insert

      public static void insert(char[] ary, int pos, char elem)
      See Also:
    • resize

      public static byte[] resize(byte[] old, int newSize)
      See Also:
    • insert

      public static void insert(byte[] ary, int pos, byte elem)
      See Also:
    • resize

      public static Object[] resize(Object[] old, int newSize)
      See Also:
    • insert

      public static void insert(Object[] ary, int pos, Object o)
      See Also:
    • delete

      public static void delete(Object[] ary, int pos, int count)
      See Also: