/** * Returns the given object surrounded by single quotes, only if the object is a {@code String}. * * @param o the given object. * @return the given object surrounded by single quotes, only if the object is a {@code String}. * @see #quote(String) */ public static Object quote(Object o) { return o instanceof String ? quote(o.toString()) : o; }
/** * Returns the given object surrounded by single quotes, only if the object is a {@code String}. * * @param o the given object. * @return the given object surrounded by single quotes, only if the object is a {@code String}. * @see #quote(String) */ public static Object quote(Object o) { return o instanceof String ? quote(o.toString()) : o; }
protected String toStringOf(Comparator<?> comparator) { if (!comparator.toString().contains("@")) return comparator.toString(); String comparatorSimpleClassName = comparator.getClass().getSimpleName(); if (comparatorSimpleClassName.length() == 0) return quote("anonymous comparator class"); // if toString has not been redefined, let's use comparator simple class name. if (comparator.toString().contains(comparatorSimpleClassName + "@")) return comparatorSimpleClassName; return comparator.toString(); }
private static String propertyNotFoundErrorMessage(String propertyName, Object target) { String targetTypeName = target.getClass().getName(); String property = quote(propertyName); Method getter = findGetter(propertyName, target); if (getter == null) { return format("No getter for property %s in %s", property, targetTypeName); } if (!isPublic(getter.getModifiers())) { return format("No public getter for property %s in %s", property, targetTypeName); } return format("Unable to find property %s in %s", property, targetTypeName); }
protected String toStringOf(Comparator<?> comparator) { if (!comparator.toString().contains("@")) return comparator.toString(); String comparatorSimpleClassName = comparator.getClass().getSimpleName(); if (comparatorSimpleClassName.length() == 0) return quote("anonymous comparator class"); // if toString has not been redefined, let's use comparator simple class name. if (comparator.toString().contains(comparatorSimpleClassName + "@")) return comparatorSimpleClassName; return comparator.toString(); }
@Override public String toString() { return format("%s[format=%s, arguments=%s]", getClass().getSimpleName(), quote(format), CONFIGURATION_PROVIDER.representation().toStringOf(arguments)); }
private static String propertyNotFoundErrorMessage(String propertyName, Object target) { String targetTypeName = target.getClass().getName(); String property = quote(propertyName); Method getter = findGetter(propertyName, target); if (getter == null) return format("No getter for property %s in %s", property, targetTypeName); if (!isPublic(getter.getModifiers())) return format("No public getter for property %s in %s", property, targetTypeName); return format("Unable to find property %s in %s", property, targetTypeName); }
private static UncheckedIOException cannotCreateNewFile(String path, String reason, Exception cause) { String message = String.format("Unable to create the new file %s", quote(path)); if (!Strings.isNullOrEmpty(reason)) { message = concat(message, ": ", reason); } if (cause == null) { throw new RuntimeException(message); } if (cause instanceof IOException) { throw new UncheckedIOException(message, (IOException) cause); } throw new RuntimeException(message, cause); }
/** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List<String> fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); checkArgument(dir.isDirectory(), "%s is not a directory", quote(dirName)); return fileNamesIn(dir, recurse); }
private static UncheckedIOException cannotCreateNewFile(String path, String reason, Exception cause) { String message = String.format("Unable to create the new file %s", quote(path)); if (!Strings.isNullOrEmpty(reason)) { message = concat(message, ": ", reason); } if (cause == null) { throw new RuntimeException(message); } if (cause instanceof IOException) { throw new UncheckedIOException(message, (IOException) cause); } throw new RuntimeException(message, cause); }
@Override public String toString() { return format("%s[format=%s, arguments=%s]", getClass().getSimpleName(), quote(format), CONFIGURATION_PROVIDER.representation().toStringOf(arguments)); }
/** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List<String> fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); checkArgument(dir.isDirectory(), "%s is not a directory", quote(dirName)); return fileNamesIn(dir, recurse); }
protected String toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy) { String comparatorDescription = comparatorBasedComparisonStrategy.getComparatorDescription(); return comparatorDescription == null ? toStringOf(comparatorBasedComparisonStrategy.getComparator()) : quote(comparatorDescription); }
protected String toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy) { String comparatorDescription = comparatorBasedComparisonStrategy.getComparatorDescription(); return comparatorDescription == null ? toStringOf(comparatorBasedComparisonStrategy.getComparator()) : quote(comparatorDescription); }
@Nonnull private LocationUnavailableException multipleMatchingNodes(@Nonnull String matchingText, @Nullable Object parentText) { String msg = String.format("There is more than one node with value '%s' under", matchingText, quote(parentText)); throw new LocationUnavailableException(msg); }
private static FilesException cannotCreateNewFile(String path, String reason, Exception cause) { String message = String.format("Unable to create the new file %s", quote(path)); if (!Strings.isNullOrEmpty(reason)) { message = concat(message, ": ", reason); } if (cause != null) { throw new FilesException(message, cause); } throw new FilesException(message); }