/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression */ public String toRegex() { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append("\\d{1,2}"); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; buf.append(dtc.toRegex()); } p = p.getNext(); } return buf.toString(); } }
void verify(SimpleDateFormat sdf, Calendar calendar, DateTokenConverter<?> dtc) { String expected = sdf.format(calendar.getTime()); // if (slashified) { // expected = expected.replace('\\', '/'); // } String regex = dtc.toRegex(); //System.out.println("expected="+expected); //System.out.println(regex); assertTrue("[" + expected + "] does not match regex [" + regex + "]", expected.matches(regex)); }
public String toRegex(boolean capturePrimaryDate, boolean captureInteger) { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { if (captureInteger) { buf.append(FileFinder.regexEscapePath("(\\d+)")); } else { buf.append(FileFinder.regexEscapePath("\\d+")); } } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; if (capturePrimaryDate && dtc.isPrimary()) { buf.append(FileFinder.regexEscapePath("(" + dtc.toRegex() + ")")); } else { buf.append(FileFinder.regexEscapePath(dtc.toRegex())); } } p = p.getNext(); } return buf.toString(); } }
/** * Given date, convert this instance to a regular expression. * * Used to compute sub-regex when the pattern has both %d and %i, and the * date is known. * * @param date - date to be converted */ public String toRegexForFixedDate(Date date) { StringBuilder buf = new StringBuilder(); Converter<Object> p = headTokenConverter; while (p != null) { if (p instanceof LiteralConverter) { buf.append(p.convert(null)); } else if (p instanceof IntegerTokenConverter) { buf.append(FileFinder.regexEscapePath("(\\d+)")); } else if (p instanceof DateTokenConverter) { DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p; if (dtc.isPrimary()) { buf.append(p.convert(date)); } else { buf.append(FileFinder.regexEscapePath(dtc.toRegex())); } } p = p.getNext(); } return buf.toString(); }