Package api

Class Util


  • public class Util
    extends java.lang.Object
    Utility class collecting some useful operations for instances of IComponent.
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addListener​(IComponent c, IPinListener listener)
      Adds the given listener to all outputs of the given component.
      static void connect​(IComponent src, int startSrc, IComponent dst, int startDst, int howMany)
      Connects outputs of the source component, starting with the given index 'startSrc', to inputs of the destination component starting with the given index 'startDst'.
      static void connect​(IComponent src, IComponent dst)
      Connects all outputs of the source component to all inputs of the destination component (or as many as possible without going out of bounds).
      static void setInputs​(IComponent c, int value)
      Sets the inputs of the given component using the binary representation of the given value.
      static void setInputs​(IComponent c, java.lang.String values)
      Sets the inputs of the given component from the given string of '0' and '1' characters, where the string is read right to left.
      static void setInputs​(IComponent c, java.lang.String values, int start)
      Sets the inputs of the given component from the given string of '0' and '1' characters, where the string is read right to left.
      static int[] stringToIntArray​(java.lang.String values)
      Converts the given string of 0's and 1's to an int array having the same length, reading right to left (the rightmost character of the string corresponds to index 0 of the array).
      static int toIntValue​(Pin[] pins)
      Returns the integer value of the array of pins, interpreted as a binary number whose least significant bit is at index 0 and whose most significant bit is at the end of the array.
      static int toIntValue​(Pin[] pins, int start, int end)
      Returns the integer value of the array of pins, interpreted as a binary number whose least significant bit is at index 'start' and whose most significant bit is at index 'end'.
      static java.lang.String toString​(Pin[] pins)
      Returns a string of 0's and 1's representing the given array of Pins, listed right to left.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • setInputs

        public static void setInputs​(IComponent c,
                                     java.lang.String values)
        Sets the inputs of the given component from the given string of '0' and '1' characters, where the string is read right to left. The rightmost character of the string corresponds to index 0 in the component's inputs. If the string contains a character other than '0' or '1' in some position, the corresponding bit in the component's inputs will not be set.
        Parameters:
        c - the component whose inputs are to be set
        values - string of 0's and 1's
      • setInputs

        public static void setInputs​(IComponent c,
                                     int value)
        Sets the inputs of the given component using the binary representation of the given value. If the value has more bits than there are inputs for the component, the excess bits are ignored.
        Parameters:
        c - the component whose inputs are to be set
        value - integer value whose binary representation will be used to set the inputs
      • setInputs

        public static void setInputs​(IComponent c,
                                     java.lang.String values,
                                     int start)
        Sets the inputs of the given component from the given string of '0' and '1' characters, where the string is read right to left. The rightmost character of the string corresponds to the given index 'start' of the component's inputs. If the string contains a character other than '0' or '1' in some position, the corresponding bit in the component's inputs will not be set. Excess input characters are ignored.
        Parameters:
        c - the component whose inputs are to be set
        values - string of 0's and 1's
        start - starting index in the component's inputs to be set
      • connect

        public static void connect​(IComponent src,
                                   IComponent dst)
        Connects all outputs of the source component to all inputs of the destination component (or as many as possible without going out of bounds).
        Parameters:
        src - source component
        dst - destination component
      • connect

        public static void connect​(IComponent src,
                                   int startSrc,
                                   IComponent dst,
                                   int startDst,
                                   int howMany)
        Connects outputs of the source component, starting with the given index 'startSrc', to inputs of the destination component starting with the given index 'startDst'. The number of connections is at most the given value 'howMany', but may be less to prevent out of bounds errors.
        Parameters:
        src - source component
        startSrc - starting index in source component's outputs
        dst - destination component
        startDst - starting index in destination component's inputs
        howMany - number of connections to make
      • toString

        public static java.lang.String toString​(Pin[] pins)
        Returns a string of 0's and 1's representing the given array of Pins, listed right to left. Index 0 in the array corresponds to the rightmost character of the string. Pins in the invalid state will be represented by the dash character '-'
        Parameters:
        pins - array of Pins
        Returns:
        string of 0's and 1's representing the Pin values, listed right to left
      • addListener

        public static void addListener​(IComponent c,
                                       IPinListener listener)
        Adds the given listener to all outputs of the given component.
        Parameters:
        c - component to which to add the listener
        listener - object implementing the IListener interface
      • stringToIntArray

        public static int[] stringToIntArray​(java.lang.String values)
        Converts the given string of 0's and 1's to an int array having the same length, reading right to left (the rightmost character of the string corresponds to index 0 of the array). Any character in the string other than '0' or '1' is converted to a -1 in the array.
        Parameters:
        values - string of 0's and 1's
        Returns:
        int array of corresponding numbers
      • toIntValue

        public static int toIntValue​(Pin[] pins)
        Returns the integer value of the array of pins, interpreted as a binary number whose least significant bit is at index 0 and whose most significant bit is at the end of the array. Returns -1 if any pin is not valid.
        Parameters:
        pins -
        Returns:
      • toIntValue

        public static int toIntValue​(Pin[] pins,
                                     int start,
                                     int end)
        Returns the integer value of the array of pins, interpreted as a binary number whose least significant bit is at index 'start' and whose most significant bit is at index 'end'. Returns -1 if any pin is not valid.
        Parameters:
        pins -
        start -
        Returns: