Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
billkable committed Sep 6, 2024
0 parents commit 4c24bf6
Show file tree
Hide file tree
Showing 973 changed files with 52,281 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .gitignore
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

5 changes: 5 additions & 0 deletions README.md
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.
19 changes: 19 additions & 0 deletions lab/.mvn/wrapper/maven-wrapper.properties
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
6 changes: 6 additions & 0 deletions lab/00-rewards-common/build.gradle
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"
}
25 changes: 25 additions & 0 deletions lab/00-rewards-common/pom.xml
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>
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 lab/00-rewards-common/src/main/java/common/datetime/SimpleDate.java
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());
}

}
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);
}
}
}
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>
Loading

0 comments on commit 4c24bf6

Please sign in to comment.