diff --git a/abstractfactoryguru/.gitignore b/abstractfactoryguru/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/abstractfactoryguru/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/abstractfactoryguru/.idea/.gitignore b/abstractfactoryguru/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/abstractfactoryguru/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/abstractfactoryguru/.idea/misc.xml b/abstractfactoryguru/.idea/misc.xml new file mode 100644 index 0000000..87a20fc --- /dev/null +++ b/abstractfactoryguru/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/abstractfactoryguru/.idea/vcs.xml b/abstractfactoryguru/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/abstractfactoryguru/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/abstractfactoryguru/.mvn/wrapper/maven-wrapper.jar b/abstractfactoryguru/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..c1dd12f Binary files /dev/null and b/abstractfactoryguru/.mvn/wrapper/maven-wrapper.jar differ diff --git a/abstractfactoryguru/.mvn/wrapper/maven-wrapper.properties b/abstractfactoryguru/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..40ca015 --- /dev/null +++ b/abstractfactoryguru/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar \ No newline at end of file diff --git a/abstractfactoryguru/mvnw b/abstractfactoryguru/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/abstractfactoryguru/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + 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 + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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 + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/abstractfactoryguru/mvnw.cmd b/abstractfactoryguru/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/abstractfactoryguru/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. 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, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/abstractfactoryguru/pom.xml b/abstractfactoryguru/pom.xml new file mode 100644 index 0000000..9acdbd4 --- /dev/null +++ b/abstractfactoryguru/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.example + abstractfactoryguru + 1.0-SNAPSHOT + abstractfactoryguru + war + + + UTF-8 + 11 + 11 + 5.9.2 + + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + 3.0.0 + provided + + jakarta.ws.rs + jakarta.ws.rs-api + 3.0.0 + provided + + jakarta.servlet + jakarta.servlet-api + 5.0.0 + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + \ No newline at end of file diff --git a/abstractfactoryguru/src/main/java/com/example/abstractfactoryguru/HelloApplication.java b/abstractfactoryguru/src/main/java/com/example/abstractfactoryguru/HelloApplication.java new file mode 100644 index 0000000..36c5898 --- /dev/null +++ b/abstractfactoryguru/src/main/java/com/example/abstractfactoryguru/HelloApplication.java @@ -0,0 +1,9 @@ +package com.example.abstractfactoryguru; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +@ApplicationPath("/api") +public class HelloApplication extends Application { + +} \ No newline at end of file diff --git a/abstractfactoryguru/src/main/java/com/example/abstractfactoryguru/HelloResource.java b/abstractfactoryguru/src/main/java/com/example/abstractfactoryguru/HelloResource.java new file mode 100644 index 0000000..bf2ab0b --- /dev/null +++ b/abstractfactoryguru/src/main/java/com/example/abstractfactoryguru/HelloResource.java @@ -0,0 +1,14 @@ +package com.example.abstractfactoryguru; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; + +@Path("/hello-world") +public class HelloResource { + @GET + @Produces("text/plain") + public String hello() { + return "Hello, World!"; + } +} \ No newline at end of file diff --git a/abstractfactoryguru/src/main/resources/META-INF/beans.xml b/abstractfactoryguru/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..4011358 --- /dev/null +++ b/abstractfactoryguru/src/main/resources/META-INF/beans.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/chapter4/AbstractFactoryTester.java b/chapter4/AbstractFactoryTester.java new file mode 100644 index 0000000..be8c9fa --- /dev/null +++ b/chapter4/AbstractFactoryTester.java @@ -0,0 +1,14 @@ +package org.programers; + +import org.programers.factory.GUIFactory; +import org.programers.factory.mac.MacFactory; + +public class AbstractFactoryTester { + public static void main(String[] args) { + GUIFactory guiFactory = MacFactory.getInstance(); + Application application = new Application(guiFactory); + + application.createUI(); + application.paint(); + } +} diff --git a/chapter4/Application.java b/chapter4/Application.java new file mode 100644 index 0000000..4793917 --- /dev/null +++ b/chapter4/Application.java @@ -0,0 +1,25 @@ +package org.programers; + +import org.programers.factory.Button; +import org.programers.factory.Checkbox; +import org.programers.factory.GUIFactory; + +public class Application { + private GUIFactory factory; + private Button button; + private Checkbox checkbox; + + public Application(GUIFactory factory) { + this.factory = factory; + } + + public void createUI() { + this.button = factory.createButton(); + this.checkbox = factory.createCheckbox(); + } + + public void paint() { + this.button.paint(); + this.checkbox.paint(); + } +} diff --git a/chapter4/factory/Button.java b/chapter4/factory/Button.java new file mode 100644 index 0000000..1e8faf7 --- /dev/null +++ b/chapter4/factory/Button.java @@ -0,0 +1,5 @@ +package org.programers.factory; + +public interface Button { + public void paint(); +} diff --git a/chapter4/factory/Checkbox.java b/chapter4/factory/Checkbox.java new file mode 100644 index 0000000..e920020 --- /dev/null +++ b/chapter4/factory/Checkbox.java @@ -0,0 +1,5 @@ +package org.programers.factory; + +public interface Checkbox { + public void paint(); +} diff --git a/chapter4/factory/GUIFactory.java b/chapter4/factory/GUIFactory.java new file mode 100644 index 0000000..d73bf11 --- /dev/null +++ b/chapter4/factory/GUIFactory.java @@ -0,0 +1,7 @@ +package org.programers.factory; + +public interface GUIFactory { + public Button createButton(); + + public Checkbox createCheckbox(); +} diff --git a/chapter4/factory/mac/MacButton.java b/chapter4/factory/mac/MacButton.java new file mode 100644 index 0000000..8570d26 --- /dev/null +++ b/chapter4/factory/mac/MacButton.java @@ -0,0 +1,10 @@ +package org.programers.factory.mac; + +import org.programers.factory.Button; + +public class MacButton implements Button { + @Override + public void paint() { + System.out.println("mac button"); + } +} diff --git a/chapter4/factory/mac/MacCheckbox.java b/chapter4/factory/mac/MacCheckbox.java new file mode 100644 index 0000000..898fad5 --- /dev/null +++ b/chapter4/factory/mac/MacCheckbox.java @@ -0,0 +1,10 @@ +package org.programers.factory.mac; + +import org.programers.factory.Checkbox; + +public class MacCheckbox implements Checkbox { + @Override + public void paint() { + System.out.println("mac checkbox"); + } +} diff --git a/chapter4/factory/mac/MacFactory.java b/chapter4/factory/mac/MacFactory.java new file mode 100644 index 0000000..3e092c1 --- /dev/null +++ b/chapter4/factory/mac/MacFactory.java @@ -0,0 +1,24 @@ +package org.programers.factory.mac; + +import org.programers.factory.Button; +import org.programers.factory.Checkbox; +import org.programers.factory.GUIFactory; + +public enum MacFactory implements GUIFactory { + + INSTANCE; + + public static MacFactory getInstance() { + return INSTANCE; + } + + @Override + public Button createButton() { + return new MacButton(); + } + + @Override + public Checkbox createCheckbox() { + return new MacCheckbox(); + } +} diff --git a/chapter4/factory/win/WinButton.java b/chapter4/factory/win/WinButton.java new file mode 100644 index 0000000..0186dce --- /dev/null +++ b/chapter4/factory/win/WinButton.java @@ -0,0 +1,10 @@ +package org.programers.factory.win; + +import org.programers.factory.Button; + +public class WinButton implements Button { + @Override + public void paint() { + System.out.println("win button"); + } +} diff --git a/chapter4/factory/win/WinCheckbox.java b/chapter4/factory/win/WinCheckbox.java new file mode 100644 index 0000000..8b35e5c --- /dev/null +++ b/chapter4/factory/win/WinCheckbox.java @@ -0,0 +1,10 @@ +package org.programers.factory.win; + +import org.programers.factory.Checkbox; + +public class WinCheckbox implements Checkbox { + @Override + public void paint() { + System.out.println("win checkbox"); + } +} diff --git a/chapter4/factory/win/WinFactory.java b/chapter4/factory/win/WinFactory.java new file mode 100644 index 0000000..ea390ff --- /dev/null +++ b/chapter4/factory/win/WinFactory.java @@ -0,0 +1,24 @@ +package org.programers.factory.win; + +import org.programers.factory.Button; +import org.programers.factory.Checkbox; +import org.programers.factory.GUIFactory; + +public enum WinFactory implements GUIFactory { + + INSTANCE; + + public static WinFactory getInstance() { + return INSTANCE; + } + + @Override + public Button createButton() { + return new WinButton(); + } + + @Override + public Checkbox createCheckbox() { + return new WinCheckbox(); + } +} diff --git a/chapter6/Application.java b/chapter6/Application.java new file mode 100644 index 0000000..c645f37 --- /dev/null +++ b/chapter6/Application.java @@ -0,0 +1,72 @@ +package chapter6; + +import java.util.ArrayList; +import java.util.List; + +import chapter6.command.CopyCommand; +import chapter6.command.CutCommand; +import chapter6.command.PasteCommand; +import chapter6.command.UndoCommand; +import chapter6.invoker.Button; +import chapter6.invoker.ShortcutContainer; +import chapter6.model.Text; + +public class Application { + + private Text clipboard; + + private List editors; + + private Editor activeEditor; + + private CommandHistory history; + public ShortcutContainer shortcutContainer; + public Button copyButton; + + public Button cutButton; + + public Button pasteButton; + + public Button undoButton; + + public Application() { + this.clipboard = new Text(); + this.shortcutContainer = new ShortcutContainer(); + this.editors = new ArrayList<>(); + this.history = new CommandHistory(); + } + + public void createUI() { + Command copy = new CopyCommand(this, activeEditor); + Command cut = new CutCommand(this, activeEditor); + Command paste = new PasteCommand(this, activeEditor); + Command undo = new UndoCommand(this, activeEditor); + + copyButton = new Button(copy); + cutButton = new Button(cut); + pasteButton = new Button(paste); + undoButton = new Button(undo); + + shortcutContainer.onKeyPress("ctrl+c", copy); + shortcutContainer.onKeyPress("ctrl+x", cut); + shortcutContainer.onKeyPress("ctrl+v", paste); + shortcutContainer.onKeyPress("ctrl+z", undo); + } + + public void undo() { + Command command = history.pop(); + if (command != null) { + command.undo(); + } + } + + public Text getClipboard() { + return clipboard; + } + + public void setClipboard(Text clipboard) { + this.clipboard = clipboard; + } + + +} diff --git a/chapter6/ApplicationTest.java b/chapter6/ApplicationTest.java new file mode 100644 index 0000000..dcb48c5 --- /dev/null +++ b/chapter6/ApplicationTest.java @@ -0,0 +1,27 @@ +package chapter6; + +import chapter6.command.CopyCommand; +import chapter6.command.CutCommand; +import chapter6.command.PasteCommand; +import chapter6.command.UndoCommand; + +public class ApplicationTest { + + public static void main(String[] args) { + Application application = new Application(); + + application.createUI(); + + application.copyButton.excuteCommand(); + application.cutButton.excuteCommand(); + application.pasteButton.excuteCommand(); + application.undoButton.excuteCommand(); + + application.shortcutContainer.getShortCut("ctrl+c"); + application.shortcutContainer.getShortCut("ctrl+x"); + application.shortcutContainer.getShortCut("ctrl+v"); + application.shortcutContainer.getShortCut("ctrl+z"); + } + + +} diff --git a/chapter6/Command.java b/chapter6/Command.java new file mode 100644 index 0000000..9755b95 --- /dev/null +++ b/chapter6/Command.java @@ -0,0 +1,27 @@ +package chapter6; + +import chapter6.model.Text; + +public abstract class Command { + protected final Application app; + + protected final Editor editor; + + protected Text backup; + + public Command(Application app, Editor editor) { + this.app = app; + this.editor = editor; + this.backup = new Text(); + } + + public void saveBackup() { + this.backup = editor.getSelection(); + } + + public void undo() { + this.editor.setEditorText(this.backup); + } + + public abstract void execute(); +} diff --git a/chapter6/CommandHistory.java b/chapter6/CommandHistory.java new file mode 100644 index 0000000..11cb875 --- /dev/null +++ b/chapter6/CommandHistory.java @@ -0,0 +1,20 @@ +package chapter6; + +import java.util.Stack; + +public class CommandHistory { + + Stack stackHistories; + + public CommandHistory() { + stackHistories = new Stack<>(); + } + + public void push(Command command) { + stackHistories.push(command); + } + + public Command pop() { + return stackHistories.pop(); + } +} diff --git a/chapter6/Editor.java b/chapter6/Editor.java new file mode 100644 index 0000000..fb28589 --- /dev/null +++ b/chapter6/Editor.java @@ -0,0 +1,23 @@ +package chapter6; + +import chapter6.model.Text; + +public class Editor { + private Text editorText; + + public Text getSelection() { + return this.editorText; + } + + public void setEditorText(Text editorText) { + this.editorText = editorText; + } + + public void deleteSelection() { + this.editorText.setText(""); + } + + public void replaceSelection(Text text) { + this.editorText.setText(text.getText()); + } +} diff --git a/chapter6/command/CopyCommand.java b/chapter6/command/CopyCommand.java new file mode 100644 index 0000000..2590f29 --- /dev/null +++ b/chapter6/command/CopyCommand.java @@ -0,0 +1,18 @@ +package chapter6.command; + +import chapter6.Application; +import chapter6.Command; +import chapter6.Editor; +import chapter6.model.Text; + +public class CopyCommand extends Command { + public CopyCommand(Application app, Editor editor) { + super(app, editor); + } + + @Override + public void execute() { + Text selectedText = editor.getSelection(); + app.setClipboard(selectedText); + } +} diff --git a/chapter6/command/CutCommand.java b/chapter6/command/CutCommand.java new file mode 100644 index 0000000..4526555 --- /dev/null +++ b/chapter6/command/CutCommand.java @@ -0,0 +1,22 @@ +package chapter6.command; + +import chapter6.Application; +import chapter6.Command; +import chapter6.Editor; + +import chapter6.model.Text; +public class CutCommand extends Command { + + public CutCommand(Application app, Editor editor) { + super(app, editor); + } + + @Override + public void execute() { + saveBackup(); + + Text selectedText = this.editor.getSelection(); + this.app.setClipboard(selectedText); + this.editor.deleteSelection(); + } +} diff --git a/chapter6/command/PasteCommand.java b/chapter6/command/PasteCommand.java new file mode 100644 index 0000000..215b3ee --- /dev/null +++ b/chapter6/command/PasteCommand.java @@ -0,0 +1,20 @@ +package chapter6.command; + +import chapter6.Application; +import chapter6.Command; +import chapter6.Editor; +import chapter6.model.Text; + +public class PasteCommand extends Command { + + public PasteCommand(Application app, Editor editor) { + super(app, editor); + } + + @Override + public void execute() { + saveBackup(); + Text curClipBoardText = app.getClipboard(); + this.editor.replaceSelection(curClipBoardText); + } +} diff --git a/chapter6/command/UndoCommand.java b/chapter6/command/UndoCommand.java new file mode 100644 index 0000000..a90e56c --- /dev/null +++ b/chapter6/command/UndoCommand.java @@ -0,0 +1,17 @@ +package chapter6.command; + +import chapter6.Application; +import chapter6.Command; +import chapter6.Editor; + +public class UndoCommand extends Command { + + public UndoCommand(Application app, Editor editor) { + super(app, editor); + } + + @Override + public void execute() { + app.undo(); + } +} diff --git a/chapter6/invoker/Button.java b/chapter6/invoker/Button.java new file mode 100644 index 0000000..0ce878b --- /dev/null +++ b/chapter6/invoker/Button.java @@ -0,0 +1,15 @@ +package chapter6.invoker; + +import chapter6.Command; + +public class Button { + private Command command; + + public Button(Command command) { + this.command = command; + } + + public void excuteCommand(){ + command.execute(); + } +} diff --git a/chapter6/invoker/ShortcutContainer.java b/chapter6/invoker/ShortcutContainer.java new file mode 100644 index 0000000..2170bd9 --- /dev/null +++ b/chapter6/invoker/ShortcutContainer.java @@ -0,0 +1,30 @@ +package chapter6.invoker; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; + +import chapter6.Command; +import chapter6.model.ShortCut; + +public class ShortcutContainer { + private List shortCuts; + + public ShortcutContainer() { + this.shortCuts = new ArrayList<>(); + } + + public void onKeyPress(String strCmd, Command command) { + ShortCut shortCut = new ShortCut(strCmd, command); + shortCuts.add(shortCut); + } + + public ShortCut getShortCut(String strCmd) { + Optional optionalShortCut = shortCuts.stream() + .filter(shortCut -> shortCut.isSame(strCmd)) + .findFirst(); + + return optionalShortCut.orElseThrow(() -> new NoSuchElementException("일치하는 명령어가 없습니다.")); + } +} diff --git a/chapter6/model/ShortCut.java b/chapter6/model/ShortCut.java new file mode 100644 index 0000000..839ec34 --- /dev/null +++ b/chapter6/model/ShortCut.java @@ -0,0 +1,22 @@ +package chapter6.model; + +import chapter6.Command; + +public class ShortCut { + private String strCmd; + + private Command command; + + public ShortCut(String strCmd, Command command) { + this.strCmd = strCmd; + this.command = command; + } + + public boolean isSame(String strCmd) { + return strCmd.equals(strCmd); + } + + public void executeCommand() { + this.command.execute(); + } +} diff --git a/chapter6/model/Text.java b/chapter6/model/Text.java new file mode 100644 index 0000000..0cad90e --- /dev/null +++ b/chapter6/model/Text.java @@ -0,0 +1,22 @@ +package chapter6.model; + +public class Text { + + private String text; + + public Text(String text) { + this.text = text; + } + + public Text() { + this.text = ""; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} diff --git a/chapter7/adapter/AdapterTest.java b/chapter7/adapter/AdapterTest.java new file mode 100644 index 0000000..a674100 --- /dev/null +++ b/chapter7/adapter/AdapterTest.java @@ -0,0 +1,15 @@ +package chapter7.adapter; + +public class AdapterTest { + public static void main(String[] args) { + RoundHole hole = new RoundHole(5); + + SquarePeg squarePeg = new SquarePeg(3); + + RoundPeg squarePegAdapter = new SquarePegAdapter(squarePeg); + + boolean result = hole.fits(squarePegAdapter); + + System.out.println(result); + } +} diff --git a/chapter7/adapter/RoundHole.java b/chapter7/adapter/RoundHole.java new file mode 100644 index 0000000..72aa3f0 --- /dev/null +++ b/chapter7/adapter/RoundHole.java @@ -0,0 +1,21 @@ +package chapter7.adapter; + +public class RoundHole { + private int radius; + + public RoundHole(int radius) { + this.radius = radius; + } + + public int getRadius() { + return radius; + } + + public boolean fits(RoundPeg peg) { + if( radius > peg.getRadius() ) { + return true; + } + + return false; + } +} diff --git a/chapter7/adapter/RoundPeg.java b/chapter7/adapter/RoundPeg.java new file mode 100644 index 0000000..48c72f3 --- /dev/null +++ b/chapter7/adapter/RoundPeg.java @@ -0,0 +1,14 @@ +package chapter7.adapter; + +public class RoundPeg { + + private int radius; + + public RoundPeg(int radius) { + this.radius = radius; + } + + public int getRadius() { + return radius; + } +} diff --git a/chapter7/adapter/SquarePeg.java b/chapter7/adapter/SquarePeg.java new file mode 100644 index 0000000..30de7c6 --- /dev/null +++ b/chapter7/adapter/SquarePeg.java @@ -0,0 +1,14 @@ +package chapter7.adapter; + +public class SquarePeg { + + private int width; + + public SquarePeg(int width) { + this.width = width; + } + + public int getWidth() { + return width; + } +} diff --git a/chapter7/adapter/SquarePegAdapter.java b/chapter7/adapter/SquarePegAdapter.java new file mode 100644 index 0000000..be0c0c8 --- /dev/null +++ b/chapter7/adapter/SquarePegAdapter.java @@ -0,0 +1,15 @@ +package chapter7.adapter; + +public class SquarePegAdapter extends RoundPeg{ + private SquarePeg peg; + + public SquarePegAdapter(SquarePeg peg) { + super(peg.getWidth()); + this.peg = peg; + } + + @Override + public int getRadius() { + return (int)(peg.getWidth() * Math.sqrt(2) / 2); + } +} diff --git a/chapter7/facade/Application.java b/chapter7/facade/Application.java new file mode 100644 index 0000000..155488b --- /dev/null +++ b/chapter7/facade/Application.java @@ -0,0 +1,11 @@ +package chapter7.facade; + +import chapter7.facade.subsystem.File; + +public class Application { + public static void main(String[] args) { + VideoConverter videoConverter = new VideoConverter(); + File mp4 = videoConverter.convertVideo("funny-cast-video.ogg", "mp4"); + mp4.save(); + } +} diff --git a/chapter7/facade/VideoConverter.java b/chapter7/facade/VideoConverter.java new file mode 100644 index 0000000..8d1d7bd --- /dev/null +++ b/chapter7/facade/VideoConverter.java @@ -0,0 +1,32 @@ +package chapter7.facade; + +import chapter7.facade.model.Buffer; +import chapter7.facade.model.Result; +import chapter7.facade.subsystem.AudioMixer; +import chapter7.facade.subsystem.BitrateReader; +import chapter7.facade.subsystem.Codec; +import chapter7.facade.subsystem.CodecFactory; +import chapter7.facade.subsystem.File; +import chapter7.facade.subsystem.MPEG4CompressionCodec; +import chapter7.facade.subsystem.OggCompressionCodec; +import chapter7.facade.subsystem.VideoFile; + +public class VideoConverter { + + public File convertVideo(String filename, String format) { + File file = new VideoFile(filename); + Codec sourceCodec = (new CodecFactory()).extract(file); + Codec destinationCodec = null; + + if ( format == "mp4") { + destinationCodec = new MPEG4CompressionCodec(); + } else { + destinationCodec = new OggCompressionCodec(); + } + + Buffer buffer = BitrateReader.read(filename, sourceCodec); + Result result = BitrateReader.convert(buffer, destinationCodec); + result = (new AudioMixer()).fix(result); + return new File(result); + } +} diff --git a/chapter7/facade/model/Buffer.java b/chapter7/facade/model/Buffer.java new file mode 100644 index 0000000..42cc04e --- /dev/null +++ b/chapter7/facade/model/Buffer.java @@ -0,0 +1,4 @@ +package chapter7.facade.model; + +public class Buffer { +} diff --git a/chapter7/facade/model/Result.java b/chapter7/facade/model/Result.java new file mode 100644 index 0000000..5a8e9a5 --- /dev/null +++ b/chapter7/facade/model/Result.java @@ -0,0 +1,4 @@ +package chapter7.facade.model; + +public class Result { +} diff --git a/chapter7/facade/subsystem/AudioMixer.java b/chapter7/facade/subsystem/AudioMixer.java new file mode 100644 index 0000000..2ec39b0 --- /dev/null +++ b/chapter7/facade/subsystem/AudioMixer.java @@ -0,0 +1,9 @@ +package chapter7.facade.subsystem; + +import chapter7.facade.model.Result; + +public class AudioMixer { + public Result fix(Result result) { + return result; + } +} diff --git a/chapter7/facade/subsystem/BitrateReader.java b/chapter7/facade/subsystem/BitrateReader.java new file mode 100644 index 0000000..adfc981 --- /dev/null +++ b/chapter7/facade/subsystem/BitrateReader.java @@ -0,0 +1,17 @@ +package chapter7.facade.subsystem; + +import chapter7.facade.model.Buffer; +import chapter7.facade.model.Result; + +public final class BitrateReader { + + private BitrateReader() { + + } + public static Buffer read(String filename, Codec codec) { + return new Buffer(); + } + public static Result convert(Buffer buffer, Codec destinationCodec) { + return new Result(); + } +} diff --git a/chapter7/facade/subsystem/Codec.java b/chapter7/facade/subsystem/Codec.java new file mode 100644 index 0000000..6d67906 --- /dev/null +++ b/chapter7/facade/subsystem/Codec.java @@ -0,0 +1,4 @@ +package chapter7.facade.subsystem; + +public interface Codec { +} diff --git a/chapter7/facade/subsystem/CodecFactory.java b/chapter7/facade/subsystem/CodecFactory.java new file mode 100644 index 0000000..a47a286 --- /dev/null +++ b/chapter7/facade/subsystem/CodecFactory.java @@ -0,0 +1,7 @@ +package chapter7.facade.subsystem; + +public class CodecFactory { + public Codec extract(File file) { + return new NormalCodec(); + } +} diff --git a/chapter7/facade/subsystem/File.java b/chapter7/facade/subsystem/File.java new file mode 100644 index 0000000..d367da7 --- /dev/null +++ b/chapter7/facade/subsystem/File.java @@ -0,0 +1,14 @@ +package chapter7.facade.subsystem; + +import chapter7.facade.model.Result; + +public class File { + + public File(String fileName){ + } + + public File(Result result) { + } + public void save() { + } +} diff --git a/chapter7/facade/subsystem/MPEG4CompressionCodec.java b/chapter7/facade/subsystem/MPEG4CompressionCodec.java new file mode 100644 index 0000000..95355b6 --- /dev/null +++ b/chapter7/facade/subsystem/MPEG4CompressionCodec.java @@ -0,0 +1,4 @@ +package chapter7.facade.subsystem; + +public class MPEG4CompressionCodec implements Codec { +} diff --git a/chapter7/facade/subsystem/NormalCodec.java b/chapter7/facade/subsystem/NormalCodec.java new file mode 100644 index 0000000..b4ed355 --- /dev/null +++ b/chapter7/facade/subsystem/NormalCodec.java @@ -0,0 +1,4 @@ +package chapter7.facade.subsystem; + +public class NormalCodec implements Codec{ +} diff --git a/chapter7/facade/subsystem/OggCompressionCodec.java b/chapter7/facade/subsystem/OggCompressionCodec.java new file mode 100644 index 0000000..158e63c --- /dev/null +++ b/chapter7/facade/subsystem/OggCompressionCodec.java @@ -0,0 +1,4 @@ +package chapter7.facade.subsystem; + +public class OggCompressionCodec implements Codec { +} diff --git a/chapter7/facade/subsystem/VideoFile.java b/chapter7/facade/subsystem/VideoFile.java new file mode 100644 index 0000000..cf23c2a --- /dev/null +++ b/chapter7/facade/subsystem/VideoFile.java @@ -0,0 +1,13 @@ +package chapter7.facade.subsystem; + +import chapter7.facade.model.Result; + +public class VideoFile extends File{ + + public VideoFile(String fileName) { + super(fileName); + } + public VideoFile(Result result) { + super(result); + } +} diff --git a/chapter8/GameAI.java b/chapter8/GameAI.java new file mode 100644 index 0000000..98812d1 --- /dev/null +++ b/chapter8/GameAI.java @@ -0,0 +1,59 @@ +package chapter8; + +import java.util.List; + +import chapter8.model.Enemy; +import chapter8.model.Map; +import chapter8.model.Position; + +public abstract class GameAI { + + private List enemies; + + private Map map; + + protected int resource; + + public GameAI() { + Position center = new Position(5,5); + this.map = new Map(center); + resource = 0; + } + + public void turn() { + collectResources(); + buildStructures(); + buildUnits(); + attack(); + } + + public void collectResources() { + resource += 10; + } + + public abstract void buildStructures(); + + public abstract void buildUnits(); + + public void attack(){ + //가장 가까운 적 호출 + Enemy enemy = closestEnemy(); + if (enemy == null) + sendScouts(map.getCenter()); + else + sendWarriors(enemy.getPosition()); + } + + public void sendScouts(Position position){ + System.out.println("send scouts to " + position.toString()); + } + + public void sendWarriors(Position position){ + System.out.println("send warriors to " + position.toString()); + } + + //가장 가까운 적 + public Enemy closestEnemy() { + return enemies.get(0); + } +} diff --git a/chapter8/MonsterAI.java b/chapter8/MonsterAI.java new file mode 100644 index 0000000..ff2b3e0 --- /dev/null +++ b/chapter8/MonsterAI.java @@ -0,0 +1,14 @@ +package chapter8; + +public class MonsterAI extends GameAI { + + @Override + public void buildStructures() { + System.out.println("몬스터는 건물을 생성하지 않습니다."); + } + + @Override + public void buildUnits() { + System.out.println("몬스터는 유닛을 만들지 않습니다."); + } +} diff --git a/chapter8/OrcsAI.java b/chapter8/OrcsAI.java new file mode 100644 index 0000000..687d8ab --- /dev/null +++ b/chapter8/OrcsAI.java @@ -0,0 +1,17 @@ +package chapter8; + +public class OrcsAI extends GameAI{ + @Override + public void buildStructures() { + System.out.println("오크 건물 생성"); + } + + @Override + public void buildUnits() { + if (super.resource > 10) { + System.out.println("고급 오크 생성"); + } else { + System.out.println("일반 오크 생성"); + } + } +} diff --git a/chapter8/model/Enemy.java b/chapter8/model/Enemy.java new file mode 100644 index 0000000..89d9063 --- /dev/null +++ b/chapter8/model/Enemy.java @@ -0,0 +1,14 @@ +package chapter8.model; + +public class Enemy { + + private Position position; + + public Enemy(Position position) { + this.position = position; + } + + public Position getPosition() { + return position; + } +} diff --git a/chapter8/model/Map.java b/chapter8/model/Map.java new file mode 100644 index 0000000..c74a62b --- /dev/null +++ b/chapter8/model/Map.java @@ -0,0 +1,14 @@ +package chapter8.model; + +public class Map { + + private Position center; + + public Map(Position center) { + this.center = center; + } + + public Position getCenter() { + return center; + } +} diff --git a/chapter8/model/Position.java b/chapter8/model/Position.java new file mode 100644 index 0000000..6c2f89c --- /dev/null +++ b/chapter8/model/Position.java @@ -0,0 +1,20 @@ +package chapter8.model; + +public class Position { + + private final int y; + private final int x; + + public Position(int y, int x) { + this.y = y; + this.x = x; + } + + public int getY() { + return y; + } + + public int getX() { + return x; + } +}