Java Code Examples for groovy.lang.GString#toString()

The following examples show how to use groovy.lang.GString#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UriBuilder.java    From http-builder-ng with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the parts of the `UriBuilder` to the `URI` object instance.
 *
 * @return the generated `URI` representing the parts contained in the builder
 */
public URI toURI() throws URISyntaxException {
    final String scheme = traverse(this, UriBuilder::getParent, UriBuilder::getScheme, Traverser::notNull);
    final Integer port = traverse(this, UriBuilder::getParent, UriBuilder::getPort, notValue(DEFAULT_PORT));
    final String host = traverse(this, UriBuilder::getParent, UriBuilder::getHost, Traverser::notNull);
    final GString path = traverse(this, UriBuilder::getParent, UriBuilder::getPath, Traverser::notNull);
    final String query = populateQueryString(traverse(this, UriBuilder::getParent, UriBuilder::getQuery, Traverser::nonEmptyMap));
    final String fragment = traverse(this, UriBuilder::getParent, UriBuilder::getFragment, Traverser::notNull);
    final String userInfo = traverse(this, UriBuilder::getParent, UriBuilder::getUserInfo, Traverser::notNull);
    final Boolean useRaw = traverse(this, UriBuilder::getParent, UriBuilder::getUseRawValues, Traverser::notNull);

    if (useRaw != null && useRaw) {
        return toRawURI(scheme, port, host, path, query, fragment, userInfo);
    } else {
        return new URI(scheme, userInfo, host, (port == null ? -1 : port), ((path == null) ? null : path.toString()), query, fragment);
    }
}
 
Example 2
Source File: StringGroovyMethods.java    From groovy with Apache License 2.0 3 votes vote down vote up
/**
 * Converts the GString to a File, or delegates to the default
 * {@link org.codehaus.groovy.runtime.DefaultGroovyMethods#asType(Object,Class)}.
 *
 * @param self a GString
 * @param c    the desired class
 * @return the converted object
 *
 * @since 1.5.0
 */
@SuppressWarnings("unchecked")
public static <T> T asType(final GString self, final Class<T> c) {
    if (c == File.class) {
        return (T) new File(self.toString());
    } else if (Number.class.isAssignableFrom(c) || c.isPrimitive()) {
        return asType(self.toString(), c);
    }
    return DefaultGroovyMethods.asType((Object) self, c);
}