MMmmm - I think I'm sounding like I'm making this more difficult for myself (and probably confusing myself and everyone else). I will try and elaborate with more information.
I have a class Vehicle Record (this has loads of exceptions i.e. try and catch and when tested on it's own works like a dream. No problems here I feel.
I then have another class VehicleVB. This has a method store, that has the following parameters and declarations which should not be changed.
In the constructor of the class VehicleVB I have:
So I go to my store method to store the VehicleRecord vr BUT I wish to exclude all values which are null or have a
string where it is empty.
I find I have no problems with this when using millions of if statements to go through each of the Strings in VehicleRecord vr i.e.
But I thought this was madness as what if you had a database with a thousand values to one key - it would be
alot of if statements. So I wondered if there was an easier way?
I then took the approach that if dbase values were equal to null or an empty String then I could just delete it after it was stored maybe?
So I tried:
But got the following error at run time
Exception in
thread "main" java.lang.NullPointerException
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.getEntry(Unknown Source)
at java.util.TreeMap.remove(Unknown Source)
at VehicleDB.store(VehicleDB.java:121)
at TestApp.main(TestApp.java:365)
I then tried:
But got the following error at run time:
Validating Registration Date: 0182
The length of the date input by user is: 4
Length of date successfully validated i.e. four digits or characters
VALIDATING YEAR
newYear is: 1982
Finished validating Registration
VALIDATING MONTH
newDate is: 01
Registration Month successfully validated
VALIDATING REGISTRATION NUMBER: ZZ43SSX
The length of the reg input by user is: 7
Length of registration: VALID i.e is 7 characters
VALIDATING FORMAT OF REGISTRATION:
First Character is a letter
3rd and 4th characters are a Digit
5th, 6th or 7th character is a Letter
2nd character is a letter or a number
VALID REGISTRATION FORMAT
Zero null values AND Zero empty strings
The Collection consists of the following:
[NV52SSD=NV52SSD 1003 Ford Mondeo White, QP43SSX=qp43SSX
3 Ford Fiesta Pink, ZZ43SSX=ZZ43SSX 0182 Ford Fiesta
Yellow]
Number of records in database is: = 3
Validating Registration Date: 0285
The length of the date input by user is: 4
Length of date successfully validated i.e. four digits or characters
VALIDATING YEAR
newYear is: 1985
Finished validating Registration
VALIDATING MONTH
newDate is: 02
Registration Month successfully validated
VALIDATING REGISTRATION NUMBER: null
The Collection consists of the following:
[NV52SSD=NV52SSD 1003 Ford Mondeo White, QP43SSX=qp43SSX
3 Ford Fiesta Pink, ZZ43SSX=ZZ43SSX 0182 Ford Fiesta
Yellow]
Number of records in database is: = 3
Finished!!!
Exception in thread "main" java.lang.NullPointerException
at VehicleRecord.validateReg(VehicleRecord.java:391)
at VehicleDB.store(VehicleDB.java:115)
at TestApp.main(TestApp.java:710)
So I decided to look at subMap views (as detailed in
http://math.hws.edu/javanotes/c12/s3.html) BUT this comes across as though you can search on the key but not the values associated with the key.
Am I making things too complicated for myself unnecisarily?