ReplacementOutputs { public static Map<PValue, ReplacementOutput> singleton( Map<TupleTag<?>, PValue> original, PValue replacement) { Entry<TupleTag<?>, PValue> originalElement = Iterables.getOnlyElement(original.entrySet()); TupleTag<?> replacementTag = Iterables.getOnlyElement(replacement.expand().entrySet()).getKey(); return Collections.singletonMap( replacement, ReplacementOutput.of( TaggedPValue.of(originalElement.getKey(), originalElement.getValue()), TaggedPValue.of(replacementTag, replacement))); } private  ReplacementOutputs(); static Map<PValue, ReplacementOutput> singleton(
      Map<TupleTag<?>, PValue> original, PValue replacement); static Map<PValue, ReplacementOutput> tagged(
      Map<TupleTag<?>, PValue> original, POutput replacement);  }
@Test public void singletonSucceeds() { Map<PValue, ReplacementOutput> replacements = ReplacementOutputs.singleton(ints.expand(), replacementInts); assertThat(replacements, Matchers.hasKey(replacementInts)); ReplacementOutput replacement = replacements.get(replacementInts); Map.Entry<TupleTag<?>, PValue> taggedInts = Iterables.getOnlyElement(ints.expand().entrySet()); assertThat(replacement.getOriginal().getTag(), equalTo(taggedInts.getKey())); assertThat(replacement.getOriginal().getValue(), equalTo(taggedInts.getValue())); assertThat(replacement.getReplacement().getValue(), equalTo(replacementInts)); }
@Test public void singletonMultipleOriginalsThrows() { thrown.expect(IllegalArgumentException.class); ReplacementOutputs.singleton( ImmutableMap.<TupleTag<?>, PValue>builder() .putAll(ints.expand()) .putAll(moreInts.expand()) .build(), replacementInts); }