version numbers and then puzzle over why things don't work when we try to use
new plugin features and forget to check what version number said feature was
introduced into the plugin and be sure that we're using that version. Yay!
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2925 6335cc39-0255-0410-8fd6-9bcaacd3b74c
so that we're 100% external dependency free no matter how you build us. This is
the path to righteousness that all of our libraries must eventually go down to
save us from the dependency frying pan and put us into the dependency fire.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2924 6335cc39-0255-0410-8fd6-9bcaacd3b74c
clearly more awesome. This is about to precipitate an upgrade from a 10 year
old hacked version of Velocity to a zero year old hacked version of Velocity
which is not going to be pleasant, but is roundabout ten years overdue.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2922 6335cc39-0255-0410-8fd6-9bcaacd3b74c
took a Function for computing weight. That would be more useful to me, usually.
The Map version could be reimplemented fairly easily with that...
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2921 6335cc39-0255-0410-8fd6-9bcaacd3b74c
of pick().
- Iterates once.
- Checks each weight for validity.
- Only generates one random number.
On that last point: huh! I don't think there's anything wrong
with what I've done, and passing a Map with all the values as 1 is
identical to calling the other form of pick on the keySet iterator.
So: maybe I can change the Iterator-based picking and plucking
to only use one random double, like this. In fact, it would make
those methods more optimal in another way: we could stop iteration
as soon as we see the Nth element, where N is (1 / random).
Deprecated getWeighted().
RFC.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2915 6335cc39-0255-0410-8fd6-9bcaacd3b74c
Maybe mdb is using a newer compiler that is behaving correctly,
but my 1.6 freaks out without these.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2910 6335cc39-0255-0410-8fd6-9bcaacd3b74c
constants up from the logger impl and back down, so we'll just use Object and
do the casting manually.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2905 6335cc39-0255-0410-8fd6-9bcaacd3b74c
- Instead of duplicating every method twice, once allowing you to specify
your own Random object, there is a static thread-safe sharable instance
that anyone can use, and a factory method to create your own instance
with a supplied Random.
- The goofy methods for picking an element from a collection but skipping
a particular value, or picking from an iterator but providing a count,
are gone.
- Instead there are two methods: pick and pluck, for picking an element
or picking and removing an element. For Iterator, only pick is available.
Optimized code paths are provided for Lists and Collections, but the API
is kept simple.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2901 6335cc39-0255-0410-8fd6-9bcaacd3b74c
adding a function type to samskivert because everyone and their mother has a
function type. This is hopefully innocuous enough and allows you to obtain
generality at the expense of verbosity:
Folds.foldLeft(new Folds.R<Integer>() {
public Integer apply (Integer zero, Integer elem) {
return Math.max(zero, elem);
}
}, 0, values);
Folds.foldLeft(new Folds.R<String>() {
public String apply (String zero, String elem) {
return zero + elem;
}
}, "", strings);
Maybe by Java 8 or 9 we'll have closures and this can become:
Folds.foldLeft((Integer b, Integer a) => Math.max(b, a))
Folds.foldLeft((String b, String a) => b + a)
or maybe:
Folds.foldLeft(#(Integer b, Integer a) { return Math.max(b, a); })
Folds.foldLeft(#(String b, String a) { return b + a; })
who knows where the syntax bike shed arguments will end up. Of course, that'll
probably hit the shelves around 2015 or so at the rate Oracle seems to be
proceeding.
If you really want to get jiggy with the functional programming, you can check
out Functional Java, which goes the whole nine yards, but sort of ignores Java's
standard collections in the process which kind of sucks:
http://functionaljava.org/
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2896 6335cc39-0255-0410-8fd6-9bcaacd3b74c
so wants to be using Scala. For example, in Java:
Folds.sum(0, values)
where values must implement Iterable and all you get is sum. In Scala:
scala> Array(1, 2, 3).getClass // a real array
res1: java.lang.Class[_] = class [I
scala> Array(1, 2, 3).sum
res2: Int = 6
scala> Vector(1, 2, 3).sum // more like ArrayList
res3: Int = 6
scala> Map(1 -> 2, 3 -> 4).keysIterator.sum // even works on Iterator
res4: Int = 4
and you can do arbitrary folds just as easily:
scala> Array(1, 2, 3).reduceLeft(math.max)
res5: Int = 3
scala> Array(2, 3, 4).reduceLeft(_*_)
res6: Int = 24
Want to specify the type of the result? Can do:
scala> Array(1, 2, 3).foldLeft(0L)(_+_)
res7: Long = 6
Have a list of maps you need to merge? No problem:
scala> List(Map(1 -> 2), Map(2 -> 3), Map(3 -> 4)).reduceLeft(_++_)
res8: scala.collection.immutable.Map[Int,Int] = Map((1,2), (2,3), (3,4))
Functional programming truly does start with fun!
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2895 6335cc39-0255-0410-8fd6-9bcaacd3b74c
abstraction, and inlining of LogBuilder code into doLog() so that odd trailing
log arguments can be included without borking our ability to also include a
Throwable as the final argument.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2894 6335cc39-0255-0410-8fd6-9bcaacd3b74c
The Loggers don't strip out the Exception if it's the last
element, so they actually *depend* on this ignoring the last odd element.
Revert my last change until I figure some reasonable compromise out.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2892 6335cc39-0255-0410-8fd6-9bcaacd3b74c
into the starter collection using addAll. Certain Collections, like
guava's Multiset have optimized addAll() methods that recognize
other Multisets.
There is also a putAll() equivalent for Maps.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2891 6335cc39-0255-0410-8fd6-9bcaacd3b74c
And SVN is being super pokey so I'm swimming against molasses and
that wasn't showing yet. Argh.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2889 6335cc39-0255-0410-8fd6-9bcaacd3b74c
If someone wants to use StringUtil.toString(), let them get
the openBox/closeBox/separators they were expected.
Gee, I hope r2885 didn't beak any Log parsing code...
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2886 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This is an incomplete fix and brings up a larger issue that I'll explain
below. Also, this breaks the customization of openBox/closeBox/separator
Strings.
First off, I know of no Collection that doesn't have a decent toString()
implementation. The java.util.Abstract* classes all do something
reasonable and most Collections are built from those.
Guava's Multiset has a defined way of representing itself as a String.
An example would be "[value1, value2 x 100]". This fix is mainly
addressed at fixing that, as this class would do the very dumb thing
if provided with a Multiset.
Do we really customize the openBox/closeBox/separator values? Should we?
The second issue comes from the way Log uses StringUtil to evaluate
the var-args it is passed. Check out the following code.
Iterator<Thing> it = Iterables.concat(_staticThings, newThings).iterator();
log.debug("About to iterate", "user", user, "request", req, "iterator", it);
while (it.hasNext()) {
...
If the logging level is above debug, this works fine. However if one day
you lower your logging level, the message will be logged and the Iterator
will be passed to String.toString(), which will suck all the elements out of it.
That's a problem.
Actually, perhaps the right thing to do is simply to change the Log class
to avoid using this, and instead just call String.valueOf() on all objects
except arrays, which can instead be String'd with the methods added to
java.util.Arrays in 1.5.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2884 6335cc39-0255-0410-8fd6-9bcaacd3b74c
Velocity stuff actually works with a non-hacked Velocity implementation, and
specifically VelocityUtil and ClasspathResourceLoader are used all over the
place for great justice, so we want to support that.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2881 6335cc39-0255-0410-8fd6-9bcaacd3b74c