Databases Reference
In-Depth Information
Here's the code for the
ValidPathExpander
:
private
static
class
IntervalPathExpander
implements
PathExpander
<
Interval
>
{
private
final
RelationshipType
relationshipType
;
private
final
Direction
direction
;
private
IntervalPathExpander
(
RelationshipType
relationshipType
,
Direction
direction
)
{
this
.
relationshipType
=
relationshipType
;
this
.
direction
=
direction
;
}
@Override
public
Iterable
<
Relationship
>
expand
(
Path
path
,
BranchState
<
Interval
>
deliveryInterval
)
{
List
<
Relationship
>
results
=
new
ArrayList
<
Relationship
>();
for
(
Relationship
r
:
path
.
endNode
()
.
getRelationships
(
relationshipType
,
direction
)
)
{
Interval
relationshipInterval
=
new
Interval
(
(
Long
)
r
.
getProperty
(
"start_date"
),
(
Long
)
r
.
getProperty
(
"end_date"
)
);
if
(
relationshipInterval
.
contains
(
deliveryInterval
.
getState
()
)
)
{
results
.
add
(
r
);
}
}
return
results
;
}
}
The
IntervalPathExpander
's constructor takes two arguments: a
relationshipType
and a
direction
. This allows the expander to be reused for different types of relationā
ships: in the case of the Global Post graph, the expander will be used to filter both
CONNECTED_TO
and
DELIVERY_ROUTE
relationships.
The expander's
expand()
method takes the
path
to the current node, and the
deliver
yInterval
as supplied by the client. Each time it is called,
expand()
iterates the relevant
relationships on the current node (the current node is given by
path.endNode()
). For
each relationship, the method then compares the relationship's interval with the delivery
interval. If the relationship's interval
contains
the delivery interval, the relationship is
added to the results.
Having looked at the
IntervalPathExpander
, we can now turn to the
ParcelRouteCal
culator
itself. This class encapsulates all the logic necessary to calculate a route between
the point where a parcel enters the network and the final delivery destination. It employs