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 DAILY_SKIP_SUNDAY
           
static Period DAILY_SUNDAY_IN_MONDAY
           
static Period FIFTEEN_MINS
           
static Period FIVE_MINS
           
static Period FOUR_HOURS
           
 long interval
          Deprecated. use getInterval() instead
static Period MONTHLY
           
 int numOfUnits
          Deprecated. use getNumOfUnits() instead
static Period ONE_HOUR
           
static Period ONE_YEAR
           
static Period ONE_MIN
           
static Period ONE_SEC
           
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
          Deprecated. use getUnit() instead
static Period WEEKLY
           
 
Method Summary
 Object clone()
          Throws CloneNotSupportedException
 int compareTo(Period another)
          Compares periods, but instead of using ordinal like enums, uses interval
static Period createCustomPeriod(String name, Unit unit, int unitsCount)
          Deprecated. Please, use createCustomPeriod(Unit, int)}
static Period createCustomPeriod(Unit unit, int unitsCount)
          Method creates custom Period.
 boolean equals(Object other)
           
static List<Period> generateAllCompliantPeriods()
          The method generates all compliant custom periods used in JForex
static List<Period> generateCompliantPeriods(String name, Unit unit, int maxUnitCount)
          Deprecated. Please, use generateCompliantPeriods(Unit, int)
static List<Period> generateCompliantPeriods(String name, Unit unit, int startUnitCount, int maxUnitCount)
          Deprecated. Please, use generateCompliantPeriods(Unit, int, int)
static List<Period> generateCompliantPeriods(Unit unit, int maxUnitCount)
          The method generates and returns the list of compliant periods for passed Unit from 1 to maxUnitCount
static List<Period> generateCompliantPeriods(Unit unit, int startUnitCount, int maxUnitCount)
          The method generates and returns the list of compliant periods for passed Unit from startUnitCount to maxUnitCount
static Period getBasicPeriodForCustom(Period period)
          Returns the biggest possible period for passed custom one.
static Period getCompliancyPeriod()
          The method returns compliancy period
 long getInterval()
          Returns interval in milliseconds.
 int getNumOfUnits()
          Returns number of units.
 Unit getUnit()
          Returns time unit.
 int hashCode()
           
static Period isPeriodBasic(Period period)
          The method checks whether the passed period is basic {TICK, TEN_SECS, ONE_MIN, FIVE_MINS, TEN_MINS, FIFTEEN_MINS, THIRTY_MINS, ONE_HOUR, FOUR_HOURS, DAILY, WEEKLY, MONTHLY} If it is basic - appropriate basic period is returned If it is not basic - null is returned
static boolean isPeriodCompliant(Period period)
          The method checks whether passed period is compliant to etalon period {DAYLY} If compliant - true is returned If not compliant - false is returned
 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

DAILY_SUNDAY_IN_MONDAY

public static final Period DAILY_SUNDAY_IN_MONDAY

DAILY_SKIP_SUNDAY

public static final Period DAILY_SKIP_SUNDAY

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
Deprecated. use getUnit() instead
Time unit


numOfUnits

public final int numOfUnits
Deprecated. use getNumOfUnits() instead
Number of time units


interval

public final long interval
Deprecated. use getInterval() instead
Time interval in milliseconds

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.

createCustomPeriod

public static Period createCustomPeriod(String name,
                                        Unit unit,
                                        int unitsCount)
Deprecated. Please, use createCustomPeriod(Unit, int)}


createCustomPeriod

public static Period createCustomPeriod(Unit unit,
                                        int unitsCount)
Method creates custom Period. Note, that the desired period has to be compliant to Period.getCompliancyPeriod() period If desired period is not compliant, then IllegalArgumentException will thrown If desired period is equal to one of the basic periods, the the appropriate basic period will be returned

Parameters:
unit -
unitsCount -
Returns:
Period

isPeriodCompliant

public static boolean isPeriodCompliant(Period period)
The method checks whether passed period is compliant to etalon period {DAYLY} If compliant - true is returned If not compliant - false is returned

Parameters:
period - period to check
Returns:
boolean

getCompliancyPeriod

public static Period getCompliancyPeriod()
The method returns compliancy period

Returns:
Period

isPeriodBasic

public static Period isPeriodBasic(Period period)
The method checks whether the passed period is basic {TICK, TEN_SECS, ONE_MIN, FIVE_MINS, TEN_MINS, FIFTEEN_MINS, THIRTY_MINS, ONE_HOUR, FOUR_HOURS, DAILY, WEEKLY, MONTHLY} If it is basic - appropriate basic period is returned If it is not basic - null is returned

Parameters:
period - period to check
Returns:
Basic Period

getBasicPeriodForCustom

public static Period getBasicPeriodForCustom(Period period)
Returns the biggest possible period for passed custom one. The returned period

Parameters:
period - custom period
Returns:
biggest possible period

generateAllCompliantPeriods

public static List<Period> generateAllCompliantPeriods()
The method generates all compliant custom periods used in JForex

Returns:
List

generateCompliantPeriods

public static List<Period> generateCompliantPeriods(String name,
                                                    Unit unit,
                                                    int maxUnitCount)
Deprecated. Please, use generateCompliantPeriods(Unit, int)


generateCompliantPeriods

public static List<Period> generateCompliantPeriods(Unit unit,
                                                    int maxUnitCount)
The method generates and returns the list of compliant periods for passed Unit from 1 to maxUnitCount

Parameters:
unit - unit of the period
maxUnitCount - maximum number of units to check
Returns:
List

generateCompliantPeriods

public static List<Period> generateCompliantPeriods(String name,
                                                    Unit unit,
                                                    int startUnitCount,
                                                    int maxUnitCount)
Deprecated. Please, use generateCompliantPeriods(Unit, int, int)


generateCompliantPeriods

public static List<Period> generateCompliantPeriods(Unit unit,
                                                    int startUnitCount,
                                                    int maxUnitCount)
The method generates and returns the list of compliant periods for passed Unit from startUnitCount to maxUnitCount

Parameters:
unit - unit of the period
startUnitCount - minimum number of units to check
maxUnitCount - maximum number of units to check
Returns:
List


Copyright © 2011. All Rights Reserved.