Java Code Examples for java.util.Collections.unmodifiableMap()

The following are Jave code examples for showing how to use unmodifiableMap() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: ImmutableMap.java   View Source Code Vote up 6 votes
public static <K, V> Map<K, V> of(
    K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
  Map<K, V> map = new HashMap<>(5);
  map.put(k1, v1);
  map.put(k2, v2);
  map.put(k3, v3);
  map.put(k4, v4);
  map.put(k5, v5);
  return Collections.unmodifiableMap(map);
}
 
Example 2
Project: apache-tomcat-7.0.73-with-comment   File: TestMapELResolver.java   View Source Code Vote up 5 votes
/**
 * Tests that the readOnly is true always when the map is not modifiable.
 */
@Test
public void testIsReadOnly04() {
    MapELResolver mapELResolver = new MapELResolver();
    ELContext context = new ELContextImpl();

    Map<Object, Object> map = Collections
            .unmodifiableMap(new HashMap<Object, Object>());
    boolean result = mapELResolver.isReadOnly(context, map, new Object());

    Assert.assertTrue(result);
    Assert.assertTrue(context.isPropertyResolved());
}
 
Example 3
Project: luna   File: Code.java   View Source Code Vote up 5 votes
private static Map<Label, BasicBlock> index(Iterable<BasicBlock> blocks) {
  Map<Label, BasicBlock> result = new HashMap<>();
  for (BasicBlock b : blocks) {
    result.put(b.label(), b);
  }
  return Collections.unmodifiableMap(result);
}
 
Example 4
Project: iTAP-controller   File: OFSwitch.java   View Source Code Vote up 5 votes
/**
 * Set the internal data structure storing this switch's port
 * to the ports specified by newPortsByNumber
 *
 * CALLER MUST HOLD WRITELOCK
 *
 * @param newPortsByNumber
 * @throws IllegaalStateException if called without holding the
 * writelock
 */
private void updatePortsWithNewPortsByNumber(
		Map<OFPort,OFPortDesc> newPortsByNumber) {
	if (!lock.writeLock().isHeldByCurrentThread()) {
		throw new IllegalStateException("Method called without " +
				"holding writeLock");
	}
	Map<String,OFPortDesc> newPortsByName =
			new HashMap<String, OFPortDesc>();
	List<OFPortDesc> newPortList =
			new ArrayList<OFPortDesc>();
	List<OFPortDesc> newEnabledPortList =
			new ArrayList<OFPortDesc>();
	List<OFPort> newEnabledPortNumbers = new ArrayList<OFPort>();

	for(OFPortDesc p: newPortsByNumber.values()) {
		newPortList.add(p);
		newPortsByName.put(p.getName().toLowerCase(), p);
		if (!p.getState().contains(OFPortState.LINK_DOWN) 
				&& !p.getConfig().contains(OFPortConfig.PORT_DOWN)) {
			newEnabledPortList.add(p);
			newEnabledPortNumbers.add(p.getPortNo());
		}
	}
	portsByName = Collections.unmodifiableMap(newPortsByName);
	portsByNumber =
			Collections.unmodifiableMap(newPortsByNumber);
	enabledPortList =
			Collections.unmodifiableList(newEnabledPortList);
	enabledPortNumbers =
			Collections.unmodifiableList(newEnabledPortNumbers);
	portList = Collections.unmodifiableList(newPortList);
}
 
Example 5
Project: elasticsearch_my   File: ThreadContext.java   View Source Code Vote up 5 votes
/**
 * Get a copy of all <em>response</em> headers.
 *
 * @return Never {@code null}.
 */
public Map<String, List<String>> getResponseHeaders() {
    Map<String, List<String>> responseHeaders = threadLocal.get().responseHeaders;
    HashMap<String, List<String>> map = new HashMap<>(responseHeaders.size());

    for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) {
        map.put(entry.getKey(), Collections.unmodifiableList(entry.getValue()));
    }

    return Collections.unmodifiableMap(map);
}
 
Example 6
Project: Equella   File: StandardJavascriptLibrary.java   View Source Code Vote up 5 votes
public StandardJavascriptLibrary()
{
	List<JavascriptModule> modules = new ArrayList<JavascriptModule>();
	modules.add(new StandardModule());
	modules.add(new JSONModule());
	modules.add(new SelectModule());

	Map<String, JavascriptModule> tempModuleMap = new HashMap<String, JavascriptModule>();
	for( JavascriptModule module : modules )
	{
		tempModuleMap.put(module.getId(), module);
	}
	moduleMap = Collections.unmodifiableMap(tempModuleMap);
}
 
Example 7
Project: openNaEF   File: Notify.java   View Source Code Vote up 5 votes
public Notify(Type type, long notifyTime, DtoChanges dtoChanges, URL url, Map<String, Object> json) {
    _type = type;
    _notifyTime = notifyTime;
    _targetVersion = dtoChanges.getTargetVersion().toString();
    _targetTime = dtoChanges.getTargetTime();
    _dtoChanges = Collections.unmodifiableMap(json);
    _uri = url.toString();
    _rawDtoChanges = dtoChanges;
}
 
Example 8
Project: jdk8u-jdk   File: SystemFlavorMap.java   View Source Code Vote up 5 votes
/**
 * An accessor to textTypeToNative map.  Since we use lazy initialization we
 * must use this accessor instead of direct access to the field which may not
 * be initialized yet. This method will initialize the field if needed.
 *
 * @return textTypeToNative
 */
private synchronized Map<String, LinkedHashSet<String>> getTextTypeToNative() {
    if (!isMapInitialized) {
        initSystemFlavorMap();
        // From this point the map should not be modified
        textTypeToNative = Collections.unmodifiableMap(textTypeToNative);
    }
    return textTypeToNative;
}
 
Example 9
Project: sqlfiles   File: SqlParser.java   View Source Code Vote up 5 votes
/**
 * Parse specified sql template to immutable map of templates. Name of template is a key for map.
 * @param text template
 * @return map with (template.name, template) entries.
 * @throws IOException
 */
public Map<String, SqlTemplate> parseToMap(Reader text) throws IOException {
    Map<String, SqlTemplate> map = new HashMap<>();
    parse(text, (template) -> {
        map.put(template.getName(), template);
    });
    return Collections.unmodifiableMap(map);
}
 
Example 10
Project: sstore-soft   File: FieldSet.java   View Source Code Vote up 4 votes
/**
 * Get a simple map containing all the fields.
 */
public Map<FieldDescriptorType, Object> getAllFields() {
  return Collections.unmodifiableMap(fields);
}
 
Example 11
Project: JavaGraph   File: AttrNode.java   View Source Code Vote up 4 votes
/** Returns an unmodifiable view on the string-to-string map of additional attributes. */
public Map<String,String> getAttributes() {
    return Collections.unmodifiableMap(this.attributeMap);
}
 
Example 12
Project: TOSCAna   File: PropertyInstance.java   View Source Code Vote up 4 votes
public Map<String, String> getPropertyValues() {
    return Collections.unmodifiableMap(propertyValues);
}
 
Example 13
Project: aws-sdk-java-v2   File: StandardBeanProperties.java   View Source Code Vote up 4 votes
private Beans(TableMap<T> annotations, Map<String, Bean<T, Object>> map) {
    this.properties = new DynamoDbMapperTableModel.Properties.Immutable<T>(annotations);
    this.map = Collections.unmodifiableMap(map);
}
 
Example 14
Project: OpenJSharp   File: Compiler.java   View Source Code Vote up 4 votes
Map<String, byte[]> getBytecode() {
    return Collections.unmodifiableMap(bytecode);
}
 
Example 15
Project: bibliome-java-utils   File: YateaHandler.java   View Source Code Vote up 4 votes
public Map<String, TermCandidate> getTermCandidates() {
	return Collections.unmodifiableMap(termCandidates);
}
 
Example 16
Project: xmlrss   File: GSRSSSignatureOutput.java   View Source Code Vote up 4 votes
public Map<ByteArray, byte[]> getParts() {
    return Collections.unmodifiableMap(signedParts);
}
 
Example 17
Project: GitHub   File: ImmutableMap.java   View Source Code Vote up 4 votes
public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2) {
  Map<K, V> map = new HashMap<>(2);
  map.put(k1, v1);
  map.put(k2, v2);
  return Collections.unmodifiableMap(map);
}
 
Example 18
Project: helper   File: SimpleScriptRegistry.java   View Source Code Vote up 4 votes
@Nonnull
@Override
public Map<Path, Script> getAll() {
    return Collections.unmodifiableMap(scripts);
}
 
Example 19
Project: CorePatch   File: DefaultDeflateCompressionDiviner.java   View Source Code Vote up 3 votes
/**
 * Returns an unmodifiable map whose keys are deflate strategies and whose values are the levels
 * that make sense to try with the corresponding strategy, in the recommended testing order.
 *
 * <ul>
 *   <li>For strategy 0, levels 1 through 9 (inclusive) are included.
 *   <li>For strategy 1, levels 4 through 9 (inclusive) are included. Levels 1, 2 and 3 are
 *       excluded because they behave the same under strategy 0.
 *   <li>For strategy 2, only level 1 is included because the level is ignored under strategy 2.
 * </ul>
 *
 * @return such a mapping
 */
private static Map<Integer, List<Integer>> getLevelsByStrategy() {
  final Map<Integer, List<Integer>> levelsByStrategy = new HashMap<>();
  // The best order for the levels is simply the order of popularity in the world, which is
  // expected to be default (6), maximum compression (9), and fastest (1).
  // The rest of the levels are rarely encountered and their order is mostly irrelevant.
  levelsByStrategy.put(0, Collections.unmodifiableList(Arrays.asList(6, 9, 1, 4, 2, 3, 5, 7, 8)));
  levelsByStrategy.put(1, Collections.unmodifiableList(Arrays.asList(6, 9, 4, 5, 7, 8)));
  // Strategy 2 does not have the concept of levels, so vacuously call it 1.
  levelsByStrategy.put(2, Collections.singletonList(1));
  return Collections.unmodifiableMap(levelsByStrategy);
}
 
Example 20
Project: openjdk-jdk10   File: HotSpotVMConfigStore.java   View Source Code Vote up 2 votes
/**
 * Gets the C++ fields exposed by this object.
 *
 * @return an unmodifiable map from VM field names to {@link VMField} objects
 */
public Map<String, VMField> getFields() {
    return Collections.unmodifiableMap(vmFields);
}