org.codehaus.groovy.runtime.GStringImpl Java Examples

The following examples show how to use org.codehaus.groovy.runtime.GStringImpl. 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: GroovyDslPropertyConverter.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@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 File: UriBuilder.java    From http-builder-ng with 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 File: UriBuilder.java    From http-builder-ng with 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 File: GString.java    From groovy with 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 File: GString.java    From groovy with 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 File: Builder.java    From groovy-cps with 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));
}