diff --git a/src/Intervals.jl b/src/Intervals.jl index 3a3d760f..3f6ed32b 100644 --- a/src/Intervals.jl +++ b/src/Intervals.jl @@ -13,13 +13,13 @@ abstract type Bound end struct Closed <: Bound end struct Open <: Bound end -bound(x::Bool) = x ? Closed : Open +bound_type(x::Bool) = x ? Closed : Open abstract type AbstractInterval{T, L <: Bound, R <: Bound} end Base.eltype(::AbstractInterval{T}) where {T} = T Base.broadcastable(x::AbstractInterval) = Ref(x) -bounds(x::AbstractInterval{T,L,R}) where {T,L,R} = (L, R) +bounds_types(x::AbstractInterval{T,L,R}) where {T,L,R} = (L, R) include("endpoint.jl") include("interval.jl") @@ -40,9 +40,10 @@ export Bound, HB, first, last, + span, + bounds_types, isclosed, anchor, - span, merge, union, union!, diff --git a/src/anchoredinterval.jl b/src/anchoredinterval.jl index 5babadb2..d7e806a9 100644 --- a/src/anchoredinterval.jl +++ b/src/anchoredinterval.jl @@ -67,8 +67,8 @@ AnchoredInterval{P,L,R}(anchor::T) where {P,T,L,R} = AnchoredInterval{P,T,L,R}(a # When an interval is anchored to the lesser endpoint, default to Inclusivity(false, true) # When an interval is anchored to the greater endpoint, default to Inclusivity(true, false) function AnchoredInterval{P,T}(anchor) where {P,T} - L = bound(P ≥ zero(P)) - R = bound(P ≤ zero(P)) + L = bound_type(P ≥ zero(P)) + R = bound_type(P ≤ zero(P)) return AnchoredInterval{P,T,L,R}(anchor) end @@ -208,7 +208,7 @@ end ##### EQUALITY ##### function Base.:(==)(a::AnchoredInterval{P,T}, b::AnchoredInterval{P,T}) where {P,T} - return anchor(a) == anchor(b) && bounds(a) == bounds(b) + return anchor(a) == anchor(b) && bounds_types(a) == bounds_types(b) end # Required for min/max of AnchoredInterval{LaxZonedDateTime} when the anchor is AMB or DNE @@ -256,7 +256,7 @@ function Base.intersect(a::AnchoredInterval{P,T}, b::AnchoredInterval{Q,T}) wher new_P = sp end - L, R = bounds(interval) + L, R = bounds_types(interval) return AnchoredInterval{new_P, T, L, R}(anchor) end diff --git a/src/deprecated.jl b/src/deprecated.jl index 273fca08..dbabd6a1 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -19,117 +19,117 @@ end function Endpoint{T,D}(ep::T, included::Bool) where {T,D} - B = bound(included) + B = bound_type(included) depwarn("`Endpoint{T,D}(ep, $included)` is deprecated, use `Endpoint{T,D,$(repr(B))}(ep)` instead.", :Endpoint) return Endpoint{T,D,B}(ep) end function LeftEndpoint(ep, included::Bool) - B = bound(included) + B = bound_type(included) depwarn("`LeftEndpoint(ep, $included)` is deprecated, use `LeftEndpoint{$(repr(B))}(ep)` instead.", :LeftEndpoint) return LeftEndpoint{B}(ep) end function RightEndpoint(ep, included::Bool) - B = bound(included) + B = bound_type(included) depwarn("`RightEndpoint(ep, $included)` is deprecated, use `RightEndpoint{$(repr(B))}(ep)` instead.", :RightEndpoint) return RightEndpoint{B}(ep) end # intervals.jl function Interval{T}(f, l, inc::Inclusivity) where T - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) depwarn("`Interval{T}(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) return Interval{T,L,R}(f, l) end function Interval{T}(f, l, x::Bool, y::Bool) where T - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) depwarn("`Interval{T}(f, l, $x, $y)` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) return Interval{T,L,R}(f, l) end function Interval(f, l, inc::Inclusivity) - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) depwarn("`Interval(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) return Interval{L,R}(f, l) end function Interval(f, l, x::Bool, y::Bool) - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) depwarn("`Interval(f, l, $x, $y)` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) return Interval{L,R}(f, l) end function inclusivity(interval::AbstractInterval{T,L,R}) where {T,L,R} - depwarn("`inclusivity(interval)` is deprecated and has no direct replacement. See `bounds(interval)` for similar functionality.", :inclusivity) + depwarn("`inclusivity(interval)` is deprecated and has no direct replacement. See `bounds_types(interval)` for similar functionality.", :inclusivity) return Inclusivity(L === Closed, R === Closed; ignore_depwarn=true) end # anchoredintervals.jl function AnchoredInterval{P,T}(anchor, inc::Inclusivity) where {P,T} - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) depwarn("`AnchoredInterval{P,T}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) return AnchoredInterval{P,T,L,R}(anchor) end function AnchoredInterval{P,T}(anchor, x::Bool, y::Bool) where {P,T} - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) depwarn("`AnchoredInterval{P,T}(anchor, $x, $y)` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) return AnchoredInterval{P,T,L,R}(anchor) end function AnchoredInterval{P}(anchor, inc::Inclusivity) where P - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) depwarn("`AnchoredInterval{P}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) return AnchoredInterval{P,L,R}(anchor) end function AnchoredInterval{P}(anchor, x::Bool, y::Bool) where P - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) depwarn("`AnchoredInterval{P}(anchor, $x, $y)` is deprecated, use `AnchoredInterval{P,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) return AnchoredInterval{P,L,R}(anchor) end function HourEnding(anchor, x::Bool, y::Bool) - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) depwarn("`HourEnding(anchor, $x, $y)` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourEnding) return HourEnding{L,R}(anchor) end function HourEnding(anchor, inc::Inclusivity) - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) depwarn("`HourEnding(anchor, $(repr(inc)))` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourEnding) return HourEnding{L,R}(anchor) end function HourBeginning(anchor, x::Bool, y::Bool) - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) depwarn("`HourBeginning(anchor, $x, $y)` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourBeginning) return HourBeginning{L,R}(anchor) end function HourBeginning(anchor, inc::Inclusivity) - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) depwarn("`HourBeginning(anchor, $(repr(inc)))` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourBeginning) return HourBeginning{L,R}(anchor) end function HE(anchor, x::Bool, y::Bool) - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) if !x && y depwarn("`HE(anchor, $x, $y)` is deprecated, use `HE(anchor)` instead.", :HE) else @@ -139,8 +139,8 @@ function HE(anchor, x::Bool, y::Bool) end function HE(anchor, inc::Inclusivity) - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) if !first(inc) && last(inc) depwarn("`HE(anchor, $(repr(inc)))` is deprecated, use `HE(anchor)` instead.", :HE) else @@ -150,8 +150,8 @@ function HE(anchor, inc::Inclusivity) end function HB(anchor, x::Bool, y::Bool) - L = bound(x) - R = bound(y) + L = bound_type(x) + R = bound_type(y) if x && !y depwarn("`HB(anchor, $x, $y)` is deprecated, use `HB(anchor)` instead.", :HB) else @@ -161,8 +161,8 @@ function HB(anchor, x::Bool, y::Bool) end function HB(anchor, inc::Inclusivity) - L = bound(first(inc)) - R = bound(last(inc)) + L = bound_type(first(inc)) + R = bound_type(last(inc)) if first(inc) && !last(inc) depwarn("`HB(anchor, $(repr(inc)))` is deprecated, use `HB(anchor)` instead.", :HB) else diff --git a/src/endpoint.jl b/src/endpoint.jl index 1fefaf67..12aa4586 100644 --- a/src/endpoint.jl +++ b/src/endpoint.jl @@ -24,8 +24,8 @@ RightEndpoint{B}(ep::T) where {T,B} = RightEndpoint{T,B}(ep) LeftEndpoint(i::AbstractInterval{T,L,R}) where {T,L,R} = LeftEndpoint{T,L}(first(i)) RightEndpoint(i::AbstractInterval{T,L,R}) where {T,L,R} = RightEndpoint{T,R}(last(i)) -bound(x::Endpoint{T,D,B}) where {T,D,B} = B -isclosed(x::Endpoint) = bound(x) === Closed +bound_type(x::Endpoint{T,D,B}) where {T,D,B} = B +isclosed(x::Endpoint) = bound_type(x) === Closed function Base.hash(x::Endpoint{T,D,B}, h::UInt) where {T,D,B} # Note: we shouldn't need to hash `T` as this is covered by the endpoint field. diff --git a/src/interval.jl b/src/interval.jl index ef07cf81..8eee2c07 100644 --- a/src/interval.jl +++ b/src/interval.jl @@ -91,7 +91,7 @@ function Interval{T}(left::LeftEndpoint{T,L}, right::RightEndpoint{T,R}) where { end function Interval{T}(left::LeftEndpoint, right::RightEndpoint) where T - Interval{T, bound(left), bound(right)}(T(left.endpoint), T(right.endpoint)) + Interval{T, bound_type(left), bound_type(right)}(T(left.endpoint), T(right.endpoint)) end function Interval(left::LeftEndpoint{S}, right::RightEndpoint{T}) where {S,T} @@ -274,7 +274,7 @@ function contiguous(a::AbstractInterval, b::AbstractInterval) left = max(LeftEndpoint(a), LeftEndpoint(b)) right = min(RightEndpoint(a), RightEndpoint(b)) - return right.endpoint == left.endpoint && bound(left) != bound(right) + return right.endpoint == left.endpoint && bound_type(left) != bound_type(right) end function Base.intersect(a::AbstractInterval{T}, b::AbstractInterval{T}) where T diff --git a/test/anchoredinterval.jl b/test/anchoredinterval.jl index b8d8d61c..f40b9495 100644 --- a/test/anchoredinterval.jl +++ b/test/anchoredinterval.jl @@ -1,4 +1,4 @@ -using Intervals: bounds, canonicalize +using Intervals: canonicalize @testset "AnchoredInterval" begin dt = DateTime(2016, 8, 11, 2) @@ -93,7 +93,7 @@ using Intervals: bounds, canonicalize @test first(interval) == DateTime(2016, 8, 11, 1, 45) @test last(interval) == dt - @test bounds(interval) == (Closed, Closed) + @test bounds_types(interval) == (Closed, Closed) @test span(interval) == -P @@ -102,7 +102,7 @@ using Intervals: bounds, canonicalize @test first(interval) == Date(2016, 8, 11) @test last(interval) == Date(2016, 8, 12) - @test bounds(interval) == (Open, Open) + @test bounds_types(interval) == (Open, Open) @test span(interval) == P # DST transition @@ -130,13 +130,13 @@ using Intervals: bounds, canonicalize interval = AnchoredInterval{-10}(10) @test first(interval) == 0 @test last(interval) == 10 - @test bounds(interval) == (Open, Closed) + @test bounds_types(interval) == (Open, Closed) @test span(interval) == 10 interval = AnchoredInterval{25}('a') @test first(interval) == 'a' @test last(interval) == 'z' - @test bounds(interval) == (Closed, Open) + @test bounds_types(interval) == (Closed, Open) @test span(interval) == 25 end