package utils
- Alphabetic
- By Inheritance
- utils
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
implicit final
class
AugmentedFuture[A] extends AnyVal
Implicit extensions for
Future
types. -
class
BufferedIterator[T] extends Iterator[T]
Iterator that pre-fetches elements from a wrapped iterator.
Iterator that pre-fetches elements from a wrapped iterator.
- T
The value type of the iterator.
-
implicit final
class
BufferedIteratorWrapper[T] extends AnyVal
Augments scala.collection.Iterator with a
buffered
method that wraps it into a BufferedIterator.Augments scala.collection.Iterator with a
buffered
method that wraps it into a BufferedIterator.- T
The value type of the iterator.
-
implicit final
class
MapValuesWithKey[K, V] extends AnyVal
Augments scala.collection.Map with an
mapValuesWithKey
method that allows mapping the values while having the keys available.Augments scala.collection.Map with an
mapValuesWithKey
method that allows mapping the values while having the keys available. Similar to the corresponding RDD operation.- K
The key type of the map.
- V
The value type of the map.
-
implicit final
class
MergeableMap[K, V] extends AnyVal
Adds a
mergeWith
method toMap
types. -
class
OnEmptyIterator[T] extends Iterator[T]
Iterator wrapper that calls a user function when there are no elements left.
Iterator wrapper that calls a user function when there are no elements left.
- T
The value type of the iterator.
-
implicit final
class
OnEmptyIteratorWrapper[T] extends AnyVal
Augments scala.collection.Iterator with an
onLast
method that registers a function to be called when there are no elements left.Augments scala.collection.Iterator with an
onLast
method that registers a function to be called when there are no elements left.- T
The value type of the iterator.
Value Members
-
def
bytesToHex(bytes: Array[Byte], lowerCase: Boolean = false): String
Converts given byte array to hexadecimal string.
Converts given byte array to hexadecimal string.
- bytes
the bytes to convert
- lowerCase
if
true
returns a lowercase string. By default the returned string contains uppercase characters- returns
the hexadecimal string
-
def
classForNameIfDerivingFrom[T](name: String)(implicit tag: ClassTag[T]): Try[Class[_ <: T]]
Tries to get a class instance extending
T
given a class name, or returns a relevant exception if not possible.Tries to get a class instance extending
T
given a class name, or returns a relevant exception if not possible.- T
the parent class/interface that the class, specified by name, must extend
- name
the name of the class to get
- tag
the ClassTag for
T
- returns
a class instance extending
T
-
def
fullOuterJoinIterator[K, V, W](iter: Iterator[(K, V)], other: Iterator[(K, W)]): Iterator[(K, (Option[V], Option[W]))]
Performs a full outer join of
iter
andother
.Performs a full outer join of
iter
andother
. For each element (k, v) initer
, the resulting iterator will either contain all pairs (k, (Some(v), Some(w))) for w inother
, or the pair (k, (Some(v), None)) if no elements inother
have key k. Similarly, for each element (k, w) inother
, the resulting iterator will either contain all pairs (k, (Some(v), Some(w))) for v initer
, or the pair (k, (None, Some(w))) if no elements initer
have key k.other
is eagerly traversed.iter
, instead, is lazily traversed. -
implicit
def
functionToPartialFunction[A, B](f: Function[A, B]): PartialFunction[A, B]
An implicit conversion that allows a function to be used as a partial function.
An implicit conversion that allows a function to be used as a partial function.
Used for instantiating OneToOne, OneToMany, ManyToOne, and ManyToMany.
-
def
hexToBytes(hex: String): Array[Byte]
Converts the given hexadecimal string to byte array.
Converts the given hexadecimal string to byte array.
- hex
even number of hexadecimal digits to convert
- returns
the converted bytes, or empty array for empty string
-
def
isSorted[T](l: Seq[T])(implicit ev1: (T) ⇒ Ordered[T]): Boolean
Checks whether a sequence of items is ordered.
Checks whether a sequence of items is ordered.
- T
the type the sequence is made of
- l
the sequence to be checked
- returns
true if the sequence is ordered
-
def
iteratorToSortedSeq[T, B](i: Iterator[T], f: (T) ⇒ B)(implicit arg0: ClassTag[T], o: Ordering[B]): IndexedSeq[T]
Sorts elements referred by an iterator returning a sorted IndexedSeq.
Sorts elements referred by an iterator returning a sorted IndexedSeq.
Iterator referred elements are stored in an array which is sorted and then returned as IndexedSeq. This is mainly needed to avoid temporary collections creation in Spark mapPartitions operations requiring that the partition elements are sorted.
- T
the type of the element referenced by the iterator
- B
the ordered type to sort on
- i
the iterator whose element should be sorted
- f
the mapping function providing the ordered data type to sort on
- o
the ordering object
- returns
the array contained the sorted elements as Seq
- Note
the used stable sort function, by specification, uses java.util.Arrays.sort unless K is a primitive type. On the contrary some specialized version of MergeSort is used. This is considered a compromise as the mentioned Java sorting function is implemented using the adaptive Timsort algorithm.
-
def
leftOuterJoinIterator[K, V, W](iter: Iterator[(K, V)], other: Iterator[(K, W)]): Iterator[(K, (V, Option[W]))]
Performs a left outer join of
iter
andother
.Performs a left outer join of
iter
andother
. For each element (k, v) initer
, the resulting iterator will either contain all pairs (k, (v, Some(w))) for w inother
, or the pair (k, (v, None)) if no elements inother
have key k.other
is eagerly traversed.iter
, instead, is lazily traversed. -
def
newInstanceOrFail[T <: AnyRef](className: String)(implicit arg0: ClassTag[T]): T
Tries to create a new instance of a class given its name.
Tries to create a new instance of a class given its name. Throws an exception if a class with that name extending
T
cannot be found, or if a default constructor for that class does not exist.- T
The type or supertype of the class.
- className
The name of the class.
- returns
A new instance of the class as instance of type
T
.
-
def
nonNegativeMod(x: Int, mod: Int): Int
Calculates 'x' modulo 'mod', takes to consideration sign of x, i.e.
Calculates 'x' modulo 'mod', takes to consideration sign of x, i.e. if 'x' is negative, than 'x' % 'mod' is negative too so function return (x % mod) + mod in that case.
- x
the modulo operation dividend
- mod
the modulo operation divisor. Negative divisors are not supported
- returns
'x' modulo 'mod' with taking into account sign of 'x'
-
def
retry[T](retryCount: Int, sleepMillis: Int)(fn: ⇒ T): T
Calls fn, and in case it throws an exception, retry at most retryCount-1 times.
Calls fn, and in case it throws an exception, retry at most retryCount-1 times.
- T
the return type of the function
- retryCount
the maximum number of tries, including the initial try
- sleepMillis
the base sleep time between retries (in milliseconds). An exponential backoff strategy is used: sleep time is sleepMillis * pow(2, retry-number).
- fn
the function to call
- returns
the value returned by the function
- Annotations
- @tailrec()
-
def
rightOuterJoinIterator[K, V, W](iter: Iterator[(K, V)], other: Iterator[(K, W)]): Iterator[(K, (Option[V], W))]
Performs a right outer join of
iter
andother
.Performs a right outer join of
iter
andother
. For each element (k, w) inother
, the resulting iterator will either contain all pairs (k, (Some(v), w)) for v initer
, or the pair (k, (None, w)) if no elements initer
have key k.other
is eagerly traversed.iter
, instead, is lazily traversed. -
def
shuffle[T](array: Array[T], rnd: Random = Random): array.type
Shuffles an array.
Shuffles an array.
- T
The type of the array's elements.
- array
The array to be shuffled.
- rnd
The random generator. If unspecified, the global
Random
generator will be used.- returns
The modified array.
- Note
This function mutates the array. The array is returned for convenience. The function is thread safe.
-
def
timeIt[R](block: ⇒ R): (R, Long)
Evaluates a block of code and returns its value and the time needed for the evaluation.
Evaluates a block of code and returns its value and the time needed for the evaluation.
- R
the type of the value returned by the evaluation
- block
the code or expression to evaluate
- returns
a tuple of the value returned from the block and time it took to execute it
-
def
tryAndWarnOnly(logger: ContextAwareLogger, message: String)(f: ⇒ Unit): Unit
Calls a function and logs a warning if an exception is thrown, without re-throwing it.
Calls a function and logs a warning if an exception is thrown, without re-throwing it.
- logger
The ContextAwareLogger used to log the warning.
- message
The error message.
- f
The function to be called.
-
def
using[X <: AnyRef { def close(): Unit }, A](resource: X)(f: (X) ⇒ A): A
A wrapper that automatically closes streams.
A wrapper that automatically closes streams. Should be used like this
using(stream) { stream => doSomethingWith(stream) }
- resource
the input stream
-
object
ConfigExtensions
Typesafe Config extensions
-
object
FicusValueReaders
Group of implicit ValueReaders to read config values using Ficus
-
object
Id
A utility object for handling string IDs in DPL.
- object Json4s