use of java.util.ArrayList in project Japid by branaway.
the class JapidDateFormat method parsePattern.
// Parse the pattern
//-----------------------------------------------------------------------
/**
* <p>Returns a list of Rules given a pattern.</p>
*
* @return a <code>List</code> of Rule objects
* @throws IllegalArgumentException if pattern is invalid
*/
protected List parsePattern() {
DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
List rules = new ArrayList();
String[] ERAs = symbols.getEras();
String[] months = symbols.getMonths();
String[] shortMonths = symbols.getShortMonths();
String[] weekdays = symbols.getWeekdays();
String[] shortWeekdays = symbols.getShortWeekdays();
String[] AmPmStrings = symbols.getAmPmStrings();
int length = mPattern.length();
int[] indexRef = new int[1];
for (int i = 0; i < length; i++) {
indexRef[0] = i;
String token = parseToken(mPattern, indexRef);
i = indexRef[0];
int tokenLen = token.length();
if (tokenLen == 0) {
break;
}
Rule rule;
char c = token.charAt(0);
switch(c) {
case // era designator (text)
'G':
rule = new TextField(Calendar.ERA, ERAs);
break;
case // year (number)
'y':
if (tokenLen >= 4) {
rule = selectNumberRule(Calendar.YEAR, tokenLen);
} else {
rule = TwoDigitYearField.INSTANCE;
}
break;
case // month in year (text and number)
'M':
if (tokenLen >= 4) {
rule = new TextField(Calendar.MONTH, months);
} else if (tokenLen == 3) {
rule = new TextField(Calendar.MONTH, shortMonths);
} else if (tokenLen == 2) {
rule = TwoDigitMonthField.INSTANCE;
} else {
rule = UnpaddedMonthField.INSTANCE;
}
break;
case // day in month (number)
'd':
rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
break;
case // hour in am/pm (number, 1..12)
'h':
rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
break;
case // hour in day (number, 0..23)
'H':
rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
break;
case // minute in hour (number)
'm':
rule = selectNumberRule(Calendar.MINUTE, tokenLen);
break;
case // second in minute (number)
's':
rule = selectNumberRule(Calendar.SECOND, tokenLen);
break;
case // millisecond (number)
'S':
rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
break;
case // day in week (text)
'E':
rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
break;
case // day in year (number)
'D':
rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
break;
case // day of week in month (number)
'F':
rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
break;
case // week in year (number)
'w':
rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
break;
case // week in month (number)
'W':
rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
break;
case // am/pm marker (text)
'a':
rule = new TextField(Calendar.AM_PM, AmPmStrings);
break;
case // hour in day (1..24)
'k':
rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
break;
case // hour in am/pm (0..11)
'K':
rule = selectNumberRule(Calendar.HOUR, tokenLen);
break;
case // time zone (text)
'z':
if (tokenLen >= 4) {
rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
} else {
rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
}
break;
case // time zone (value)
'Z':
if (tokenLen == 1) {
rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
} else {
rule = TimeZoneNumberRule.INSTANCE_COLON;
}
break;
case // literal text
'\'':
String sub = token.substring(1);
if (sub.length() == 1) {
rule = new CharacterLiteral(sub.charAt(0));
} else {
rule = new StringLiteral(sub);
}
break;
default:
throw new IllegalArgumentException("Illegal pattern component: " + token);
}
rules.add(rule);
}
return rules;
}
use of java.util.ArrayList in project Japid by branaway.
the class JapidMailer method addBcc.
@SuppressWarnings("unchecked")
public static void addBcc(Object... bccs) {
HashMap<String, Object> map = getInfoMap();
List bccsList = (List<String>) map.get(BCCS);
if (bccsList == null) {
bccsList = new ArrayList<String>();
map.put(BCCS, bccsList);
}
bccsList.addAll(Arrays.asList(bccs));
infos.set(map);
}
use of java.util.ArrayList in project Japid by branaway.
the class JapidMailer method addCc.
@SuppressWarnings("unchecked")
public static void addCc(Object... ccs) {
HashMap<String, Object> map = getInfoMap();
List ccsList = (List<String>) map.get(CCS);
if (ccsList == null) {
ccsList = new ArrayList<String>();
map.put(CCS, ccsList);
}
ccsList.addAll(Arrays.asList(ccs));
infos.set(map);
}
use of java.util.ArrayList in project Japid by branaway.
the class JapidPlugin method buildRoutes.
private void buildRoutes() {
List<Route> oldRoutes = Router.routes;
List<Route> newRoutes = new ArrayList<Route>(oldRoutes.size());
if (this.lastApplicationClassloaderState == Play.classloader.currentState && recentAddedRoutes != null && this.ctxPath == Play.ctxPath) {
JapidFlags.debug("classloader state not changed. Use cached auto-routes.");
newRoutes = new ArrayList<Route>(recentAddedRoutes);
} else {
// rebuild the dynamic route table
long start = System.nanoTime();
boolean ctxChanged = this.ctxPath != Play.ctxPath;
for (ApplicationClass ac : Play.classes.all()) {
// check cache
RouterClass r = routerCache.get(ac.name);
if (r != null && !ctxChanged && r.matchHash(ac.sigChecksum)) {
// no change
// JapidFlags.debug(ac.name + " has not changed. ");
} else {
Class<?> javaClass = ac.javaClass;
if (javaClass != null && javaClass.getName().startsWith("controllers.") && javaClass.getAnnotation(AutoPath.class) != null) {
JapidFlags.debug("generate route for: " + ac.name);
r = new RouterClass(javaClass, appPath, ac.sigChecksum);
} else
continue;
}
this.routerCache.put(ac.name, r);
newRoutes.addAll(r.buildRoutes());
}
//
JapidFlags.debug("rebuilding auto paths took(/ms): " + StringUtils.durationInMsFromNanos(start, System.nanoTime()));
this.recentAddedRoutes = new ArrayList<Route>(newRoutes);
this.lastApplicationClassloaderState = Play.classloader.currentState;
}
// copy fixed routes from the old route
for (Iterator<Route> iterator = oldRoutes.iterator(); iterator.hasNext(); ) {
Route r = iterator.next();
if (r.routesFileLine != RouterMethod.AUTO_ROUTE_LINE) {
newRoutes.add(r);
}
}
Router.routes = newRoutes;
}
use of java.util.ArrayList in project Japid by branaway.
the class RegMatch method findAllIn.
/**
* get all the group(0) matches in string.
*
* @author Bing Ran (bing.ran@gmail.com)
* @param p
* @param string
* @return
*/
static List<String> findAllIn(Pattern p, String string) {
List<String> ret = new ArrayList<String>();
Matcher matcher = p.matcher(string);
while (matcher.find()) {
ret.add(matcher.group());
}
return ret;
}
Aggregations