org.protempa.proposition.interval.IntervalFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protempa-framework Show documentation
Show all versions of protempa-framework Show documentation
Protempa Framework is the core of Protempa.
/*
* #%L
* Protempa Framework
* %%
* Copyright (C) 2012 - 2013 Emory University
* %%
* Licensed 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.
* #L%
*/
package org.protempa.proposition.interval;
import org.apache.commons.collections4.map.ReferenceMap;
import org.protempa.proposition.value.AbsoluteTimeGranularity;
import org.protempa.proposition.value.Granularity;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* A factory for creating {@link Interval} objects. A subclass of
* {@link Interval} will be returned that is optimized for the arguments that
* are provided to this factory's getInstance
methods.
*
* @author Andrew Post
*/
public final class IntervalFactory {
private static class DefaultIntervalContainer {
private static Interval defaultInterval = new DefaultInterval();
}
private static final Map, Interval> cache = new ReferenceMap<>();
/**
* Returns an interval specified by the given minimum start, maximum start,
* minimum finish and maximum finish and corresponding granularities. The
* interpretation of the starts and finishes depends on the
* {@link Granularity} implementations specifiied by the
* startGran
and finishGran
arguments. For
* example, if startGran
is an instance of
* {@link AbsoluteTimeGranularity}, minStart
and
* maxStart
are interpreted as date/times.
*
* @param minStart the earliest start of the interval, represented as a
* {@link Long}. If null
, the earliest start will be unbounded.
* @param maxStart the latest start of the interval, represented as a
* {@link Long}. if null
, the latest start will be unbounded.
* @param startGran the {@link Granularity} of the minStart
and
* maxStart
.
* @param minFinish the earliest finish of the interval, represented as a
* {@link Long}. If null
, the earliest finish will be
* unbounded.
* @param maxFinish the latest finish of the interval, represented as a
* {@link Long}. If null
, the latest finish will be unbounded.
* @param finishGran the {@link Granularity} of the minFinish
* and maxFinish
.
* @return an {@link Interval}.
*/
public Interval getInstance(Long minStart, Long maxStart,
Granularity startGran, Long minFinish, Long maxFinish,
Granularity finishGran) {
List