Code Monkey home page Code Monkey logo

utils's Introduction

Java Utility Classes

Build Status codecov License

Currently this library contains the following utility classes:

  • ArrayUtils - Utility library for working with Arrays
  • DateUtils - Utility library for working with Dates
  • EnumUtils - Utility library for working with Enums
  • IterableUtils - Utility library for working with Iterables
  • RandomCollectionUtils - Utility library to generate random collections
  • RandomArrayUtils - Utility library to generate random arrays
  • RandomDateUtils - Utility library to return random dates, e.g., Instants, ZonedDateTimes, LocalDates, Dates, etc.
    • Currently supports java.util.Date and all the dates, times, instants, and durations from Java 8's date and time API
  • RandomEnumUtils - Utility library to retrieve random elements from enum instances
  • RandomNumberUtils - Utility library to return random numbers. Unlike Apaches RandomUtils, this supports negative numbers

Example Usage

@Test
public void managerWithFiveSubordinatesHasFavoriteEmployee() {
  Employee manager = createEmployee(JobTitle.MANAGER);
  manager.subordinates = RandomCollectionUtils.randomListFrom(this::createSubordinate, 5);
  Employee favoriteEmployee = IterableUtils.randomFrom(manager.subordinates);
  assertTrue(manager.subordinates.contains(favoriteEmployee));
}

private Employee createEmployee(JobTitle jobTitle) {
  Employee employee = new Employee();
  employee.jobTitle = jobTitle;
  employee.birthDateTime = RandomDateUtils.randomPastZonedDateTime();
  employee.startDate = RandomDateUtils.randomLocalDate();
  employee.endDate = RandomDateUtils.randomLocalDateAfter(employee.startDate);
  employee.clockInTime = RandomDateUtils.randomLocalTime();
  employee.clockOutTime = RandomDateUtils.randomLocalTimeAfter(employee.clockInTime);
  employee.lunchTime = RandomDateUtils.randomLocalTime(employee.clockInTime, employee.clockOutTime);
  employee.subordinates = Collections.emptyList();
  return employee;
}

private Employee createSubordinate() {
  JobTitle[] excludes = new JobTitle[] { JobTitle.MANAGER, JobTitle.SUPERVISOR };
  return createEmployee(RandomEnumUtils.random(JobTitle.class, excludes));
}

private class Employee {

  JobTitle jobTitle;
  ZonedDateTime birthDateTime;
  LocalDate startDate;
  LocalDate endDate;
  LocalTime clockInTime;
  LocalTime clockOutTime;
  LocalTime lunchTime;
  List<Employee> subordinates;
}

private enum JobTitle {
  MANAGER, SUPERVISOR, DEVELOPER, TESTER
}

Where can I get the latest release?

You can download source and binaries from the releases page.

Alternatively you can pull it from the central Maven repositories:

<dependency>
  <groupId>com.github.rkumsher</groupId>
  <artifactId>utils</artifactId>
  <version>1.3</version>
</dependency>

License

This code is under the Apache Licence v2.

utils's People

Contributors

rkumsher avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.