parent
526c2965e1
commit
f19ca264bb
@ -1,39 +1,45 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<classpath> |
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"> |
||||
<attributes> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> |
||||
<attributes> |
||||
<attribute name="test" value="true"/> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="src" output="target/classes" path="target/generated-resources/gwt"> |
||||
<attributes> |
||||
<attribute name="ignore_optional_problems" value="true"/> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="output" path="target/classes"/> |
||||
</classpath> |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<classpath> |
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"> |
||||
<attributes> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> |
||||
<attributes> |
||||
<attribute name="test" value="true"/> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="src" output="target/classes" path="target/generated-resources/gwt"> |
||||
<attributes> |
||||
<attribute name="ignore_optional_problems" value="true"/> |
||||
<attribute name="optional" value="true"/> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> |
||||
<attributes> |
||||
<attribute name="maven.pomderived" value="true"/> |
||||
<attribute name="test" value="true"/> |
||||
</attributes> |
||||
</classpathentry> |
||||
<classpathentry kind="output" path="target/classes"/> |
||||
</classpath> |
||||
|
||||
@ -0,0 +1,24 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
public class CompetitionDetails implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 2167132205051467946L; |
||||
|
||||
private Set<CompetitionGroup> cpGroups; |
||||
|
||||
public Set<CompetitionGroup> getCpGroups() { |
||||
return cpGroups; |
||||
} |
||||
|
||||
public void parseCompetitionGroups(String text) { |
||||
cpGroups = new HashSet<>(); |
||||
String[] lines = text.split("\n"); |
||||
for (String line: lines) { |
||||
cpGroups.add(CompetitionGroup.parseLine(line)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,70 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.io.Serializable; |
||||
import java.net.URISyntaxException; |
||||
import java.net.URL; |
||||
import java.nio.charset.Charset; |
||||
import java.util.List; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
import com.google.common.io.Files; |
||||
|
||||
public class CompetitionGroup implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 8670759590642549124L; |
||||
public static final int OPEN_END_MAX_YEAR = 9999; |
||||
public static final int OPEN_END_MIN_YEAR = 0; |
||||
|
||||
private static final Pattern YEAR_PATTERN = Pattern.compile("[^a-zA-Z](\\d{2,4})"); |
||||
private static final Rules RULES = new Rules(); |
||||
private int minBirthYear; |
||||
private int maxBirthYear = OPEN_END_MAX_YEAR; |
||||
|
||||
public int getOldestBirthYear() { |
||||
return minBirthYear; |
||||
} |
||||
|
||||
public int getYoungestBirthYear() { |
||||
return maxBirthYear; |
||||
} |
||||
|
||||
public static CompetitionGroup parseLine(String line) { |
||||
CompetitionGroup competitionGroup = new CompetitionGroup(); |
||||
|
||||
Matcher matcher = YEAR_PATTERN.matcher(line); |
||||
if (matcher.find()) { |
||||
competitionGroup.minBirthYear = Integer.parseInt(matcher.group(1)); |
||||
} |
||||
if (matcher.find()) { |
||||
competitionGroup.maxBirthYear = Integer.parseInt(matcher.group(1)); |
||||
} else { |
||||
if (RULES.isYoungestOnly(line)) { |
||||
competitionGroup.maxBirthYear = competitionGroup.minBirthYear; |
||||
competitionGroup.minBirthYear = OPEN_END_MIN_YEAR; |
||||
} |
||||
} |
||||
|
||||
return competitionGroup; |
||||
} |
||||
|
||||
private static class Rules { |
||||
final String youngest; |
||||
|
||||
public Rules() { |
||||
URL uri = getClass().getResource("CompetitionGroupRules.txt"); |
||||
try { |
||||
List<String> lines = Files.readLines(new File(uri.toURI()), Charset.defaultCharset()); |
||||
youngest = lines.get(0); |
||||
} catch (IOException | URISyntaxException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
public boolean isYoungestOnly(String line) { |
||||
return line.toLowerCase().contains(youngest); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1 @@ |
||||
älter |
||||
@ -0,0 +1,27 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.net.URL; |
||||
import java.nio.charset.Charset; |
||||
|
||||
import org.apache.commons.io.FileUtils; |
||||
|
||||
public class AbstractCompetitionDataTests { |
||||
|
||||
public AbstractCompetitionDataTests() { |
||||
super(); |
||||
} |
||||
|
||||
public String getGroupTable1() throws IOException, URISyntaxException { |
||||
URL uri = getClass().getResource("CompetitionGroupsBezirksEinzelMS2018.txt"); |
||||
return FileUtils.readFileToString(new File(uri.toURI()), Charset.defaultCharset()); |
||||
} |
||||
|
||||
public String getGroupTable2() throws IOException, URISyntaxException { |
||||
URL uri = getClass().getResource("CompetitionGroupsLM2018Trampolin.txt"); |
||||
return FileUtils.readFileToString(new File(uri.toURI()), Charset.defaultCharset()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
public class CompetitionDetailsTest extends AbstractCompetitionDataTests { |
||||
|
||||
@Test |
||||
public void parseGroupInsertsElementPerLine() throws Exception { |
||||
|
||||
CompetitionDetails detail = new CompetitionDetails(); |
||||
detail.parseCompetitionGroups(getGroupTable1()); |
||||
assertEquals(8, detail.getCpGroups().size()); |
||||
|
||||
detail = new CompetitionDetails(); |
||||
detail.parseCompetitionGroups(getGroupTable2()); |
||||
assertEquals(6, detail.getCpGroups().size()); |
||||
|
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
public class CompetitionGroupLineParseTest { |
||||
|
||||
@Test |
||||
public void testTwo4DigitYears() { |
||||
|
||||
CompetitionGroup group = CompetitionGroup.parseLine("Schüler – innen E 2008 -2009 P4"); |
||||
assertEquals(2009, group.getYoungestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Heranwachsende 2001-1995 P8"); |
||||
assertEquals(1995, group.getYoungestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Jugend C: Jg. 2004/2005 W11 - W13"); |
||||
assertEquals(2005, group.getYoungestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Schüler – innen E 2008 -2009 P4"); |
||||
assertEquals(2008, group.getOldestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Jugend E: 2008 und jünger P8 - W11"); |
||||
assertEquals(2008, group.getOldestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Heranwachsende 2001-1995 P8"); |
||||
assertEquals(2001, group.getOldestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Jugend C: Jg. 2004/2005 W11 - W13"); |
||||
assertEquals(2004, group.getOldestBirthYear()); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void testOneYearIsYoungest() { |
||||
|
||||
CompetitionGroup group = CompetitionGroup.parseLine("Erwachsene: Jg. 1996 und älter W15 - FIG A"); |
||||
assertEquals(1996, group.getYoungestBirthYear()); |
||||
} |
||||
|
||||
@Test |
||||
public void testOneYearIsOldest() { |
||||
CompetitionGroup group = CompetitionGroup.parseLine("Schüler – innen F 2010 und jünger P3"); |
||||
assertEquals(2010, group.getOldestBirthYear()); |
||||
|
||||
group = CompetitionGroup.parseLine("Jugend E: 2008 und jünger P8 - W11"); |
||||
assertEquals(2008, group.getOldestBirthYear()); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void testRegexPattern() { |
||||
Pattern pattern = Pattern.compile("\\d{2,4}"); |
||||
String twoYears = "text 1999 bis 2009 text"; |
||||
Matcher matcher = pattern.matcher(twoYears); |
||||
assertTrue("didnt find first year", matcher.find()); |
||||
assertEquals("1999", matcher.group()); |
||||
assertTrue("didnt find second year", matcher.find()); |
||||
assertEquals("2009", matcher.group()); |
||||
} |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
Schüler – innen F 2010 und jünger P3 |
||||
Schüler – innen E 2008 -2009 P4 |
||||
Schüler – innen D 2006 - 2007 P5 |
||||
Schüler – innen C 2004 - 2005 P6 |
||||
Schüler – innen B 2002 - 2003 P7 |
||||
Heranwachsende 2001-1995 P8 |
||||
Turner - innen 1996 -1989 P8 |
||||
Oldies 1988 und älter P5 |
||||
@ -0,0 +1,6 @@ |
||||
Jugend E: 2008 und jünger P8 - W11 |
||||
Jugend D: Jg. 2006/2007 W9 (alte M5) - W11 |
||||
Jugend C: Jg. 2004/2005 W11 - W13 |
||||
Jugend B: Jg. 2002/2003 W13 - W15 |
||||
Jugend A: Jg. 1997-2001 W15 - FIG A |
||||
Erwachsene: Jg. 1996 und älter W15 - FIG A |
||||
Loading…
Reference in new issue