本文整理匯總了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]);
}