Java 类com.google.common.collect.ImmutableListMultimap.Builder 实例源码

项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableListMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimapWithDuplicates() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 1);
  toPut.put("bar", 5);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 4);
  moreToPut.put("foo", 7);
  moreToPut.put("foo", 2);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
  assertEquals(9, multimap.size());
}
项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
}
项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
}
项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:guava-mock    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableListMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimapWithDuplicates() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 1);
  toPut.put("bar", 5);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 4);
  moreToPut.put("foo", 7);
  moreToPut.put("foo", 2);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
  assertEquals(9, multimap.size());
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:googles-monorepo-demo    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:metasfresh-webui-api    文件:PickingHuRowsRepository.java   
private ListMultimap<Integer, PickedHUEditorRow> retrievePickedHUsIndexedByPickingSlotId(@NonNull final List<I_M_Picking_Candidate> pickingCandidates)
{
    final Map<Integer, PickedHUEditorRow> huId2huRow = new HashMap<>();

    final Builder<Integer, PickedHUEditorRow> builder = ImmutableListMultimap.builder();

    for (final I_M_Picking_Candidate pickingCandidate : pickingCandidates)
    {
        final int huId = pickingCandidate.getM_HU_ID();
        if (huId2huRow.containsKey(huId))
        {
            continue;
        }

        final HUEditorRow huEditorRow = huEditorRepo.retrieveForHUId(huId);
        final boolean pickingCandidateProcessed = isPickingCandidateProcessed(pickingCandidate);
        final PickedHUEditorRow row = new PickedHUEditorRow(huEditorRow, pickingCandidateProcessed);

        huId2huRow.put(huId, row);

        builder.put(pickingCandidate.getM_PickingSlot_ID(), row);
    }

    return builder.build();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableListMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimapWithDuplicates() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 1);
  toPut.put("bar", 5);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 4);
  moreToPut.put("foo", 7);
  moreToPut.put("foo", 2);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
  assertEquals(9, multimap.size());
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableListMultimap.Builder<String, Integer> builder =
      new Builder<String, Integer>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() {
    @Override public String getKey() {
      return holder.string;
    }
    @Override public Integer getValue() {
      return 1;
    }
  };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimapWithDuplicates() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 1);
  toPut.put("bar", 5);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 4);
  moreToPut.put("foo", 7);
  moreToPut.put("foo", 2);
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
  assertEquals(9, multimap.size());
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 3, 6, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(3, 6).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(new Ordering<String>() {
    @Override
    public int compare(String left, String right) {
      return left.length() - right.length();
    }
  });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder();
  assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:guava-libraries    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder
      = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:armeria    文件:MediaType.java   
/**
 * <em>Replaces</em> all parameters with the given attribute with a single parameter with the
 * given value. If multiple parameters with the same attributes are necessary use
 * {@link #withParameters}. Prefer {@link #withCharset} for setting the {@code charset} parameter
 * when using a {@link Charset} object.
 *
 * @throws IllegalArgumentException if either {@code attribute} or {@code value} is invalid
 */
public MediaType withParameter(String attribute, String value) {
    checkNotNull(attribute);
    checkNotNull(value);
    String normalizedAttribute = normalizeToken(attribute);
    Builder<String, String> builder = ImmutableListMultimap.builder();
    for (Entry<String, String> entry : parameters.entries()) {
        String key = entry.getKey();
        if (!normalizedAttribute.equals(key)) {
            builder.put(key, entry.getValue());
        }
    }
    builder.put(normalizedAttribute, normalizeParameterValue(normalizedAttribute, value));
    MediaType mediaType = new MediaType(type, subtype, builder.build());
    // Return one of the constants if the media type is a known type.
    return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
项目:armeria    文件:MediaType.java   
private static MediaType create(String type, String subtype, Multimap<String, String> parameters) {
    checkNotNull(type);
    checkNotNull(subtype);
    checkNotNull(parameters);
    String normalizedType = normalizeToken(type);
    String normalizedSubtype = normalizeToken(subtype);
    checkArgument(
            !WILDCARD.equals(normalizedType) || WILDCARD.equals(normalizedSubtype),
            "A wildcard type cannot be used with a non-wildcard subtype");
    Builder<String, String> builder = ImmutableListMultimap.builder();
    for (Entry<String, String> entry : parameters.entries()) {
        String attribute = normalizeToken(entry.getKey());
        builder.put(attribute, normalizeParameterValue(attribute, entry.getValue()));
    }
    MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build());
    // Return one of the constants if the media type is a known type.
    return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableListMultimap.Builder<String, Integer> builder = new Builder<>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry =
      new AbstractMapEntry<String, Integer>() {
        @Override
        public String getKey() {
          return holder.string;
        }

        @Override
        public Integer getValue() {
          return 1;
        }
      };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimapWithDuplicates() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 1);
  toPut.put("bar", 5);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 4);
  moreToPut.put("foo", 7);
  moreToPut.put("foo", 2);
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
  assertEquals(9, multimap.size());
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(
      new Ordering<String>() {
        @Override
        public int compare(String left, String right) {
          return left.length() - right.length();
        }
      });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysAndValuesBy() {
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.put("b", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(Collections.reverseOrder());
  builder.orderValuesBy(Collections.reverseOrder());
  builder.put("c", 4);
  builder.put("a", 2);
  builder.put("b", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder();
  assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("b")).containsExactly(6, 3).inOrder();
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilder_withMutableEntry() {
  ImmutableListMultimap.Builder<String, Integer> builder = new Builder<>();
  final StringHolder holder = new StringHolder();
  holder.string = "one";
  Entry<String, Integer> entry =
      new AbstractMapEntry<String, Integer>() {
        @Override
        public String getKey() {
          return holder.string;
        }

        @Override
        public Integer getValue() {
          return 1;
        }
      };

  builder.put(entry);
  holder.string = "two";
  assertEquals(Arrays.asList(1), builder.build().get("one"));
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimap() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 3);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 5);
  moreToPut.put("foo", 7);
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 3, 6, 7), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5), multimap.get("bar"));
  assertEquals(7, multimap.size());
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderPutAllMultimapWithDuplicates() {
  Multimap<String, Integer> toPut = LinkedListMultimap.create();
  toPut.put("foo", 1);
  toPut.put("bar", 4);
  toPut.put("foo", 2);
  toPut.put("foo", 1);
  toPut.put("bar", 5);
  Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
  moreToPut.put("foo", 6);
  moreToPut.put("bar", 4);
  moreToPut.put("foo", 7);
  moreToPut.put("foo", 2);
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.putAll(toPut);
  builder.putAll(moreToPut);
  Multimap<String, Integer> multimap = builder.build();
  assertEquals(Arrays.asList(1, 2, 1, 6, 7, 2), multimap.get("foo"));
  assertEquals(Arrays.asList(4, 5, 4), multimap.get("bar"));
  assertEquals(9, multimap.size());
}
项目:guava    文件:ImmutableListMultimapTest.java   
public void testBuilderOrderKeysByDuplicates() {
  ImmutableListMultimap.Builder<String, Integer> builder = ImmutableListMultimap.builder();
  builder.put("bb", 3);
  builder.put("d", 2);
  builder.put("a", 5);
  builder.orderKeysBy(
      new Ordering<String>() {
        @Override
        public int compare(String left, String right) {
          return left.length() - right.length();
        }
      });
  builder.put("cc", 4);
  builder.put("a", 2);
  builder.put("bb", 6);
  ImmutableListMultimap<String, Integer> multimap = builder.build();
  assertThat(multimap.keySet()).containsExactly("d", "a", "bb", "cc").inOrder();
  assertThat(multimap.values()).containsExactly(2, 5, 2, 3, 6, 4).inOrder();
  assertThat(multimap.get("a")).containsExactly(5, 2).inOrder();
  assertThat(multimap.get("bb")).containsExactly(3, 6).inOrder();
}