[jOOQ/jOOQ#2968] Added a Range<T> interface
This change makes AbstractRange<T> private, which is much more aligned with jOOQ's general API design
This commit is contained in:
parent
cec7dbb4b5
commit
4118a5bba4
@ -44,14 +44,14 @@ import org.jooq.BindingGetResultSetContext;
|
||||
import org.jooq.BindingGetStatementContext;
|
||||
import org.jooq.BindingRegisterContext;
|
||||
import org.jooq.BindingSetStatementContext;
|
||||
import org.jooq.postgres.extensions.types.AbstractRange;
|
||||
import org.jooq.postgres.extensions.types.Range;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>range</code> data types.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractRangeBinding<U extends AbstractRange<?>> extends AbstractPostgresBinding<Object, U> {
|
||||
abstract class AbstractRangeBinding<U extends Range<?>> extends AbstractPostgresBinding<Object, U> {
|
||||
|
||||
// TODO: This looks just like the AbstractInetBinding. Perhaps rename?
|
||||
|
||||
|
||||
@ -40,14 +40,14 @@ package org.jooq.postgres.extensions.converters;
|
||||
import static org.jooq.tools.StringUtils.isBlank;
|
||||
|
||||
import org.jooq.impl.AbstractConverter;
|
||||
import org.jooq.postgres.extensions.types.AbstractRange;
|
||||
import org.jooq.postgres.extensions.types.Range;
|
||||
|
||||
/**
|
||||
* A converter for {@link AbstractRange} types.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractRangeConverter<X, U extends AbstractRange<X>> extends AbstractConverter<Object, U> {
|
||||
abstract class AbstractRangeConverter<X, U extends Range<X>> extends AbstractConverter<Object, U> {
|
||||
|
||||
public AbstractRangeConverter(Class<U> toType) {
|
||||
super(Object.class, toType);
|
||||
|
||||
@ -37,7 +37,6 @@
|
||||
*/
|
||||
package org.jooq.postgres.extensions.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -47,7 +46,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public abstract class AbstractRange<T> implements Serializable {
|
||||
abstract class AbstractRange<T> implements Range<T> {
|
||||
|
||||
private final T lower;
|
||||
private final T upper;
|
||||
@ -63,27 +62,29 @@ public abstract class AbstractRange<T> implements Serializable {
|
||||
this.upperIncluding = upper != null && upperIncluding;
|
||||
}
|
||||
|
||||
/**
|
||||
* In PostgreSQL, a [x,x) range is considered "empty".
|
||||
*/
|
||||
@Override
|
||||
public /* non-final */ boolean isEmpty() {
|
||||
return lowerIncluding && !upperIncluding && Objects.equals(lower, upper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public final T lower() {
|
||||
return lower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean lowerIncluding() {
|
||||
return lowerIncluding;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public final T upper() {
|
||||
return upper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean upperIncluding() {
|
||||
return upperIncluding;
|
||||
}
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.postgres.extensions.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A <code>RANGE</code> type.
|
||||
*/
|
||||
public interface Range<T> extends Serializable {
|
||||
|
||||
/**
|
||||
* In PostgreSQL, a [x,x) range is considered "empty".
|
||||
*/
|
||||
boolean isEmpty();
|
||||
|
||||
/**
|
||||
* The lower bound of the range.
|
||||
*/
|
||||
@Nullable
|
||||
T lower();
|
||||
|
||||
/**
|
||||
* Whether the {@link #lower()} bound of the range is included in the range.
|
||||
*/
|
||||
boolean lowerIncluding();
|
||||
|
||||
/**
|
||||
* The upper bound of the range.
|
||||
*/
|
||||
@Nullable
|
||||
T upper();
|
||||
|
||||
/**
|
||||
* Whether the {@link #upper()} bound of the range is included in the range.
|
||||
*/
|
||||
boolean upperIncluding();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user