/** * New List and add values * * @param values list values * @param <T> list type * @return return array list */ @SafeVarargs public static <T> List<T> newLists(T... values) { if(null == values || values.length == 0){ Assert.notNull(values, "values not is null."); } return Arrays.asList(values); }
/** * Set to start the web server to monitor port, the default is 9000 * * @param port web server port, default is 9000 * @return blade */ public Blade listen(int port) { Assert.greaterThan(port, 0, "server port not is negative number."); this.environment.set(ENV_KEY_SERVER_PORT, port); return this; }
public ByteArray(byte[] bytes, int offset, int length) { Assert.notNull(bytes, "bytes"); Assert.isTrue(offset >= 0, "offset", offset); if (length == Integer.MIN_VALUE) { length = bytes.length - offset; } Assert.isTrue(length >= 0 && length <= bytes.length - offset, "length"); this.bytes = bytes; this.offset = offset; this.length = length; }
public void setBasePackage(String basePackage) { Assert.notBlank(basePackage); packages.add(basePackage + ".controller"); packages.add(basePackage + ".service"); packages.add(basePackage + ".config"); packages.add(basePackage + ".context"); packages.add(basePackage + ".plugins"); packages.add(basePackage + ".init"); packages.add(basePackage + ".interceptor"); }
/** * Add a route list * * @param routes route list * @return return blade */ public Blade routes(List<Route> routes) { Assert.notEmpty(routes, "Routes not is empty!"); routers.addRoutes(routes); return this; }
private static String badPositionIndexes(int start, int end, int size) { if (start < 0 || start > size) { return badPositionIndex(start, size, "start index"); } if (end < 0 || end > size) { return badPositionIndex(end, size, "end index"); } // end < start return format("end index (%s) must not be less than start index (%s)", end, start); }
public static void checkPositionIndexes(int start, int end, int size) { // Carefully optimized for execution by hotspot (explanatory comment // above) if (start < 0 || end < start || end > size) { throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size)); } }
/** * Setting blade web root path * * @param webRoot web root path * @return return blade */ public Blade webRoot(final String webRoot) { Assert.notBlank(webRoot); bConfig.setWebRoot(webRoot); return this; }
/** * load blade application config file * * @param location * @return */ public static Blade $(String location) { Assert.notEmpty(location); Blade blade = BladeHolder.$; blade.loadAppConf(location); return blade; }
/** * New List and add values * * @param values list values * @param <T> list type * @return return array list */ @SafeVarargs public static <T> List<T> newLists(T... values) { if(null == values || values.length == 0){ Assert.notNull(values, "values not is null."); } return Arrays.asList(values); }
/** * Set cookie. e.g: key1=val1; key2=val2; * * @param name * @param value * @return */ public HttpRequest cookie(final String name, final String value) { Assert.notEmpty(name, "Cookie name must not be empty"); Assert.notNull(value); this.cookies.put(name, value); this.executeCookie(getConnection()); return this; }
/** * Setting Properties configuration file File path based on classpath * * @param location properties file name * @return return blade */ public Blade loadAppConf(String location) { Assert.notBlank(location); bConfig.load(location); return this; }
/** * Get response cookie * * @param name cookie name * @return cookie value */ public String cookie(final String name) { Assert.notEmpty(name, "Cookie name must not be empty"); return this.cookies().get(name); }
/** * Set to start the web server to monitor port, the default is 9000 * * @param port web server port, default is 9000 * @return blade */ public Blade listen(int port) { Assert.greaterThan(port, 0, "server port not is negative number."); this.environment.set(ENV_KEY_SERVER_PORT, port); return this; }
/** * New Set and add values * * @param values set values * @param <T> set type * @return return HashSet */ @SafeVarargs public static <T> Set<T> newSets(T... values) { if(null == values || values.length == 0){ Assert.notNull(values, "values not is null."); } return new HashSet<>(Arrays.asList(values)); }
/** * set base package * * @param basePackage * @return */ public Blade basePackage(String basePackage) { Assert.notBlank(basePackage); bConfig.setBasePackage(basePackage); return this; }
/** * Set to start the web server to listen the IP address and port * The default will listen 0.0.0.0:9000 * * @param address ip address * @param port web server port * @return blade */ public Blade listen(@NonNull String address, int port) { Assert.greaterThan(port, 0, "server port not is negative number."); this.environment.set(ENV_KEY_SERVER_ADDRESS, address); this.environment.set(ENV_KEY_SERVER_PORT, port); return this; }
/** * New Set and add values * * @param values set values * @param <T> set type * @return return HashSet */ @SafeVarargs public static <T> Set<T> newSets(T... values) { if(null == values || values.length == 0){ Assert.notNull(values, "values not is null."); } return new HashSet<>(Arrays.asList(values)); }