|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions |
| 6 | + * are met: |
| 7 | + * |
| 8 | + * - Redistributions of source code must retain the above copyright |
| 9 | + * notice, this list of conditions and the following disclaimer. |
| 10 | + * |
| 11 | + * - Redistributions in binary form must reproduce the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer in the |
| 13 | + * documentation and/or other materials provided with the distribution. |
| 14 | + * |
| 15 | + * - Neither the name of Oracle or the names of its |
| 16 | + * contributors may be used to endorse or promote products derived |
| 17 | + * from this software without specific prior written permission. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | + * |
| 31 | + * |
| 32 | + * |
| 33 | + * JavaMoney Examples |
| 34 | + * Copyright 2014, Werner Keil |
| 35 | + * and individual contributors by the @author tags. |
| 36 | + * |
| 37 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 38 | + * you may not use this file except in compliance with the License. |
| 39 | + * You may obtain a copy of the License at |
| 40 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 41 | + * Unless required by applicable law or agreed to in writing, software |
| 42 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 43 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 44 | + * See the License for the specific language governing permissions and |
| 45 | + * limitations under the License. |
| 46 | + */ |
| 47 | +package org.javamoney.examples.console.java10; |
| 48 | + |
| 49 | +import java.util.List; |
| 50 | +import java.util.ArrayList; |
| 51 | +import java.time.chrono.IsoChronology; |
| 52 | +import java.time.LocalDate; |
| 53 | + |
| 54 | +import javax.money.MonetaryAmount; |
| 55 | + |
| 56 | +import org.javamoney.moneta.Money; |
| 57 | + |
| 58 | +/** |
| 59 | + * |
| 60 | + * @author Werner Keil |
| 61 | + * |
| 62 | + */ |
| 63 | +public class Person { |
| 64 | + |
| 65 | + public enum Sex { |
| 66 | + MALE, FEMALE |
| 67 | + } |
| 68 | + |
| 69 | + final String name; |
| 70 | + final LocalDate birthday; |
| 71 | + final Sex gender; |
| 72 | + final String emailAddress; |
| 73 | + final MonetaryAmount salary; |
| 74 | + |
| 75 | + Person(String nameArg, LocalDate birthdayArg, Sex genderArg, |
| 76 | + String emailArg, MonetaryAmount salArg) { |
| 77 | + name = nameArg; |
| 78 | + birthday = birthdayArg; |
| 79 | + gender = genderArg; |
| 80 | + emailAddress = emailArg; |
| 81 | + salary = salArg; |
| 82 | + } |
| 83 | + |
| 84 | + public int getAge() { |
| 85 | + return birthday.until(IsoChronology.INSTANCE.dateNow()).getYears(); |
| 86 | + } |
| 87 | + |
| 88 | + public MonetaryAmount getSalary() { |
| 89 | + return salary; |
| 90 | + } |
| 91 | + |
| 92 | + public void printPerson() { |
| 93 | + System.out.println(name + ", " + this.getAge()); |
| 94 | + } |
| 95 | + |
| 96 | + public Sex getGender() { |
| 97 | + return gender; |
| 98 | + } |
| 99 | + |
| 100 | + public String getName() { |
| 101 | + return name; |
| 102 | + } |
| 103 | + |
| 104 | + public String getEmailAddress() { |
| 105 | + return emailAddress; |
| 106 | + } |
| 107 | + |
| 108 | + LocalDate getBirthday() { |
| 109 | + return birthday; |
| 110 | + } |
| 111 | + |
| 112 | + public static int compareByAge(Person a, Person b) { |
| 113 | + return a.birthday.compareTo(b.birthday); |
| 114 | + } |
| 115 | + |
| 116 | + public static int compareBySalary(Person a, Person b) { |
| 117 | + return a.salary.compareTo(b.salary); |
| 118 | + } |
| 119 | + |
| 120 | + public static List<Person> createRoster() { |
| 121 | + final List<Person> roster = new ArrayList<>(); |
| 122 | + roster.add(new Person("Fred", IsoChronology.INSTANCE.date(1980, 6, 20), |
| 123 | + Person. Sex. MALE, "[email protected]", Money. of( 100000, "USD"))); |
| 124 | + roster.add(new Person("Jane", IsoChronology.INSTANCE.date(1990, 7, 15), |
| 125 | + Person. Sex. FEMALE, "[email protected]", Money. of( 80000, "USD"))); |
| 126 | + roster.add(new Person("George", IsoChronology.INSTANCE |
| 127 | + . date( 1991, 8, 13), Person. Sex. MALE, "[email protected]", |
| 128 | + Money.of(70000, "USD"))); |
| 129 | + roster.add(new Person("Bob", IsoChronology.INSTANCE.date(2000, 9, 12), |
| 130 | + Person. Sex. MALE, "[email protected]", Money. of( 25000, "USD"))); |
| 131 | + |
| 132 | + return roster; |
| 133 | + } |
| 134 | + |
| 135 | +} |
0 commit comments