This commit is contained in:
navid.sassan 2020-11-23 16:24:44 +01:00
parent c35ba96302
commit 34197dc3da
5 changed files with 3613 additions and 3613 deletions

206
09/gradlew.bat vendored
View File

@ -1,103 +1,103 @@
@rem @rem
@rem Copyright 2015 the original author or authors. @rem Copyright 2015 the original author or authors.
@rem @rem
@rem Licensed under the Apache License, Version 2.0 (the "License"); @rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License. @rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at @rem You may obtain a copy of the License at
@rem @rem
@rem https://www.apache.org/licenses/LICENSE-2.0 @rem https://www.apache.org/licenses/LICENSE-2.0
@rem @rem
@rem Unless required by applicable law or agreed to in writing, software @rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS, @rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter. @rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto init
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto init
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:init :init
@rem Get command-line arguments, handling Windows variants @rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args :win9xME_args
@rem Slurp the command line arguments. @rem Slurp the command line arguments.
set CMD_LINE_ARGS= set CMD_LINE_ARGS=
set _SKIP=2 set _SKIP=2
:win9xME_args_slurp :win9xME_args_slurp
if "x%~1" == "x" goto execute if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%* set CMD_LINE_ARGS=%*
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1 exit /b 1
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal
:omega :omega

View File

@ -1,81 +1,81 @@
import java.util.*; import java.util.*;
import java.text.*; import java.text.*;
/** /**
* @author flurin gishamer * @author flurin gishamer
* holds information about a single competitor from * holds information about a single competitor from
* the zurich marathon * the zurich marathon
*/ */
public class Competitor implements Comparable<Competitor> { public class Competitor implements Comparable<Competitor> {
private String name; private String name;
private String country; private String country;
private long time; private long time;
private int jg; private int jg;
private int startNr; private int startNr;
private int rank; private int rank;
public Competitor(int startNr, String name, int jg, String country, String time) throws Exception { public Competitor(int startNr, String name, int jg, String country, String time) throws Exception {
this.name = name; this.name = name;
this.country = country; this.country = country;
this.jg = jg; this.jg = jg;
this.startNr = startNr; this.startNr = startNr;
this.time = parseTime(time); this.time = parseTime(time);
} }
public String getName() { public String getName() {
return name; return name;
} }
public int getJg() { public int getJg() {
return jg; return jg;
} }
public void setRank(int rank) { public void setRank(int rank) {
this.rank = rank; this.rank = rank;
} }
private static long parseTime(String s) throws ParseException { private static long parseTime(String s) throws ParseException {
DateFormat sdf = new SimpleDateFormat("HH:mm:ss.S"); DateFormat sdf = new SimpleDateFormat("HH:mm:ss.S");
Date date = sdf.parse(s); Date date = sdf.parse(s);
return date.getTime(); return date.getTime();
} }
public String toString() { public String toString() {
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss.S"); SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss.S");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(" Start Nr: "); sb.append(" Start Nr: ");
sb.append(startNr); sb.append(startNr);
sb.append(" "); sb.append(" ");
sb.append(name); sb.append(name);
sb.append(" "); sb.append(" ");
sb.append(Integer.toString(jg)); sb.append(Integer.toString(jg));
sb.append(" "); sb.append(" ");
sb.append(country); sb.append(country);
sb.append(" "); sb.append(" ");
sb.append(df.format(new Date(time))); sb.append(df.format(new Date(time)));
return sb.toString(); return sb.toString();
} }
@Override @Override
public int compareTo(Competitor toCompare) { public int compareTo(Competitor toCompare) {
int c = name.compareTo(toCompare.name); int c = name.compareTo(toCompare.name);
c = (c != 0)?c:jg - toCompare.jg; c = (c != 0)?c:jg - toCompare.jg;
return c; return c;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 1; int hash = 1;
hash = hash * 13 + name.hashCode(); hash = hash * 13 + name.hashCode();
hash = hash * 17 + jg; hash = hash * 17 + jg;
return hash; return hash;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) return false; if (obj == null) return false;
return (compareTo((Competitor)obj) == 0); return (compareTo((Competitor)obj) == 0);
} }
} }

View File

@ -1,88 +1,88 @@
import java.util.*; import java.util.*;
public class MyHashtable<K,V> implements java.util.Map<K,V> { public class MyHashtable<K,V> implements java.util.Map<K,V> {
private K[] keys = (K[]) new Object[10]; private K[] keys = (K[]) new Object[10];
private V[] values = (V[]) new Object[10]; private V[] values = (V[]) new Object[10];
private int hash(Object k) { private int hash(Object k) {
int h = Math.abs(k.hashCode()); int h = Math.abs(k.hashCode());
return h % keys.length; return h % keys.length;
} }
public MyHashtable(int size) { public MyHashtable(int size) {
// to be done // to be done
} }
// Removes all mappings from this map (optional operation). // Removes all mappings from this map (optional operation).
public void clear() { public void clear() {
// to be done // to be done
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Associates the specified value with the specified key in this map (optional operation). // Associates the specified value with the specified key in this map (optional operation).
public V put(K key, V value) { public V put(K key, V value) {
// to be done // to be done
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns the value to which this map maps the specified key. // Returns the value to which this map maps the specified key.
public V get(Object key) { public V get(Object key) {
// to be done // to be done
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns true if this map contains no key-value mappings. // Returns true if this map contains no key-value mappings.
public boolean isEmpty() { public boolean isEmpty() {
// to be done // to be done
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Removes the mapping for this key from this map if present (optional operation). // Removes the mapping for this key from this map if present (optional operation).
public V remove(Object key) { public V remove(Object key) {
// to be done (Aufgabe 3) // to be done (Aufgabe 3)
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns the number of key-value mappings in this map. // Returns the number of key-value mappings in this map.
public int size() { public int size() {
// to be done // to be done
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// ======================================================================= // =======================================================================
// Returns a set view of the keys contained in this map. // Returns a set view of the keys contained in this map.
public Set keySet() { public Set keySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Copies all of the mappings from the specified map to this map (optional operation). // Copies all of the mappings from the specified map to this map (optional operation).
public void putAll(Map t) { public void putAll(Map t) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns a collection view of the values contained in this map. // Returns a collection view of the values contained in this map.
public Collection values() { public Collection values() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns true if this map contains a mapping for the specified key. // Returns true if this map contains a mapping for the specified key.
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns true if this map maps one or more keys to the specified value. // Returns true if this map maps one or more keys to the specified value.
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns a set view of the mappings contained in this map. // Returns a set view of the mappings contained in this map.
public Set entrySet() { public Set entrySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Compares the specified object with this map for equality. // Compares the specified object with this map for equality.
public boolean equals(Object o) { public boolean equals(Object o) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
// Returns the hash code value for this map. // Returns the hash code value for this map.
public int hashCode() { public int hashCode() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,179 +1,179 @@
import org.junit.Test; import org.junit.Test;
import org.junit.Before; import org.junit.Before;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.*; import java.util.*;
class Town { class Town {
int hashCode; int hashCode;
String name; String name;
String nb; String nb;
Town (int hashCode, String name, String nb) { Town (int hashCode, String name, String nb) {
this.name = name; this.hashCode = hashCode; this.nb = nb; this.name = name; this.hashCode = hashCode; this.nb = nb;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == null || !(o instanceof Town)) return false; if (o == null || !(o instanceof Town)) return false;
return ((Town)o).name.equals(this.name); return ((Town)o).name.equals(this.name);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return hashCode; return hashCode;
} }
@Override @Override
public String toString() { public String toString() {
return name+" "+hashCode; return name+" "+hashCode;
} }
} }
public class HashTest { public class HashTest {
Map<Town,Town> hashmap; Map<Town,Town> hashmap;
List<Town> towns; List<Town> towns;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
towns = new LinkedList<>(); towns = new LinkedList<>();
towns.add(new Town(5,"Bari","BA")); towns.add(new Town(5,"Bari","BA"));
towns.add(new Town(8,"Bologna","BO")); towns.add(new Town(8,"Bologna","BO"));
towns.add(new Town(3,"Catania","CA")); towns.add(new Town(3,"Catania","CA"));
towns.add(new Town(9,"Firenze","FI")); towns.add(new Town(9,"Firenze","FI"));
towns.add(new Town(0,"Genova","GV")); towns.add(new Town(0,"Genova","GV"));
towns.add(new Town(12,"Milano","MI")); towns.add(new Town(12,"Milano","MI"));
towns.add(new Town(7,"Napoli","NA")); towns.add(new Town(7,"Napoli","NA"));
towns.add(new Town(7,"Palermo","PA")); towns.add(new Town(7,"Palermo","PA"));
towns.add(new Town(7,"Roma","RM")); towns.add(new Town(7,"Roma","RM"));
towns.add(new Town(5,"Torino","TO")); towns.add(new Town(5,"Torino","TO"));
hashmap = new MyHashtable<>(100); hashmap = new MyHashtable<>(100);
} }
@Test @Test
public void testAdd() { public void testAdd() {
hashmap.clear(); hashmap.clear();
Town t0 = towns.get(0); Town t0 = towns.get(0);
hashmap.put(t0,t0); hashmap.put(t0,t0);
Town t1 = hashmap.get(t0); Town t1 = hashmap.get(t0);
assertEquals(t0,t1); assertEquals(t0,t1);
} }
@Test @Test
public void testAdd2() { public void testAdd2() {
hashmap.clear(); hashmap.clear();
Town t0 = towns.get(0); Town t0 = towns.get(0);
Town t1 = towns.get(1); Town t1 = towns.get(1);
hashmap.put(t0,t0); hashmap.put(t0,t0);
hashmap.put(t1,t1); hashmap.put(t1,t1);
Town t2 = hashmap.get(t0); Town t2 = hashmap.get(t0);
assertEquals(t0,t2); assertEquals(t0,t2);
t2 = hashmap.get(t1); t2 = hashmap.get(t1);
assertEquals(t1,t2); assertEquals(t1,t2);
} }
@Test @Test
public void testAdd3() { public void testAdd3() {
hashmap.clear(); hashmap.clear();
Town t0 = towns.get(0); Town t0 = towns.get(0);
hashmap.remove(t0); hashmap.remove(t0);
hashmap.put(t0,t0); hashmap.put(t0,t0);
hashmap.put(t0,t0); hashmap.put(t0,t0);
assertEquals(1, hashmap.size()); assertEquals(1, hashmap.size());
Town t1 = hashmap.get(t0); Town t1 = hashmap.get(t0);
assertEquals(t0,t1); assertEquals(t0,t1);
} }
@Test @Test
public void testAdd4() { public void testAdd4() {
hashmap.clear(); hashmap.clear();
Town t0 = towns.get(0); Town t0 = towns.get(0);
hashmap.put(t0,t0); hashmap.put(t0,t0);
hashmap.put(t0,t0); hashmap.put(t0,t0);
assertEquals(1, hashmap.size()); assertEquals(1, hashmap.size());
} }
@Test @Test
public void testSize() { public void testSize() {
hashmap.clear(); hashmap.clear();
assertEquals(0, hashmap.size()); assertEquals(0, hashmap.size());
testAdd2(); testAdd2();
assertEquals(2, hashmap.size()); assertEquals(2, hashmap.size());
} }
@Test @Test
public void testRemove() { public void testRemove() {
hashmap.clear(); hashmap.clear();
Town t0 = towns.get(0); Town t0 = towns.get(0);
Town t1 = towns.get(1); Town t1 = towns.get(1);
hashmap.put(t0,t0); hashmap.put(t0,t0);
hashmap.remove(t0); hashmap.remove(t0);
assertEquals(0, hashmap.size()); assertEquals(0, hashmap.size());
hashmap.put(t0,t0); hashmap.put(t0,t0);
hashmap.remove(t1); hashmap.remove(t1);
assertEquals(1, hashmap.size()); assertEquals(1, hashmap.size());
hashmap.remove(t0); hashmap.remove(t0);
assertEquals(0, hashmap.size()); assertEquals(0, hashmap.size());
} }
@Test @Test
public void testCompetitor() { public void testCompetitor() {
try { try {
Competitor c1 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0"); Competitor c1 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0");
Competitor c2 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0"); Competitor c2 = new Competitor(1,"Röthlin Viktor",74,"Magglingen/Macolin","2:11:05.0");
Competitor c3 = new Competitor(1,"Röthlin Viktor",75,"Magglingen/Macolin","2:11:05.0"); Competitor c3 = new Competitor(1,"Röthlin Viktor",75,"Magglingen/Macolin","2:11:05.0");
Competitor c4 = new Competitor(1,"Röthlin Pavel",74,"Magglingen/Macolin","2:11:05.0"); Competitor c4 = new Competitor(1,"Röthlin Pavel",74,"Magglingen/Macolin","2:11:05.0");
assertEquals("test1",c1,c2); assertEquals("test1",c1,c2);
assertTrue("test2",c1.compareTo(c2) == 0); assertTrue("test2",c1.compareTo(c2) == 0);
assertFalse("test3",c1.compareTo(c3) == 0); assertFalse("test3",c1.compareTo(c3) == 0);
assertTrue("test4",c1.hashCode() == c2.hashCode()); assertTrue("test4",c1.hashCode() == c2.hashCode());
assertFalse("test5",c1.hashCode() == c3.hashCode()); assertFalse("test5",c1.hashCode() == c3.hashCode());
assertFalse("test6",c1.hashCode() == c4.hashCode()); assertFalse("test6",c1.hashCode() == c4.hashCode());
} catch (Exception e) { } catch (Exception e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
@Test @Test
public void testMixed() { public void testMixed() {
hashmap.clear(); hashmap.clear();
Map<Town,Town> hashmap2 = new HashMap<>(); Map<Town,Town> hashmap2 = new HashMap<>();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
Town c = towns.get((int)(Math.random()*towns.size())); Town c = towns.get((int)(Math.random()*towns.size()));
// System.out.println(""+ c); // System.out.println(""+ c);
int op = (int)(Math.random()*2); int op = (int)(Math.random()*2);
switch (op) { switch (op) {
case 0 : hashmap.put(c,c); hashmap2.put(c,c); break; case 0 : hashmap.put(c,c); hashmap2.put(c,c); break;
case 1 : hashmap.remove(c); hashmap2.remove(c); break; case 1 : hashmap.remove(c); hashmap2.remove(c); break;
} }
} }
assertEquals(hashmap2.size(), hashmap.size()); assertEquals(hashmap2.size(), hashmap.size());
for (Town t : towns) { for (Town t : towns) {
Town c1 = hashmap.get(t); Town c1 = hashmap.get(t);
Town c2 = hashmap2.get(t); Town c2 = hashmap2.get(t);
assertEquals(c1,c2); assertEquals(c1,c2);
} }
} }
@Test @Test
public void testMixedWithOveflow() { public void testMixedWithOveflow() {
Map<Town,Town> hashmap = new MyHashtable<>(4); Map<Town,Town> hashmap = new MyHashtable<>(4);
Map<Town,Town> hashmap2 = new HashMap<>(); Map<Town,Town> hashmap2 = new HashMap<>();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
Town c = towns.get((int)(Math.random()*towns.size())); Town c = towns.get((int)(Math.random()*towns.size()));
// System.out.println(""+ c); // System.out.println(""+ c);
int op = (int)(Math.random()*2); int op = (int)(Math.random()*2);
switch (op) { switch (op) {
case 0 : hashmap.put(c,c); hashmap2.put(c,c); break; case 0 : hashmap.put(c,c); hashmap2.put(c,c); break;
case 1 : hashmap.remove(c); hashmap2.remove(c); break; case 1 : hashmap.remove(c); hashmap2.remove(c); break;
} }
} }
assertEquals(hashmap2.size(), hashmap.size()); assertEquals(hashmap2.size(), hashmap.size());
for (Town t : towns) { for (Town t : towns) {
Town c1 = hashmap.get(t); Town c1 = hashmap.get(t);
Town c2 = hashmap2.get(t); Town c2 = hashmap2.get(t);
assertEquals(c1,c2); assertEquals(c1,c2);
} }
} }
} }