本文整理汇总了Java中com.google.common.collect.ImmutableListMultimap.Builder类的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Builder类属于com.google.common.collect.ImmutableListMultimap包,在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuilder_withMutableEntry
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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"));
}
示例2: testBuilderPutAllMultimap
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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());
}
示例3: testBuilderPutAllMultimapWithDuplicates
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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());
}
示例4: testBuilderOrderKeysBy
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}
示例5: testBuilderOrderKeysByDuplicates
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}
示例6: testBuilderOrderValuesBy
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}
示例7: testBuilderOrderKeysAndValuesBy
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}
示例8: retrievePickedHUsIndexedByPickingSlotId
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}
示例9: withParameter
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
/**
* <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);
}
示例10: create
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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);
}
示例11: testBuilder_withMutableEntry
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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"));
}
示例12: testBuilderPutAllMultimap
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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());
}
示例13: testBuilderPutAllMultimapWithDuplicates
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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());
}
示例14: testBuilderOrderKeysByDuplicates
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}
示例15: testBuilderOrderKeysAndValuesBy
import com.google.common.collect.ImmutableListMultimap.Builder; //导入依赖的package包/类
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();
}