All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zkoss.bind.impl.AllocUtil Maven / Gradle / Ivy

There is a newer version: 10.0.0-jakarta
Show newest version
/* AllocUtil.java

	Purpose:
		
	Description:
		
	History:
		2014/5/14 Created by henrichen

Copyright (C) 2014 Potix Corporation. All Rights Reserved.
 */
package org.zkoss.bind.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * For ZK-2289, Memory allocation utility.
 * @author henrichen
 * @since 7.0.3
 */
public class AllocUtil {
	public static AllocUtil inst = new AllocUtil();

	/**
	 * Put key, value into the specified map.
	 * @param map the map to be put key, value in.
	 * @param key the key
	 * @param value the value
	 * @return the map
	 */
	public  Map putMap(Map map, K key, V value) {
		if (map == null) {
			map = new HashMap();
		}
		map.put(key, value);
		return map;
	}

	/**
	 * Put key, value into the specified LinkedHashMap.
	 * @param map the LinkedHashMap to be put key, value in.
	 * @param key the key
	 * @param value the value
	 * @return the map
	 */
	public  Map putLinkedHashMap(Map map, K key, V value) {
		if (map == null) {
			map = new LinkedHashMap();
		}
		map.put(key, value);
		return map;
	}

	/**
	 * Prepare a suitable LinkedHashMap that optimize the space.
	 */
	public  Map newLinkedHashMap(int size) {
		return new LinkedHashMap();
	}

	/**
	 * Add value into the specified set.
	 * @param set the set to be add value in
	 * @param value the value
	 * @return the set
	 */
	public  Set addSet(Set set, V value) {
		if (set == null) {
			set = new HashSet();
		}
		set.add(value);
		return set;
	}

	public  Set addLinkedHashSet(Set set, V value) {
		if (set == null) {
			set = new LinkedHashSet();
		}
		set.add(value);
		return set;
	}

	public  Set addWeakIdentityHashSet(Set set, V value) {
		if (set == null) {
			set = new WeakIdentityMap().keySet();
		}
		set.add(value);
		return set;
	}

	/**
	 * Add value into the spcified list.
	 * @param list the list to be add value in
	 * @param value the value
	 * @return the list
	 */
	public  List addList(List list, V value) {
		if (list == null) {
			list = new ArrayList();
		}
		list.add(value);
		return list;
	}

	/**
	 * Returns the processed script.
	 * @param script
	 */
	public Object processScript(Object script) {
		return script;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy