/** * Gets the remote address of request. * * @return remote address */ public String remoteAddr() { return Requests.getRemoteAddr(request); }
public static boolean containMethod(final Set<Method> methods, final Method method) { for (final Method m : methods) { if (matchSignature(m, method) && matchModifier(m, method)) { return true; } } return false; }
public static Field getMatch(final Set<Field> fields, final Field field) { for (final Field f : fields) { if (match(f, field)) { return f; } } return null; }
public static Set<Field> getOwnFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields); final Set<Field> ret = new HashSet<>(); final Set<Field> inheritedFields = getInheritedFields(clazz); final Set<Field> overriddenFields = getHiddenFields(clazz); for (final Field declaredField : declaredFieldSet) { if (!containField(inheritedFields, declaredField) && !containField(overriddenFields, declaredField)) { ret.add(declaredField); } } return ret; }
public static Set<Method> getOwnMethods(final Class<?> clazz) { final Method[] methods = clazz.getDeclaredMethods(); final Set<Method> declaredMethodSet = CollectionUtils.arrayToSet(methods); final Set<Method> ret = new HashSet<>(); final Set<Method> inheritedMethods = getInheritedMethods(clazz); final Set<Method> overriddenMethods = getOverriddenMethods(clazz); for (final Method declaredMethod : declaredMethodSet) { if (!containMethod(inheritedMethods, declaredMethod) && !containMethod(overriddenMethods, declaredMethod)) { ret.add(declaredMethod); } } return ret; }
public static Method getMatch(final Set<Method> methods, final Method maybeSuperclassMethod, final boolean matchInheritance) { for (final Method m : methods) { if (!matchInheritance) { if (matchModifier(m, maybeSuperclassMethod) && matchSignature(m, maybeSuperclassMethod)) { return m; } } else { if (matchInheritance(m, maybeSuperclassMethod)) { return m; } } } return null; }
public static void main(String[] args) { List<TimeZoneWithDisplayNames> returnedZones = TimeZones.getInstance().getTimeZones(); for (TimeZoneWithDisplayNames zone : returnedZones) { System.out.println(zone.getDisplayName()); } }
/** * Gets stopwatch from the specified parent stopwatch with the specified task title. * * @param parent the specified parent * @param taskTitle the specified task title * @return stopwatch, returns {@code null} if not found */ private static Stopwatch get(final Stopwatch parent, final String taskTitle) { if (taskTitle.equals(parent.getTaskTitle())) { return parent; } for (final Stopwatch leaf : parent.getLeaves()) { final Stopwatch ret = get(leaf, taskTitle); if (null != ret) { return ret; } } return null; }
/** * Starts a task timing with the specified task title. * * @param taskTitle the specified task title */ public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
/** * Builds the annotated fields of this annotated type. */ private void initAnnotatedFields() { final Set<Field> hiddenFields = Reflections.getHiddenFields(beanClass); inject(hiddenFields); final Set<Field> inheritedFields = Reflections.getInheritedFields(beanClass); inject(inheritedFields); final Set<Field> ownFields = Reflections.getOwnFields(beanClass); inject(ownFields); }
/** * Gest a {@link java.util.Locale} with the specified locale string. * * @param localeString the specified locale string * @return locale */ public static Locale getLocale(final String localeString) { final String language = getLanguage(localeString); final String country = getCountry(localeString); // // XXX: variant return new Locale(language, country); } }
/** * Ends the timing of the recent task started by {@link #start(java.lang.String)}. */ public static void end() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return; // Donoting.... } final Stopwatch recent = getRecentRunning(root); if (null == recent) { return; } recent.setEndTime(System.currentTimeMillis()); // Ends timing }
/** * Match the given <code>path</code> against the corresponding part of the given * <code>pattern</code>, according to this PathMatcher's matching strategy. * <p>Determines whether the pattern at least matches as far as the given base * path goes, assuming that a full path may then match as well. * * @param pattern the pattern to match against * @param path the path String to test * @return <code>true</code> if the supplied <code>path</code> matched, * <code>false</code> if it didn't */ public static boolean matchStart(String pattern, String path) { return doMatch(pattern, path, false); }
@Override public String gen() { return Ids.genTimeMillisId(); }
public static boolean isConcrete(final Type type) { return isConcrete((Class<?>) type); }
/** * Gets the elapsed time percent of root. * * @return percent of root */ public float getPercentOfRoot() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return 0; } final float rootElapsedTime = (float) root.getElapsedTime(); if (0 == rootElapsedTime) { // Denominator is equals to zero return 0; } return getElapsedTime() / rootElapsedTime * HUNDRED; }
/** * get rootPath from locationPattern. * <p> * if "/context/** / *.xml" should get the result "/context/" * </p> * * @param locationPattern locationPattern * @return the RootPath string. */ private static String getRootPath(final String locationPattern) { int rootDirEnd = locationPattern.length(); while (AntPathMatcher.isPattern(locationPattern.substring(0, rootDirEnd))) { rootDirEnd = locationPattern.lastIndexOf('/', rootDirEnd - 2) + 1; } return locationPattern.substring(0, rootDirEnd); }
/** * Gets a value from {@link org.b3log.latke.Latkes#getLocale() the current locale} specified language properties * file with the specified key. * * @param key the specified key * @return value */ public String get(final String key) { return get(Keys.LANGUAGE, key, Locales.getLocale()); }
/** * Determines whether exists a variable specified by the given expression * in the specified template. * * @param template the specified template * @param expression the given expression, for example, * "${aVariable}", "<#list recentComments as comment>" * @return {@code true} if it exists, returns {@code false} otherwise */ public static boolean hasExpression(final Template template, final String expression) { final TemplateElement rootTreeNode = template.getRootTreeNode(); return hasExpression(template, expression, rootTreeNode); }
/** * Does the given <code>path</code> represent a pattern that can be matched * by an implementation of this interface? * <p>If the return value is <code>false</code>, then the {@link #match} * method does not have to be used because direct equality comparisons * on the static path Strings will lead to the same result. * * @param path the path String to check * @return <code>true</code> if the given <code>path</code> represents a pattern */ public static boolean match(String pattern, String path) { return doMatch(pattern, path, true); }