com.dukascopy.api
Class Period

java.lang.Object
  extended by com.dukascopy.api.Period
All Implemented Interfaces:
Serializable, Comparable<Period>

public final class Period
extends Object
implements Comparable<Period>, Serializable

Represents periods of bars. This class is used as enum in java 1.5 and later, but defined as class to allow creation of custom period.

See Also:
Serialized Form

Field Summary
static Period DAILY
           
static Period FIFTEEN_MINS
           
static Period FIVE_MINS
           
static Period FOUR_HOURS
           
 long interval
          Time interval in milliseconds
static Period MONTHLY
           
 int numOfUnits
          Number of time units
static Period ONE_HOUR
           
static Period ONE_MIN
           
static Period ONE_SEC
           
static Period ONE_YEAR
           
static Period TEN_MINS
           
static Period TEN_SECS
           
static Period THIRTY_MINS
           
static Period THIRTY_SECS
           
static Period TICK
          Defines period of tick.
static Period TWENTY_MINS
           
static Period TWENTY_SECS
           
static Period TWO_SECS
           
 Unit unit
          Time unit
static Period WEEKLY
           
 
Constructor Summary
Period(Unit unit, int nUnits)
          Creates custom period
 
Method Summary
 Object clone()
          Throws CloneNotSupportedException
 int compareTo(Period another)
          Compares periods, but instead of using ordinal like enums, uses interval
 boolean equals(Object other)
           
 long getInterval()
          Returns interval in milliseconds.
 int getNumOfUnits()
          Returns number of units.
 Unit getUnit()
          Returns time unit.
 int hashCode()
           
 boolean isSmallerThan(Period period)
          Checks whether this periods time interval is smaller than the one of period
 String name()
          Name of predefined constant exactly how it was defined or null if it's custom period
 int ordinal()
           
 String toString()
           
static Period valueOf(String name)
          Returns one of the predefined periods with specified name.
static Period[] values()
          Returns array of predefined periods
static Period[] valuesForIndicator()
          Returns array of predefined periods applicable to indicators
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TICK

public static final Period TICK
Defines period of tick. All methods usually returning interval or unit will return null or -1


ONE_SEC

public static final Period ONE_SEC

TWO_SECS

public static final Period TWO_SECS

TEN_SECS

public static final Period TEN_SECS

TWENTY_SECS

public static final Period TWENTY_SECS

THIRTY_SECS

public static final Period THIRTY_SECS

ONE_MIN

public static final Period ONE_MIN

FIVE_MINS

public static final Period FIVE_MINS

TEN_MINS

public static final Period TEN_MINS

FIFTEEN_MINS

public static final Period FIFTEEN_MINS

TWENTY_MINS

public static final Period TWENTY_MINS

THIRTY_MINS

public static final Period THIRTY_MINS

ONE_HOUR

public static final Period ONE_HOUR

FOUR_HOURS

public static final Period FOUR_HOURS

DAILY

public static final Period DAILY

WEEKLY

public static final Period WEEKLY

MONTHLY

public static final Period MONTHLY

ONE_YEAR

public static final Period ONE_YEAR

unit

public final Unit unit
Time unit


numOfUnits

public final int numOfUnits
Number of time units


interval

public final long interval
Time interval in milliseconds

Constructor Detail

Period

public Period(Unit unit,
              int nUnits)
Creates custom period

Parameters:
unit - time unit
nUnits - number of time units
Method Detail

getUnit

public final Unit getUnit()
Returns time unit. Returns null for TICK

Returns:
time unit

getNumOfUnits

public final int getNumOfUnits()
Returns number of units. Returns -1 for TICK

Returns:
number of units or -1 if it's TICK

getInterval

public final long getInterval()
Returns interval in milliseconds. For TICK returns -1. For periods with variable length returns only one static value, MONTLY = 30 days, ONE_YEAR = (long) (365.24 * 24 * 60 * 60 * 1000L)

Returns:
interval in milliseconds or -1 if it's TICK

equals

public final boolean equals(Object other)
Overrides:
equals in class Object

clone

public final Object clone()
                   throws CloneNotSupportedException
Throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

compareTo

public final int compareTo(Period another)
Compares periods, but instead of using ordinal like enums, uses interval

Specified by:
compareTo in interface Comparable<Period>

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

toString

public final String toString()
Overrides:
toString in class Object

ordinal

public int ordinal()

name

public String name()
Name of predefined constant exactly how it was defined or null if it's custom period

Returns:
name of period or null for custom periods

valueOf

public static final Period valueOf(String name)
Returns one of the predefined periods with specified name. Throws IllegalArgumentException if there is no predefined period with specified name (all custom periods will throw it)

Parameters:
name - name of the period constant, exactly how it defined
Returns:
period

values

public static final Period[] values()
Returns array of predefined periods

Returns:
predefined periods

valuesForIndicator

public static final Period[] valuesForIndicator()
Returns array of predefined periods applicable to indicators

Returns:
predefined periods

isSmallerThan

public boolean isSmallerThan(Period period)
Checks whether this periods time interval is smaller than the one of period

Parameters:
period -
Returns:
false if period time interval is smaller or is null. True if period time interval is bigger.


Copyright © 2009. All Rights Reserved.