Commit b473db0c authored by Tobias Meuser's avatar Tobias Meuser
Browse files

First working version of privacy-sensitive communication

parent 0a1cfdb4
......@@ -61,4 +61,8 @@ public class PrivacyComponent implements HostComponent {
public PrivacyLevel getPrivacyLevel() {
return _privacy;
}
public void setPrivacyLevel(PrivacyLevel pPrivacy) {
_privacy = pPrivacy;
}
}
......@@ -35,6 +35,8 @@ public class PrivacyComponentFactory implements HostComponentFactory {
private double _sum = 0;
private Random _random = Randoms.getRandom(getClass());
private double[] _ratio;
@Override
public HostComponent createComponent(Host pHost) {
PrivacyLevel level = PrivacyLevel.NO_PRIVACY;
......@@ -53,11 +55,19 @@ public class PrivacyComponentFactory implements HostComponentFactory {
return privacyComponent;
}
public void setPrivacyFrequency(PrivacyLevelFrequency pPrivacyLevel) {
_levels.add(pPrivacyLevel);
_sum += pPrivacyLevel.getProbability();
public void setRatio(String pRatio) {
String[] split = pRatio.split("-");
_ratio = new double[split.length];
for (int i = 0; i < split.length; i++) {
_ratio[i] = Double.valueOf(split[i]);
_sum += _ratio[i];
}
}
public void setPrivacy(PrivacyLevel pPrivacyLevel) {
_levels.add(new PrivacyLevelFrequency(pPrivacyLevel, _ratio[_levels.size()]));
PrivacyLevel.PRIVACY_LEVELS.add(pPrivacyLevel.getLevel());
PrivacyLevel.PRIVACY_LEVELS.add(pPrivacyLevel);
}
public static class PrivacyLevelFrequency {
......
......@@ -30,8 +30,8 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> {
}
imprecisionAreaRadius = pImprecisionAreaRadius;
String[] responsibilityLevels;
if (responsibility.contains(";")) {
responsibilityLevels = responsibility.split(";");
if (responsibility.trim().length() > 0) {
responsibilityLevels = responsibility.trim().split(";");
} else {
responsibilityLevels = new String[0];
}
......@@ -41,6 +41,17 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> {
}
}
public String getResponsibility() {
StringBuffer result = new StringBuffer();
for (int i = 0; i < responsibility.length; i++) {
if (i != 0) {
result.append(";");
}
result.append(responsibility[i]);
}
return result.toString();
}
public int getId() {
return id;
}
......@@ -77,6 +88,10 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> {
@Override
public int compareTo(PrivacyLevel pArg0) {
return Double.compare(imprecisionAreaRadius, pArg0.getImprecisionAreaRadius());
int compare = Double.compare(imprecisionAreaRadius, pArg0.getImprecisionAreaRadius());
if (compare == 0) {
compare = Double.compare(id, pArg0.getId());
}
return compare;
}
}
......@@ -38,6 +38,15 @@ public class DeterministicExponentialLifetimeDistribution implements LifetimeDis
_percentile = pPercentile;
}
@XMLConfigurableConstructor({ "duration" })
public DeterministicExponentialLifetimeDistribution(long pEventDuration) {
_averageEventDuration = pEventDuration;
_existProbability = 1 - 1 / (double) (pEventDuration / Time.SECOND);
_percentile = 0.5;
}
@Override
public long getLifetime() {
return (long) Math.ceil(Math.log(_percentile) / Math.log(_existProbability)) * Time.SECOND;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment