Filter data when insert into List

We use list for storing data but there is no way to insertation filter. I mean when i want to insert a specific type of data like a list that always store which string has this value. here i gave one example list that  always filterine during the insertation period. lets consider we have one collection that contain all the car make names. now we need one list that will store only Honda make name.

I used here two class HondaList and ToyotaList that act as list.

———————-HondaList.java

import java.util.LinkedList;
class HondaList extends LinkedList<String> {

public HondaList() {
super();
}

public boolean add(String make) {
if (make.indexOf(“Honda”) == -1) {
return false;
} else {
super.add(make);
return true;
}
}
}
—————- ToyotaList.java

import java.util.LinkedList;
class ToyotaList extends LinkedList<String> {

public ToyotaList() {
super();
}

public boolean add(String make) {
if (make.indexOf(“Toyota”) == -1) {
return false;
} else {
super.add(make);
return true;
}
}
}

—————— Main Class

public class ListDataFilterDemo {
private HondaList hondaList;
private ToyotaList toyotaList;

public ListDataFilterDemo() {
this.hondaList = new HondaList();
this.toyotaList = new ToyotaList();
}

public void addData(){
hondaList.add(“Honda Civic 2002”);
hondaList.add(“Honda Accord 2002”);
hondaList.add(“Toyota Corolla 2002”);

toyotaList.add(“Honda Civic 2002”);
toyotaList.add(“Honda Accord 2002”);
toyotaList.add(“Toyota Corolla 2002”);

for (String make : hondaList) {
System.out.println(make);
}

for (String make : toyotaList) {
System.out.println(make);
}
}

public static void main(String[] args) {
try {
ListDataFilterDemo demo = new ListDataFilterDemo();
demo.addData();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

————- Output

Honda Civic 2002
Honda Accord 2002
Toyota Corolla 2002

HondaList adds all data except Honda data same ToyotaList does.

Making workspace (Set up Eclipse, Tomcat, Ant, Maven, Spring Ide, SVN)

I used eclipse IDE for creating my working environment.

  • Download eclipse.  if you want old version visit this site http://archive.eclipse.org/eclipse/downloads/. unzipped that zip file into your desired location. i used here eclipse v3.4.1.
  • Download tomcat. i used tomcat 5.27 (Windows Service Installer). during installation set the jre path. I guess you have already installed jdk 1.4 or later. install tomcat plugins: download plugins from http://www.easyeclipse.org/site/plugins/tomcat-launcher.html. here you can get some installment information too.

Now run the tomcat server and check this address – http://localhost:8080. you can change the port number by editing tomcat-home/conf/server.xml file.

  • After install tomcat plugins restart your the eclipse by execute the following commands.
    command prompt > eclipse -clean
    Now you can see tomcat in eclipse. Before using the plugin, you must set Tomcat home : Window > Preferences, select Tomcat and set the Tomcat version and Tomcat home fields.
  • Ant : download ant. unzipped your desired location. update your computer env path.click win-key + pause/break key and click Advance tab and select environment variables. create new system variable –
    ANT_HOME=D:/ Development Tools/Java/apache-ant-1.7.0-bin
    update path variable
    PATH= …..;D:/Development Tools/Java/apache-ant-1.7.0-bin/bin

Ensure these two environment variable are set by typing following on command prompt
echo %ANT_HOME%
echo %PATH%

lets check is it installed. open command prompt -> ant press enter. it shows-Buildfile: build.xml does not exist!.  that means it is works.

lets configure eclipse ant. Click Windose -> Prefreneces -> Ant (Runtime) select Classpath tab. now click Ant Home button and set the ant home location.

  • Download Maven.Unzip the maven download to your computer:  D:/Development Tools/Java/maven-2.0.9. update your computer env path.click win-key + pause/break key and click Advance tab and select environment variables. create new system variable –
    M2_HOME=D:/Development Tools/Java/maven-2.0.9
    update path variable
    PATH= …..;D:/Development Tools/Java/maven-2.0.9/bin  Ensure these two environment variable are set by typing following on command prompt

    echo %JAVA_HOME%
    echo %M2_HOME%
    echo %PATH%

type in command prompt ->mvn –version . if this command shows its version that means it works.

You can install maven plugins. use http://m2eclipse.codehaus.org/update/ this link for install this plugin (read the following paragraph for how to install plugins).

please use this link -http://m2eclipse.sonatype.org/update/  this is more update than http://m2eclipse.codehaus.org/update/

  • Click help menu of eclipse and select software update. select available software tab and click add site button. put http://springide.org/updatesite value into location and press OK. after restart you eclipse you will get spring features. lets check is it installed. Press ctrl+N , type spring into new wizard text field then you can see spring tree.
  • SVN: you can download svn client version.

for plugings -Click help menu of eclipse and select software update. select available software tab and click add site button. put http://subclipse.tigris.org/update_1.0.x    value into location and press OK.

or visit this page – http://subclipse.tigris.org/

after restart you eclipse click window->open perspective->other you will see SVN Repository Exploring.

Note – for unzipped i used 7-Zip software this is free.