.equals(), the other way

The new year bring with it a new project for me.
The new project came new colleagues.
And the new colleagues write funny stuff.
One colleague has his own way to check if two strings are the the same:

if (nodeId.compareTo("HEADER") == 0) {
	// ...
}
if (nodeId.compareTo("SHEET") == 0) {
	// ...
}
if (nodeId.compareTo("FOOTER") == 0) {
	// ...
}


Interview

Interviewer: So, if you have to connect to a db
Me: [nod]
I: if you have some problems during the connection…
Me: [nod]
I: how do you handle it?
Me: transactionality?
I: yes
Me: how do I implement it?
I: yes
Me: annotations. On an abstr…
I: no
Me: wha..?
I: wrong
Me: really?
I: yes, you close the connection in the finally block. That’s the right answer


Problem created, problem solved

Many thanks to Emanuele for submitting the code.

This is how you create the problem:

   Long.parseLong(Long.toString(id.longValue()));



And this is how you’re going to solve it:

   try {
           mId = Long.parseLong(Long.toString(id.longValue()));
           log.debug("id: " + id.longValue());
       } catch (NullPointerException npEx) {
           log.debug("NullPointerException npEx :: " + npEx.getMessage());
           return ActionSupport.ERROR;
       } catch (NumberFormatException nfEx) {
           log.debug("NumberFormatException nfEx :: " + nfEx.getMessage());
           return ActionSupport.ERROR;
       } catch (Exception gnEx) {
           log.debug("Exception gnEx :: " + gnEx.getMessage());
           return ActionSupport.ERROR;
       }

Someone said “If you are not part of the solution then you are part of the problem”.
The guy who has wrote this chunk of code, eventually is part of both.


The mailbox

It’s full. All the 120 megabytes.
AD 2011.


The hard way

If you have to initialize a boolean, you can use ‘true’ or ‘false’. It’s easy.

But if you feel a little more fancy you can use something like that:

	boolean result = (IU.getId_profile()+"-"+IU.getId_project()+"-"+IU.getId_LEV())
		  .equals(IU.getId_profile()+"-"+IU.getId_project()+"-"+IU.getId_LEV());


Date Parsing Perversion /4

		public static long parseDate(String month,String day,String time_year)
			throws Exception
		{
			int pos_2p;
			try 
			{
				GregorianCalendar calendar = new GregorianCalendar();
				if((pos_2p=time_year.indexOf(":"))!=-1)
					calendar.set(calendar.get(Calendar.YEAR),
					((Month_STR.indexOf(month)+1+4)/4)-1,
					Integer.parseInt(day),
					Integer.parseInt(time_year.substring(0,pos_2p)),
					Integer.parseInt(time_year.substring(pos_2p+1)),
					0);
				else
					calendar.set(Integer.parseInt(time_year),
					((Month_STR.indexOf(month)+1+4)/4)-1,
					Integer.parseInt(day),
					0,0);
					
				return calendar.getTime().getTime();
				
			} 
			catch (Exception e) 
			{
				e.printStackTrace();
			}
			return 0;
		}

.getTime().getTime()


Cycle

function clearValueTab()
{
	var ITD="";
	for(var i1 = 0; i1 < 3; i1++)
		for(var i2 = 0; i2 < 2; i2++)
			for(var i3 = 0; i3 < 2; i3++)
				for(var i4 = 0; i4 < 2; i4++)
				{
					ITD=(i1==0?'N':(i1==1?'S':'F'))
						+(i2==0?'N':'S')
						+(i3==0?'N':'S')
						+(i4==0?'N':'S');
					if(document.getElementById(ITD+"_T"))
						document.getElementById(ITD+"_T")
							.parentNode.style.display="none";	
				}
}

Hope that this stuff works. I’m not going to touch it.

Just found in the codebase of the big TLC company


Follow

Get every new post delivered to your Inbox.