当前位置: 首页>>代码示例>>Java>>正文


Java GString类代码示例

本文整理汇总了Java中groovy.lang.GString的典型用法代码示例。如果您正苦于以下问题:Java GString类的具体用法?Java GString怎么用?Java GString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GString类属于groovy.lang包,在下文中一共展示了GString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

import groovy.lang.GString; //导入依赖的package包/类
public void add(final Closure transformer) {
    transformers.add(new Transformer<T, T>() {
        public T transform(T original) {
            transformer.setDelegate(original);
            transformer.setResolveStrategy(Closure.DELEGATE_FIRST);
            Object value = transformer.call(original);
            if (type.isInstance(value)) {
                return type.cast(value);
            }
            if (type == String.class && value instanceof GString) {
                return type.cast(value.toString());
            }
            return original;
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:17,代码来源:ChainingTransformer.java

示例2: wrap

import groovy.lang.GString; //导入依赖的package包/类
private Map<String, Object> wrap(final Map<String, Object> model) {
	return new HashMap<String, Object>(model) {
        @Override
        public Object get(final Object property) {
            if (property instanceof String || property instanceof GString) {
                String key = property.toString();
                if ("include".equals(key)) {
                    return new MethodClosure(GroovyTemplateEngine.this, "doInclude").curry(this);
                }
            	try {
            		return extractors.extractAndTransform(db, key, model, new TemplateEngineAdapter.NoopAdapter());
            	} catch(NoModelExtractorException e) {
            		// fallback to parent model
            	}
            }

            return super.get(property);
        }
    };
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:21,代码来源:GroovyTemplateEngine.java

示例3: wrap

import groovy.lang.GString; //导入依赖的package包/类
private Map<String, Object> wrap(final Map<String, Object> model) {
    return new HashMap<String, Object>(model) {
        @Override
        public Object get(final Object property) {
        	if (property instanceof String || property instanceof GString) {
        		String key = property.toString();
	try {
		put(key, extractors.extractAndTransform(db, key, model, new TemplateEngineAdapter.NoopAdapter()));
	} catch (NoModelExtractorException e) {
		// should never happen, as we iterate over existing extractors
	}
        	}

            return super.get(property);
        }
    };
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:18,代码来源:GroovyMarkupTemplateEngine.java

示例4: asGroovyValue

import groovy.lang.GString; //导入依赖的package包/类
public static <T> GroovyValue<T> asGroovyValue(Class<T> expectedType, Object value) {
	if (value instanceof Closure) {
		return new ClosureBasedGroovyValue<>((Closure) value, expectedType);
	}
	
	if (value == null || expectedType.isInstance(value)) {
		return new SimpleGroovyValue<>((T) value);
	}
	
	if (value instanceof GString && expectedType.equals(String.class)) {
		return (GroovyValue<T>) new GStringGroovyValue((GString) value);
	}
	
	throw new IllegalArgumentException("I don't know what to do with " + value.getClass().getCanonicalName()
		+ ". Expecting " + expectedType.getCanonicalName() + " or Closure");
}
 
开发者ID:Unity-Group,项目名称:gradle-lazy-credentials,代码行数:17,代码来源:GroovyValues.java

示例5: toURI

import groovy.lang.GString; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:22,代码来源:UriBuilder.java

示例6: addImport

import groovy.lang.GString; //导入依赖的package包/类
private void addImport(final ImportCustomizer customizer, final Object value) {
    if (value==null) return;
    if (value instanceof Collection) {
        for (Object e : (Collection)value) {
            addImport(customizer, e);
        }
    } else if (value instanceof String) {
        customizer.addImports((String)value);
    } else if (value instanceof Class) {
        customizer.addImports(((Class) value).getName());
    } else if (value instanceof GString) {
        customizer.addImports(value.toString());
    } else {
        throw new RuntimeException("Unsupported import value type ["+value+"]");
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ImportCustomizerFactory.java

示例7: coerceArgument

import groovy.lang.GString; //导入依赖的package包/类
public Object coerceArgument(Object argument) {
    Class argumentClass = argument.getClass();
    if (argumentClass.getName().charAt(0) != '[') return argument;
    Class argumentComponent = argumentClass.getComponentType();

    Class paramComponent = getTheClass().getComponentType();
    if (paramComponent.isPrimitive()) {
        argument = DefaultTypeTransformation.convertToPrimitiveArray(argument, paramComponent);
    } else if (paramComponent == String.class && argument instanceof GString[]) {
        GString[] strings = (GString[]) argument;
        String[] ret = new String[strings.length];
        for (int i = 0; i < strings.length; i++) {
            ret[i] = strings[i].toString();
        }
        argument = ret;
    } else if (paramComponent==Object.class && argumentComponent.isPrimitive()){
        argument = DefaultTypeTransformation.primitiveArrayBox(argument);
    }
    return argument;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ArrayCachedClass.java

示例8: wrap

import groovy.lang.GString; //导入依赖的package包/类
public static Class[] wrap(Class[] classes) {
    Class[] wrappedArguments = new Class[classes.length];
    for (int i = 0; i < wrappedArguments.length; i++) {
        Class c = classes[i];
        if (c == null) continue;
        if (c.isPrimitive()) {
            if (c == Integer.TYPE) {
                c = Integer.class;
            } else if (c == Byte.TYPE) {
                c = Byte.class;
            } else if (c == Long.TYPE) {
                c = Long.class;
            } else if (c == Double.TYPE) {
                c = Double.class;
            } else if (c == Float.TYPE) {
                c = Float.class;
            }
        } else if (isSuperclass(c, GString.class)) {
            c = String.class;
        }
        wrappedArguments[i] = c;
    }
    return wrappedArguments;
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:MetaClassHelper.java

示例9: adjustNewValue

import groovy.lang.GString; //导入依赖的package包/类
private static Object adjustNewValue(Object[] objects, Object newValue) {
    Class arrayComponentClass = objects.getClass().getComponentType();
    Object adjustedNewVal = newValue;
    if (newValue instanceof Number) {
        if (!arrayComponentClass.equals(newValue.getClass())) {
            adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass);
        }
    } else if (Character.class.isAssignableFrom(arrayComponentClass)) {
        adjustedNewVal = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
    } else if (Number.class.isAssignableFrom(arrayComponentClass)) {
        if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
            Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
            adjustedNewVal = DefaultTypeTransformation.castToType(ch, arrayComponentClass);
        }
    } else if (arrayComponentClass.isArray()) {
        adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass);
    }
    return adjustedNewVal;
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:ObjectArrayPutAtMetaMethod.java

示例10: hasAttributeTypes

import groovy.lang.GString; //导入依赖的package包/类
/**
 * Checks if the given attributes Map has the correct types. This handles the GString case since that is a Groovy
 * special class that is converted to String dynamically.
 *
 * @param attributes The attributes map.
 * @param types      The types.
 * @return True if the map contains the correct types, false otherwise.
 */
@SuppressWarnings("unchecked")
public static boolean hasAttributeTypes(Map<String, Object> attributes, Map<String, Class<?>> types) {
  if (attributes == null) {
    return false;
  }

  for (String key : types.keySet()) {
    Object value = attributes.get(key);
    if (value == null) {
      continue;
    }

    Class type = types.get(key);
    if (type == String.class && !(value instanceof String || value instanceof GString)) {
      return false;
    } else if (type != String.class && !type.isAssignableFrom(value.getClass())) {
      return false;
    }
  }

  return true;
}
 
开发者ID:savant-build,项目名称:savant-core,代码行数:31,代码来源:GroovyTools.java

示例11: getValue

import groovy.lang.GString; //导入依赖的package包/类
@Override
public T getValue() {
	if (value.get() == null) {
		T newValue = closure.call();
		if (newValue instanceof GString && expectedType.equals(String.class)) {
			newValue = (T) newValue.toString();
		}
		if (newValue != null && !expectedType.isInstance(newValue)) {
			throw new IllegalArgumentException("Expected value of type " + expectedType.getCanonicalName()
				+ ". Got " + newValue.getClass().getCanonicalName() + " instead.");
		}
		value.compareAndSet(null, new ValueContainer(newValue));
	}
	return value.get().value;
}
 
开发者ID:Unity-Group,项目名称:gradle-lazy-credentials,代码行数:16,代码来源:GroovyValues.java

示例12: resolveConstructorArguments

import groovy.lang.GString; //导入依赖的package包/类
protected List<Object> resolveConstructorArguments(Object[] args, int start, int end) {
	Object[] constructorArgs = Arrays.copyOfRange(args, start, end);
	for (int i = 0; i < constructorArgs.length; i++) {
		if (constructorArgs[i] instanceof GString) {
			constructorArgs[i] = constructorArgs[i].toString();
		}
		else if (constructorArgs[i] instanceof List) {
			constructorArgs[i] = manageListIfNecessary((List) constructorArgs[i]);
		}
		else if (constructorArgs[i] instanceof Map){
			constructorArgs[i] = manageMapIfNecessary((Map) constructorArgs[i]);
		}
	}
	return Arrays.asList(constructorArgs);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:GroovyBeanDefinitionReader.java

示例13: applyPropertyToBeanDefinition

import groovy.lang.GString; //导入依赖的package包/类
protected void applyPropertyToBeanDefinition(String name, Object value) {
	if (value instanceof GString) {
		value = value.toString();
	}
	if (addDeferredProperty(name, value)) {
		return;
	}
	else if (value instanceof Closure) {
		GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
		try {
			Closure callable = (Closure) value;
			Class<?> parameterType = callable.getParameterTypes()[0];
			if (parameterType.equals(Object.class)) {
				this.currentBeanDefinition = new GroovyBeanDefinitionWrapper("");
				callable.call(this.currentBeanDefinition);
			}
			else {
				this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, parameterType);
				callable.call((Object) null);
			}

			value = this.currentBeanDefinition.getBeanDefinition();
		}
		finally {
			this.currentBeanDefinition = current;
		}
	}
	this.currentBeanDefinition.addProperty(name, value);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:GroovyBeanDefinitionReader.java

示例14: applyPropertyToBeanDefinition

import groovy.lang.GString; //导入依赖的package包/类
protected void applyPropertyToBeanDefinition(String name, Object value) {
	if (value instanceof GString) {
		value = value.toString();
	}
	if (addDeferredProperty(name, value)) {
		return;
	}
	else if (value instanceof Closure) {
		GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
		try {
			Closure callable = (Closure) value;
			Class<?> parameterType = callable.getParameterTypes()[0];
			if (Object.class == parameterType) {
				this.currentBeanDefinition = new GroovyBeanDefinitionWrapper("");
				callable.call(this.currentBeanDefinition);
			}
			else {
				this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, parameterType);
				callable.call((Object) null);
			}

			value = this.currentBeanDefinition.getBeanDefinition();
		}
		finally {
			this.currentBeanDefinition = current;
		}
	}
	this.currentBeanDefinition.addProperty(name, value);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:GroovyBeanDefinitionReader.java

示例15: toRawURI

import groovy.lang.GString; //导入依赖的package包/类
private URI toRawURI(final String scheme, final Integer port, final String host, final GString path, final String query, final String fragment, final String userInfo) throws URISyntaxException {
    return new URI(format("%s%s%s%s%s%s%s",
        scheme == null ? "" : (scheme.endsWith("://") ? scheme : scheme + "://"),
        userInfo == null ? "" : (userInfo.endsWith("@") ? userInfo : userInfo + "@"),
        host == null ? "" : host,
        port == null ? "" : ":" + port.toString(),
        path == null ? "" : (!path.toString().startsWith("/") && !path.toString().isEmpty() ? "/" + path : path),
        query != null ? "?" + query : "",
        fragment == null ? "" : (!fragment.startsWith("#") ? "#" + fragment : fragment)
    ));
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:12,代码来源:UriBuilder.java


注:本文中的groovy.lang.GString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。