Created
November 5, 2015 08:10
-
-
Save hussachai/47be34d6c08547bc59ef to your computer and use it in GitHub Desktop.
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
package org.openjdk.jmh.samples; | |
import java.time.LocalDate; | |
import java.time.Month; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Random; | |
public class Pet { | |
public static enum Type { | |
CAT, DOG | |
} | |
public static enum Color { | |
BLACK, WHITE, BROWN, GREEN | |
} | |
private String name; | |
private Type type; | |
private LocalDate birthdate; | |
private Color color; | |
private int weight; | |
public Pet(String name, Type type, LocalDate birthdate, Color color, int weight){ | |
this.name = name; | |
this.type = type; | |
this.birthdate = birthdate; | |
this.color = color; | |
this.weight = weight; | |
} | |
@Override | |
public String toString(){ | |
return String.format("%s: {name: '%s', birthdate: '%s', color: '%s', weigth: %d}", | |
type, name, birthdate, color, weight); | |
} | |
public String getName() { | |
return name; | |
} | |
public Type getType() { | |
return type; | |
} | |
public LocalDate getBirthdate() { | |
return birthdate; | |
} | |
public Color getColor() { | |
return color; | |
} | |
public int getWeight() { | |
return weight; | |
} | |
private static final List<String> NAMES = Arrays.asList( | |
"Angel", "Amazing", "Babe", "Baboo", "Bambi", "Bear", "Boo", "Bubby", "Buddy", "Bunny", | |
"Candy", "Champ", "Cinnamon", "Cookie", "Cutie", "Daisy", "Dear", "Doll", "Dove", | |
"Goofy", "Handsome", "Hero", "Hottie", "Hunky", "Hunny", "Kitten", "Kitty", "Lala", | |
"Love", "Luv", "Mama", "Mami", "Monkey", "Muffin", "Peanut", "Pinky", "Pooh", "Poopie"); | |
public static List<Pet> createPets(int n){ | |
LocalDate today = LocalDate.now(); | |
Random rand = new Random(); | |
List<Pet> pets = new ArrayList<>(); | |
for(int i = 0; i < n; i++){ | |
String name = NAMES.get(rand.nextInt(NAMES.size())); | |
Type type = rand.nextBoolean()? Type.DOG: Type.CAT; | |
int age = rand.nextInt(13); | |
LocalDate birthdate = LocalDate.of( | |
today.getYear() - age, | |
Month.values()[rand.nextInt(Month.values().length)], rand.nextInt(27) + 1); | |
Color color = Color.values()[rand.nextInt(Color.values().length)]; | |
int weight = (age * 10) + rand.nextInt(15); | |
Pet pet = new Pet(name, type, birthdate, color, weight); | |
pets.add(pet); | |
} | |
return pets; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment