@Override public boolean validate(int cIndex, String exp, IRule rule) { // TODO Auto-generated method stub int noOfoccurs = 0; char c = exp.charAt(cIndex); int sIndex = 0; // search index. while ((sIndex = exp.indexOf(c, sIndex)) >= 0) { noOfoccurs++; sIndex = sIndex + 1; // start search from next car } if (noOfoccurs > rule.getMaxOccurs() || noOfoccurs < rule.getMinOccurs()) return false; return true; }
@Override public boolean validate(int cIndex, String exp, IRule rule) { // TODO Auto-generated method stub int noOfrepetitions = 0; char c = exp.charAt(cIndex); int sIndex = 0; // search index. int prevIndex = -1; while ((sIndex = exp.indexOf(c, sIndex)) >= 0) { if (prevIndex != -1 && prevIndex == sIndex - 1) noOfrepetitions++; else if (prevIndex != sIndex - 1) noOfrepetitions = 0; if (noOfrepetitions > rule.getRepeatitions() - 1) return false; prevIndex = sIndex; sIndex = sIndex + 1; } return true; }