AttractionPoint.java 2.88 KB
Newer Older
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * PeerfactSim.KOM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package de.tud.kom.p2psim.impl.topology.movement.modular.attraction;

import java.util.Random;

import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.PositionListener;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.NotSupportedException;
import de.tudarmstadt.maki.simonstrator.api.Randoms;

/**
 * This is the implementation of a AttractionPoint, which implements the
 * {@link MovementSupported} interface. So a {@link AttractionPoint} has the
 * ability to be moved.
 * 
 * @author Christoph Muenker
 * @version 1.0, 02.07.2013
 */
public class AttractionPoint implements MovementSupported {
	protected static Random rnd = Randoms.getRandom(AttractionPoint.class);

	private PositionVector posVec;

	private double minSpeed;

	private double maxSpeed;

	public AttractionPoint(PositionVector posVec, double minSpeed,
			double maxSpeed) {
		this.posVec = posVec;

		this.minSpeed = minSpeed;
		this.maxSpeed = maxSpeed;
	}

	@Override
	public PositionVector getRealPosition() {
		return posVec;
	}

	@Override
	public void positionChanged() {
		// needed?
	}

	@Override
	public void addPositionListener(PositionListener listener) {
		throw new NotSupportedException();
	}

	@Override
	public void removePositionListener(PositionListener listener) {
		throw new NotSupportedException();
	}

	@Override
	public void addMovementListener(MovementListener listener) {
		throw new NotSupportedException();
	}

	@Override
	public void removeMovementListener(MovementListener listener) {
		throw new NotSupportedException();
	}

	@Override
	public boolean movementActive() {
		return true;
	}

	@Override
	public double getMinMovementSpeed() {
		return minSpeed;
	}

	@Override
	public double getMaxMovementSpeed() {
		return maxSpeed;
	}

	@Override
	public double getMovementSpeed() {
		double min_speed;
		double max_speed;

		min_speed = getMinMovementSpeed();
		max_speed = getMaxMovementSpeed();

		double value = rnd.nextDouble();
		double speed = (value * (max_speed - min_speed)) + min_speed;
		return speed;
	}

}