Monday, November 16, 2009

Filtering Collection

package org.jai.core.collections;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class CollectionsFilter {

public static void main(String[] args) {
List list = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6, 7,
8, 9, 10 });
Collection evenNumbers = Utils.filter(list,
new Predicate() {
public boolean apply(Integer i) {
if (i % 2 == 0) {
return true;
}
return false;
}
});

Collection oddNumbers = Utils.filter(list,
new Predicate() {
public boolean apply(Integer i) {
if (i % 2 != 0) {
return true;
}
return false;
}
});
System.out.println("EVEN Numbers > " + evenNumbers);
System.out.println("ODD Numbers > " + oddNumbers);
}

}

Wednesday, October 14, 2009

Passion

It’s passion that makes the difference
Between a good performance and an inspiring performance
to go beyond competence.
It’s passion that lifts a person head and shoulders
above the rest in difficult times.

A strong commitment brings your whole being
into play – body, mind, and spirit,
making you feel more vital and fully alive;
enabling you to tap inner strengths,
resources, abilities and energies
that you didn’t know existed.

When you have fire in your heart, it lifts your entire life;
days go faster, life’s chores become more interesting.
you gain more resilience, more buoyancy,
and when you are spirited,
it radiates to every one around you.

 

 

EasyMock Weird Error

java.lang.NoSuchMethodError: org.easymock.internal.RecordState.(Lorg/easymock/internal/IMocksBehavior;)V
at org.easymock.internal.MocksControl.reset(MocksControl.java:66)
at org.easymock.internal.MocksControl.(MocksControl.java:29)
at org.easymock.classextension.internal.MocksClassControl.(MocksClassControl.java:19
)

As a thumb rule…
Should you find any “L”s or “V”s in the exception stack trace, just check your CLASSPATH. There might be class files(jar files) conflict. Don’t just get bluffed by the Exception message: NoSuchMethodError. The Class and the method will be there…but it might be there more than ONCE.

I got this message while I was trying PowerMock. This distribution has its own EasyMock jar file and my project is also referencing an existing (old version) easy mock jar file. This was fixed when I reorderd the jar file in Order & Export tab of Eclipse’s Java Build Path.

org.hibernate.HibernateException: Wrong column type Found: char, expected: varchar2(255)

Problem:
org.hibernate.HibernateException: Wrong column type Found: char, expected: varchar2(255)

This exception was raised for the mapping:

@Column(name = "CNTRY_NM")
public String getCountry() {
return country;
}

Analysis: This means to say that Hibernate has found char as the dataType of the column in the DATABASE and in your mapping you specified the data type as String.

    By default, the Hibernate converts java.lang.String to varchar2(255).

In other words, the data type of ‘CNTRY_NM’ column was defined as CHAR(50 Byte) in the database. Where as the data type of the corresponding attribute in the Entity class is java.lang.String. As there is a mismatch in the columns, the exception is thrown. When you specify schema validation by Hibernate (hibernate.hbm2ddl.auto = validate) this exception is thrown.

Solution:
@Column(name = "CNTRY_NM", columnDefinition = "char")
public String getCountry() {
return country;
}

Monday, July 6, 2009

Smart Tags


Provide “…choices for enhancing content and layout…”

Feature of Win XP.

Identified by “purple dashed underlining”.

Similar to hyperlinks but more complex and interactive.

When the cursor hovers over a Smart Tagged word, a drop down list appears with a selection of links related to the word.

A button on the toolbar turns the Smart Tag option on and off.

Callout 11 Smart Tag Actions buttonCallout 22 Smart tag indicator

Each smart tag recognizer identifies a type of data, such as names, dates, or telephone numbers, and contains the logic needed to provide one or more actions for each data type.

When you type text into a new document or open an existing document, the logic in the smart tag looks for words that match the data types in the list. When the smart tag finds a match, it places a smart tag indicator— a dotted purple line— under the term and enables the appropriate actions.

The actions you can take depend on the type of data that Word recognizes and labels with a smart tag.

For example, "Nate Sun" in the previous example is recognized as a "person name" smart tag with actions you can take, such as Open Contact, Schedule a Meeting, Add to Contacts, or Insert Address.

Smart Tags recognize patterns (e.g. a part number) and associate actions within Microsoft Office (Word, Excel, PowerPoint, and Outlook). These actions provide a quick way to get information about the part recognized from SAP and AeroPDM.

Smart Tags are indicated by a small purple triangle in Excel or a purple underline in Word/Outlook/PowerPoint

source: Microsoft.

Improving Code Quality with PMD and Eclipse | installation & usage

PMD is a static code analyzer for Java. It scans Java source code and looks for potential problems like:
  • Possible bugs - empty try/catch/finally/switch statements
  • Dead code - unused local variables, parameters and private methods
  • Suboptimal code - wasteful String/StringBuffer usage
  • Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
  • Duplicate code - copied/pasted code means copied/pasted bugs

Follow the below steps to integrate the plugin in Eclipse:

If you are behind a corporate firewall, set the proxy in Eclipse.

Window -> Preferences -> General -> Network Conncetions.

Select Manual proxy configuration.

HTTP Proxy :xxx.yyy.mmm.nnn

Port: 8080

  1. Navigate to Help | Software Updates | Find and Install...
  2. Select "Search for new features to install" and click Next
  3. Click New Remote Site...
  4. Enter a name (PMD) and the URL http://pmd.sourceforge.net/eclipse


  1. In Sites to include in search check PMD and click Finish
  2. In the Search Results dialog check PMD for Eclipse 3 3.1.0 and click Next
  1. Accept the terms of the license agreements and click Next
  2. Click Finish.
  3. Wait for Eclipse to download the required jar files, then click Install
  4. Restart the workbench. This will load the PMD plugin.
  5. Navigate to Window | Show View | Other...
  6. Select PMD | PMD Violations
  7. PMD Violations view should appear at the bottom pane

Set up Preferences

  1. Download the XMl ruleset file to your workspace directory.
  2. Windows ->Preferences -> PMD -> Rules Configuration
  3. Clear All
  4. Confirm by clicking OK
  5. Import rule set...
  6. Browse
  7. Select the file you downloaded above
  8. Click OK to complete import
  9. Click OK to close Windows -> Preferences
  10. When prompted to perform a full rebuild, select yes.

How to use it?

Before launching Eclipse make sure you have enough memory for PMD. This is particularly important when analyzing large projects. In these situations PMD tends to be memory-hungry. Hence, make sure to start with as much memory as you can afford, for example 512M (eclipse.exe -vmargs -Xmx512M)

If PMD Violations view is not open navigate to Window | Show View | Other... and select PMD | PMD Violations

More -> http://pmd.sourceforge.net/


Followers