Skip to content

Commit 4c24bf6

Browse files
author
Bill Kable
committed
initial commit
0 parents  commit 4c24bf6

973 files changed

Lines changed: 52281 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Operating System Files
2+
3+
*.DS_Store
4+
Thumbs.db
5+
*.sw?
6+
.#*
7+
*#
8+
*~
9+
*.sublime-*
10+
11+
# Build Artifacts
12+
13+
.gradle/
14+
build/
15+
target/
16+
bin/
17+
out/
18+
dependency-reduced-pom.xml
19+
20+
# Eclipse Project Files
21+
22+
.classpath
23+
.project
24+
.metadata
25+
.loadpath
26+
bin/
27+
.settings/
28+
29+
# IntelliJ IDEA Files
30+
31+
*.iml
32+
*.ipr
33+
*.iws
34+
*.idea
35+
36+
.vscode/
37+
README.html
38+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Core Spring and Spring Boot Lab Projects
2+
3+
Labs for the Core Spring and Spring Boot courses
4+
5+
To import these labs into your IDE, import the parent pom `lab/pom.xml` as Maven projects or `lab/build.gradle` as Gradle projects.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip

lab/00-rewards-common/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apply plugin: 'java-library'
2+
3+
dependencies {
4+
api "org.hibernate.orm:hibernate-core"
5+
api "com.fasterxml.jackson.core:jackson-annotations"
6+
}

lab/00-rewards-common/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>00-rewards-common</artifactId>
5+
<organization>
6+
<name>Spring Training</name>
7+
<url>https://spring.io/training</url>
8+
</organization>
9+
<packaging>jar</packaging>
10+
<parent>
11+
<groupId>io.spring.training.core-spring</groupId>
12+
<artifactId>parentProject</artifactId>
13+
<version>3.3.1</version>
14+
</parent>
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.fasterxml.jackson.core</groupId>
18+
<artifactId>jackson-annotations</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.hibernate.orm</groupId>
22+
<artifactId>hibernate-core</artifactId>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package common.datetime;
2+
3+
public class DateInterval {
4+
5+
private SimpleDate start;
6+
7+
private SimpleDate end;
8+
9+
public DateInterval(SimpleDate start, SimpleDate end) {
10+
this.start = start;
11+
this.end = end;
12+
}
13+
14+
public SimpleDate getStart() {
15+
return start;
16+
}
17+
18+
public SimpleDate getEnd() {
19+
return end;
20+
}
21+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package common.datetime;
2+
3+
import java.io.Serializable;
4+
import java.util.Calendar;
5+
import java.util.Date;
6+
import java.util.GregorianCalendar;
7+
import java.text.SimpleDateFormat;
8+
9+
/**
10+
* A simple wrapper around a calendar for working with dates like 12/29/1977. Does not consider time.
11+
*/
12+
public class SimpleDate implements Serializable {
13+
14+
private static final long serialVersionUID = 2285962420279644602L;
15+
16+
private GregorianCalendar base;
17+
18+
/**
19+
* Create a new simple date.
20+
* @param month the month
21+
* @param day the day
22+
* @param year the year
23+
*/
24+
public SimpleDate(int month, int day, int year) {
25+
init(new GregorianCalendar(year, month - 1, day));
26+
}
27+
28+
SimpleDate(long time) {
29+
GregorianCalendar cal = new GregorianCalendar();
30+
cal.setTimeInMillis(time);
31+
init(cal);
32+
}
33+
34+
private SimpleDate() {
35+
init(new GregorianCalendar());
36+
}
37+
38+
private void init(GregorianCalendar cal) {
39+
this.base = trimToDays(cal);
40+
}
41+
42+
private GregorianCalendar trimToDays(GregorianCalendar cal) {
43+
cal.set(Calendar.HOUR_OF_DAY, 0);
44+
cal.set(Calendar.MINUTE, 0);
45+
cal.set(Calendar.SECOND, 0);
46+
cal.set(Calendar.MILLISECOND, 0);
47+
return cal;
48+
}
49+
50+
/**
51+
* Returns this simple date as a <code>java.util.Date</code>
52+
* @return this simple date as a Date
53+
*/
54+
public Date asDate() {
55+
return base.getTime();
56+
}
57+
58+
/**
59+
* Returns this date in milliseconds since 1970.
60+
* @return
61+
*/
62+
public long inMilliseconds() {
63+
return asDate().getTime();
64+
}
65+
66+
public int compareTo(Object date) {
67+
SimpleDate other = (SimpleDate) date;
68+
return asDate().compareTo(other.asDate());
69+
}
70+
71+
public boolean equals(Object day) {
72+
if (!(day instanceof SimpleDate other)) {
73+
return false;
74+
}
75+
return (base.equals(other.base));
76+
}
77+
78+
public int hashCode() {
79+
return 29 * base.hashCode();
80+
}
81+
82+
/**
83+
* Returns todays date. A convenient static factory method.
84+
*/
85+
public static SimpleDate today() {
86+
return new SimpleDate();
87+
}
88+
89+
/**
90+
* Converts the specified date to a SimpleDate. Will trim hour, minute, second, and millisecond fields.
91+
* @param date the java.util.Date
92+
* @return the simple date
93+
*/
94+
public static SimpleDate valueOf(Date date) {
95+
return valueOf(date.getTime());
96+
}
97+
98+
/**
99+
* Converts the specified long time value to a SimpleDate. Will trim hour, minute, second, and millisecond fields.
100+
* @param time time in millseconds since 1970
101+
* @return the time as a SimpleDate
102+
*/
103+
public static SimpleDate valueOf(long time) {
104+
return new SimpleDate(time);
105+
}
106+
107+
@Override
108+
public String toString() {
109+
return new SimpleDateFormat().format(base.getTime());
110+
}
111+
112+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package common.datetime;
2+
3+
import java.beans.PropertyEditorSupport;
4+
import java.text.DateFormat;
5+
import java.text.ParseException;
6+
import java.util.Locale;
7+
8+
/**
9+
* A formatter for Simple date properties. Converts object values to well-formatted strings and strings back to
10+
* values. Usable by a data binding framework for binding user input to the model.
11+
*/
12+
public class SimpleDateEditor extends PropertyEditorSupport {
13+
14+
private final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
15+
16+
@Override
17+
public String getAsText() {
18+
SimpleDate date = (SimpleDate) getValue();
19+
if (date == null) {
20+
return "";
21+
} else {
22+
return dateFormat.format(date.asDate());
23+
}
24+
}
25+
26+
@Override
27+
public void setAsText(String text) throws IllegalArgumentException {
28+
try {
29+
setValue(SimpleDate.valueOf(dateFormat.parse(text)));
30+
} catch (ParseException e) {
31+
throw new IllegalArgumentException("Unable to convert String '" + text + "' to a SimpleDate", e);
32+
}
33+
}
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
<p>
4+
Shared classes for representing date and time.
5+
</p>
6+
</body>
7+
</html>

0 commit comments

Comments
 (0)