本文整理汇总了Java中com.google.common.collect.Iterators.getOnlyElement方法的典型用法代码示例。如果您正苦于以下问题:Java Iterators.getOnlyElement方法的具体用法?Java Iterators.getOnlyElement怎么用?Java Iterators.getOnlyElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Iterators
的用法示例。
在下文中一共展示了Iterators.getOnlyElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expandAndTestShorthandStatement
import com.google.common.collect.Iterators; //导入方法依赖的package包/类
private Model expandAndTestShorthandStatement(Statement toExpand, IRI expandedPredicate) {
model.add(toExpand);
Model expanded = SHORTHAND_EXPANDER.apply(model);
assertThat(expanded.size(), is(2));
Statement firstStatement =
Iterators.getOnlyElement(
expanded
.filter(null, expandedPredicate, null)
.iterator()
);
assertThat(firstStatement.getSubject(), is(toExpand.getSubject()));
assertThat(firstStatement.getObject(), instanceOf(BNode.class));
Statement otherSt =
Iterators.getOnlyElement(
expanded
.filter((Resource)firstStatement.getObject(), null, null)
.iterator()
);
assertThat(otherSt.getPredicate(), is(Rr.constant));
assertThat(otherSt.getObject(), is(toExpand.getObject()));
return expanded;
}
示例2: transform
import com.google.common.collect.Iterators; //导入方法依赖的package包/类
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
AbstractInsnNode[] match = Iterators.getOnlyElement(matcher.match("BIPUSH ISTORE", m -> {
IntInsnNode push = (IntInsnNode) m[0];
if (push.operand != 50) {
return false;
}
VarInsnNode store = (VarInsnNode) m[1];
LocalVariableNode node = AsmUtils.getLocalVariable(method, store.var, store);
return node != null && node.name.equals("resource") && node.desc.equals("I");
}));
method.instructions.remove(match[0]);
method.instructions.remove(match[1]);
}