File: ParameterValues.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (57 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package tim.prune.function.compress;

import java.util.HashMap;

import tim.prune.config.ParamSet;
import tim.prune.function.compress.methods.CompressionMethod;

public class ParameterValues extends HashMap<CompressionMethodType, String>
{
	public ParameterValues()
	{
		put(CompressionMethodType.NEARBY_WITH_FACTOR, "200");
		put(CompressionMethodType.WACKY_POINTS, "2");
		put(CompressionMethodType.SINGLETONS, "2");
		put(CompressionMethodType.DOUGLAS_PEUCKER, "2000");
		put(CompressionMethodType.NEARBY_WITH_DISTANCE, "10");
		put(CompressionMethodType.TOO_SLOW, "2");
		put(CompressionMethodType.TOO_FAST, "40");
		put(CompressionMethodType.TIME_DIFFERENCE, "20");
	}

	public void applyNewStyleConfig(String inConfigString)
	{
		for (CompressionMethod method : MethodList.fromConfigString(inConfigString))
		{
			if (method != null && method.getType() != CompressionMethodType.DUPLICATES) {
				applyParameter(method.getType(), method.getParam());
			}
		}
	}

	public void applyOldStyleConfig(String inConfigString)
	{
		ParamSet params = new ParamSet(inConfigString);
		final CompressionMethodType[] allTypes = new CompressionMethodType[] {
			CompressionMethodType.DUPLICATES,
			CompressionMethodType.NEARBY_WITH_FACTOR, CompressionMethodType.WACKY_POINTS,
			CompressionMethodType.SINGLETONS, CompressionMethodType.DOUGLAS_PEUCKER
		};
		for (int i=1; i<allTypes.length; i++) {
			applyParameter(allTypes[i], params.getParam(i));
		}
	}

	/** Overwrite the default value with the value read from the config */
	private void applyParameter(CompressionMethodType inMethod, String inParam)
	{
		if (inParam != null && !inParam.isEmpty()) {
			put(inMethod, inParam);
		}
	}

	/** @return the value for the given method, or an empty string */
	public String getValue(CompressionMethodType inType) {
		return getOrDefault(inType, "");
	}
}