List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.eclipse.ebr.maven.EclipseIpLogUtil.java
private Xpp3Dom getIpLogXml(final Model recipePom, final SortedMap<Artifact, Model> dependencies, final Xpp3Dom existingIpLog, final Map<String, String> existingCqs, final Map<String, Xpp3Dom> existingLicenses) { final Xpp3Dom ipLog = new Xpp3Dom("ip_log"); ipLog.setAttribute("version", "1.0"); final Xpp3Dom project = new Xpp3Dom("project"); project.setAttribute("id", recipePom.getArtifactId()); project.setAttribute("version", getProjectVersion(recipePom, existingIpLog)); project.setAttribute("status", "done"); ipLog.addChild(project);// w w w . j a v a 2 s . c o m final Xpp3Dom info = new Xpp3Dom("info"); createChild(info, "name", getProjectName(recipePom, existingIpLog)); createChild(info, "origin", getProjectOrigin(recipePom, existingIpLog)); createChild(info, "reference", getProjectReference(recipePom, existingIpLog)); createChild(info, "repository", Strings.nullToEmpty(getProjectRepository(recipePom, existingIpLog))); createChild(info, "location", Strings.nullToEmpty(getProjectLocation(recipePom, existingIpLog))); createChild(info, "tag", getProjectTag(recipePom, existingIpLog)); project.addChild(info); final Xpp3Dom[] existingContacts = getContact(existingIpLog); if ((existingContacts != null) && (existingContacts.length > 0)) { for (final Xpp3Dom contact : existingContacts) { project.addChild(contact); } } else { final Xpp3Dom contact = new Xpp3Dom("contact"); createChild(contact, "name", ""); createChild(contact, "email", ""); createChild(contact, "company", ""); project.addChild(contact); } final Xpp3Dom existingNotes = getNotes(existingIpLog); if (existingNotes != null) { project.addChild(existingNotes); } for (final Entry<Artifact, Model> dependency : dependencies.entrySet()) { appenLegalInfo(project, dependency.getKey(), dependency.getValue(), existingCqs, existingLicenses); } return ipLog; }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleCompleteMultipartUpload(HttpServletResponse response, InputStream is, BlobStore blobStore, String containerName, String blobName, String uploadId) throws IOException, S3Exception { MultipartUpload mpu;// w w w .j a v a2 s. c om if (Quirks.MULTIPART_REQUIRES_STUB.contains(getBlobStoreType(blobStore))) { Blob stubBlob = blobStore.getBlob(containerName, uploadId); BlobAccess access = blobStore.getBlobAccess(containerName, uploadId); mpu = MultipartUpload.create(containerName, blobName, uploadId, stubBlob.getMetadata(), new PutOptions().setBlobAccess(access)); } else { mpu = MultipartUpload.create(containerName, blobName, uploadId, new MutableBlobMetadataImpl(), new PutOptions()); } // List parts to get part sizes and to map multiple Azure parts // into single parts. ImmutableMap.Builder<Integer, MultipartPart> builder = ImmutableMap.builder(); for (MultipartPart part : blobStore.listMultipartUpload(mpu)) { builder.put(part.partNumber(), part); } ImmutableMap<Integer, MultipartPart> partsByListing = builder.build(); List<MultipartPart> parts = new ArrayList<>(); String blobStoreType = getBlobStoreType(blobStore); if (blobStoreType.equals("azureblob")) { // TODO: how to sanity check parts? for (MultipartPart part : blobStore.listMultipartUpload(mpu)) { parts.add(part); } } else { CompleteMultipartUploadRequest cmu = new XmlMapper().readValue(is, CompleteMultipartUploadRequest.class); // use TreeMap to allow runt last part SortedMap<Integer, String> requestParts = new TreeMap<>(); if (cmu.parts != null) { for (CompleteMultipartUploadRequest.Part part : cmu.parts) { requestParts.put(part.partNumber, part.eTag); } } for (Iterator<Map.Entry<Integer, String>> it = requestParts.entrySet().iterator(); it.hasNext();) { Map.Entry<Integer, String> entry = it.next(); MultipartPart part = partsByListing.get(entry.getKey()); if (part == null) { throw new S3Exception(S3ErrorCode.INVALID_PART); } long partSize = part.partSize(); if (partSize < blobStore.getMinimumMultipartPartSize() && partSize != -1 && it.hasNext()) { throw new S3Exception(S3ErrorCode.ENTITY_TOO_SMALL); } if (part.partETag() != null && !equalsIgnoringSurroundingQuotes(part.partETag(), entry.getValue())) { throw new S3Exception(S3ErrorCode.INVALID_PART); } parts.add(MultipartPart.create(entry.getKey(), partSize, part.partETag(), part.lastModified())); } } if (parts.isEmpty()) { // Amazon requires at least one part throw new S3Exception(S3ErrorCode.MALFORMED_X_M_L); } String eTag = blobStore.completeMultipartUpload(mpu, parts); if (Quirks.MULTIPART_REQUIRES_STUB.contains(getBlobStoreType(blobStore))) { blobStore.removeBlob(containerName, uploadId); } try (Writer writer = response.getWriter()) { XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument(); xml.writeStartElement("CompleteMultipartUploadResult"); xml.writeDefaultNamespace(AWS_XMLNS); // TODO: bogus value writeSimpleElement(xml, "Location", "http://Example-Bucket.s3.amazonaws.com/" + blobName); writeSimpleElement(xml, "Bucket", containerName); writeSimpleElement(xml, "Key", blobName); if (eTag != null) { writeSimpleElement(xml, "ETag", maybeQuoteETag(eTag)); } xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
From source file:edu.stanford.epad.common.pixelmed.SegmentationObjectsFileWriter.java
private int[] sort_frames_by_position(AttributeList geometry, double[][] positions, int frame_num) throws DicomException { int[] index = new int[frame_num]; double[] distances = new double[frame_num]; class DoubleArrayComparator implements Comparator<List<Double>> { public int compare(List<Double> o1, List<Double> o2) { int val; if (o1.get(0) > o2.get(0)) val = 1; else if (o1.get(0) < o2.get(0)) val = -1; else { if (o1.get(1) > o2.get(1)) val = 1; else if (o1.get(1) < o2.get(1)) val = -1; else val = 0; }//from w w w .j av a2s. co m return val; } } SortedMap<ArrayList<Double>, Integer> sorting = new TreeMap<ArrayList<Double>, Integer>( new DoubleArrayComparator()); GeometryOfSlice slice_geometry; AttributeList geometry_list = (AttributeList) geometry.clone(); ArrayList<Double> key; for (int i = 0; i < frame_num; i++) { Attribute a = new DecimalStringAttribute(TagFromName.ImagePositionPatient); if (positions != null) { a.addValue(positions[i][0]); a.addValue(positions[i][1]); a.addValue(positions[i][2]); } else { a.addValue(0); a.addValue(0); a.addValue(0); } geometry_list.put(a); slice_geometry = new GeometryOfSliceFromAttributeList(geometry_list); distances[i] = slice_geometry.getDistanceAlongNormalFromOrigin(); key = new ArrayList<Double>(2); key.add(0, distances[i]); key.add(1, (double) i); sorting.put(key, 0); } // k will be the index of sorted keys. int k = 1; for (Map.Entry<ArrayList<Double>, Integer> entry : sorting.entrySet()) { sorting.put(entry.getKey(), k++); } for (int i = 0; i < frame_num; i++) { key = new ArrayList<Double>(2); key.add(0, distances[i]); key.add(1, (double) i); index[i] = sorting.get(key); } return index; }
From source file:org.gaul.s3proxy.S3ProxyHandler.java
private void handleListParts(HttpServletRequest request, HttpServletResponse response, BlobStore blobStore, String containerName, String blobName, String uploadId) throws IOException, S3Exception { // support only the no-op zero case String partNumberMarker = request.getParameter("part-number-marker"); if (partNumberMarker != null && !partNumberMarker.equals("0")) { throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED); }/*from w ww . j ava 2s .co m*/ // TODO: how to reconstruct original mpu? MultipartUpload mpu = MultipartUpload.create(containerName, blobName, uploadId, createFakeBlobMetadata(blobStore), new PutOptions()); List<MultipartPart> parts; if (getBlobStoreType(blobStore).equals("azureblob")) { // map Azure subparts back into S3 parts SortedMap<Integer, Long> map = new TreeMap<>(); for (MultipartPart part : blobStore.listMultipartUpload(mpu)) { int virtualPartNumber = part.partNumber() / 10_000; Long size = map.get(virtualPartNumber); map.put(virtualPartNumber, (size == null ? 0L : (long) size) + part.partSize()); } parts = new ArrayList<>(); for (Map.Entry<Integer, Long> entry : map.entrySet()) { String eTag = ""; // TODO: bogus value Date lastModified = null; // TODO: bogus value parts.add(MultipartPart.create(entry.getKey(), entry.getValue(), eTag, lastModified)); } } else { parts = blobStore.listMultipartUpload(mpu); } String encodingType = request.getParameter("encoding-type"); try (Writer writer = response.getWriter()) { XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer); xml.writeStartDocument(); xml.writeStartElement("ListPartsResult"); xml.writeDefaultNamespace(AWS_XMLNS); if (encodingType != null && encodingType.equals("url")) { writeSimpleElement(xml, "EncodingType", encodingType); } writeSimpleElement(xml, "Bucket", containerName); writeSimpleElement(xml, "Key", encodeBlob(encodingType, blobName)); writeSimpleElement(xml, "UploadId", uploadId); writeInitiatorStanza(xml); writeOwnerStanza(xml); writeSimpleElement(xml, "StorageClass", "STANDARD"); // TODO: pagination /* writeSimpleElement(xml, "PartNumberMarker", "1"); writeSimpleElement(xml, "NextPartNumberMarker", "3"); writeSimpleElement(xml, "MaxParts", "2"); writeSimpleElement(xml, "IsTruncated", "true"); */ for (MultipartPart part : parts) { xml.writeStartElement("Part"); writeSimpleElement(xml, "PartNumber", String.valueOf(part.partNumber())); Date lastModified = part.lastModified(); if (lastModified != null) { writeSimpleElement(xml, "LastModified", formatDate(lastModified)); } String eTag = part.partETag(); if (eTag != null) { writeSimpleElement(xml, "ETag", maybeQuoteETag(eTag)); } writeSimpleElement(xml, "Size", String.valueOf(part.partSize())); xml.writeEndElement(); } xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
From source file:org.madsonic.controller.RESTController.java
public void getArtists(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request);//from www .j a v a2 s .com XMLBuilder builder = createXMLBuilder(request, response, true); String username = securityService.getCurrentUsername(request); builder.add("artists", "ignoredArticles", settingsService.getIgnoredArticles(), false); List<Artist> artists = artistDao.getAlphabetialArtists(0, Integer.MAX_VALUE); SortedMap<MusicIndex, SortedSet<MusicIndex.SortableArtistWithArtist>> indexedArtists = musicIndexService .getIndexedArtists(artists, 1); //TODO: fixed Default Index for (Map.Entry<MusicIndex, SortedSet<MusicIndex.SortableArtistWithArtist>> entry : indexedArtists .entrySet()) { builder.add("index", "name", entry.getKey().getIndex(), false); for (MusicIndex.SortableArtistWithArtist sortableArtist : entry.getValue()) { AttributeSet attributes = createAttributesForArtist(sortableArtist.getArtist(), username); builder.add("artist", attributes, true); } builder.end(); } builder.endAll(); response.getWriter().print(builder); }
From source file:org.apache.accumulo.server.tabletserver.Tablet.java
private static TServerInstance lookupLastServer(KeyExtent extent, SortedMap<Key, Value> tabletsKeyValues) { for (Entry<Key, Value> entry : tabletsKeyValues.entrySet()) { if (entry.getKey().getColumnFamily().compareTo(TabletsSection.LastLocationColumnFamily.NAME) == 0) { return new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier()); }/* ww w. ja v a2s. co m*/ } return null; }
From source file:org.apache.hadoop.hbase.master.RegionManager.java
private int regionsToGiveOtherServers(final int numUnassignedRegions, final HServerLoad thisServersLoad) { if (master.getServerManager().hasBlacklistedServersInTest()) { // For unit testing. Otherwise, we will always think we should give regions to blacklisted // servers, but will not actually assign any. return 0; }/*w ww.j a v a2 s. c o m*/ SortedMap<HServerLoad, Collection<String>> lightServers = master.getServerManager().getServersToLoad() .getLightServers(thisServersLoad); // Examine the list of servers that are more lightly loaded than this one. // Pretend that we will assign regions to these more lightly loaded servers // until they reach load equal with ours. Then, see how many regions are // left unassigned. That is how many regions we should assign to this server int nRegions = 0; for (Map.Entry<HServerLoad, Collection<String>> e : lightServers.entrySet()) { HServerLoad lightLoad = new HServerLoad(e.getKey()); do { lightLoad.setNumberOfRegions(lightLoad.getNumberOfRegions() + 1); nRegions += 1; } while (lightLoad.compareTo(thisServersLoad) <= 0 && nRegions < numUnassignedRegions); nRegions *= e.getValue().size(); if (nRegions >= numUnassignedRegions) { break; } } return nRegions; }
From source file:org.madsonic.controller.RESTController.java
public void getIndexes(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request);/*from ww w . j ava 2 s. c om*/ XMLBuilder builder = createXMLBuilder(request, response, true); String username = securityService.getCurrentUser(request).getUsername(); int userGroupId = securityService.getCurrentUserGroupId(request); long ifModifiedSince = getLongParameter(request, "ifModifiedSince", 0L); long lastModified = leftController.getLastModified(request); if (lastModified <= ifModifiedSince) { builder.endAll(); response.getWriter().print(builder); return; } builder.add("indexes", false, new Attribute("lastModified", lastModified), new Attribute("ignoredArticles", settingsService.getIgnoredArticles())); List<MusicFolder> musicFolders = settingsService.getAllMusicFolders(userGroupId, settingsService.isSortMediaFileFolder()); Integer musicFolderId = getIntParameter(request, "musicFolderId"); if (musicFolderId != null) { for (MusicFolder musicFolder : musicFolders) { if (musicFolderId.equals(musicFolder.getId())) { musicFolders = Arrays.asList(musicFolder); break; } } } List<MediaFile> shortcuts = leftController.getShortcuts(musicFolders, settingsService.getShortcutsAsArray()); for (MediaFile shortcut : shortcuts) { builder.add("shortcut", createAttributesForArtist(shortcut, username), true); } SortedMap<MusicIndex, SortedSet<MusicIndex.SortableArtistforGenre>> indexedArtists = leftController .getMusicFolderContent(musicFolders, null, "1", false).getIndexedArtists(); for (Map.Entry<MusicIndex, SortedSet<MusicIndex.SortableArtistforGenre>> entry : indexedArtists .entrySet()) { builder.add("index", "name", entry.getKey().getIndex(), false); for (MusicIndex.SortableArtistforGenre artist : entry.getValue()) { for (MediaFile mediaFile : artist.getMediaFiles()) { if (mediaFile.isDirectory()) { Date starredDate = mediaFileDao.getMediaFileStarredDate(mediaFile.getId(), username); builder.add("artist", true, new Attribute("name", artist.getName()), new Attribute("id", mediaFile.getId()), new Attribute("starred", StringUtil.toISO8601(starredDate))); } } } builder.end(); } // Add children Player player = playerService.getPlayer(request, response); List<MediaFile> singleSongs = leftController.getSingleSongs(musicFolders, false); for (MediaFile singleSong : singleSongs) { builder.add("child", createAttributesForMediaFile(player, singleSong, username), true); } builder.endAll(); response.getWriter().print(builder); }
From source file:org.apache.accumulo.server.tabletserver.Tablet.java
private static long lookupFlushID(KeyExtent extent, SortedMap<Key, Value> tabletsKeyValues) { Text row = extent.getMetadataEntry(); for (Entry<Key, Value> entry : tabletsKeyValues.entrySet()) { Key key = entry.getKey(); if (key.getRow().equals(row) && TabletsSection.ServerColumnFamily.FLUSH_COLUMN .equals(key.getColumnFamily(), key.getColumnQualifier())) return Long.parseLong(entry.getValue().toString()); }/*from w ww . ja v a 2s .c o m*/ return -1; }
From source file:org.apache.accumulo.server.tabletserver.Tablet.java
private static long lookupCompactID(KeyExtent extent, SortedMap<Key, Value> tabletsKeyValues) { Text row = extent.getMetadataEntry(); for (Entry<Key, Value> entry : tabletsKeyValues.entrySet()) { Key key = entry.getKey(); if (key.getRow().equals(row) && TabletsSection.ServerColumnFamily.COMPACT_COLUMN .equals(key.getColumnFamily(), key.getColumnQualifier())) return Long.parseLong(entry.getValue().toString()); }//www. j av a 2 s.c o m return -1; }