com.cloudera.api
Class ApiUtils

java.lang.Object
  extended by com.cloudera.api.ApiUtils

public final class ApiUtils
extends Object

A collection of utility methods and common constants used by API code.


Field Summary
static String DOT_SNAPSHOT_DIR
          A special path component contained in the path for an HDFS snapshot dir.
 
Method Summary
static
<T> T
baseEquals(T object, Object other)
          Checks whether the other object has the same class as the given object, and casts it to the given object's type.
static void checkLimit(int limit)
          Check that the given limit is positive.
static void checkOffsetAndLimit(int offset, int limit)
          Check that the given values are sane.
static Date getFromDate(String fromString, Date toDate, org.joda.time.Duration window)
          Calculate the fromDate.
static Date newDateFromMillis(long millis)
           
static Date newDateFromString(String value)
           
static org.joda.time.Instant newInstantFromString(String value)
           
static org.joda.time.Period newPeriodFromString(String value)
           
static String printDate(Date date)
           
static String printDate(org.joda.time.Instant instant)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOT_SNAPSHOT_DIR

public static final String DOT_SNAPSHOT_DIR
A special path component contained in the path for an HDFS snapshot dir. Copied from org.apache.hadoop.hdfs.protocol.HdfsConstants.

See Also:
Constant Field Values
Method Detail

newInstantFromString

public static org.joda.time.Instant newInstantFromString(String value)

newDateFromString

public static Date newDateFromString(String value)

newDateFromMillis

public static Date newDateFromMillis(long millis)

newPeriodFromString

public static org.joda.time.Period newPeriodFromString(String value)

printDate

public static String printDate(Date date)

printDate

public static String printDate(org.joda.time.Instant instant)

getFromDate

public static Date getFromDate(String fromString,
                               Date toDate,
                               org.joda.time.Duration window)
Calculate the fromDate. If the fromString is not provided, then the fromDate calculated from the toDate and the window.

Parameters:
fromString - A string representation of the from date.
toDate - The to date for this period
window - The duration of this period
Returns:
the Date object that corresponds to the from date

baseEquals

public static <T> T baseEquals(T object,
                               Object other)
Checks whether the other object has the same class as the given object, and casts it to the given object's type.

The pattern for using this in an implementation of equals() would be:

MyType that = ApiUtils.baseEquals(this, other); return this == that || (that != null && Objects.equal(...) && Objects.equal(...));

Parameters:
object - The object being compared.
other - The object being compared against.
Returns:
other, if it's not null and has the same class as object; null otherwise.

checkOffsetAndLimit

public static void checkOffsetAndLimit(int offset,
                                       int limit)
Check that the given values are sane.

Parameters:
offset - Value to use as offset of a list.
limit - Value to use as limit of a list's size.

checkLimit

public static void checkLimit(int limit)
Check that the given limit is positive.

Parameters:
limit - Value to use as limit of a list's size.


Copyright © Cloudera, Inc. Released under Apache License, Version 2.0.