This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PropertyChangeListenerAdapter implements PropertyChangeListener { | |
final private ChangeListener changeListener; | |
public PropertyChangeListenerAdapter(ChangeListener changeListener) { | |
this.changeListener = changeListener; | |
} | |
@Override | |
public void propertyChange(PropertyChangeEvent evt) { | |
changeListener.stateChanged(new ChangeEvent(evt.getSource())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Safely handles ControlThrowable | |
* | |
* See: [[https://www.sumologic.com/2014/05/05/why-you-should-never-catch-throwable-in-scala/ Why you should never catch Throwable in Scala ]] | |
* | |
* See: [[https://github.com/scala/scala/blob/2.12.x/src/library/scala/util/control/NonFatal.scala scala.util.control.NonFatal.scala] | |
*/ | |
trait CatchSafely { | |
import scala.util.control.ControlThrowable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transmit[R: ClassTag](message: R, validations: (R => Seq[Option[Throwable]])*) = { | |
val conditions: Seq[Option[Throwable]] = | |
(Seq.empty[Option[Throwable]] /: (for { validation <- validations } yield { validation(message)} )) { | |
case (acc, item) => acc ++ item } | |
val lines = | |
(0 /: conditions.flatten) { | |
case (n, e) => | |
val line = n + 1 | |
log.error(s"VALIDATION #${line} :: " + e.getMessage + s"\n" + e.getStackTraceString) | |
line } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collection.generic.CanBuildFrom | |
import collection.immutable.TreeMap | |
object test { | |
class TraversableW[A](t: Traversable[A]) { | |
def as[CC[X] <: Traversable[X]](implicit cbf: CanBuildFrom[Nothing, A, CC[A]]): CC[A] = t.map(identity)(collection.breakOut) | |
def to[Result](implicit cbf: CanBuildFrom[Nothing, A, Result]): Result = t.map(identity)(collection.breakOut) | |
} | |
implicit def ToTraverseableW[A](t: Traversable[A]): TraversableW[A] = new TraversableW[A](t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Employee(id: Int, firstName: String, lastName: String) | |
object Employee { | |
// Note that because `Ordering[A]` is not contravariant, the declaration | |
// must be type-parametrized in the event that you want the implicit | |
// ordering to apply to subclasses of `Employee`. | |
implicit def orderingByName[A <: Employee]: Ordering[A] = | |
Ordering.by(e => (e.lastName, e.firstName)) | |
val orderingById: Ordering[Employee] = Ordering.by(e => e.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#-*- mode: scala; -*- | |
###################################################################### | |
# This Scala scripts extracts versions and dependencies from a list | |
# of pom.xml files passed as argument to the script. | |
###################################################################### | |
exec scala "$0" "$@" | |
!# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
import org.apache.commons.io.FileUtils; | |
public class Resource { | |
private static java.net.URLStreamHandler cp = new org.ops4j.pax.url.classpath.Handler(); | |
private final URL url; | |
private final String paths[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util.implicits | |
object RichConfig extends RichConfig | |
trait RichConfig { | |
import com.typesafe.config.Config | |
import net.ceedubs.ficus.Ficus._ | |
import util.types.Database | |
implicit class RichConfig(config: Config) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.{ Map, HashMap, Set, MultiMap } | |
// val evictedModuleIDs: Seq[ModuleID] = ... | |
val evicteds: Map[String, Set[ModuleID]] = | |
(new HashMap[String, Set[ModuleID]] with MultiMap[String, ModuleID] /: evictedModuleIDs) { | |
case (acc, m) => | |
val key = s"${m.organization}:${m.name}" | |
acc.addBinding(key, m) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Ctx(_state: State) { | |
val state: State = _state | |
val xt: Extracted = Project.extract(state) | |
val bs: BuildStructure = xt.structure | |
val pr: ProjectRef = ProjectRef(bs.root, bs.rootProject(bs.root)) //i.e.: the root project! | |
} |