Skip to content

WeightedEdge abstraction #3

@trs123

Description

@trs123

Java seems not to have an abstraction of numbers or arithmetic values.

I first thought that the class Numbers would fill this role and designed a WeightedEdge<V, W extends Number> like this

public interface WeightedEdge<V, W extends Number> {
    W weight();
}

but this does not allow to formulate calculations with the weights, i.e. something like

public interface WeightedPath<V, E extends WeightedEdge<V, W>, W extends Number> 
    extends Path<V, E> {

    default W distance() {
        // Problem: Number.plus() does not exist
        return edges().reduce((sum, edge) -> sum.plus(edge.weight())); 
    }
}

So do we have to declare WeightedEdge to always use double for weights??

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions