Re-factor org.jquantlib.time.Period class to match with QL097, implement all operator methods

Bug #1209858 reported by Zahid Hussain
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
JQuantLib
Fix Released
Medium
Richard Gomes

Bug Description

Many operator related methods are missing in org.jquantlib.time.Period class.
Example:
C++:

    inline Period operator-(const Period& p) {
        return Period(-p.length(),p.units());
    }
This function simply creates a new instances using passed Period.
I don't see any equivalent method in Java. However, there is a minus() method but it uses instances variables.
    public Period minus() {
        return new Period(-this.length, this.units);
    }

Note: many operator related methods in Period are required to implement Schedule.java

=============
Relationships
=============
child of http://bugs.launchpad.net/bugs/jquantlib-394

Tags: code-review
Revision history for this message
Richard Gomes (frgomes) wrote :
Download full text (3.3 KiB)

Ideally, we should mimic QuantLib/C++ API as close as possible.
Below you can see an skeleton produced by our Python script:
-------------------------------

public class Period {

    //
    // private fields
    //

    private int length_;
    private TimeUnit units_;

    //
    // public methods
    //

    public Period() {
        throw new UnsupportedOperationException();
    }

    public Period(int n, TimeUnit units) {
        throw new UnsupportedOperationException();
    }

    public Period(Frequency f) {
        throw new UnsupportedOperationException();
    }

    public int length() /* @ReadOnly */ {
        throw new UnsupportedOperationException();
    }

    public TimeUnit units() /* @ReadOnly */ {
        throw new UnsupportedOperationException();
    }

    public Frequency frequency() /* @ReadOnly */ {
        throw new UnsupportedOperationException();
    }

    public Period addAssign(final Period p) {
        throw new UnsupportedOperationException();
    }

    public Period subAssign(final Period p) {
        throw new UnsupportedOperationException();
    }

    public Period divAssign(int n) {
        throw new UnsupportedOperationException();
    }

    public void normalize() {
        throw new UnsupportedOperationException();
    }

    public double years(final Period ref) {
        throw new UnsupportedOperationException();
    }

    public double months(final Period ref) {
        throw new UnsupportedOperationException();
    }

    public double weeks(final Period ref) {
        throw new UnsupportedOperationException();
    }

    public double days(final Period ref) {
        throw new UnsupportedOperationException();
    }

    public Period mul(T n, TimeUnit units) {
        throw new UnsupportedOperationException();
    }

    public Period mul(TimeUnit units, T n) {
        throw new UnsupportedOperationException();
    }

    public Period sub(final Period ref) {
        throw new UnsupportedOperationException();
    }

    public Period mul(int n, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public Period mul(final Period ref, int n) {
        throw new UnsupportedOperationException();
    }

    public Period div(final Period ref, int n) {
        throw new UnsupportedOperationException();
    }

    public Period add(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public Period sub(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public boolean lt(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public boolean eq(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public boolean ne(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public boolean gt(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public boolean le(final Period ref, final Period ref) {
        throw new UnsupportedOperationException();
    }

    public boolean ge(fi...

Read more...

Revision history for this message
Mufaddal Karachi (levenshtein) wrote :

Completed translation.

Revision history for this message
Richard Gomes (frgomes) wrote :

Closed

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.