本文整理了Java中groovy.lang.Tuple
类的一些代码示例,展示了Tuple
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple
类的具体详情如下:
包路径:groovy.lang.Tuple
类名称:Tuple
[英]Represents a list of Integer objects from a specified int up to but not including a given and to.
[中]表示从指定整数到但不包括给定和到的整数对象的列表。
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Invoke a method on the given object with the given arguments.
*
* @param object The object the method should be invoked on.
* @param methodName The name of the method to invoke.
* @param arguments The arguments to the invoked method as null, a Tuple, an array or a single argument of any type.
*
* @return The result of the method invocation.
*/
public Object invokeMethod(Object object, String methodName, Object arguments) {
if (arguments == null) {
return invokeMethod(object, methodName, MetaClassHelper.EMPTY_ARRAY);
}
if (arguments instanceof Tuple) {
Tuple tuple = (Tuple) arguments;
return invokeMethod(object, methodName, tuple.toArray());
}
if (arguments instanceof Object[]) {
return invokeMethod(object, methodName, (Object[]) arguments);
} else {
return invokeMethod(object, methodName, new Object[]{arguments});
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static Tuple createTuple(Object[] array) {
return new Tuple(array);
}
代码示例来源:origin: groovy/groovy-core
public void testHashCodeAndEquals() {
Tuple a = new Tuple(new Object[]{"a", "b", "c"});
Tuple b = new Tuple(new Object[]{"a", "b", "c"});
Tuple c = new Tuple(new Object[]{"d", "b", "c"});
Tuple d = new Tuple(new Object[]{"a", "b"});
Tuple2<String, String> e = new Tuple2<String, String>("a", "b");
Tuple2<String, String> f = new Tuple2<String, String>("a", "c");
assertEquals("hashcode", a.hashCode(), b.hashCode());
assertTrue("hashcode", a.hashCode() != c.hashCode());
assertEquals("a and b", a, b);
assertFalse("a != c", a.equals(c));
assertFalse("!a.equals(null)", a.equals(null));
assertTrue("d.equals(e)", d.equals(e));
assertTrue("e.equals(d)", e.equals(d));
assertFalse("!e.equals(f)", e.equals(f));
assertFalse("!f.equals(e)", f.equals(e));
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Tuple)) return false;
Tuple that = (Tuple) o;
int size = size();
if (size != that.size()) return false;
for (int i = 0; i < size; i++) {
if (!DefaultTypeTransformation.compareEqual(get(i), that.get(i))) {
return false;
}
}
return true;
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
public boolean equals(Object that) {
if (that instanceof Tuple) {
return equals((Tuple) that);
}
return false;
}
代码示例来源:origin: groovy/groovy-core
public void testGetOutOfTuple() {
try {
t.get(-1);
fail("Should have thrown IndexOut");
}
catch (IndexOutOfBoundsException e) {
// worked
}
try {
t.get(10);
fail("Should have thrown IndexOut");
}
catch (IndexOutOfBoundsException e) {
// worked
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
public boolean equals(Object that) {
if (that instanceof Tuple) {
return equals((Tuple) that);
}
return false;
}
代码示例来源:origin: groovy/groovy-core
public void testSize() {
assertEquals("Size of " + t, 3, t.size());
assertEquals("get(0)", "a", t.get(0));
assertEquals("get(1)", "b", t.get(1));
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
public List<Object> getUpdatedParams(List<Object> params, List<Tuple> indexPropList) {
List<Object> updatedParams = new ArrayList<Object>();
for (Tuple tuple : indexPropList) {
int index = (Integer) tuple.get(0);
String prop = (String) tuple.get(1);
if (index < 0 || index >= params.size())
throw new IllegalArgumentException("Invalid index " + index + " should be in range 1.." + params.size());
updatedParams.add(prop.equals("<this>") ? params.get(index) : InvokerHelper.getProperty(params.get(index), prop));
}
return updatedParams;
}
代码示例来源:origin: crashub/crash
private static Object[] unwrapArgs(Object arguments) {
if (arguments == null) {
return MetaClassHelper.EMPTY_ARRAY;
} else if (arguments instanceof Tuple) {
Tuple tuple = (Tuple) arguments;
return tuple.toArray();
} else if (arguments instanceof Object[]) {
return (Object[])arguments;
} else {
return new Object[]{arguments};
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static Tuple createTuple(Object[] array) {
return new Tuple(array);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
public boolean equals(Object that) {
if (that instanceof Tuple) {
return equals((Tuple) that);
}
return false;
}
代码示例来源:origin: org.codehaus.groovy/groovy-sql
public List<Object> getUpdatedParams(List<Object> params, List<Tuple> indexPropList) {
List<Object> updatedParams = new ArrayList<Object>();
for (Tuple tuple : indexPropList) {
int index = (Integer) tuple.get(0);
String prop = (String) tuple.get(1);
if (index < 0 || index >= params.size())
throw new IllegalArgumentException("Invalid index " + index + " should be in range 1.." + params.size());
try {
updatedParams.add(prop.equals("<this>") ? params.get(index) : InvokerHelper.getProperty(params.get(index), prop));
} catch(MissingPropertyException mpe) {
throw new IllegalArgumentException("Property '" + prop + "' not found for parameter " + index);
}
}
return updatedParams;
}
代码示例来源:origin: apache/tinkerpop
@Override
public Object invokeMethod(final Object object, final String name, final Object args) {
if (args == null) {
return invokeMethod(object, name, MetaClassHelper.EMPTY_ARRAY);
} else if (args instanceof Tuple) {
return invokeMethod(object, name, ((Tuple) args).toArray());
} else if (args instanceof Object[]) {
return invokeMethod(object, name, (Object[]) args);
} else {
return invokeMethod(object, name, new Object[]{args});
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
@SuppressWarnings("unchecked")
@Override
public List<E> subList(int fromIndex, int toIndex) {
int size = toIndex - fromIndex;
E[] newContent = (E[]) new Object[size];
System.arraycopy(contents, fromIndex, newContent, 0, size);
return new Tuple<>(newContent);
}
代码示例来源:origin: org.kohsuke.droovy/groovy
public boolean equals(Object that) {
if (that instanceof Tuple) {
return equals((Tuple) that);
}
return false;
}
代码示例来源:origin: org.codehaus.groovy/groovy-jsr223
@Override
public Object invokeMethod(Object object, String name, Object args) {
if (args == null) {
return invokeMethod(object, name, MetaClassHelper.EMPTY_ARRAY);
}
if (args instanceof Tuple) {
return invokeMethod(object, name, ((Tuple) args).toArray());
}
if (args instanceof Object[]) {
return invokeMethod(object, name, (Object[]) args);
} else {
return invokeMethod(object, name, new Object[]{args});
}
}
代码示例来源:origin: apache/groovy
private static String adaptForNamedParams(String sql, List<Tuple> indexPropList) {
StringBuilder newSql = new StringBuilder();
int txtIndex = 0;
Matcher matcher = NAMED_QUERY_PATTERN.matcher(sql);
while (matcher.find()) {
newSql.append(sql, txtIndex, matcher.start()).append('?');
String indexStr = matcher.group(1);
if (indexStr == null) indexStr = matcher.group(3);
int index = (indexStr == null || indexStr.length() == 0 || ":".equals(indexStr)) ? 0 : Integer.parseInt(indexStr) - 1;
String prop = matcher.group(2);
if (prop == null) prop = matcher.group(4);
indexPropList.add(new Tuple(index, prop == null || prop.length() == 0 ? "<this>" : prop));
txtIndex = matcher.end();
}
newSql.append(sql.substring(txtIndex)); // append ending SQL after last param.
return newSql.toString();
}
代码示例来源:origin: org.crsh/crsh.shell.core
static Object[] unwrapArgs(Object arguments) {
if (arguments == null) {
return MetaClassHelper.EMPTY_ARRAY;
} else if (arguments instanceof Tuple) {
Tuple tuple = (Tuple) arguments;
return tuple.toArray();
} else if (arguments instanceof Object[]) {
return (Object[])arguments;
} else {
return new Object[]{arguments};
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
public static Tuple createTuple(Object[] array) {
return new Tuple(array);
}
内容来源于网络,如有侵权,请联系作者删除!