本文整理汇总了Java中com.google.common.collect.ImmutableListMultimap类的典型用法代码示例。如果您正苦于以下问题:Java ImmutableListMultimap类的具体用法?Java ImmutableListMultimap怎么用?Java ImmutableListMultimap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImmutableListMultimap类属于com.google.common.collect包,在下文中一共展示了ImmutableListMultimap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTasks
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
public void runTasks() {
Multimaps.asMap(ImmutableListMultimap.copyOf(taskQueue)).values().forEach(tasks -> {
int size = tasks.size();
while (size > 0) {
int last = size - 1;
Task<?> current = tasks.get(last);
if (current.done()) {
taskQueue.get(current.getClass()).remove(last);
size--;
continue;
}
current.tick();
return;
}
});
}
示例2: testProcess
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Test
public void testProcess() {
String taskName = "task";
JavaUtils.setFieldWithoutCheckedException(
ReflectionUtils.findField(TaskProcessorRegistryImpl.class, "taskProcessorMap")
, registry
, ImmutableListMultimap.builder()
.put(taskName, Pair.of(Objects.class, taskProcessor))
.build()
);
registry.process(taskName, "some body");
Mockito.verify(taskMapper, Mockito.atLeastOnce()).map(Mockito.anyString(), Mockito.any());
Mockito.verify(taskProcessor, Mockito.atLeastOnce()).process(Mockito.any());
}
示例3: modifyTypes
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
/** Applies the supplied modifications to the GraphQLTypes. */
private static BiMap<String, GraphQLType> modifyTypes(
BiMap<String, GraphQLType> mapping,
ImmutableListMultimap<String, TypeModification> modifications) {
BiMap<String, GraphQLType> result = HashBiMap.create(mapping.size());
for (String key : mapping.keySet()) {
if (mapping.get(key) instanceof GraphQLObjectType) {
GraphQLObjectType val = (GraphQLObjectType) mapping.get(key);
if (modifications.containsKey(key)) {
for (TypeModification modification : modifications.get(key)) {
val = modification.apply(val);
}
}
result.put(key, val);
} else {
result.put(key, mapping.get(key));
}
}
return result;
}
示例4: withParameter
import com.google.common.collect.ImmutableListMultimap; //导入依赖的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);
ImmutableListMultimap.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());
// if the attribute isn't charset, we can just inherit the current parsedCharset
if (!normalizedAttribute.equals(CHARSET_ATTRIBUTE)) {
mediaType.parsedCharset = this.parsedCharset;
}
// Return one of the constants if the media type is a known type.
return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
示例5: create
import com.google.common.collect.ImmutableListMultimap; //导入依赖的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");
ImmutableListMultimap.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);
}
示例6: getAttachmentsForItems
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public ListMultimap<Item, Attachment> getAttachmentsForItems(Collection<Item> items)
{
if( items.isEmpty() )
{
return ImmutableListMultimap.of();
}
List<Attachment> attachments = getHibernateTemplate().findByNamedParam(
"select a from Item i join i.attachments a where i in (:items) order by index(a) ASC", "items", items);
ListMultimap<Item, Attachment> multiMap = ArrayListMultimap.create();
for( Attachment attachment : attachments )
{
multiMap.put(attachment.getItem(), attachment);
}
return multiMap;
}
示例7: getAttachmentsForItemIds
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public ListMultimap<Long, Attachment> getAttachmentsForItemIds(Collection<Long> ids)
{
if( ids.isEmpty() )
{
return ImmutableListMultimap.of();
}
List<Object[]> attachments = getHibernateTemplate().findByNamedParam(
"select a, i.id from Item i join i.attachments a where i.id in (:items) order by index(a) ASC", "items",
ids);
ListMultimap<Long, Attachment> multiMap = ArrayListMultimap.create();
for( Object[] attachmentRow : attachments )
{
multiMap.put((Long) attachmentRow[1], (Attachment) attachmentRow[0]);
}
return multiMap;
}
示例8: getHistoryForItemIds
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public ListMultimap<Long, HistoryEvent> getHistoryForItemIds(Collection<Long> ids)
{
if( ids.isEmpty() )
{
return ImmutableListMultimap.of();
}
List<Object[]> history = getHibernateTemplate().findByNamedParam(
"select h, i.id from Item i join i.history h where i.id in (:items) order by index(h)", "items", ids);
ListMultimap<Long, HistoryEvent> multiMap = ArrayListMultimap.create();
for( Object[] historyRow : history )
{
multiMap.put((Long) historyRow[1], (HistoryEvent) historyRow[0]);
}
return multiMap;
}
示例9: getNavigationNodesForItemIds
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public ListMultimap<Long, ItemNavigationNode> getNavigationNodesForItemIds(Collection<Long> ids)
{
if( ids.isEmpty() )
{
return ImmutableListMultimap.of();
}
List<Object[]> node = getHibernateTemplate().findByNamedParam(
"select n, i.id from ItemNavigationNode n join n.item i where i.id in (:items) order by n.index ASC",
"items", ids);
ListMultimap<Long, ItemNavigationNode> multiMap = ArrayListMultimap.create();
for( Object[] nodeRow : node )
{
multiMap.put((Long) nodeRow[1], (ItemNavigationNode) nodeRow[0]);
}
return multiMap;
}
示例10: getDrmAcceptancesForItemIds
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Override
public ListMultimap<Long, DrmAcceptance> getDrmAcceptancesForItemIds(Collection<Long> itemIds)
{
if( itemIds.isEmpty() )
{
return ImmutableListMultimap.of();
}
final List<Object[]> drmAcceptances = getHibernateTemplate().findByNamedParam(
"select d, item.id from DrmAcceptance d where item.id in (:items) order by d.date DESC", "items", itemIds);
final ListMultimap<Long, DrmAcceptance> multiMap = ArrayListMultimap.create();
for( Object[] asseptRow : drmAcceptances )
{
multiMap.put((Long) asseptRow[1], (DrmAcceptance) asseptRow[0]);
}
return multiMap;
}
示例11: getCommentsForItems
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
@Transactional(propagation = Propagation.MANDATORY)
public Multimap<Long, Comment> getCommentsForItems(Collection<Long> itemIds)
{
if( itemIds.isEmpty() )
{
return ImmutableListMultimap.of();
}
List<Object[]> attachments = getHibernateTemplate()
.findByNamedParam("select c, i.id from Item i join i.comments c where i.id in (:items)", "items", itemIds);
ListMultimap<Long, Comment> multiMap = ArrayListMultimap.create();
for( Object[] attachmentRow : attachments )
{
multiMap.put((Long) attachmentRow[1], (Comment) attachmentRow[0]);
}
return multiMap;
}
示例12: withParameter
import com.google.common.collect.ImmutableListMultimap; //导入依赖的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);
ImmutableListMultimap.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);
}
示例13: get
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Override
public MultimapResource<K> get() {
ListMultimap<String, String> multimap = ArrayListMultimap.create();
MultimapResource<K> resource = new MultimapResource<>(key);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(path.openStream()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.trim().isEmpty()) {
continue;
}
List<String> fields = Arrays.asList(line.split("\t"));
apply(fields, multimap);
}
} catch (Exception e) {
throw new RuntimeException("Error initializing TSV resource.", e);
}
resource.multimap(ImmutableListMultimap.copyOf(multimap));
resource.mappingFunction(mappingFunction);
return resource;
}
示例14: provideParameterMap
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
/**
* Provides an immutable representation of the servlet request parameters.
*
* <p>This performs a shallow copy of the {@code Map<String, String[]>} data structure from the
* servlets API, each time this is provided. This is almost certainly less expensive than the
* thread synchronization expense of {@link javax.inject.Singleton @Singleton}.
*
* <p><b>Note:</b> If a parameter is specified without a value, e.g. {@code /foo?lol} then an
* empty string value is assumed, since Guava's multimap doesn't permit {@code null} mappings.
*
* @see HttpServletRequest#getParameterMap()
*/
@Provides
@ParameterMap
static ImmutableListMultimap<String, String> provideParameterMap(HttpServletRequest req) {
ImmutableListMultimap.Builder<String, String> params = new ImmutableListMultimap.Builder<>();
@SuppressWarnings("unchecked") // Safe by specification.
Map<String, String[]> original = req.getParameterMap();
for (Map.Entry<String, String[]> param : original.entrySet()) {
if (param.getValue().length == 0) {
params.put(param.getKey(), "");
} else {
params.putAll(param.getKey(), param.getValue());
}
}
return params.build();
}
示例15: populatesTransaction
import com.google.common.collect.ImmutableListMultimap; //导入依赖的package包/类
@Test
public void populatesTransaction() throws Exception {
final ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes());
final Payee payee = new Payee();
final Account account = new Account();
Security security = new Security();
when(importFile.getAccount()).thenReturn(account);
when(importFile.parse(inputStream)).thenReturn(singletonList(
ImmutableListMultimap.of(dateField, "01/15/1990", payeeField, PAYEE_NAME, securityField, SECURITY_NAME)));
ImportContext context = new GroupedDetailImportContext(importFile, payeeMapper, securityMapper, categoryMapper);
when(payeeMapper.get(PAYEE_NAME)).thenReturn(payee);
when(securityMapper.get(SECURITY_NAME)).thenReturn(security);
List<Transaction> transactions = context.parseTransactions(inputStream);
assertThat(transactions).hasSize(1);
assertThat(transactions.get(0).getAccount()).isSameAs(account);
assertThat(transactions.get(0).getDate()).isEqualTo(new SimpleDateFormat("yyyy/MM/dd").parse("1990/01/15"));
assertThat(transactions.get(0).getPayee()).isSameAs(payee);
assertThat(transactions.get(0).getSecurity()).isSameAs(security);
}