List of usage examples for java.util Collections unmodifiableSortedMap
public static <K, V> SortedMap<K, V> unmodifiableSortedMap(SortedMap<K, ? extends V> m)
From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java
/** * Creates a new instance using the provided information. * * @param protocol the {@link Protocol} for the new instance. Use * {@code null} for "any"./*from w ww .j a v a 2 s .com*/ * @param network the network for the new instance. Use {@code null} or * blank for "any". * @param mimeType the mime-type for the new instance. Use {@code null} or * {@link MimeType#ANYANY} for "any". * @param attributes an {@link EnumMap} with {@link DLNAAttribute}s for the * new instance. */ public ProtocolInfo(Protocol protocol, String network, MimeType mimeType, EnumMap<DLNAAttribute.Type, DLNAAttribute<?>> attributes) { this.protocol = protocol == null ? Protocol.ALL : protocol; this.network = isBlank(network) ? WILDCARD : network; this.mimeType = mimeType == null ? MimeType.ANYANY : mimeType; this.attributes = Collections.unmodifiableSortedMap(dlnaAttributesToAttributes(attributes)); this.attributesString = generateAttributesString(); this.additionalInfo = this.attributesString; this.stringValue = generateStringValue(); }
From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java
/** * Creates a new instance based on a {@link DLNAProfiles} profile. * * @param protocol the {@link Protocol} for the new instance. * @param profile the {@link DLNAProfiles} profile for the new instance. *///from w w w . j av a2 s.co m public ProtocolInfo(Protocol protocol, DLNAProfiles profile) { this.protocol = protocol == null ? Protocol.ALL : protocol; this.network = WILDCARD; this.mimeType = createMimeType(profile.getContentFormat()); SortedMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> tmpAttributes = createEmptyAttributesMap(); DLNAOrgProfileName profileName = DLNAOrgProfileName.FACTORY.createProfileName(profile.getCode()); tmpAttributes.put(profileName.getName(), profileName); this.attributes = Collections.unmodifiableSortedMap(tmpAttributes); this.attributesString = generateAttributesString(); this.additionalInfo = this.attributesString; this.stringValue = generateStringValue(); }
From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java
/** * Creates a new instance based on a {@link DLNAProfiles} profile and * additional {@link DLNAAttribute}s.//from w ww . jav a 2s . c om * * @param protocol the {@link Protocol} for the new instance. * @param profile the {@link DLNAProfiles} profile for the new instance. * @param dlnaAttributes an {@link EnumMap} with {@link DLNAAttribute}s for * the new instance. */ public ProtocolInfo(Protocol protocol, DLNAProfiles profile, EnumMap<DLNAAttribute.Type, DLNAAttribute<?>> dlnaAttributes) { this.protocol = protocol == null ? Protocol.ALL : protocol; this.network = WILDCARD; this.mimeType = createMimeType(profile.getContentFormat()); TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> tmpAttributes = dlnaAttributesToAttributes( dlnaAttributes); DLNAOrgProfileName profileName = DLNAOrgProfileName.FACTORY.createProfileName(profile.getCode()); tmpAttributes.put(profileName.getName(), profileName); this.attributes = Collections.unmodifiableSortedMap(tmpAttributes); this.attributesString = generateAttributesString(); this.additionalInfo = this.attributesString; this.stringValue = generateStringValue(); }
From source file:hudson.model.Job.java
/** * Gets all the builds in a map. */ public SortedMap<Integer, RunT> getBuildsAsMap() { return Collections.unmodifiableSortedMap(_getRuns()); }
From source file:jenkins.model.Jenkins.java
/** * Obtains the thread dump of all slaves (including the master.) * * <p>//from w w w . j a v a2s. c o m * Since this is for diagnostics, it has a built-in precautionary measure against hang slaves. */ public Map<String, Map<String, String>> getAllThreadDumps() throws IOException, InterruptedException { checkPermission(ADMINISTER); // issue the requests all at once Map<String, Future<Map<String, String>>> future = new HashMap<String, Future<Map<String, String>>>(); for (Computer c : getComputers()) { try { future.put(c.getName(), RemotingDiagnostics.getThreadDumpAsync(c.getChannel())); } catch (Exception e) { LOGGER.info("Failed to get thread dump for node " + c.getName() + ": " + e.getMessage()); } } if (toComputer() == null) { future.put("master", RemotingDiagnostics.getThreadDumpAsync(FilePath.localChannel)); } // if the result isn't available in 5 sec, ignore that. // this is a precaution against hang nodes long endTime = System.currentTimeMillis() + 5000; Map<String, Map<String, String>> r = new HashMap<String, Map<String, String>>(); for (Entry<String, Future<Map<String, String>>> e : future.entrySet()) { try { r.put(e.getKey(), e.getValue().get(endTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS)); } catch (Exception x) { StringWriter sw = new StringWriter(); x.printStackTrace(new PrintWriter(sw, true)); r.put(e.getKey(), Collections.singletonMap("Failed to retrieve thread dump", sw.toString())); } } return Collections.unmodifiableSortedMap(new TreeMap<String, Map<String, String>>(r)); }
From source file:nl.strohalm.cyclos.utils.EntityHelper.java
/** * Returns a Map with basic properties for the given entity *//*ww w . j ava 2 s . c o m*/ public static Map<String, PropertyDescriptor> propertyDescriptorsFor(final Entity entity) { final Class<? extends Entity> clazz = getRealClass(entity); SortedMap<String, PropertyDescriptor> properties = cachedPropertiesByClass.get(clazz); if (properties == null) { properties = new TreeMap<String, PropertyDescriptor>(); final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(clazz); for (final PropertyDescriptor descriptor : propertyDescriptors) { final String name = descriptor.getName(); boolean ok = name.equals("id"); if (!ok) { final Method readMethod = descriptor.getReadMethod(); if (readMethod != null) { final Class<?> declaringClass = readMethod.getDeclaringClass(); ok = !declaringClass.equals(Entity.class) && !declaringClass.equals(CustomFieldsContainer.class); } } if (ok) { properties.put(name, descriptor); } } properties = Collections.unmodifiableSortedMap(properties); cachedPropertiesByClass.put(clazz, properties); } return properties; }
From source file:org.apache.nifi.provenance.MiNiFiPersistentProvenanceRepository.java
private void recover() throws IOException { long maxId = -1L; final List<File> filesToRecover = new ArrayList<>(); for (final File file : configuration.getStorageDirectories()) { final File[] matchingFiles = file.listFiles(new FileFilter() { @Override//from w ww . j a va2 s .c om public boolean accept(final File pathname) { final String filename = pathname.getName(); if (!filename.contains(FILE_EXTENSION) || filename.endsWith(TEMP_FILE_SUFFIX)) { return false; } final String baseFilename = filename.substring(0, filename.indexOf(".")); return NUMBER_PATTERN.matcher(baseFilename).matches(); } }); for (final File matchingFile : matchingFiles) { filesToRecover.add(matchingFile); } } final SortedMap<Long, Path> sortedPathMap = new TreeMap<>(new Comparator<Long>() { @Override public int compare(final Long o1, final Long o2) { return Long.compare(o1, o2); } }); File maxIdFile = null; for (final File file : filesToRecover) { final String filename = file.getName(); final String baseName = filename.substring(0, filename.indexOf(".")); final long fileFirstId = Long.parseLong(baseName); sortedPathMap.put(fileFirstId, file.toPath()); if (fileFirstId > maxId) { maxId = fileFirstId; maxIdFile = file; } } if (maxIdFile != null) { // Determine the max ID in the last file. try (final RecordReader reader = RecordReaders.newRecordReader(maxIdFile, getAllLogFiles(), maxAttributeChars)) { final long eventId = reader.getMaxEventId(); if (eventId > maxId) { maxId = eventId; checkAndSetMaxEventId(maxId); } } catch (final IOException ioe) { logger.error("Failed to read Provenance Event File {} due to {}", maxIdFile, ioe); logger.error("", ioe); } } // Establish current max event ID and increment generator to pick up from this point checkAndSetMaxEventId(maxId); idGenerator.set(maxId + 1); try { final Set<File> recoveredJournals = recoverJournalFiles(); filesToRecover.addAll(recoveredJournals); // Find the file that has the greatest ID File greatestMinIdFile = null; long greatestMinId = 0L; for (final File recoveredJournal : recoveredJournals) { // if the file was removed because the journals were empty, don't count it if (!recoveredJournal.exists()) { continue; } final String basename = StringUtils.substringBefore(recoveredJournal.getName(), "."); try { final long minId = Long.parseLong(basename); sortedPathMap.put(minId, recoveredJournal.toPath()); if (greatestMinIdFile == null || minId > greatestMinId) { greatestMinId = minId; greatestMinIdFile = recoveredJournal; } } catch (final NumberFormatException nfe) { // not a file we care about... } } // Read the records in the last file to find its max id if (greatestMinIdFile != null) { try (final RecordReader recordReader = RecordReaders.newRecordReader(greatestMinIdFile, Collections.<Path>emptyList(), maxAttributeChars)) { maxId = recordReader.getMaxEventId(); } } // set the ID Generator 1 greater than the max id idGenerator.set(maxId + 1); } catch (final IOException ioe) { logger.error("Failed to recover Journal Files due to {}", ioe.toString()); logger.error("", ioe); } idToPathMap.set(Collections.unmodifiableSortedMap(sortedPathMap)); logger.trace("In recovery, path map: {}", sortedPathMap); logger.info("Recovered records"); recoveryFinished.set(true); }
From source file:org.apache.tika.parser.pkg.TikaArchiveStreamFactory.java
public SortedMap<String, ArchiveStreamProvider> getArchiveInputStreamProviders() { if (archiveInputStreamProviders == null) { archiveInputStreamProviders = Collections .unmodifiableSortedMap(findAvailableArchiveInputStreamProviders()); }//from w w w .j a va 2 s. c o m return archiveInputStreamProviders; }
From source file:org.apache.tika.parser.pkg.TikaArchiveStreamFactory.java
public SortedMap<String, ArchiveStreamProvider> getArchiveOutputStreamProviders() { if (archiveOutputStreamProviders == null) { archiveOutputStreamProviders = Collections .unmodifiableSortedMap(findAvailableArchiveOutputStreamProviders()); }//from w ww .j a v a 2s .c om return archiveOutputStreamProviders; }
From source file:org.apache.tika.parser.pkg.TikaCompressorStreamFactory.java
public SortedMap<String, CompressorStreamProvider> getCompressorInputStreamProviders() { if (compressorInputStreamProviders == null) { compressorInputStreamProviders = Collections .unmodifiableSortedMap(findAvailableCompressorInputStreamProviders()); }//from w w w .j a v a2 s . c om return compressorInputStreamProviders; }