@Override public void init(Object param) { E.illegalArgumentIfNot(param instanceof List, "2 parameters expected for beforeFirst function"); List<String> list = (List) param; E.illegalArgumentIfNot(list.size() == 2, "2 parameters expected for beforeFirst function"); String targetStr = list.get(0); String search = list.get(1); retVal = S.cut(targetStr).beforeFirst(search); }
@Override public boolean verify(Object value) { E.illegalArgumentIfNot(value instanceof Comparable); Class<?> commonSuperType = $.commonSuperTypeOf(initVal, value); E.illegalArgumentIfNot(Comparable.class.isAssignableFrom(commonSuperType), "Expected value (%s) cannot be compared to found value (%s)", initVal, value); Comparable expected = (Comparable) this.initVal; Comparable found = (Comparable) value; return type.applyTo(expected, found); } }
@Override public void init(Object param) { E.illegalArgumentIfNot(param instanceof List, "2 parameters expected for afterLast function"); List<String> list = (List) param; E.illegalArgumentIfNot(list.size() == 2, "2 parameters expected for afterLast function"); String targetStr = list.get(0); String search = list.get(1); retVal = S.cut(targetStr).afterLast(search); }
@Override public boolean verify(Object value) { E.illegalArgumentIfNot(value instanceof Comparable); Class<?> commonSuperType = $.commonSuperTypeOf(initVal, value); E.illegalArgumentIfNot(Comparable.class.isAssignableFrom(commonSuperType), "Expected value (%s) cannot be compared to found value (%s)", initVal, value); Comparable expected = (Comparable) this.initVal; Comparable found = (Comparable) value; return type.applyTo(expected, found); } }
@Override public void init(Object param) { E.illegalArgumentIfNot(param instanceof List, "2 parameters expected for afterLast function"); List<String> list = (List) param; E.illegalArgumentIfNot(list.size() == 2, "2 parameters expected for afterLast function"); String targetStr = list.get(0); String search = list.get(1); retVal = S.cut(targetStr).afterLast(search); }
public ArrayObjectIterator(Object o) { E.NPE(o); E.illegalArgumentIfNot(o.getClass().isArray()); this.o = o; this.len = Array.getLength(o); }
public BigLines(File file) { E.illegalArgumentIfNot(file.exists() && file.isFile() && file.canRead(), "file must exists and be a readable file: " + file); this.file = file; this.firstLine = fetch(0); }
@Override public boolean verify(Object value) { E.illegalArgumentIfNot(value instanceof Comparable); Class<?> commonSuperType = $.commonSuperTypeOf(initVal, value); E.illegalArgumentIfNot(Comparable.class.isAssignableFrom(commonSuperType), "Expected value (%s) cannot be compared to found value (%s)", initVal, value); Comparable expected = (Comparable) this.initVal; Comparable found = (Comparable) value; return type.applyTo(expected, found); } }
@Override public void init(Object param) { E.illegalArgumentIfNot(param instanceof List, "2 parameters expected for beforeFirst function"); List<String> list = (List) param; E.illegalArgumentIfNot(list.size() == 2, "2 parameters expected for beforeFirst function"); String targetStr = list.get(0); String search = list.get(1); retVal = S.cut(targetStr).beforeFirst(search); }
public BigLines(File file) { E.illegalArgumentIfNot(file.exists() && file.isFile() && file.canRead(), "file must exists and be a readable file: " + file); this.file = file; this.firstLine = fetch(0); }
public ArrayObjectIterator(Object o) { E.NPE(o); E.illegalArgumentIfNot(o.getClass().isArray()); this.o = o; this.len = Array.getLength(o); }
/** * Returns a file reader * * @param file * the file to be read * @return a reader that reads the file specified */ public static Reader reader(File file) { E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath()); try { return new FileReader(file); } catch (IOException e) { throw E.ioException(e); } }
/** * Returns a file reader * * @param file * the file to be read * @return a reader that reads the file specified */ public static Reader reader(File file) { E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath()); try { return new FileReader(file); } catch (IOException e) { throw E.ioException(e); } }
@Override public void init(Object param) { E.illegalArgumentIfNot(param instanceof List, "At least 2 parameters expected for subStr function"); List<String> params = (List<String>) param; targetStr = S.ensure(params.get(0)).strippedOff(S.DOUBLE_QUOTES); String sBegin = params.get(1); E.illegalArgumentIfNot(S.isInt(sBegin), "the 2nd parameter must be valid integer"); int begin = Integer.parseInt(sBegin); E.illegalArgumentIf(begin < 0, "the 2nd parameter must be valid integer"); int end = -1; if (params.size() > 2) { String sEnd = params.get(2); E.illegalArgumentIfNot(S.isInt(sEnd), "the 3nd parameter must be valid integer"); end = Integer.parseInt(sEnd); E.illegalArgumentIf(end < begin, "the 3nd parameter not be less than the 2nd parameter"); if (end > targetStr.length()) { end = targetStr.length(); } } targetStr = -1 == end ? targetStr.substring(begin) : targetStr.substring(begin, end); }
@Override public void init(Object param) { E.illegalArgumentIfNot(param instanceof List, "At least 2 parameters expected for subStr function"); List<String> params = (List<String>) param; targetStr = S.ensure(params.get(0)).strippedOff(S.DOUBLE_QUOTES); String sBegin = params.get(1); E.illegalArgumentIfNot(S.isInt(sBegin), "the 2nd parameter must be valid integer"); int begin = Integer.parseInt(sBegin); E.illegalArgumentIf(begin < 0, "the 2nd parameter must be valid integer"); int end = -1; if (params.size() > 2) { String sEnd = params.get(2); E.illegalArgumentIfNot(S.isInt(sEnd), "the 3nd parameter must be valid integer"); end = Integer.parseInt(sEnd); E.illegalArgumentIf(end < begin, "the 3nd parameter not be less than the 2nd parameter"); if (end > targetStr.length()) { end = targetStr.length(); } } targetStr = -1 == end ? targetStr.substring(begin) : targetStr.substring(begin, end); }
public static JarEntry jarEntry(URL url, $.Var<JarFile> jarFileBag) { E.illegalArgumentIfNot("jar".equals(url.getProtocol()), "jar URL expected"); String path = url.getPath(); E.unexpectedIfNot(path.startsWith("file:"), "Expected `file:` prefix in the path, found: " + path); E.unexpectedIfNot(path.contains("!"), "`!` not found in the path: " + path); S.Pair pair = S.binarySplit(path, '!'); String jarFilePath = pair.left().substring(5); String entryPath = pair.right(); try { JarFile jarFile = new JarFile(jarFilePath); jarFileBag.set(jarFile); if (entryPath.startsWith("/")) { entryPath = entryPath.substring(1); } return jarFile.getJarEntry(entryPath); } catch (IOException e) { throw E.ioException(e); } }
public static JarEntry jarEntry(URL url, $.Var<JarFile> jarFileBag) { E.illegalArgumentIfNot("jar".equals(url.getProtocol()), "jar URL expected"); String path = url.getPath(); E.unexpectedIfNot(path.startsWith("file:"), "Expected `file:` prefix in the path, found: " + path); E.unexpectedIfNot(path.contains("!"), "`!` not found in the path: " + path); S.Pair pair = S.binarySplit(path, '!'); String jarFilePath = pair.left().substring(5); String entryPath = pair.right(); try { JarFile jarFile = new JarFile(jarFilePath); jarFileBag.set(jarFile); if (entryPath.startsWith("/")) { entryPath = entryPath.substring(1); } return jarFile.getJarEntry(entryPath); } catch (IOException e) { throw E.ioException(e); } }
@Override public <DAO extends Dao> DAO newDaoInstance(Class<DAO> aClass) { E.illegalArgumentIfNot(isValidDaoClass(aClass), "The class is not a JPA Dao: %s", aClass); JPADao dao = $.cast(app().getInstance(aClass)); dao.setJPAService(this); return $.cast(dao); }
/** * Implement Java Servlet's `RequestDispatcher.forward(String)` semantic. * * This method has the following restrictions: * * 1. the URL must be started with single `/`. i.e. it must be absolute PATH of current service. * 2. the request method must be `GET`. * * @param url * the url template * @param args * the url argument */ public void forward(String url, Object... args) { E.illegalArgumentIfNot(url.startsWith("/"), "forward URL must starts with single '/'"); E.illegalArgumentIf(url.startsWith("//"), "forward URL must starts with single `/`"); E.unexpectedIfNot(H.Method.GET == req().method(), "forward only support on HTTP GET request"); uploads.clear(); extraParams.clear(); bodyParams = null; String target = S.fmt(url, args); urlPath = UrlPath.of(target); UndertowRequest req = $.cast(req()); state = State.CREATED; req.forward(target); final RequestHandler requestHandler = router.getInvoker(H.Method.GET, url, this); requestHandler.handle(this); }
/** * Implement Java Servlet's `RequestDispatcher.forward(String)` semantic. * * This method has the following restrictions: * * 1. the URL must be started with single `/`. i.e. it must be absolute PATH of current service. * 2. the request method must be `GET`. * * @param url * the url template * @param args * the url argument */ public void forward(String url, Object... args) { E.illegalArgumentIfNot(url.startsWith("/"), "forward URL must starts with single '/'"); E.illegalArgumentIf(url.startsWith("//"), "forward URL must starts with single `/`"); E.unexpectedIfNot(H.Method.GET == req().method(), "forward only support on HTTP GET request"); uploads.clear(); extraParams.clear(); bodyParams = null; String target = S.fmt(url, args); urlPath = UrlPath.of(target); UndertowRequest req = $.cast(req()); state = State.CREATED; req.forward(target); final RequestHandler requestHandler = router.getInvoker(H.Method.GET, url, this); requestHandler.handle(this); }