Skip to content
Snippets Groups Projects
Commit 4ff4d221 authored by Goik Martin's avatar Goik Martin
Browse files

Direction example source code

parent f2e5a440
No related branches found
No related tags found
No related merge requests found
Showing
with 419 additions and 0 deletions
/target/
/.settings/
.classpath
.project
dependency-reduced-pom.xml
*.log
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.hdm_stuttgart.mi.sd1</groupId>
<artifactId>compass</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>compass</name>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1SectToolsOfTheTrade2.html</url>
<description>Basic Java project.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<linksource>true</linksource>
<additionalOptions>
<additionalOption>-html5</additionalOption>
</additionalOptions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.sd1.direction.Direction</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</plugins>
</build>
</project>
package de.hdm_stuttgart.mi.sd1;
import de.hdm_stuttgart.mi.sd1.direction.Direction;
public class Driver {
public static void main(String[] args) {
final Direction northWest = Direction.NW;
System.out.println(northWest);
}
}
package de.hdm_stuttgart.mi.sd1.direction;
/**
* Representing eight compass directions.
*/
public enum Direction {
N( 0, "north"),
NE( 45, "north by east"),
E( 90, "east"),
SE(135, "south by east"),
S( 180, "south"),
SW(225, "south by west"),
W( 270, "west"),
NW(315, "north by west");
/**
* A direction specified by angle and informal description.
*
* @param degree A value ranging from 0 (N) to 315 (NW) mimic a compass rose.
* @param fullName The usual informal name i.e. north by west.
*/
Direction(final int degree, final String fullName) {
this.degree = degree;
this.fullName = fullName;
}
@Override
public String toString() {
return fullName + " (" + degree + "°)";
}
public final int degree;
public final String fullName;
}
\ No newline at end of file
/target/
/.settings/
.classpath
.project
dependency-reduced-pom.xml
*.log
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.hdm_stuttgart.mi.sd1</groupId>
<artifactId>compass</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<name>compass</name>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1SectToolsOfTheTrade2.html</url>
<description>Basic Java project.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<linksource>true</linksource>
<additionalOptions>
<additionalOption>-html5</additionalOption>
</additionalOptions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.sd1.direction.Direction</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</plugins>
</build>
</project>
package de.hdm_stuttgart.mi.sd1;
import de.hdm_stuttgart.mi.sd1.direction.Direction;
public class Driver {
public static void main(String[] args) {
final Direction southWest = Direction.SW;
System.out.println("Direction: " + southWest);
System.out.println(" Opposite: " + southWest.opposite());
}
}
package de.hdm_stuttgart.mi.sd1.direction;
/**
* Representing eight compass directions.
*/
public enum Direction {
N( 0, "north"),
NE( 45, "north by east"),
E( 90, "east"),
SE(135, "south by east"),
S( 180, "south"),
SW(225, "south by west"),
W( 270, "west"),
NW(315, "north by west");
/**
* A direction specified by angle and informal description.
*
* @param degree A value ranging from 0 (N) to 315 (NW) mimic a compass rose.
* @param fullName The usual informal name i.e. north by west.
*/
Direction(final int degree, final String fullName) {
this.degree = degree;
this.fullName = fullName;
}
/**
* Turning a given direction i.e. {@link #SE} into its counterpart {@link #NW}.
*
* @return Direction opposite to the current one.
*/
public Direction opposite() {
switch (this) {
case N: return S;
case NE: return SW;
case E: return W;
case SE: return NW;
case S: return N;
case SW: return NE;
case W: return E;
case NW: return SE;
default: return null; // Unreachable, but our compiler does not know.
}
}
@Override
public String toString() {
return fullName + " (" + degree + "°)";
}
public final int degree;
public final String fullName;
}
\ No newline at end of file
/target/
/.settings/
.classpath
.project
dependency-reduced-pom.xml
*.log
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.hdm_stuttgart.mi.sd1</groupId>
<artifactId>compass</artifactId>
<version>3.0</version>
<packaging>jar</packaging>
<name>compass</name>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1SectToolsOfTheTrade2.html</url>
<description>Basic Java project.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<linksource>true</linksource>
<additionalOptions>
<additionalOption>-html5</additionalOption>
</additionalOptions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.hdm_stuttgart.mi.sd1.direction.Direction</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</plugins>
</build>
</project>
package de.hdm_stuttgart.mi.sd1;
import de.hdm_stuttgart.mi.sd1.direction.Direction;
public class Driver {
public static void main(String[] args) {
final Direction southWest = Direction.SW;
System.out.println("Direction: " + southWest);
System.out.println(" Opposite: " + southWest.opposite());
}
}
package de.hdm_stuttgart.mi.sd1.direction;
/**
* Representing eight compass directions.
*/
public enum Direction {
N( 0, "north"),
NE( 45, "north by east"),
E( 90, "east"),
SE(135, "south by east"),
S( 180, "south"),
SW(225, "south by west"),
W( 270, "west"),
NW(315, "north by west");
/**
* A direction specified by angle and informal description.
*
* @param degree A value ranging from 0 (N) to 315 (NW) mimic a compass rose.
* @param fullName The usual informal name i.e. north by west.
*/
Direction(final int degree, final String fullName) {
this.degree = degree;
this.fullName = fullName;
}
/**
* Turning a given direction i.e. {@link #SE} into its counterpart {@link #NW}.
*
* @return Direction opposite to the current one.
*/
public Direction opposite() {
return values()[ (ordinal() + 4) % 8];
}
@Override
public String toString() {
return fullName + " (" + degree + "°)";
}
public final int degree;
public final String fullName;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment