Interface BalanceChecker_Interface

All Known Implementing Classes:
BalanceChecker

public interface BalanceChecker_Interface
Interface for the BalancChecker.
Author:
Dr. Lillis
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPair(Character open, Character close)
    Adds a pair of matching characters.
    boolean
    Checks the given string and uses the pairs of symbols previously added with addPair to see if the string has balanced symbols.
    boolean
    Checks to see if the given character has already been added as a closing character.
    boolean
    Checks to see if the given character has already been added as an opening character.
    boolean
    Returns true if the two given characters are a pair of matching characters that have been previously added with the addPair method.
  • Method Details

    • addPair

      void addPair(Character open, Character close) throws DuplicateCharacterException
      Adds a pair of matching characters. For example '(' matches with ')' and '{' matches with '}'.
      Parameters:
      open - An opening character
      close - The corresponding closing character
      Throws:
      DuplicateCharacterException - if either character has already been added.
    • isBalanced

      boolean isBalanced(String s)
      Checks the given string and uses the pairs of symbols previously added with addPair to see if the string has balanced symbols. If the string has balanced symbols, this method returns true, otherwise it returns false. If no pairs have been added, the string is considered to be balanced.
      Parameters:
      s - The string to be checked for balanced symbols
      Returns:
      true if the string s has balanced symbols, returns false otherwise
    • isOpening

      boolean isOpening(Character ch)
      Checks to see if the given character has already been added as an opening character.
      Parameters:
      ch - The symbol to check
      Returns:
      true if the given character has already been added as an opening character, returns false otherwise.
    • isClosing

      boolean isClosing(Character ch)
      Checks to see if the given character has already been added as a closing character.
      Parameters:
      ch - The symbol to check
      Returns:
      true if the given character has already been added as a closing character, returns false otherwise.
    • match

      boolean match(Character ch1, Character ch2)
      Returns true if the two given characters are a pair of matching characters that have been previously added with the addPair method. The first symbol is assumed to be an opening character. The method returns true if the second character is the closing character that corresponds to the first.
      Parameters:
      ch1 - The first character to check
      ch2 - The second character to check
      Returns:
      true if the symbols are a matching pair that has been previously added with the addPair method.