Using Collections.copy for list

Using java Collections to copy array list

I have seen lot’s of people using Collections.copy and most of times you see this error on console

Exception in thread "main" java.lang.IndexOutOfBoundsException:
Source does not fit in dest.

Normally we use following code to copy an array-list

ArrayList<String> items = new ArrayList<String>();

items.add("item 1");
items.add("item 2");
items.add("item 6");

ArrayList<String> items2= new ArrayList<String>(items.size());
Collections.copy(items2,items);

Only problem in the above code is that for list items2 we are assuming that it has same capacity as list items. If you see the code carefully, it is only setting up initial capacity not size and Collections api check for size instead of capacity of list and it result to exception.

IMO there should be an improvement in collection api to copy items, based on capacity, instead of size. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6350752 .

Solution

You can use any of following option to copy a list

ArrayList<String> items2= new ArrayList<String>(items);
ArrayList<String> items2 = (ArrayList<String>)items.clone();

References

http://java.sun.com/javase/6/docs/api/java/util/Collections.html#copy(java.util.List,%20java.util.List)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6350752

Dealing with Multiple Outlook profiles

Recently I was on client site of one of my companies prestigious client for the gathering of some new business requirement and understanding of their existing work model. I faced a typical yet very common problem which i think most of you have faced on your clientele’ visit.

Dealing with multiple outlook profiles specially when you are for a long term client site visit and had to juggle between your company mail account and a new mail id provided by your client to interact with their technical/Business team.

So, here is one common solution which i think most of you might be aware but this blog entry is for those who are still uaware of it. 🙂

The answer is “Extra Outlook”

Steps to configure:

1. Download Extra Outlook from http://www.hammerofgod.com/download/ExtraOutlook.zip,
2. Create a new profile in outlook. Control Panel -> Mail -> Add,
3. Create a bat file with the entry,
extraoutlook.exe “C:\Program Files\Microsoft Office\Office12\outlook.exe” /profile “New Profile”
4. Save the file with extension “.bat”,
5. Open the first instance normally by the outlook icon provided in the start menu,
6. Open second instance by running the bat file from command prompt or by double click.

Note:

1. Keep the bat file in same folder where the extraoutlook.exe is kept,
2. Provide the outlook.exe path as per your machine installation.

Jetspeed2 Statistics Engine

Jetspeed 2 has inbuilt feature of statics, statics engine track all the portlet, pages and users.
All this information stored in database. so can be access and used any time.

statics engine keep track of

Number of time served
Max time taken in executing page/portlet
Avg time taken in executing page/portlet
Min time taken in executing page/portlet

It doesn’t have very good interface, but very use full of statics purpose for porltet
As only container can tell exact time take in execution of a portlet

Jetpseed2 allows you to disable statistics engine. by tweaking [/WEB-INF/assembly/statistics.xml].
It also gives small performance boost.

logging to console can be enable/disable by changing the constructor-0 argument to ture or false.
Database logging can be enable/disable by changing the constructor-1 argument to true or false.

<beans>
<!-- Statistics Implementation -->
<bean id="PortalStatistics"
class="org.apache.jetspeed.statistics.impl.PortalStatisticsImpl"
init-method="springInit"
destroy-method="springDestroy"
>
<!-- logToCLF -->
<constructor-arg index='0' type="boolean"><value>false</value></constructor-arg>

<!-- logToDatabase -->
<constructor-arg  index='1'  type="boolean"><value>true</value></constructor-arg>