Thursday, December 9, 2010

How to make list.toArray() return a specific class


debugStringsArray = new String[] {
"productId", "browseNode", "brand", "merchant", "productSource", "priceMetricDAL", "calculatedCPC",
"mexpMerchantIsActive", "yield", "mexpCatId", "relevance", "boost", "ctr", "tags"
};
if (newGrid) {
// boy it's a PITA to append to an already-initialized array
List debugStringsList = new ArrayList();
for (String debugString : debugStringsArray) {
debugStringsList.add(debugString);
}
debugStringsList.add("productTitle");
debugStringsList.add("imageFile");

// here is how you get around the fact that ordinary list.toArray() returns Object[]
debugStringsArray = new String[debugStringsList.size()];
debugStringsArray = debugStringsList.toArray(debugStringsArray);
}

// ETA: It's actually not that much of a PITA:
ArrayUtils.add(Object[] array, Object element) // convenience method

Wednesday, December 8, 2010

Do not forget: Stay out of debt

To create a fresh copy (not pointing at the source items) use:

Collections.copy(destList, srcList);

Tuesday, November 30, 2010

LinkedHashMap

If you have a HashMap in a particular order and want to make sure it gets maintained, use LinkedHashMap.


// LinkedHashMap remembers the order in which the items are added to the list,
// which preserves the sorting coming from the db
Map<String, List<TopSellerDO>> topSellersByCategoryMap = new LinkedHashMap<String, List<TopSellerDO>>();

Tuesday, November 2, 2010

JSTL code to iterate over a Map

Helpful snippet of JSTL code to iterate over a
Map<String, List<SomeDO>>

<c:set var="topSellersByCategoryMap" value="${results.topSellersByCategoryMap}"/>

<c:forEach var="entry" items="${topSellersByCategoryMap}">
  Name: ${entry.key}
  Value: ${entry.value}

    <c:forEach var="listitem" items="${entry.value}">
      Item: ${listitem.merchant.domain}
    </c:forEach>
</c:forEach>

Thursday, July 22, 2010

Yeats poem

This was quoted in an email from Congressman Alan Grayson and I forgot how much I love it. Putting it here to hold onto for another day.

TURNING and turning in the widening gyre
The falcon cannot hear the falconer;
Things fall apart; the centre cannot hold;
Mere anarchy is loosed upon the world,
The blood-dimmed tide is loosed, and everywhere
The ceremony of innocence is drowned;
The best lack all conviction, while the worst
Are full of passionate intensity.

William Butler Yeats, "The Second Coming"

Wednesday, September 30, 2009

Eight stages on the wheel of spiritual development

In Nature and the Human Soul: Cultivating Wholeness and Community in a Fragmented World, Bill Plotkin describes eight stages on the wheel of spiritual development: Innocent, Explorer, Thespian, Wanderer, Soul Apprentice, Artisan, Master and Sage.

I was an Innocent until around 12-14.

I was an Explorer while I was drinking and finding my way.

I was a Thespian when I began "Acting as If."

I was a Wanderer when I began looking for HP.

I was a Soul Apprentice through my last years living in NYC.

I am now in the Artisan stage. Let's hope it lasts a long time. I'm really not ready to be a Master or a Sage yet.

Friday, April 3, 2009

how to point to a You Tube video part way in

http://www.youtube.com/watch?v=GK1TsjU5MfU#t=0m30s