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

aQute.launcher.LauncherSystemProperties Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
package aQute.launcher;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

class LauncherSystemProperties extends Properties {
	private static final long			serialVersionUID	= 1L;
	private final Map	userSet				= new HashMap<>();

	LauncherSystemProperties(Properties... properties) {
		for (Properties p : properties) {
			for (Map.Entry e : p.entrySet()) {
				super.put(e.getKey(), e.getValue());
			}
		}
		Properties sysProps = System.getProperties();
		if (sysProps instanceof LauncherSystemProperties) {
			synchronized (sysProps) {
				for (Map.Entry e : ((LauncherSystemProperties) sysProps).userSet.entrySet()) {
					Object key = e.getKey();
					Object value = e.getValue();
					if (value != null) {
						put(key, value);
					} else {
						remove(key);
					}
				}
			}
		}
	}

	@Override
	public synchronized Object put(Object key, Object value) {
		Object existing = super.put(key, value);
		userSet.put(key, value);
		return existing;
	}

	@Override
	public synchronized Object remove(Object key) {
		Object existing = super.remove(key);
		if (existing != null) {
			userSet.put(key, null);
		}
		return existing;
	}

	@Override
	public synchronized void clear() {
		super.clear();
		userSet.clear();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy