All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rapiddweller.common.math.IntTimePair Maven / Gradle / Ivy

Go to download

'rapiddweller Common' is an open source Java library forked from Databene Commons by Volker Bergmann. It provides extensions to the Java core library by utility classes, abstract concepts and concrete implementations.

There is a newer version: 2.0.1-jdk-11
Show newest version
/* (c) Copyright 2020 by Volker Bergmann. All rights reserved. */

package com.rapiddweller.common.math;

import com.rapiddweller.common.RegexUtil;

import java.time.LocalTime;

/**
 * Combines an int and a {@link LocalTime} to a pair.

* Created: 27.02.2020 18:35:44 * * @author Volker Bergmann * @since 1.0.12 */ public class IntTimePair { private static final String TIMED_INT_PATTERN = "^(\\-?\\d+) (\\d{2,2}:\\d{2})$"; private final int index; private final LocalTime time; /** * Instantiates a new Int time pair. * * @param index the index * @param time the time */ public IntTimePair(int index, LocalTime time) { this.index = index; this.time = time; } /** * Gets index. * * @return the index */ public int getIndex() { return index; } /** * Gets time. * * @return the time */ public LocalTime getTime() { return time; } @Override public String toString() { return index + " " + time; } /** * Parse int time pair. * * @param spec the spec * @return the int time pair */ public static IntTimePair parse(String spec) { String[] groups = RegexUtil.parse(spec, TIMED_INT_PATTERN); if (groups == null) { throw new IllegalArgumentException("No match for " + spec); } int index = Integer.parseInt(groups[0]); LocalTime time = LocalTime.parse(groups[1]); return new IntTimePair(index, time); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy