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

com.mugui.base.client.net.cache.CacheMessage Maven / Gradle / Ivy

The newest version!
package com.mugui.base.client.net.cache;



import com.mugui.base.base.ApplicationContext;
import com.mugui.base.base.Component;
import com.mugui.base.client.net.base.Cache;
import com.mugui.base.client.net.base.ManagerInterface;
import com.mugui.base.client.net.classutil.DataSave;

import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;



@Component
public class CacheMessage implements ManagerInterface {
	private static HashMap map = null;

	public void init() {
		clear();
		map = new HashMap<>();
	}

	public Set> entrySet() {
		return map.entrySet();
	}

	private ApplicationContext applicationContext = null;

	@Override
	public boolean init(Object object) {
		Class name = (Class) object;
		init();
		applicationContext = (ApplicationContext) DataSave.context;
		for (Class class_name : DataSave.initClassList(name)) {
			if (class_name.isAnnotationPresent(Cache.class)) {
				Cache filter = class_name.getAnnotation(Cache.class);
				map.put(filter.hashCode() + "", (CacheModel) applicationContext.getBean(class_name));
			}
		}

		return false;
	}

	@Override
	public boolean clear() {
		if (map != null)
			map.clear();
		return true;
	}

	@Override
	public boolean is(String name) {
		if (map == null) {
			throw new NullPointerException("please run init");
		}
		return !map.isEmpty() && map.get(name) != null;
	}

	@Override
	public CacheModel del(String name) {
		if (map == null) {
			throw new NullPointerException("please run init");
		}
		return map.remove(name);
	}

	@Override
	public CacheModel get(String name) {
		if (map == null) {
			throw new NullPointerException("please run init");
		}
		return map.get(name);
	}

	@Override
	public boolean add(String name, CacheModel object) {
		if (map == null) {
			throw new NullPointerException("please run init");
		}
		return true;
	}

	@Override
	public boolean isInit() {
		// TODO Auto-generated method stub
		return false;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy