Skip to content

Commit

Permalink
#339 Refactoring of BasicStatisticValue: Having an abstract class wit…
Browse files Browse the repository at this point in the history
…h subclasses for the individual types now.
  • Loading branch information
tabergma committed Feb 12, 2016
1 parent 466bf4f commit 8ac399b
Show file tree
Hide file tree
Showing 23 changed files with 614 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import de.metanome.algorithm_integration.result_receiver.ColumnNameMismatchException;
import de.metanome.algorithm_integration.result_receiver.CouldNotReceiveResultException;
import de.metanome.algorithm_integration.result_receiver.OmniscientResultReceiver;
import de.metanome.algorithm_integration.results.basic_statistic_values.BasicStatisticValue;

import javax.xml.bind.annotation.XmlTransient;
import java.util.HashMap;
Expand All @@ -38,23 +39,23 @@ public class BasicStatistic implements Result {
private static final long serialVersionUID = -8010850754433867718L;

protected ColumnCombination columnCombination;
protected Map<String, BasicStatisticValue> statisticName2Value;
protected Map<String, BasicStatisticValue> statisticMap;

/**
* Exists for serialization.
*/
protected BasicStatistic() {
this.columnCombination = new ColumnCombination();
this.statisticName2Value = new HashMap<>();
this.statisticMap = new HashMap<>();
}

public BasicStatistic(ColumnIdentifier... columnIdentifier) {
this.columnCombination = new ColumnCombination(columnIdentifier);
this.statisticName2Value = new HashMap<>();
this.statisticMap = new HashMap<>();
}

public void addStatistic(String statisticName, BasicStatisticValue statisticValue) {
this.statisticName2Value.put(statisticName, statisticValue);
this.statisticMap.put(statisticName, statisticValue);
}

/**
Expand All @@ -68,12 +69,12 @@ public void setColumnCombination(ColumnCombination columnCombination) {
this.columnCombination = columnCombination;
}

public Map<String, BasicStatisticValue> getStatisticName2Value() {
return statisticName2Value;
public Map<String, BasicStatisticValue> getStatisticMap() {
return statisticMap;
}

public void setStatisticName2Value(Map<String, BasicStatisticValue> statisticName2Value) {
this.statisticName2Value = statisticName2Value;
public void setStatisticMap(Map<String, BasicStatisticValue> statisticMap) {
this.statisticMap = statisticMap;
}

@Override
Expand All @@ -87,7 +88,7 @@ public void sendResultTo(OmniscientResultReceiver resultReceiver)
public String toString() {
String str = columnCombination.toString() + COLUMN_VALUE_SEPARATOR;

for (Map.Entry<String, BasicStatisticValue> entry : this.statisticName2Value.entrySet()) {
for (Map.Entry<String, BasicStatisticValue> entry : this.statisticMap.entrySet()) {
str += entry.getKey() + NAME_COLUMN_SEPARATOR + entry.getValue() + STATISTIC_SEPARATOR;
}

Expand All @@ -100,7 +101,7 @@ public int hashCode() {
int result = 1;
result = prime * result + ((columnCombination == null) ? 0 : columnCombination.hashCode());
result = prime * result
+ ((this.statisticName2Value.isEmpty()) ? 0 : this.statisticName2Value.hashCode());
+ ((this.statisticMap.isEmpty()) ? 0 : this.statisticMap.hashCode());
return result;
}

Expand All @@ -123,7 +124,7 @@ public boolean equals(Object obj) {
} else if (!columnCombination.equals(other.columnCombination)) {
return false;
}
if (!this.statisticName2Value.equals(other.statisticName2Value)) {
if (!this.statisticMap.equals(other.statisticMap)) {
return false;
}
return true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2016 by the Metanome project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.metanome.algorithm_integration.results.basic_statistic_values;


import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
* Represents the abstract value of a basic statistic result.
* @param <T> The type of the value.
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = BasicStatisticValueDouble.class, name = "BasicStatisticValueDouble"),
@JsonSubTypes.Type(value = BasicStatisticValueFloat.class, name = "BasicStatisticValueFloat"),
@JsonSubTypes.Type(value = BasicStatisticValueInteger.class, name = "BasicStatisticValueInteger"),
@JsonSubTypes.Type(value = BasicStatisticValueString.class, name = "BasicStatisticValueString"),
@JsonSubTypes.Type(value = BasicStatisticValueLong.class, name = "BasicStatisticValueLong"),
@JsonSubTypes.Type(value = BasicStatisticValueStringList.class, name = "BasicStatisticValueStringList"),
@JsonSubTypes.Type(value = BasicStatisticValueIntegerList.class, name = "BasicStatisticValueIntegerList"),
})
public abstract class BasicStatisticValue<T> implements Comparable {

protected T value;

// Exists for serialization
public BasicStatisticValue() {}

public BasicStatisticValue(T value) {
this.value = value;
}

public T getValue() {
return value;
}

public void setValue(T value) {
this.value = value;
}

@Override
public abstract String toString();

@Override
public abstract int hashCode();

@Override
public abstract boolean equals(Object obj);

@Override
public abstract int compareTo(Object o);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2016 by the Metanome project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.metanome.algorithm_integration.results.basic_statistic_values;


import com.fasterxml.jackson.annotation.JsonTypeName;

/**
* Represents a double value for a basic statistic.
*/
@JsonTypeName("BasicStatisticValueDouble")
public class BasicStatisticValueDouble extends BasicStatisticValue<Double> implements Comparable {

public BasicStatisticValueDouble() {
super();
}

public BasicStatisticValueDouble(Double value) {
super(value);
}

@Override
public String toString() {
return this.value.toString();
}

@Override
public int hashCode() {
return this.value.hashCode();
}

@Override
public boolean equals(Object obj) {
return obj instanceof BasicStatisticValueDouble && this.value.equals(((BasicStatisticValueDouble) obj).getValue());
}

@Override
public int compareTo(Object o) {
if (o instanceof BasicStatisticValueDouble) {
BasicStatisticValueDouble other = (BasicStatisticValueDouble) o;
return (other.getValue()).compareTo(this.value);
}
return -1;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2016 by the Metanome project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.metanome.algorithm_integration.results.basic_statistic_values;


import com.fasterxml.jackson.annotation.JsonTypeName;

/**
* Represents a float value for a basic statistic.
*/
@JsonTypeName("BasicStatisticValueFloat")
public class BasicStatisticValueFloat extends BasicStatisticValue<Float> implements Comparable {

public BasicStatisticValueFloat() {
super();
}

public BasicStatisticValueFloat(Float value) {
super(value);
}

@Override
public String toString() {
return this.value.toString();
}

@Override
public int hashCode() {
return this.value.hashCode();
}

@Override
public boolean equals(Object obj) {
return obj instanceof BasicStatisticValueFloat && this.value.equals(((BasicStatisticValueFloat) obj).getValue());
}

@Override
public int compareTo(Object o) {
if (o instanceof BasicStatisticValueFloat) {
BasicStatisticValueFloat other = (BasicStatisticValueFloat) o;
return (other.getValue()).compareTo(this.value);
}
return -1;
}

}
Loading

0 comments on commit 8ac399b

Please sign in to comment.