Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2012 International Business Machines Corp. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.ibm.jbatch.container.jsl.impl;
 
 
 public class UnmarshalledJSLComparator {
 
 	public static boolean equals(JSLJob job1JSLJob job2) {
 		if(job1 == null && job2 == nullreturn true;
 		if(job1 == null || job2 == nullreturn false;
 		
 		boolean stillEqual = true;
 		//for each attribute, stillEqual && equal(that attribute)
 		stillEqual = stillEqual &&
 				equals(job1.getListeners(), job2.getListeners()) &&
 				equals(job1.getProperties(), job2.getProperties()) &&
 				true;
 		return stillEqual;
 	}

Compare two <properties> elements and their contents. The properties need not be in the same order.

Parameters:
jslprops1 first <properties> element, could be null
jslprops2 second <properties> element, could be null
Returns:
whether JSLProperties contain the same property names/values
 
 	public static boolean equals(JSLProperties jslprops1JSLProperties jslprops2) {
 		//TODO: test cases
 		if(jslprops1 == null && jslprops2 == nullreturn true;
 		if(jslprops1 == null || jslprops2 == nullreturn false;
 		
 		boolean stillEqual = true;
 		for(Property prop1 : jslprops1.getPropertyList()) {
 			boolean isListenerInOtherList = false;
 			for(Property prop2 : jslprops2.getPropertyList()) {
 				if(equals(prop1prop2))
 					isListenerInOtherList = true;
 			}
 			stillEqual = stillEqual && isListenerInOtherList;
 		}
 		return stillEqual;
 	}

Checks parameters for null before .equals() comparison between them. To be used on leaf nodes of JSLJob hierarchy, e.g.; Java Strings or other built-ins.

Parameters:
o1
o2
Returns:
true if o1 == o2 == null or if o1.equals(o2), and false otherwise.
 
 	public static boolean nullSafeEquals(Object o1Object o2) {
 		if(o1 == null && o2 == nullreturn true// null == null
 		if(o1 == null || o2 == nullreturn false// null != non-null
 		return o1.equals(o2); //evaluate
 	}
 	
 	public static boolean equals(Property prop1Property prop2) {
 		if(prop1 == null && prop2 == nullreturn true;
 		if(prop1 == null || prop2 == nullreturn false;
 		
 		return nullSafeEquals(prop1.getName(), prop2.getName()) &&
 				nullSafeEquals(prop1.getValue(), prop2.getValue());
 	}
 	
 	public static boolean equals(Listeners listeners1Listeners listeners2) {
 		if(listeners1 == null && listeners2 == nullreturn true;
 		if(listeners1 == null || listeners2 == nullreturn false;
 		
 		boolean stillEqual = true;
 		for(Listener listener1 : listeners1.getListenerList()) {
 			boolean isListenerInOtherList = false;
 			for(Listener listener2 : listeners2.getListenerList()) {
 				if(equals(listener1listener2))
 					isListenerInOtherList = true;
 			}
 			stillEqual = stillEqual && isListenerInOtherList;
 		}
		return stillEqual;
	}
	public static boolean equals(Listener listener1Listener listener2) {
		if(listener1 == null && listener2 == nullreturn true;
		if(listener1 == null || listener2 == nullreturn false;
		boolean stillEqual = true;
		stillEqual = stillEqual &&
				nullSafeEquals(listener1.getRef(), listener2.getRef()) &&
				equals(listener1.getProperties(), listener2.getProperties());
		return stillEqual;
	}
	public static boolean equals(Step step1Step step2) {
		if(step1 == null && step2 == nullreturn true;
		if(step1 == null || step2 == nullreturn false;
		//TODO: finish with remaining fields
		return equals(step1.getChunk(), step2.getChunk()) &&
				equals(step1.getListeners(), step2.getListeners()) &&
				equals(step1.getProperties(), step2.getProperties()) &&
	}
	public static boolean equals(Chunk chunk1Chunk chunk2) {
		if(chunk1 == null && chunk2 == nullreturn true;
		if(chunk1 == null || chunk2 == nullreturn false;
		return 	nullSafeEquals(chunk1.getCheckpointPolicy(), chunk2.getCheckpointPolicy()) &&
				nullSafeEquals(chunk1.getItemCount(), chunk2.getItemCount()) &&
				nullSafeEquals(chunk1.getTimeLimit(), chunk2.getTimeLimit()) &&
				nullSafeEquals(chunk1.getProcessor(), chunk2.getProcessor()) &&
				nullSafeEquals(chunk1.getReader(), chunk2.getReader()) &&
				nullSafeEquals(chunk1.getSkipLimit(), chunk2.getSkipLimit()) &&
				nullSafeEquals(chunk1.getWriter(), chunk2.getWriter());
	}
New to GrepCode? Check out our FAQ X