private static Format createFormatter(String className) { Class<? extends Format> formatterClass = Classes.forName(className); if (Types.isKindOf(formatterClass, Format.class)) { return Classes.newInstance(formatterClass); } return null; } }
/** * Create configuration object with name. * * @param name configuration object name. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. */ public Config(String name) { Params.notNullOrEmpty(name, "Root name"); this.name = name; }
/** * Join collection of objects, converted to string, using space as separator. Returns null if given objects array is * null and empty if empty. * * @param objects collection of objects to join. * @return joined string. */ public static String join(Iterable<?> objects) { return join(objects, " "); }
/** * Create an object instance of the requested type. If type is a {@link List} uses * {@link Classes#getListDefaultImplementation(Type)}. * * @param type object type. * @return newly created instance. */ public Object newInstance(Class<?> type) { if (Types.isKindOf(type, List.class)) { type = Classes.getListDefaultImplementation(type); } return Classes.newInstance(type); }
@Override public UploadedFile getUploadedFile(String partName) { Params.notNullOrEmpty(partName, "Form part name"); // key of the uploaded files map is normalized to Java member name return uploadedFiles.get(Strings.toMemberName(partName)); }
/** * Construct content instance. * * @param converterRegistry converter manager, * @param model model object. * @throws IllegalArgumentException if <code>model</code> parameter is null. */ public Content(Object model) throws IllegalArgumentException { Params.notNull(model, "Model"); this.model = model; }
/** * Remove extension from given file and create a new one with resulting path. * * @param file file to remove extension from. * @return newly created file without extension. * @throws IllegalArgumentException if <code>file</code> parameter is null. */ public static File removeExtension(File file) throws IllegalArgumentException { Params.notNull(file, "File"); return new File(removeExtension(file.getPath())); }
@Override public String toString() { return Strings.concat(cause, ": ", message); } }
@Override public boolean has(String name, Locale... locale) { Params.notNullOrEmpty(name, "Name"); Params.notNullOrEmpty(locale, "Locale"); return maps(locale[0]).containsKey(name); }
/** * Test if type is map. Returns true if type implements, directly or through inheritance, {@link Map} interface. * * @param t type to test. * @return true if type is map. */ public static boolean isMap(Type t) { return Types.isKindOf(t, Map.class); }
/** * Test if type is a character, primitive or boxing. * * @param t type to test. * @return true if type is character. */ public static boolean isCharacter(Type t) { return equalsAny(t, char.class, Character.class); }
/** * Create new collection of given type. * * @param type collection type. * @param <T> collection type. * @return newly create collection. */ public static <T extends Collection<?>> T newCollection(Type type) { return newRegisteredInstance(COLLECTIONS, type); }
/** Get single locale repository iterator. */ @Override public Iterator<I18nFile> iterator() { return new FileIterator(); }
/** * Factory method for I18N pool instances. Returned pool instance may be single or multiple locale, depending on this * repository configuration, see {@link #multiLocale}. This factory method just delegates {@link I18nPoolFactory}. * * @param <T> instance type. * @return I18N pool instance. */ public <T> I18nPool<T> getPoolInstance() { return I18nPoolFactory.getInstance(multiLocale); }
/** * Create instance key with given value. * * @param value instance key value. * @throws IllegalArgumentException if key value is null. */ public InstanceKey(String value) { Params.notNull(value, "Key value"); this.value = value; }
/** * Test if type is a calendar date. * * @param t type to test. * @return true if type is a calendar date. */ public static boolean isDate(Type t) { return isKindOf(t, Date.class); }
/** * Construct a new case-sensitive wildcard filter instance. * * @param pattern pattern used to match file names and strings. * @throws IllegalArgumentException if the pattern is null or empty. */ public WildcardFilter(String pattern) { Params.notNullOrEmpty(pattern, "Pattern"); this.pattern = pattern; }
@Override public String getValue() { return Strings.join(classNames); } }
/** * Construct redirect instance for given location, relative or absolute. See * {@link HttpServletResponse#sendRedirect(String)} for a discussion about location syntax and processing. * * @param location redirect location, absolute or relative. * @throws IllegalArgumentException if <code>location</code> argument is null. */ public Redirect(String location) { Params.notNull(location, "Redirect location."); this.location = location; }
/** * Test if type is a stream, either bytes or characters stream. * * @param type type to test. * @return true type is a stream. */ public static boolean isStream(Type type) { return Types.isKindOf(type, InputStream.class, Reader.class); } }