diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7447f89a59769d232b07bf72eb111bc4618c8e59 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1a91290981e8e934e41a4331d1bfa164c3cf2334 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# 1.8 Telefonbuch + +**Voraussetzung**: +Vorlesung zum Thema Maps. + +**Ziel**: +Kennenlernen der API von `Map` und `SortedMap` durch einen Reverse-Engineering-Ansatz, bei dem eine Java-API-Dokumentation als Pflichtenheft verwendet wird. + +**Dauer**: +< 1 Stunde + +## Aufgabenstellung +Erstellen Sie eine Klasse `PhoneBook` (dt. Telefonbuch), die für die Verwaltung von Kontakteinträgen zuständig ist. Halten Sie sich bei der Implementierung der Klasse streng an die bereitgestellte JavaDoc. + +### Schritte zur Umsetzung +1. **JavaDoc öffnen:** Die JavaDoc finden Sie unter dem oben genannten Link. Laden Sie das Projekt als ZIP-Datei herunter und entpacken Sie es lokal. Im Verzeichnis `doc` finden Sie eine Datei `index.html`, die Sie mit einem Browser öffnen können. + +2. **Dokumentation als Pflichtenheft:** Die Dokumentation enthält genaue Angaben zu Klassen, Methoden und Attributen. Diese Dokumentation muss als Pflichtenheft verstanden werden, das 1:1 umgesetzt werden soll. + +3. **Implementierung der Klasse `PhoneBook`:** + - Entwickeln Sie die Klasse basierend auf den Vorgaben der JavaDoc. + - Achten Sie darauf, alle beschriebenen Klassen, Methoden und Attribute exakt wie angegeben zu implementieren. + +4. **Überprüfung:** Stellen Sie sicher, dass Ihre Implementierung mit der Dokumentation übereinstimmt und die geforderten Funktionalitäten korrekt umgesetzt sind. \ No newline at end of file diff --git a/phonebook/.gitattributes b/phonebook/.gitattributes deleted file mode 100644 index 00a51aff5e5a83d6313f3bd15fadc601a205b66f..0000000000000000000000000000000000000000 --- a/phonebook/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# These are explicitly windows files and should use crlf -*.bat text eol=crlf - diff --git a/phonebook/.gitignore b/phonebook/.gitignore deleted file mode 100644 index f198ec547b9190a094cdd1e56458a0ed7b8c23c8..0000000000000000000000000000000000000000 --- a/phonebook/.gitignore +++ /dev/null @@ -1,216 +0,0 @@ -# Created by https://www.gitignore.io/api/java,gradle,eclipse,intellij,visualstudiocode -# Edit at https://www.gitignore.io/?templates=java,gradle,eclipse,intellij,visualstudiocode - -### Eclipse ### -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# CDT- autotools -.autotools - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Annotation Processing -.apt_generated/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Eclipse Patch ### -# Eclipse Core -.project - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Annotation Processing -.apt_generated - -.sts4-cache/ - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Intellij Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr - -# Sonarlint plugin -.idea/**/sonarlint/ - -# SonarQube Plugin -.idea/**/sonarIssues.xml - -# Markdown Navigator plugin -.idea/**/markdown-navigator.xml -.idea/**/markdown-navigator/ - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history - -### Gradle ### -.gradle -build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -### Gradle Patch ### -**/build/ - -# End of https://www.gitignore.io/api/java,gradle,eclipse,intellij,visualstudiocode \ No newline at end of file diff --git a/phonebook/build.gradle b/phonebook/build.gradle deleted file mode 100644 index 214ea8ead3ad540e622efeeada4c170ea8c66362..0000000000000000000000000000000000000000 --- a/phonebook/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java project to get you started. - * For more details take a look at the Java Quickstart chapter in the Gradle - * User Manual available at https://docs.gradle.org/6.3/userguide/tutorial_java_projects.html - */ - -plugins { - // Apply the java plugin to add support for Java - id 'java' - - // Apply the application plugin to add support for building a CLI application. - id 'application' -} - -repositories { - // Use jcenter for resolving dependencies. - // You can declare any Maven/Ivy/file repository here. - jcenter() -} - -dependencies { - // This dependency is used by the application. - implementation 'com.google.guava:guava:28.2-jre' - - // Use JUnit Jupiter API for testing. - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' - - // Use JUnit Jupiter Engine for testing. - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' -} - -application { - // Define the main class for the application. - mainClassName = 'io.fp.phonebook.App' -} - -test { - // Use junit platform for unit tests - useJUnitPlatform() -} diff --git a/phonebook/gradle/wrapper/gradle-wrapper.jar b/phonebook/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 490fda8577df6c95960ba7077c43220e5bb2c0d9..0000000000000000000000000000000000000000 Binary files a/phonebook/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/phonebook/gradle/wrapper/gradle-wrapper.properties b/phonebook/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 41dfb87909a877d96c3af4adccce4c7a301b55a2..0000000000000000000000000000000000000000 --- a/phonebook/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/phonebook/gradlew b/phonebook/gradlew deleted file mode 100644 index 2fe81a7d95e4f9ad2c9b2a046707d36ceb3980b3..0000000000000000000000000000000000000000 --- a/phonebook/gradlew +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# 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 -# -# https://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. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/phonebook/gradlew.bat b/phonebook/gradlew.bat deleted file mode 100644 index 62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d..0000000000000000000000000000000000000000 --- a/phonebook/gradlew.bat +++ /dev/null @@ -1,103 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@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 obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@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 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -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. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@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% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/phonebook/settings.gradle b/phonebook/settings.gradle deleted file mode 100644 index 43621cc760e4afdf4cb9308dd5ac963f116b471d..0000000000000000000000000000000000000000 --- a/phonebook/settings.gradle +++ /dev/null @@ -1,10 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/6.3/userguide/multi_project_builds.html - */ - -rootProject.name = 'campus' diff --git a/phonebook/src/main/java/io/fp/phonebook/App.java b/phonebook/src/main/java/io/fp/phonebook/App.java deleted file mode 100644 index 0e4c991520e2ca813ada9fc12c17969569bcca93..0000000000000000000000000000000000000000 --- a/phonebook/src/main/java/io/fp/phonebook/App.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.fp.phonebook; - -public class App { - public static void main(String... args){ - PhoneBook b1 = new PhoneBook(); - - try { - b1.createContact("Michi Be", 111, 888, 999); - b1.createContact("Martin Pat", 222); - b1.createContact("Michi Be", 333); - b1.createContact("Martin Pat", 444); - } catch (Exception e) { - e.printStackTrace(); - } - - System.out.println("Ausgabe Person mit Nummer 222 und restliche Nummern."); - System.out.println("Name: " + b1.getPerson(222) + " Numbers: " + b1.getPhoneNumbers(b1.getPerson(222))); - System.out.println(); - System.out.println("Ausgabe gesamtes Buch."); - System.out.println(b1.getBook()); - System.out.println(); - - System.out.println("Ausgabe Nummern l�schen von Michi Be."); - System.out.println(b1.deleteEntriesOfAPerson("Michi Be")); - System.out.println(); - System.out.println("Ausgabe Nummer 222 l�schen."); - System.out.println(b1.deleteEntryByPhoneNumber(222)); - System.out.println(); - System.out.println("Ausgabe gesamtes Buch."); - System.out.println(b1.getBook()); - } -} diff --git a/phonebook/src/test/java/io/fp/phonebook/test.keep b/phonebook/src/test/java/io/fp/phonebook/test.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/phonebook/App.java b/src/phonebook/App.java new file mode 100644 index 0000000000000000000000000000000000000000..1ff325c5e41b46cc3ef5b8ecd59d13f4fa7cc0fb --- /dev/null +++ b/src/phonebook/App.java @@ -0,0 +1,32 @@ +package phonebook; + +public class App { + public static void main(String... args) { + PhoneBook b1 = new PhoneBook(); + + try { + b1.createContact("Michi", 111, 888, 999); + b1.createContact("Martin", 222); + b1.createContact("Michi", 333); + b1.createContact("Martin", 444); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Retrieve name and other numbers of person with number 222"); + System.out.println("Name: " + b1.getPerson(222) + " Numbers: " + b1.getPhoneNumbers(b1.getPerson(222))); + System.out.println(); + System.out.println("Retrieve entire book"); + System.out.println(b1.getBook()); + System.out.println(); + + System.out.println("Delete numbers of Michi and print them:"); + System.out.println(b1.deleteEntriesOfAPerson("Michi")); + System.out.println(); + System.out.println("Delete phone number 222 and print owner name:"); + System.out.println(b1.deleteEntryByPhoneNumber(222)); + System.out.println(); + System.out.println("Retrieve entire book"); + System.out.println(b1.getBook()); + } +} diff --git a/phonebook/src/main/java/io/fp/phonebook/PhoneBook.java b/src/phonebook/PhoneBook.java similarity index 67% rename from phonebook/src/main/java/io/fp/phonebook/PhoneBook.java rename to src/phonebook/PhoneBook.java index 5747027f92bd51210f796bee9875dcdf1968a8cc..0272e429e12528b6508b4d41be3b99581682bfd8 100644 --- a/phonebook/src/main/java/io/fp/phonebook/PhoneBook.java +++ b/src/phonebook/PhoneBook.java @@ -1,90 +1,100 @@ -package io.fp.phonebook; +package phonebook; + import java.util.*; /** - * An object that manages contacts. For this purpose it is using the TreeMap implementation. + * An object that manages contacts. For this purpose it is using the TreeMap + * implementation. * A phone book cannot contain duplicate phone numbers (<strong>K</strong>eys), * but it can contain duplicate persons (<strong>V</strong>alues). */ public class PhoneBook { private SortedMap<Integer, String> book; - + /** * Initializes the variable {@link book} in the constructor. */ public PhoneBook() { - book = new TreeMap<Integer, String>(); + book = new TreeMap<Integer, String>(); } /** * Creates a new contact entry in the phone book. * Generates for every key element <tt>phoneNumbers</tt> a map entry. - * If even a single phone number is already in use in the phone book this method will throw a {@link PhoneBookException}. + * If even a single phone number is already in use in the phone book this method + * will throw a {@link PhoneBookException}. * No numbers should be added at all, if a {@link PhoneBookException} is thrown. * - * @param person name of the contact person + * @param person name of the contact person * @param phoneNumbers all phone numbers of the contact person - * @throws PhoneBookException if an entered phone number is already in use. The exception message contains the related number and the person's name which is using this number. + * @throws PhoneBookException if an entered phone number is already in use. The + * exception message contains the related number and + * the person's name which is using this number. */ - public void createContact(String person, Integer... phoneNumbers) throws PhoneBookException{ - for(Integer num : phoneNumbers){ - if(book.containsKey(num)){ - throw new PhoneBookException("Number '"+num+ "' is already used by "+book.get(num)); + public void createContact(String person, Integer... phoneNumbers) throws PhoneBookException { + for (Integer num : phoneNumbers) { + if (book.containsKey(num)) { + throw new PhoneBookException("Number '" + num + "' is already used by " + book.get(num)); } } - for(Integer num : phoneNumbers){ - book.put(num, person); + for (Integer num : phoneNumbers) { + book.put(num, person); } } - /** + /** * Returns the person's name to which the specified phone number is mapped, * or {@code null} if this phone book contains no mapping for the phone number. + * * @param phoneNumber of the person - * @return person's name + * @return person's name */ - public String getPerson(Integer phoneNumber){ + public String getPerson(Integer phoneNumber) { return book.get(phoneNumber); - } + } /** * Returns a set of all phone numbers of a specified person. + * * @param person specified person * @return all phone numbers of the person */ - public Set<Integer> getPhoneNumbers(String person){ + public Set<Integer> getPhoneNumbers(String person) { Set<Integer> foundPhoneNumbers = new HashSet<Integer>(); - for(Map.Entry<Integer,String> entry : book.entrySet()){ - if(entry.getValue().equals(person)){ - foundPhoneNumbers.add((Integer)entry.getKey()); + for (Map.Entry<Integer, String> entry : book.entrySet()) { + if (entry.getValue().equals(person)) { + foundPhoneNumbers.add((Integer) entry.getKey()); } } return foundPhoneNumbers; } /** - * Deletes the phone book entry which matches the specified phone number and returns the persons's name of the deleted entry, + * Deletes the phone book entry which matches the specified phone number and + * returns the persons's name of the deleted entry, * or {@code null} if this phone book contains no mapping for the phone number. + * * @param phoneNumber of the entry which will be deleted * @return the person's name of the deleted entry */ - public String deleteEntryByPhoneNumber(Integer phoneNumber){ + public String deleteEntryByPhoneNumber(Integer phoneNumber) { return book.remove(phoneNumber); } /** * Deletes all phone book entries of a specified person. + * * @param person of the entries which will be deleted * @return the phone numbers of the deleted entry */ - public Set<Integer> deleteEntriesOfAPerson(String person){ - + public Set<Integer> deleteEntriesOfAPerson(String person) { + Set<Integer> removedPhoneNumbers = new HashSet<Integer>(); - for(Map.Entry<Integer,String> entry : book.entrySet()) { - if(entry.getValue().equals(person)){ - removedPhoneNumbers.add((Integer)entry.getKey()); + for (Map.Entry<Integer, String> entry : book.entrySet()) { + if (entry.getValue().equals(person)) { + removedPhoneNumbers.add((Integer) entry.getKey()); } } book.keySet().removeAll(removedPhoneNumbers); @@ -94,12 +104,13 @@ public class PhoneBook { /** * Deletes all entries of the phone book. */ - public void clearPhoneBook(){ + public void clearPhoneBook() { book.clear(); } /** * Returns the map of the phone book. + * * @return map with contact entries */ public SortedMap<Integer, String> getBook() { @@ -130,6 +141,4 @@ public class PhoneBook { return false; return true; } - - -} +} \ No newline at end of file diff --git a/phonebook/src/main/java/io/fp/phonebook/PhoneBookException.java b/src/phonebook/PhoneBookException.java similarity index 94% rename from phonebook/src/main/java/io/fp/phonebook/PhoneBookException.java rename to src/phonebook/PhoneBookException.java index 16868df7c4e1212e84041b3c50f24d230f7e3966..b21d81f10b400badc06b344a3498caa52b098804 100644 --- a/phonebook/src/main/java/io/fp/phonebook/PhoneBookException.java +++ b/src/phonebook/PhoneBookException.java @@ -1,4 +1,4 @@ -package io.fp.phonebook; +package phonebook; /** * Thrown to indicate that something in a method of a {@link PhoneBook} has been failed. */