consolidated all Util stuff in com.sap.sse.common.Util now

This commit is contained in:
Axel Uhl committed 2014-06-03 00:01:14 +02:00
1 parent cb9354b1a0
commit 53a0b36e8e
249 files changed
+1646 -1651

No files matched your search

@@ -31,9 +31,9 @@ public interface Color extends Serializable {
final Color BLUE = new RGBColor(0, 0, 255);
com.sap.sse.common.UtilNew.Triple<Integer, Integer, Integer> getAsRGB();
com.sap.sse.common.Util.Triple<Integer, Integer, Integer> getAsRGB();
com.sap.sse.common.UtilNew.Triple<Float, Float, Float> getAsHSV();
com.sap.sse.common.Util.Triple<Float, Float, Float> getAsHSV();
String getAsHtml();
}
@@ -4,8 +4,8 @@ import java.util.Map;
import java.util.Set;
import com.sap.sse.common.Named;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.UtilNew.Pair;
import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Pair;
/**
* Describes sources of official regatta results which may be imported and applied to <code>ScoreCorrection</code>
@@ -21,7 +21,7 @@ public interface ScoreCorrectionProvider extends Named {
* score corrections taken at different times. Later score corrections are expected to be cumulative, meaning they
* also contain all previous corrections.
*/
public Map<String, Set<UtilNew.Pair<String, TimePoint>>> getHasResultsForBoatClassFromDateByEventName() throws Exception;
public Map<String, Set<Util.Pair<String, TimePoint>>> getHasResultsForBoatClassFromDateByEventName() throws Exception;
/**
* @param eventName
@@ -13,7 +13,7 @@ import java.util.UUID;
import com.sap.sailing.domain.common.LeaderboardType;
import com.sap.sailing.domain.common.RegattaAndRaceIdentifier;
import com.sap.sailing.domain.common.ScoringSchemeType;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
public abstract class AbstractLeaderboardDTO implements Serializable {
private static final long serialVersionUID = -205106531931903527L;
@@ -277,12 +277,12 @@ public abstract class AbstractLeaderboardDTO implements Serializable {
return false;
}
public List<UtilNew.Pair<RaceColumnDTO, FleetDTO>> getLiveRaces(long serverTimePointAsMillis) {
List<UtilNew.Pair<RaceColumnDTO, FleetDTO>> result = new ArrayList<UtilNew.Pair<RaceColumnDTO, FleetDTO>>();
public List<Util.Pair<RaceColumnDTO, FleetDTO>> getLiveRaces(long serverTimePointAsMillis) {
List<Util.Pair<RaceColumnDTO, FleetDTO>> result = new ArrayList<Util.Pair<RaceColumnDTO, FleetDTO>>();
for (RaceColumnDTO race : getRaceList()) {
for (FleetDTO fleet : race.getFleets()) {
if (race.isLive(fleet, serverTimePointAsMillis)) {
result.add(new UtilNew.Pair<RaceColumnDTO, FleetDTO>(race, fleet));
result.add(new Util.Pair<RaceColumnDTO, FleetDTO>(race, fleet));
}
}
}
@@ -176,14 +176,14 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
/**
* @param previousVersion needed because after serialization/deserialization, the transient {@link #previousLeaderboard} will be <code>null</code>
*/
public Set<com.sap.sse.common.UtilNew.Pair<CompetitorDTO, K>> getAllUnchangedCompetitorsAndKeys(LeaderboardDTO previousVersion) {
Set<com.sap.sse.common.UtilNew.Pair<CompetitorDTO, K>> result = new HashSet<com.sap.sse.common.UtilNew.Pair<CompetitorDTO,K>>();
public Set<com.sap.sse.common.Util.Pair<CompetitorDTO, K>> getAllUnchangedCompetitorsAndKeys(LeaderboardDTO previousVersion) {
Set<com.sap.sse.common.Util.Pair<CompetitorDTO, K>> result = new HashSet<com.sap.sse.common.Util.Pair<CompetitorDTO,K>>();
for (Map.Entry<K, long[]> raceColumnNameAndBitSet : unchanged.entrySet()) {
final long[] bitset = raceColumnNameAndBitSet.getValue();
if (bitset == null) {
// this means that all entries for the column are unchanged for all competitors
for (CompetitorDTO competitor : previousVersion.competitors) {
result.add(new com.sap.sse.common.UtilNew.Pair<CompetitorDTO, K>(competitor, raceColumnNameAndBitSet.getKey()));
result.add(new com.sap.sse.common.Util.Pair<CompetitorDTO, K>(competitor, raceColumnNameAndBitSet.getKey()));
}
} else {
int competitorNumber = 0;
@@ -191,7 +191,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
long bitValue = 1;
for (int bit=0; bit<Long.SIZE; bit++) {
if ((bitset[arrayIndex] & bitValue) != 0) {
result.add(new com.sap.sse.common.UtilNew.Pair<CompetitorDTO, K>(previousVersion.competitors.get(competitorNumber), raceColumnNameAndBitSet.getKey()));
result.add(new com.sap.sse.common.Util.Pair<CompetitorDTO, K>(previousVersion.competitors.get(competitorNumber), raceColumnNameAndBitSet.getKey()));
}
bitValue <<= 1;
competitorNumber++;
@@ -258,7 +258,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
* @author Axel Uhl (d043530)
*
*/
static class UnchangedLegDetails extends UnchangedWithCompetitorsInBitSet<com.sap.sse.common.UtilNew.Pair<String, Integer>> {
static class UnchangedLegDetails extends UnchangedWithCompetitorsInBitSet<com.sap.sse.common.Util.Pair<String, Integer>> {
private static final long serialVersionUID = 8726138955651801210L;
UnchangedLegDetails() {} // for (de)serialization
@@ -276,7 +276,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
* by <code>null</code>, meaning the race column / leg details are unchnaged for all competitors.
*/
public void compact() {
for (com.sap.sse.common.UtilNew.Pair<String, Integer> key : getAllUnchangedKeys()) {
for (com.sap.sse.common.Util.Pair<String, Integer> key : getAllUnchangedKeys()) {
if (key.getB() != null) {
tryToCompact(key);
}
@@ -289,11 +289,11 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
* or for which all entries in the race column are unchanged.
*/
@Override
protected int getNumberOfSetBits(com.sap.sse.common.UtilNew.Pair<String, Integer> key) {
protected int getNumberOfSetBits(com.sap.sse.common.Util.Pair<String, Integer> key) {
int result;
if (key.getB() != null) {
long[] bitset = getUnchangedBitset(key);
long[] nullBitset = getUnchangedBitset(new com.sap.sse.common.UtilNew.Pair<String, Integer>(key.getA(), null));
long[] nullBitset = getUnchangedBitset(new com.sap.sse.common.Util.Pair<String, Integer>(key.getA(), null));
long[] orBitset = or(bitset, nullBitset);
result = getNumberOfBitsSet(orBitset);
} else {
@@ -412,16 +412,16 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
}
final Set<CompetitorDTO> rowsUnchangedForCompetitors = new HashSet<CompetitorDTO>();
if (rowsUnchanged != null) {
for (com.sap.sse.common.UtilNew.Pair<CompetitorDTO, Void> rowUnchanged : rowsUnchanged.getAllUnchangedCompetitorsAndKeys(previousVersion)) {
for (com.sap.sse.common.Util.Pair<CompetitorDTO, Void> rowUnchanged : rowsUnchanged.getAllUnchangedCompetitorsAndKeys(previousVersion)) {
rowsUnchangedForCompetitors.add(rowUnchanged.getA());
rows.put(rowUnchanged.getA(), previousVersion.rows.get(rowUnchanged.getA()));
}
}
final Set<com.sap.sse.common.UtilNew.Pair<CompetitorDTO, String>> allUnchangedLeaderboardEntriesAsCompetitorsAndColumnNames =
unchangedLeaderboardEntries == null ? new HashSet<com.sap.sse.common.UtilNew.Pair<CompetitorDTO,String>>() :
final Set<com.sap.sse.common.Util.Pair<CompetitorDTO, String>> allUnchangedLeaderboardEntriesAsCompetitorsAndColumnNames =
unchangedLeaderboardEntries == null ? new HashSet<com.sap.sse.common.Util.Pair<CompetitorDTO,String>>() :
unchangedLeaderboardEntries.getAllUnchangedCompetitorsAndKeys(previousVersion);
if (unchangedLeaderboardEntries != null) {
for (com.sap.sse.common.UtilNew.Pair<CompetitorDTO, String> competitorAndColumnName : allUnchangedLeaderboardEntriesAsCompetitorsAndColumnNames) {
for (com.sap.sse.common.Util.Pair<CompetitorDTO, String> competitorAndColumnName : allUnchangedLeaderboardEntriesAsCompetitorsAndColumnNames) {
CompetitorDTO previousCompetitor = competitorAndColumnName.getA();
if (!rowsUnchangedForCompetitors.contains(previousCompetitor)) { // only care if not the entire row was marked unchanged
LeaderboardEntryDTO previousEntry = previousVersion.rows.get(previousCompetitor).fieldsByRaceColumnName.get(
@@ -434,14 +434,14 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
}
}
if (legDetailsUnchanged != null) {
for (com.sap.sse.common.UtilNew.Pair<CompetitorDTO, com.sap.sse.common.UtilNew.Pair<String, Integer>> competitorInPreviosAndColumnNameAndLegDetailsIndex : legDetailsUnchanged
for (com.sap.sse.common.Util.Pair<CompetitorDTO, com.sap.sse.common.Util.Pair<String, Integer>> competitorInPreviosAndColumnNameAndLegDetailsIndex : legDetailsUnchanged
.getAllUnchangedCompetitorsAndKeys(previousVersion)) {
CompetitorDTO previousCompetitor = competitorInPreviosAndColumnNameAndLegDetailsIndex.getA();
final String raceColumnName = competitorInPreviosAndColumnNameAndLegDetailsIndex.getB().getA();
// if it's already clear that the entire LeaderboardEntryDTO was unchanged, the entry in legDetailsUnchanged was
// merely a hint for column compression within legDetailsUnchanged and doesn't need to be handled here
if (!allUnchangedLeaderboardEntriesAsCompetitorsAndColumnNames
.contains(new com.sap.sse.common.UtilNew.Pair<CompetitorDTO, String>(previousCompetitor, raceColumnName))) {
.contains(new com.sap.sse.common.Util.Pair<CompetitorDTO, String>(previousCompetitor, raceColumnName))) {
final LeaderboardRowDTO leaderboardRowDTO = rows.get(previousCompetitor);
LeaderboardEntryDTO leaderboardEntry = leaderboardRowDTO == null ? null
: leaderboardRowDTO.fieldsByRaceColumnName.get(raceColumnName);
@@ -605,7 +605,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
// also mark all leg details for the competitor for this column as unchanged; this will ensure
// that column compression can work for leg details
getLegDetailsUnchanged(previousVersion).unchanged(competitorAndRow.getKey(),
new com.sap.sse.common.UtilNew.Pair<String, Integer>(raceColumnNameAndLeaderboardEntry.getKey(), null));
new com.sap.sse.common.Util.Pair<String, Integer>(raceColumnNameAndLeaderboardEntry.getKey(), null));
} else {
LeaderboardEntryDTO newLeaderboardEntryDTO = new LeaderboardEntryDTO();
cloner.clone(raceColumnNameAndLeaderboardEntry.getValue(), newLeaderboardEntryDTO);
@@ -626,7 +626,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
&& previousVersion.competitors.contains(competitorAndRow.getKey())) {
getLegDetailsUnchanged(previousVersion).unchanged(
competitorAndRow.getKey(),
new com.sap.sse.common.UtilNew.Pair<String, Integer>(raceColumnNameAndLeaderboardEntry.getKey(),
new com.sap.sse.common.Util.Pair<String, Integer>(raceColumnNameAndLeaderboardEntry.getKey(),
legDetailsIndex));
newLeaderboardEntryDTO.legDetails.set(legDetailsIndex, null);
}
@@ -640,7 +640,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
// however, mark the legDetails as unchanged in legDetailsUnchanged so as to allow for
// all-column compression
getLegDetailsUnchanged(previousVersion).unchanged(competitorAndRow.getKey(),
new com.sap.sse.common.UtilNew.Pair<String, Integer>(raceColumnNameAndLeaderboardEntry.getKey(), null));
new com.sap.sse.common.Util.Pair<String, Integer>(raceColumnNameAndLeaderboardEntry.getKey(), null));
}
}
}
@@ -692,7 +692,7 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme
if (row != null && row.fieldsByRaceColumnName != null) {
for (Map.Entry<String, LeaderboardEntryDTO> e : row.fieldsByRaceColumnName.entrySet()) {
getUnchangedLeaderboardEntries(previousVersion).unchanged(competitor, e.getKey());
getLegDetailsUnchanged(previousVersion).unchanged(competitor, new com.sap.sse.common.UtilNew.Pair<String, Integer>(e.getKey(), /* all legs unchanged */ null));
getLegDetailsUnchanged(previousVersion).unchanged(competitor, new com.sap.sse.common.Util.Pair<String, Integer>(e.getKey(), /* all legs unchanged */ null));
}
}
}
@@ -1,14 +1,14 @@
package com.sap.sailing.domain.common.impl;
import com.sap.sailing.domain.common.Color;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
public abstract class AbstractColor implements Color {
private static final long serialVersionUID = 7758884012281863458L;
@Override
public String getAsHtml() {
UtilNew.Triple<Integer, Integer, Integer> asRGB = getAsRGB();
Util.Triple<Integer, Integer, Integer> asRGB = getAsRGB();
return "#" + toBrowserHexValue(asRGB.getA()) + toBrowserHexValue(asRGB.getB())
+ toBrowserHexValue(asRGB.getC());
}
@@ -6,7 +6,7 @@ import java.util.List;
import com.sap.sailing.domain.common.Color;
import com.sap.sailing.domain.common.ColorMap;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
/**
@@ -64,7 +64,7 @@ public class ColorMapImpl<T> implements ColorMap<T> {
public boolean addBlockedColor(Color color) {
boolean result = false;
if(color != null) {
UtilNew.Triple<Float, Float, Float> asHSV = color.getAsHSV();
Util.Triple<Float, Float, Float> asHSV = color.getAsHSV();
result = blockedColors.add(new HSVColor(asHSV.getA(), asHSV.getB(), asHSV.getC()));
}
return result;
@@ -73,7 +73,7 @@ public class ColorMapImpl<T> implements ColorMap<T> {
public boolean removeBlockedColor(Color color) {
boolean result = false;
if(color != null) {
UtilNew.Triple<Float, Float, Float> asHSV = color.getAsHSV();
Util.Triple<Float, Float, Float> asHSV = color.getAsHSV();
result = blockedColors.remove(new HSVColor(asHSV.getA(), asHSV.getB(), asHSV.getC()));
}
return result;
@@ -1,6 +1,6 @@
package com.sap.sailing.domain.common.impl;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
/**
* A color defined in the HSV color schema (hue, saturation, brightness) Hue is a degree between 0.0 and 360.0
@@ -35,7 +35,7 @@ public class HSVColor extends AbstractColor {
}
@Override
public UtilNew.Triple<Integer, Integer, Integer> getAsRGB() {
public Util.Triple<Integer, Integer, Integer> getAsRGB() {
float r, b, g;
if (saturation == 0) {
@@ -80,14 +80,14 @@ public class HSVColor extends AbstractColor {
b = q;
}
}
UtilNew.Triple<Integer, Integer, Integer> RGBColor = new UtilNew.Triple<Integer, Integer, Integer>(Math.round(r * 255),
Util.Triple<Integer, Integer, Integer> RGBColor = new Util.Triple<Integer, Integer, Integer>(Math.round(r * 255),
Math.round(g * 255), Math.round(b * 255));
return RGBColor;
}
@Override
public UtilNew.Triple<Float, Float, Float> getAsHSV() {
return new UtilNew.Triple<Float, Float, Float>(hue, saturation, brightness);
public Util.Triple<Float, Float, Float> getAsHSV() {
return new Util.Triple<Float, Float, Float>(hue, saturation, brightness);
}
@Override
@@ -2,7 +2,7 @@ package com.sap.sailing.domain.common.impl;
import java.net.URLEncoder;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
/**
* This class is used by our backend, in GWT-client code and by the Android app. Therefore we cannot use classes like
@@ -18,7 +18,7 @@ public class QRCodeUtils {
return apkUrl + "#" + fragmentKey + "=" + encodedIdentifier;
}
public static UtilNew.Pair<String, String> splitQRContent(String qrCodeContent) {
public static Util.Pair<String, String> splitQRContent(String qrCodeContent) {
int fragmentIndex = qrCodeContent.lastIndexOf('#');
if (fragmentIndex == -1 || fragmentIndex == 0 || qrCodeContent.length() == fragmentIndex + 1) {
throw new IllegalArgumentException("There is no server or identifier.");
@@ -31,7 +31,7 @@ public class QRCodeUtils {
deviceIdentifier = deviceIdentifier.replaceAll("%20", " ");
String apkUrl = qrCodeContent.substring(0, fragmentIndex);
return new UtilNew.Pair<String, String>(deviceIdentifier, apkUrl);
return new Util.Pair<String, String>(deviceIdentifier, apkUrl);
}
}
@@ -1,6 +1,6 @@
package com.sap.sailing.domain.common.impl;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
/**
* A color defined in the RGB color schema
@@ -66,11 +66,11 @@ public class RGBColor extends AbstractColor {
}
@Override
public UtilNew.Triple<Integer, Integer, Integer> getAsRGB() {
return new UtilNew.Triple<Integer, Integer, Integer>(red, green, blue);
public Util.Triple<Integer, Integer, Integer> getAsRGB() {
return new Util.Triple<Integer, Integer, Integer>(red, green, blue);
}
public UtilNew.Triple<Float, Float, Float> getAsHSV() {
public Util.Triple<Float, Float, Float> getAsHSV() {
float hue, saturation, brightness;
int cmax = (red > green) ? red : green;
if (blue > cmax) {
@@ -107,7 +107,7 @@ public class RGBColor extends AbstractColor {
}
}
UtilNew.Triple<Float, Float, Float> HSVColor = new UtilNew.Triple<Float, Float, Float>(hue, saturation, brightness);
Util.Triple<Float, Float, Float> HSVColor = new Util.Triple<Float, Float, Float>(hue, saturation, brightness);
return HSVColor;
}
@@ -3,9 +3,9 @@ package com.sap.sailing.domain.common.impl;
import com.sap.sailing.domain.common.Duration;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.TimeRange;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
public class TimeRangeImpl extends UtilNew.Pair<TimePoint, TimePoint> implements TimeRange {
public class TimeRangeImpl extends Util.Pair<TimePoint, TimePoint> implements TimeRange {
public static final TimePoint BeginningOfTime = new MillisecondsTimePoint(Long.MIN_VALUE);
public static final TimePoint EndOfTime = new MillisecondsTimePoint(Long.MAX_VALUE);
private static final long serialVersionUID = 8710198176227507300L;
@@ -7,7 +7,7 @@ import com.sap.sailing.domain.common.impl.KnotSpeedImpl;
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
import com.sap.sailing.domain.common.impl.RadianBearingImpl;
import com.sap.sailing.domain.common.scalablevalue.ScalableValue;
import com.sap.sse.common.UtilNew;
import com.sap.sse.common.Util;
/**
* Separately scales speed and bearing. Instead of considering speed and bearing a single vector that can be scaled, the
@@ -19,7 +19,7 @@ import com.sap.sse.common.UtilNew;
* @author Axel Uhl (d043530)
*
*/
public class ScalableSpeedWithBearing implements ScalableValue<UtilNew.Triple<Speed, Double, Double>, SpeedWithBearing> {
public class ScalableSpeedWithBearing implements ScalableValue<Util.Triple<Speed, Double, Double>, SpeedWithBearing> {
private final Speed speed;
private final double sin;
private final double cos;
@@ -42,7 +42,7 @@ public class ScalableSpeedWithBearing implements ScalableValue<UtilNew.Triple<Sp
}
@Override
public ScalableSpeedWithBearing add(ScalableValue<UtilNew.Triple<Speed, Double, Double>, SpeedWithBearing> t) {
public ScalableSpeedWithBearing add(ScalableValue<Util.Triple<Speed, Double, Double>, SpeedWithBearing> t) {
Speed newSpeed = new KnotSpeedImpl(speed.getKnots() + t.getValue().getA().getKnots());
return new ScalableSpeedWithBearing(newSpeed, sin+t.getValue().getB(), cos+t.getValue().getC());
}
@@ -61,8 +61,8 @@ public class ScalableSpeedWithBearing implements ScalableValue<UtilNew.Triple<Sp
}
@Override
public UtilNew.Triple<Speed, Double, Double> getValue() {
return new UtilNew.Triple<Speed, Double, Double>(speed, sin, cos);
public Util.Triple<Speed, Double, Double> getValue() {
return new Util.Triple<Speed, Double, Double>(speed, sin, cos);
}
}