Skip to content

Commit

Permalink
Rename bound/bounds to bound_type/bounds_types
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Jun 11, 2020
1 parent 4c37673 commit 11f70ed
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 52 deletions.
7 changes: 4 additions & 3 deletions src/Intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -40,9 +40,10 @@ export Bound,
HB,
first,
last,
span,
bounds_types,
isclosed,
anchor,
span,
merge,
union,
union!,
Expand Down
8 changes: 4 additions & 4 deletions src/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -256,7 +256,7 @@ function Base.intersect(a::AnchoredInterval{P,T}, b::AnchoredInterval{Q, T}) whe
new_P = sp
end

L, R = bounds(interval)
L, R = bounds_types(interval)
return AnchoredInterval{new_P, T, L, R}(anchor)
end

Expand Down
72 changes: 36 additions & 36 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/endpoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -266,7 +266,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
Expand Down
10 changes: 5 additions & 5 deletions test/anchoredinterval.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Intervals: bounds, canonicalize
using Intervals: canonicalize

@testset "AnchoredInterval" begin
dt = DateTime(2016, 8, 11, 2)
Expand Down Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 11f70ed

Please sign in to comment.