List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:com.tasktop.c2c.server.internal.cloud.hp.HPCloudService.java
protected static Node convertServerToNode(Server server) { Node node = new Node(); node.setIdentity(String.valueOf(server.getId())); Multimap<String, Address> addressMap = server.getAddresses(); // There may be a bug in the JClouds code: both public and private IPs appear // for the same "private" key in the map; the private IP is first, the public IP is second if (addressMap != null) { for (String key : addressMap.keySet()) { Collection<Address> addresses = addressMap.get(key); if (addresses != null && addresses.size() > 1) { for (Address address : addresses) { try { if (!InetAddress.getByName(address.getAddr()).isSiteLocalAddress()) { node.setIpAddress(address.getAddr()); break; }// w ww. j a v a2 s . c o m } catch (UnknownHostException e) { LOGGER.debug("Caught Exception examining IP: " + address.getAddr(), e); } } } } } node.setName(server.getName()); node.setStatus(convertServerStatusToNodeStatus(server.getStatus())); // URI is left null but it is not yet needed return node; }
From source file:org.eclipse.wb.internal.core.model.property.event.ListenerInfo.java
static void useSimpleNamesWherePossible(List<ListenerInfo> listeners) { // prepare map: simple name -> qualified names Multimap<String, String> simplePropertyNames = HashMultimap.create(); for (ListenerInfo listener : listeners) { String qualifiedName = listener.getName(); String simpleName = getSimpleName(qualifiedName); simplePropertyNames.put(simpleName, qualifiedName); }//w w w . j a v a 2 s . c o m // if simple name is unique, use it for (ListenerInfo listener : listeners) { String qualifiedName = listener.getName(); String simpleName = getSimpleName(qualifiedName); if (simplePropertyNames.get(simpleName).size() == 1) { listener.m_name = simpleName; } } }
From source file:org.jboss.errai.idea.plugin.ui.TemplateUtil.java
private static TemplateMetaData getTemplateMetaData(PsiAnnotation annotation, Project project) { if (annotation == null) return null; final String qualifiedName = annotation.getQualifiedName(); if (qualifiedName == null) return null; if (!qualifiedName.equals(Types.TEMPLATED)) { annotation = findTemplatedAnnotation(annotation); if (annotation == null) return null; }/*www.j a va 2s. c om*/ final PsiClass templateClass = PsiUtil.getTopLevelClass(annotation); if (templateClass == null) { return null; } final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes(); final String templateName; if (attributes.length == 0) { templateName = templateClass.getName() + ".html"; } else { if (!(attributes[0].getValue() instanceof PsiLiteralExpression)) { return null; } final PsiLiteralExpression literalExpression = (PsiLiteralExpression) attributes[0].getValue(); if (literalExpression == null) { return null; } String text = literalExpression.getText().replace(Util.INTELLIJ_MAGIC_STRING, ""); templateName = text.substring(1, text.length() - 1); } final PsiFile containingFile = templateClass.getContainingFile().getOriginalFile(); PsiDirectory containerDir = containingFile.getParent(); if (containerDir == null) { return null; } final TemplateExpression reference = TemplateUtil.parseReference(templateName); final String fileName; if ("".equals(reference.getFileName())) { fileName = templateClass.getName() + ".html"; } else { fileName = reference.getFileName(); } final VirtualFile virtualFile = containerDir.getVirtualFile(); VirtualFile fileByRelativePath = virtualFile.findFileByRelativePath(fileName); if (fileByRelativePath != null && fileByRelativePath.isDirectory()) { fileByRelativePath = null; } // if we didn't find the file in the current container, // and this is a maven project, it might located in the resources folder if (fileByRelativePath == null) { // see if this is a maven project check for a pom.xml in the root folder VirtualFile vProjectDir = project.getBaseDir(); VirtualFile vPom = vProjectDir.findChild("pom.xml"); if (vPom != null) { // look in the src/main/resources folder for the corresponding html file String containerPath = virtualFile.getPath(); String resourcePath = containerPath.replaceAll("src/main/java", "src/main/resources"); File resourceFile = new File(resourcePath, fileName); VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(resourceFile); if (vf != null) { fileByRelativePath = vf; } } } final XmlTag rootTag; if (fileByRelativePath == null) { rootTag = null; } else if (reference.getRootNode().equals("")) { final PsiFile file = PsiManager.getInstance(project).findFile(fileByRelativePath); if (file != null) { rootTag = ((XmlFile) file).getRootTag(); } else { rootTag = null; } } else { Multimap<String, TemplateDataField> allDataFieldTags = findAllDataFieldTags(fileByRelativePath, null, project, true); final Collection<TemplateDataField> dataFieldReference = allDataFieldTags.get(reference.getRootNode()); // if both data-field and id are the same, dataFieldReference will have // two reference to the same element. So, the root tag is valid if we have // any values in the iterator Iterator<TemplateDataField> dataFieldIterator = dataFieldReference.iterator(); if (dataFieldIterator.hasNext()) { rootTag = dataFieldIterator.next().getTag(); } else { rootTag = null; } } return new TemplateMetaData(reference, attributes.length == 0, attributes.length == 0 ? null : attributes[0], templateClass, fileByRelativePath, rootTag, project); }
From source file:ubicrypt.core.FileSynchronizer.java
/** return only files which are not in conflict */ static Multimap<UUID, FileProvenience> withoutConflicts(final Multimap<UUID, FileProvenience> all) { return all.asMap().entrySet().stream() .filter(entry -> entry.getValue().stream() .filter(fp -> entry.getValue().stream() .filter(fp2 -> fp.getFile().compare(fp2.getFile()) != VClock.Comparison.conflict) .collect(Collectors.toList()).size() == entry.getValue().size()) .collect(Collectors.toList()).size() == entry.getValue().size()) .collect(LinkedHashMultimap::create, (multimap, entry) -> multimap.putAll(entry.getKey(), all.get(entry.getKey())), (m1, m2) -> m1.putAll(m2)); }
From source file:org.sonar.server.permission.ws.template.TemplateGroupsAction.java
private static WsPermissions.WsGroupsResponse buildResponse(List<GroupDto> groups, List<PermissionTemplateGroupDto> groupPermissions, Paging paging) { Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getPermission())); WsPermissions.WsGroupsResponse.Builder response = WsPermissions.WsGroupsResponse.newBuilder(); groups.forEach(group -> {//from ww w. j a va 2 s.c o m WsPermissions.Group.Builder wsGroup = response.addGroupsBuilder().setName(group.getName()); if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } setNullable(group.getDescription(), wsGroup::setDescription); wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); }); response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()) .setTotal(paging.total()); return response.build(); }
From source file:org.jetbrains.jet.buildergen.EntityBuilder.java
private static void bindOverriddenRelations(Entity entity, Set<Entity> alreadyBound) { if (!alreadyBound.add(entity)) return;//from www .j a v a 2 s .c om Multimap<String, Relation<?>> superRelations = HashMultimap.create(); for (Entity superEntity : entity.getSuperEntities()) { bindOverriddenRelations(superEntity, alreadyBound); for (Relation<?> relation : superEntity.getRelations()) { superRelations.put(relation.getName(), relation); } } Set<String> explicitlyOverridden = Sets.newHashSet(); for (Relation<?> relation : Lists.newArrayList(entity.getRelations())) { relation.getOverriddenRelations().addAll(superRelations.get(relation.getName())); explicitlyOverridden.add(relation.getName()); } // "fake overrides" for (Map.Entry<String, Collection<Relation<?>>> entry : superRelations.asMap().entrySet()) { String relationName = entry.getKey(); Collection<Relation<?>> overriddenRelations = entry.getValue(); Relation<?> someOverridden = ContainerUtil.getFirstItem(overriddenRelations); RelationWithTarget<Object> fakeOverride = new RelationWithTarget<Object>( someOverridden.getMultiplicity(), relationName, someOverridden.getTarget()); fakeOverride.getOverriddenRelations().addAll(overriddenRelations); entity.getRelations().add(fakeOverride); } }
From source file:org.apache.shindig.gadgets.http.HttpResponse.java
/** * Attempts to determine the encoding of the body. If it can't be determined, we use * DEFAULT_ENCODING instead.//from www . j a v a2 s.c o m * * @return The detected encoding or DEFAULT_ENCODING. */ private static Charset getAndUpdateEncoding(Multimap<String, String> headers, byte[] body) { if (body == null || body.length == 0) { return DEFAULT_ENCODING; } Collection<String> values = headers.get("Content-Type"); if (!values.isEmpty()) { String contentType = values.iterator().next(); String[] parts = StringUtils.split(contentType, ';'); if (parts == null || parts.length == 0 || BINARY_CONTENT_TYPES.contains(parts[0])) { return DEFAULT_ENCODING; } if (parts.length == 2) { int offset = parts[1].toLowerCase().indexOf("charset="); if (offset != -1) { String charset = parts[1].substring(offset + 8).toUpperCase(); // Some servers include quotes around the charset: // Content-Type: text/html; charset="UTF-8" if (charset.length() >= 2 && charset.startsWith("\"") && charset.endsWith("\"")) { charset = charset.substring(1, charset.length() - 1); } try { return charsetForName(charset); } catch (IllegalArgumentException e) { // fall through to detection } } } Charset encoding = EncodingDetector.detectEncoding(body, fastEncodingDetection, customEncodingDetector); // Record the charset in the content-type header so that its value can be cached // and re-used. This is a BIG performance win. values.clear(); values.add(contentType + "; charset=" + encoding.name()); return encoding; } else { // If no content type was specified, we'll assume an unknown binary type. return DEFAULT_ENCODING; } }
From source file:org.opentripplanner.graph_builder.impl.osm.AreaGroup.java
public static List<AreaGroup> groupAreas(Map<Area, OSMLevel> areasLevels) { DisjointSet<Area> groups = new DisjointSet<Area>(); Multimap<OSMNode, Area> areasForNode = LinkedListMultimap.create(); for (Area area : areasLevels.keySet()) { for (Ring ring : area.outermostRings) { for (Ring inner : ring.holes) { for (OSMNode node : inner.nodes) { areasForNode.put(node, area); }/* w w w .j a v a 2s. com*/ } for (OSMNode node : ring.nodes) { areasForNode.put(node, area); } } } // areas that can be joined must share nodes and levels for (OSMNode osmNode : areasForNode.keySet()) { for (Area area1 : areasForNode.get(osmNode)) { OSMLevel level1 = areasLevels.get(area1); for (Area area2 : areasForNode.get(osmNode)) { OSMLevel level2 = areasLevels.get(area2); if ((level1 == null && level2 == null) || (level1 != null && level1.equals(level2))) { groups.union(area1, area2); } } } } List<AreaGroup> out = new ArrayList<AreaGroup>(); for (Set<Area> areaSet : groups.sets()) { try { out.add(new AreaGroup(areaSet)); } catch (AreaGroup.RingConstructionException e) { for (Area area : areaSet) { LOG.debug("Failed to create merged area for " + area + ". This area might not be at fault; it might be one of the other areas in this list."); out.add(new AreaGroup(Arrays.asList(area))); } } } return out; }
From source file:com.zimbra.cs.service.mail.Sync.java
private static void encodePagedDelete(Element eDeleted, PagedDelete pgDelete, SyncToken newSyncToken, TypedIdList tombstones, boolean typedDeletes) { Collection<Integer> itemIds = pgDelete.getAllIds(); if (itemIds.isEmpty()) { eDeleted.detach();/* ww w .ja va 2 s . c o m*/ } else { if (typedDeletes) { Multimap<MailItem.Type, Integer> type2Id = pgDelete.getTypedItemIds(); StringBuilder typed = new StringBuilder(); for (MailItem.Type type : type2Id.keySet()) { String eltName = elementNameForType(type); typed.setLength(0); for (Integer id : type2Id.get(type)) { typed.append(typed.length() == 0 ? "" : ",").append(id); } eDeleted.addElement(eltName).addAttribute(MailConstants.A_IDS, typed.toString()); } } StringBuilder deleted = new StringBuilder(); for (Integer itemId : itemIds) { deleted.append(deleted.length() == 0 ? "" : ",").append(itemId); } eDeleted.addAttribute(MailConstants.A_IDS, deleted.toString()); } if (pgDelete.isDeleteOverFlow()) { newSyncToken.setDeleteItemId(pgDelete.getLastItemId()); newSyncToken.setDeleteModSeq(pgDelete.getCutOffModsequnce() - 1); } }
From source file:msi.gama.application.workspace.WorkspaceModelsManager.java
public static void loadModelsLibrary() { while (!GamaBundleLoader.LOADED && !GamaBundleLoader.ERRORED) { try {// ww w . ja v a2s . c om Thread.sleep(100); DEBUG.OUT("Waiting for GAML subsystem to load..."); } catch (final InterruptedException e) { } } if (GamaBundleLoader.ERRORED) { GAMA.getGui().tell("Error in loading GAML language subsystem. Please consult the logs"); return; } DEBUG.OUT("Synchronous link of models library..."); final Multimap<Bundle, String> pluginsWithModels = GamaBundleLoader.getPluginsWithModels(); for (final Bundle plugin : pluginsWithModels.keySet()) { for (final String entry : pluginsWithModels.get(plugin)) { linkModelsToWorkspace(plugin, entry, false); } } final Multimap<Bundle, String> pluginsWithTests = GamaBundleLoader.getPluginsWithTests(); for (final Bundle plugin : pluginsWithTests.keySet()) { for (final String entry : pluginsWithTests.get(plugin)) { linkModelsToWorkspace(plugin, entry, true); } } }