Java Code Examples for java.util.Collections#unmodifiableSortedMap()

The following examples show how to use java.util.Collections#unmodifiableSortedMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricRegistryImpl.java    From metrics with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends Metric> SortedMap<MetricName, T> getMetrics(Class<T> klass, MetricFilter filter) {
    final TreeMap<MetricName, T> timers = new TreeMap<MetricName, T>();
    for (Map.Entry<MetricName, Metric> entry : metrics.entrySet()) {
        if (klass.isInstance(entry.getValue()) && filter.matches(entry.getKey(),
                entry.getValue())) {
            timers.put(entry.getKey(), (T) entry.getValue());
        } else if (entry.getValue() instanceof DynamicMetricSet) {
            for (Map.Entry<MetricName, Metric> dynamicEntry:
                    ((DynamicMetricSet) entry.getValue()).getDynamicMetrics().entrySet()) {
                if (klass.isInstance(dynamicEntry.getValue()) &&
                        filter.matches(dynamicEntry.getKey(), dynamicEntry.getValue())) {
                    timers.put(dynamicEntry.getKey(), (T) dynamicEntry.getValue());
                }
            }
        }
    }
    return Collections.unmodifiableSortedMap(timers);
}
 
Example 2
Source File: OldCollectionsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
 */
public void test_unmodifiableSortedMapLjava_util_SortedMap() {
    try {
        // Regression for HARMONY-93
        Collections.unmodifiableSortedMap(null);
        fail("Assert 0: unmodifiableSortedMap(null) must throw NPE");
    } catch (NullPointerException e) {
        // expected
    }
}
 
Example 3
Source File: ModifyContextImpl.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public ModifyContextImpl ( final String channelId, final BlobStore store, final CacheStore cacheStore, final ChannelState state, final Map<String, String> aspectStates, final Map<String, ArtifactInformation> artifacts, final Map<MetaKey, CacheEntryInformation> cacheEntries, final Map<MetaKey, String> extractedMetaData, final Map<MetaKey, String> providedMetaData )
{
    Objects.requireNonNull ( channelId );
    Objects.requireNonNull ( store );
    Objects.requireNonNull ( cacheStore );

    this.channelId = channelId;

    this.store = store;
    this.cacheStore = cacheStore;

    this.state = new Builder ( state );

    // main collections

    this.modAspectStates = new TreeMap<> ( aspectStates );
    this.modCacheEntries = new HashMap<> ( cacheEntries );
    this.modArtifacts = new HashMap<> ( artifacts );
    this.modGeneratorArtifacts = this.modArtifacts.values ().stream ().filter ( art -> art.is ( FACET_GENERATOR ) ).collect ( toMap ( ArtifactInformation::getId, a -> a ) );
    this.modExtractedMetadata = new HashMap<> ( extractedMetaData );
    this.modProvidedMetadata = new HashMap<> ( providedMetaData );

    // create unmodifiable collections

    this.aspectStates = Collections.unmodifiableSortedMap ( this.modAspectStates );
    this.cacheEntries = Collections.unmodifiableMap ( this.modCacheEntries );
    this.artifacts = Collections.unmodifiableMap ( this.modArtifacts );
    this.generatorArtifacts = Collections.unmodifiableMap ( this.modGeneratorArtifacts );
    this.extractedMetadata = Collections.unmodifiableMap ( this.modExtractedMetadata );
    this.providedMetadata = Collections.unmodifiableMap ( this.modProvidedMetadata );

    // aspect context

    this.aspectContext = new AspectContextImpl ( this, Activator.getProcessor () );
}
 
Example 4
Source File: Collections2Test.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
 */
public void test_unmodifiableSortedMapLjava_util_SortedMap() {
    try {
        // Regression for HARMONY-93
        Collections.unmodifiableSortedMap(null);
        fail("Assert 0: unmodifiableSortedMap(null) must throw NPE");
    } catch (NullPointerException e) {
        // expected
    }
}
 
Example 5
Source File: TCharset.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public static SortedMap<String, java.nio.charset.Charset> availableCharsets() {
    final TreeMap<String, java.nio.charset.Charset> m =
            new TreeMap<>(
                    String.CASE_INSENSITIVE_ORDER);
    put(standardProvider.charsets(), m);
    return Collections.unmodifiableSortedMap(m);
}
 
Example 6
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static <K, V> Map<K, V> unmodifiableMap(Map<K, ? extends V> map) {
  if (map instanceof SortedMap) {
    return Collections.unmodifiableSortedMap((SortedMap<K, ? extends V>) map);
  } else {
    return Collections.unmodifiableMap(map);
  }
}
 
Example 7
Source File: DayPeriod.java    From Time4A with Apache License 2.0 5 votes vote down vote up
private DayPeriod(
    Locale locale, // optional
    String calendarType,
    SortedMap<PlainTime, String> codeMap
) {
    super();

    this.locale = locale;
    this.calendarType = calendarType;
    this.codeMap = Collections.unmodifiableSortedMap(codeMap);

}
 
Example 8
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static <K, V> Map<K, V> unmodifiableMap(Map<K, ? extends V> map) {
  if (map instanceof SortedMap) {
    return Collections.unmodifiableSortedMap((SortedMap<K, ? extends V>) map);
  } else {
    return Collections.unmodifiableMap(map);
  }
}
 
Example 9
Source File: ChannelInformation.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private ChannelInformation ( final String id, final Set<String> names, final String description, final ChannelState state, final SortedMap<MetaKey, String> metaData, final SortedMap<String, String> aspectStates )
{
    super ( id, names, description );

    this.state = state;
    this.metaData = Collections.unmodifiableSortedMap ( metaData );
    this.aspectStates = Collections.unmodifiableSortedMap ( aspectStates );
}
 
Example 10
Source File: RemotableRadioButtonGroup.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public void setKeyLabels(Map<String, String> keyLabels) {
    if (keyLabels == null || keyLabels.isEmpty()) {
        throw new IllegalArgumentException("keyLabels must be non-null & non-empty");
    }
    // keep previously SortedMaps (such as by sequence number) sorted. 
    if (keyLabels instanceof SortedMap) {
        this.keyLabels = Collections.unmodifiableSortedMap((SortedMap)keyLabels);
    } else {
        this.keyLabels = Collections.unmodifiableMap(new LinkedHashMap<String, String>(keyLabels));
    }
}
 
Example 11
Source File: java_util_Collections_UnmodifiableSortedMap.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.unmodifiableSortedMap(map);
}
 
Example 12
Source File: java_util_Collections_UnmodifiableSortedMap.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getAnotherObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    return Collections.unmodifiableSortedMap(map);
}
 
Example 13
Source File: java_util_Collections_UnmodifiableSortedMap.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.unmodifiableSortedMap(map);
}
 
Example 14
Source File: MetricId.java    From semantic-metrics with Apache License 2.0 4 votes vote down vote up
private MetricId(String key, SortedMap<String, String> tags, boolean isAlreadyUnmodifiable) {
    this.key = key;
    this.tags = isAlreadyUnmodifiable ? tags : Collections.unmodifiableSortedMap(tags);
    this.hash = calculateHashCode(key, tags);
}
 
Example 15
Source File: ConfigPropertyTemplateImpl.java    From Diorite with MIT License 4 votes vote down vote up
@Nullable
@Override
public T get(ConfigPropertyValue<T> propertyValue)
{
    T rawValue = propertyValue.getRawValue();
    if (rawValue == null)
    {
        return null;
    }
    if (this.returnUnmodifiableCollections)
    {
        if (rawValue instanceof Collection)
        {
            if (rawValue instanceof Set)
            {
                if (rawValue instanceof NavigableSet)
                {
                    return (T) Collections.unmodifiableNavigableSet((NavigableSet<?>) rawValue);
                }
                if (rawValue instanceof SortedSet)
                {
                    return (T) Collections.unmodifiableSortedSet((SortedSet<?>) rawValue);
                }
                return (T) Collections.unmodifiableSet((Set<?>) rawValue);
            }
            if (rawValue instanceof List)
            {
                return (T) Collections.unmodifiableList((List<?>) rawValue);
            }
            return (T) Collections.unmodifiableCollection((Collection<?>) rawValue);
        }
        else if (rawValue instanceof Map)
        {
            if (rawValue instanceof NavigableMap)
            {
                return (T) Collections.unmodifiableNavigableMap((NavigableMap<?, ?>) rawValue);
            }
            if (rawValue instanceof SortedMap)
            {
                return (T) Collections.unmodifiableSortedMap((SortedMap<?, ?>) rawValue);
            }
            return (T) Collections.unmodifiableMap((Map<?, ?>) rawValue);
        }
    }
    return rawValue;
}
 
Example 16
Source File: Tables.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public SortedMap<R, Map<C, V>> rowMap() {
  Function<Map<C, V>, Map<C, V>> wrapper = unmodifiableWrapper();
  return Collections.unmodifiableSortedMap(Maps.transformValues(delegate().rowMap(), wrapper));
}
 
Example 17
Source File: Tables.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public SortedMap<R, Map<C, V>> rowMap() {
  Function<Map<C, V>, Map<C, V>> wrapper = unmodifiableWrapper();
  return Collections.unmodifiableSortedMap(Maps.transformValues(delegate().rowMap(), wrapper));
}
 
Example 18
Source File: AspectMapModel.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public SortedMap<String, String> getAspects ()
{
    return Collections.unmodifiableSortedMap ( this.map );
}
 
Example 19
Source File: java_util_Collections_UnmodifiableSortedMap.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected SortedMap<String, String> getObject() {
    SortedMap<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    return Collections.unmodifiableSortedMap(map);
}
 
Example 20
Source File: FilterCapabilities.java    From arctic-sea with Apache License 2.0 2 votes vote down vote up
/**
 * Get temporal operators
 *
 * @return temporal operators
 */
public SortedMap<TimeOperator, SortedSet<QName>> getTemporalOperators() {
    return Collections.unmodifiableSortedMap(temporalOperators);
}