Question: implement of brute force in java public class PatternMatching { /** * Brute force pattern matching algorithm to find all matches. * * You should

implement of brute force in java
 public class PatternMatching { /**  * Brute force pattern matching algorithm to find all matches.  *  * You should check each substring of the text from left to right,  * stopping early if you find a mismatch.  *  * @throws IllegalArgumentException if the pattern is null or of length 0  * @throws IllegalArgumentException if text or comparator is null  * @param pattern the pattern you are searching for in a body of text  * @param text the body of text where you search for pattern  * @param comparator you MUST use this for checking character equality  * @return list containing the starting index for each match found  */  public static List bruteForce(CharSequence pattern, CharSequence text, CharacterComparator comparator) { if (pattern == null || pattern.length() == 0) { throw new IllegalArgumentException(""); } if (text == null || comparator == null) { throw new IllegalArgumentException(""); } /// code }

}

public class CharacterComparator implements Comparator { private int count; /**  * To be used when comparing characters. Keeps count of  * how many times this method has been called.  * @param a first character to be compared  * @param b second character to be compared  * @return negative value if a is less than b, positive  * if a is greater than b, and 0 otherwise  */  @Override public int compare(Character a, Character b) { count++; return a - b; } /**  * Returns the number of times compare has been used  * @return the number of times compare has been used  */  public int getCount() { return count; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!