Interface BalanceChecker_Interface
- All Known Implementing Classes:
BalanceChecker
public interface BalanceChecker_Interface
Interface for the BalancChecker.
- Author:
- Dr. Lillis
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a pair of matching characters.booleanisBalanced(String s) Checks the given string and uses the pairs of symbols previously added with addPair to see if the string has balanced symbols.booleanChecks to see if the given character has already been added as a closing character.booleanChecks to see if the given character has already been added as an opening character.booleanReturns true if the two given characters are a pair of matching characters that have been previously added with the addPair method.
-
Method Details
-
addPair
Adds a pair of matching characters. For example '(' matches with ')' and '{' matches with '}'.- Parameters:
open- An opening characterclose- The corresponding closing character- Throws:
DuplicateCharacterException- if either character has already been added.
-
isBalanced
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
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
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
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 checkch2- The second character to check- Returns:
- true if the symbols are a matching pair that has been previously added with the addPair method.
-