Java Code Examples for org.codehaus.groovy.runtime.GStringImpl

The following examples show how to use org.codehaus.groovy.runtime.GStringImpl. These examples are extracted from open source projects. 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
@Override
public Object testSide(Object object) {
	if (object instanceof GString) {
		boolean anyPattern = Arrays.stream(((GString) object).getValues())
				.anyMatch(it -> it instanceof RegexProperty);
		if (!anyPattern) {
			return object;
		}
		List<Object> generatedValues = Arrays.stream(((GString) object).getValues())
				.map(it -> it instanceof RegexProperty
						? ((RegexProperty) it).generate() : it)
				.collect(Collectors.toList());
		Object[] arrayOfObjects = generatedValues.toArray();
		String[] strings = Arrays.copyOf(((GString) object).getStrings(),
				((GString) object).getStrings().length, String[].class);
		String newUrl = new GStringImpl(arrayOfObjects, strings).toString();
		return new Url(newUrl);
	}
	return object;
}
 
Example 2
Source Project: http-builder-ng   Source File: UriBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the path part of the URI.
 *
 * @param str the path part of the URI
 * @return a reference to the builder
 */
public UriBuilder setPath(final String str) {
    final String[] parts;
    if (str.startsWith("/")) {
        parts = new String[]{str};
    } else {
        final String base = getPath().toString();
        parts = new String[]{base, base.endsWith("/") ? "" : "/", str};
    }

    return setPath(new GStringImpl(EMPTY, parts));
}
 
Example 3
Source Project: http-builder-ng   Source File: UriBuilder.java    License: Apache License 2.0 5 votes vote down vote up
protected final void populateFrom(final URI uri) {
    boolean useRaw = useRawValues != null ? useRawValues : false;

    try {
        setScheme(uri.getScheme());
        setPort(uri.getPort());
        setHost(uri.getHost());

        final String path = useRaw ? uri.getRawPath() : uri.getPath();
        if (path != null) {
            setPath(new GStringImpl(EMPTY, new String[]{path}));
        }

        final String rawQuery = useRaw ? uri.getRawQuery() : uri.getQuery();
        if (rawQuery != null) {
            if (useRaw) {
                setQuery(extractQueryMap(rawQuery));
            } else {
                setQuery(Form.decode(new StringBuilder(rawQuery), UTF_8));
            }
        }

        setFragment(useRaw ? uri.getRawFragment() : uri.getFragment());
        setUserInfo(useRaw ? uri.getRawUserInfo() : uri.getUserInfo());
    } catch (IOException e) {
        //this seems o.k. to just convert to a runtime exception,
        //we started with a valid URI, so this should never happen.
        throw new RuntimeException(e);
    }
}
 
Example 4
Source Project: groovy   Source File: GString.java    License: Apache License 2.0 4 votes vote down vote up
public GString plus(GString that) {
    Object[] values = getValues();

    return new GStringImpl(appendValues(values, that.getValues()), appendStrings(getStrings(), that.getStrings(), values.length));
}
 
Example 5
Source Project: groovy   Source File: GString.java    License: Apache License 2.0 4 votes vote down vote up
public GString plus(String that) {
    return plus(new GStringImpl(EMPTY_OBJECT_ARRAY, new String[]{that}));
}
 
Example 6
Source Project: groovy-cps   Source File: Builder.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@code "Foo bar zot ${x}"} kind of string
 */
public Block gstring(int line, Block listOfValues, Block listOfStrings) {
    return new_(line, GStringImpl.class,
            cast(line,listOfValues, Object[].class,true),
            cast(line,listOfStrings,String[].class,true));
}