Skip to content

Instantly share code, notes, and snippets.

View zvozin's full-sized avatar

Alex Zuzin zvozin

View GitHub Profile
public static <T> List<String> toString(List<T> aListOfTs) {
List<String> toPrint = new ArrayList<String>();
for (T aT : aListOfTs) {
toPrint.add(aT.toString());
}
return toPrint;
}
public static <T> Collection<T> toStringFiltered(List<T> aListOfTs) {
return Collections2.filter(aListOfTs, new Predicate<T>()
{
public boolean apply(T from) {
return from.toString().isEmpty();
}
});
}
public static <T> List<String> toString(List<T> aListOfTs) {
List<String> toPrint = new ArrayList<String>();
for (T aT : aListOfTs) {
toPrint.add(aT.toString());
}
return toPrint;
}
aListOfTs.map(_.toString)
public static <T> Collection<String> toString(List<T> aListOfTs) {
return Collections2.transform(aListOfTs, new Function<T, String>()
{
public String apply(T from) {
return from.toString();
}
});
}
public static <T> Collection<T> toStringFiltered(List<T> aListOfTs) {
return Collections2.filter(aListOfTs, new Predicate<T>()
{
public boolean apply(T from) {
return from.toString().isEmpty();
}
});
}
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
public void doWithFields(Class<?> clazz) {
ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback()
{
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
System.out.println(field);
}
});
}
@zvozin
zvozin / steps-of-scala-objects-1.scala
Created June 25, 2011 06:03
Scala Object definition
object ShinyNewObject{
val lovelyProperty = "Property we share"
val notSoLovelyProperty = 3.14
def weCanHazDoStuff(stuff: String) = doingCoolStuffHere(stuff)
}
@zvozin
zvozin / BufferActor.scala
Last active December 17, 2015 09:19
Time-and-space bounded Scalaz-based actor. Buffers elements of type A until either buffer size has been reached, or the time bound has elapsed.
import scalaz.concurrent.Actor
import collection.mutable.ArrayBuffer
import java.util.Timer
/**
* Usage:
*
* <code>
* val buffer = BufferActor[String](onFlush = _ foreach (println(_), onError = println(_))
* buffer ! "Now we're talking!"