-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4c24bf6
Showing
973 changed files
with
52,281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Operating System Files | ||
|
||
*.DS_Store | ||
Thumbs.db | ||
*.sw? | ||
.#* | ||
*# | ||
*~ | ||
*.sublime-* | ||
|
||
# Build Artifacts | ||
|
||
.gradle/ | ||
build/ | ||
target/ | ||
bin/ | ||
out/ | ||
dependency-reduced-pom.xml | ||
|
||
# Eclipse Project Files | ||
|
||
.classpath | ||
.project | ||
.metadata | ||
.loadpath | ||
bin/ | ||
.settings/ | ||
|
||
# IntelliJ IDEA Files | ||
|
||
*.iml | ||
*.ipr | ||
*.iws | ||
*.idea | ||
|
||
.vscode/ | ||
README.html | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Core Spring and Spring Boot Lab Projects | ||
|
||
Labs for the Core Spring and Spring Boot courses | ||
|
||
To import these labs into your IDE, import the parent pom `lab/pom.xml` as Maven projects or `lab/build.gradle` as Gradle projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 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 | ||
# | ||
# http://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. | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apply plugin: 'java-library' | ||
|
||
dependencies { | ||
api "org.hibernate.orm:hibernate-core" | ||
api "com.fasterxml.jackson.core:jackson-annotations" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>00-rewards-common</artifactId> | ||
<organization> | ||
<name>Spring Training</name> | ||
<url>https://spring.io/training</url> | ||
</organization> | ||
<packaging>jar</packaging> | ||
<parent> | ||
<groupId>io.spring.training.core-spring</groupId> | ||
<artifactId>parentProject</artifactId> | ||
<version>3.3.1</version> | ||
</parent> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate.orm</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
21 changes: 21 additions & 0 deletions
21
lab/00-rewards-common/src/main/java/common/datetime/DateInterval.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package common.datetime; | ||
|
||
public class DateInterval { | ||
|
||
private SimpleDate start; | ||
|
||
private SimpleDate end; | ||
|
||
public DateInterval(SimpleDate start, SimpleDate end) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public SimpleDate getStart() { | ||
return start; | ||
} | ||
|
||
public SimpleDate getEnd() { | ||
return end; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
lab/00-rewards-common/src/main/java/common/datetime/SimpleDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package common.datetime; | ||
|
||
import java.io.Serializable; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* A simple wrapper around a calendar for working with dates like 12/29/1977. Does not consider time. | ||
*/ | ||
public class SimpleDate implements Serializable { | ||
|
||
private static final long serialVersionUID = 2285962420279644602L; | ||
|
||
private GregorianCalendar base; | ||
|
||
/** | ||
* Create a new simple date. | ||
* @param month the month | ||
* @param day the day | ||
* @param year the year | ||
*/ | ||
public SimpleDate(int month, int day, int year) { | ||
init(new GregorianCalendar(year, month - 1, day)); | ||
} | ||
|
||
SimpleDate(long time) { | ||
GregorianCalendar cal = new GregorianCalendar(); | ||
cal.setTimeInMillis(time); | ||
init(cal); | ||
} | ||
|
||
private SimpleDate() { | ||
init(new GregorianCalendar()); | ||
} | ||
|
||
private void init(GregorianCalendar cal) { | ||
this.base = trimToDays(cal); | ||
} | ||
|
||
private GregorianCalendar trimToDays(GregorianCalendar cal) { | ||
cal.set(Calendar.HOUR_OF_DAY, 0); | ||
cal.set(Calendar.MINUTE, 0); | ||
cal.set(Calendar.SECOND, 0); | ||
cal.set(Calendar.MILLISECOND, 0); | ||
return cal; | ||
} | ||
|
||
/** | ||
* Returns this simple date as a <code>java.util.Date</code> | ||
* @return this simple date as a Date | ||
*/ | ||
public Date asDate() { | ||
return base.getTime(); | ||
} | ||
|
||
/** | ||
* Returns this date in milliseconds since 1970. | ||
* @return | ||
*/ | ||
public long inMilliseconds() { | ||
return asDate().getTime(); | ||
} | ||
|
||
public int compareTo(Object date) { | ||
SimpleDate other = (SimpleDate) date; | ||
return asDate().compareTo(other.asDate()); | ||
} | ||
|
||
public boolean equals(Object day) { | ||
if (!(day instanceof SimpleDate other)) { | ||
return false; | ||
} | ||
return (base.equals(other.base)); | ||
} | ||
|
||
public int hashCode() { | ||
return 29 * base.hashCode(); | ||
} | ||
|
||
/** | ||
* Returns todays date. A convenient static factory method. | ||
*/ | ||
public static SimpleDate today() { | ||
return new SimpleDate(); | ||
} | ||
|
||
/** | ||
* Converts the specified date to a SimpleDate. Will trim hour, minute, second, and millisecond fields. | ||
* @param date the java.util.Date | ||
* @return the simple date | ||
*/ | ||
public static SimpleDate valueOf(Date date) { | ||
return valueOf(date.getTime()); | ||
} | ||
|
||
/** | ||
* Converts the specified long time value to a SimpleDate. Will trim hour, minute, second, and millisecond fields. | ||
* @param time time in millseconds since 1970 | ||
* @return the time as a SimpleDate | ||
*/ | ||
public static SimpleDate valueOf(long time) { | ||
return new SimpleDate(time); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new SimpleDateFormat().format(base.getTime()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
lab/00-rewards-common/src/main/java/common/datetime/SimpleDateEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package common.datetime; | ||
|
||
import java.beans.PropertyEditorSupport; | ||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.util.Locale; | ||
|
||
/** | ||
* A formatter for Simple date properties. Converts object values to well-formatted strings and strings back to | ||
* values. Usable by a data binding framework for binding user input to the model. | ||
*/ | ||
public class SimpleDateEditor extends PropertyEditorSupport { | ||
|
||
private final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); | ||
|
||
@Override | ||
public String getAsText() { | ||
SimpleDate date = (SimpleDate) getValue(); | ||
if (date == null) { | ||
return ""; | ||
} else { | ||
return dateFormat.format(date.asDate()); | ||
} | ||
} | ||
|
||
@Override | ||
public void setAsText(String text) throws IllegalArgumentException { | ||
try { | ||
setValue(SimpleDate.valueOf(dateFormat.parse(text))); | ||
} catch (ParseException e) { | ||
throw new IllegalArgumentException("Unable to convert String '" + text + "' to a SimpleDate", e); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
lab/00-rewards-common/src/main/java/common/datetime/package.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<body> | ||
<p> | ||
Shared classes for representing date and time. | ||
</p> | ||
</body> | ||
</html> |
Oops, something went wrong.