Thursday, July 26, 2018

Collections such as HashMap and
HashSet use the hashcode value of an object to determine how the object should
be stored in the collection, and the hashcode is used again to help locate the object
in the collection.
Hashing retrieval is a two-step process.
1. Find the right bucket (using hashCode())
2. Search the bucket for the right element (using equals() ).
 If superclass is serializable then subclass is automatically serializable.

Wednesday, July 25, 2018

Singleton Pattern with synchronization:
------------------------------------------------
// Java code to explain double check locking
public class GFG
{
  // private instance, so that it can be
  // accessed by only by getInstance() method
  private static GFG instance;
  private GFG()
  {
    // private constructor
  }
  public static GFG getInstance()
  {
    if (instance == null)
    {
      //synchronized block to remove overhead
      synchronized (GFG.class)
      {
        if(instance==null)
        {
          // if instance is null, initialize
          instance = new GFG();
        }
       
      }
    }
    return instance;
  }
}
---------------------------------------------------------------------

  1. Check that the variable is initialized (without obtaining the lock). If it is initialized, return it immediately.
  2. Obtain the lock.
  3. Double-check whether the variable has already been initialized: if another thread acquired the lock first, it may have already done the initialization. If so, return the initialized variable.
  4. Otherwise, initialize and return the variable.
SpringBoot with STS Getting Started..
https://www.javacodegeeks.com/2018/07/spring-boot-project-sts.html

Tuesday, July 24, 2018

Slave of Sleep. More than half the life has already finished. Mother save me from sleep.......

Monday, July 23, 2018

Conditional Display of Custom Fields using javascript:

function showHideWorkerFollowOn() {
var elements = document.getElementsByClassName("followOnFor");

for(var i = 0; i < elements.length; i++) {

var str = elements[i].id;
var ary = str.split("-");
var parentCustomFieldDefId = parseInt(ary[1]);
var customFieldDefId = parseInt(ary[2]);

if (parentCustomFieldDefId > 0 && document.getElementById("cfIndex-"+parentCustomFieldDefId)) { // only for follow on
var cfIndex = document.getElementById("cfIndex-"+parentCustomFieldDefId).value;
var cfType = document.getElementById("cfType-"+parentCustomFieldDefId).value;
           
var selectedValue = "";
if (cfType == 'SELECT' || cfType == 'LONG_SELECT') {

var id = "wcustomFields[" + cfIndex + "].value";
selectedValue = document.getElementById(id).value;
 
} else if (cfType == 'SMALL_TEXT' || cfType == 'LARGE_TEXT' || cfType == 'DRILL_DOWN') {

var id = "wcustomFields[" + cfIndex + "].value";
selectedValue = document.getElementById(id).value;
}
else if (cfType == 'RADIO') {

var el = "clientWorker.customFields[" + cfIndex + "].value";
var cfValues = document.getElementsByName(el);
for(var j = 0; j < cfValues.length; j++) {
if(cfValues[j].checked) {
selectedValue = cfValues[j].value;
}
}

} else if (cfType == 'MULTISELECT_CHECKBOX') {

var found = false;
var cfValues = document.getElementsByClassName("cfMulti-"+parentCustomFieldDefId);
for(var j = 0; j < cfValues.length; j++) {
if (cfValues[j].checked && cfValues[j].value == elements[i].value) {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, cfValues[j].value);
found = true;
}
}
if (!found) {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, "");
}

}

if (cfType != 'MULTISELECT_CHECKBOX') {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, selectedValue);
}

}

}
}

function showHideWorkerFollowOnLogic(customFieldDefId, elementValue, selectedValue) {
var followOnDivId = "cfRow-" + customFieldDefId;
var followOnDivValueListId = "cfRow-" + customFieldDefId+"-valueList";
var showThisFollowOn = "showThisFollowOn-" + customFieldDefId;

if (document.getElementById(followOnDivId)) {

if (elementValue == selectedValue) {
document.getElementById(followOnDivId).style.display = 'block';
document.getElementById(followOnDivValueListId).style.display = 'block';
document.getElementById(followOnDivId).removeAttribute('style');
document.getElementById(followOnDivValueListId).removeAttribute('style');

document.getElementById(showThisFollowOn).value = true;
} else {

document.getElementById(followOnDivId).style.display = 'none';
document.getElementById(followOnDivValueListId).style.display = 'none';
document.getElementById(showThisFollowOn).value = false;

var cfIndex = document.getElementById("cfIndex-"+customFieldDefId).value;
var cfType = document.getElementById("cfType-"+customFieldDefId).value;

if (cfType == 'SMALL_TEXT' || cfType == 'LARGE_TEXT' || cfType == 'DRILL_DOWN' ) {

var el = "wcustomFields[" + cfIndex + "].value";
var cfValues = document.getElementsByName(el);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].value = "";
}

} else if (cfType == 'SELECT' || cfType == 'LONG_SELECT') {

var id = "wcustomFields[" + cfIndex + "].value";
document.getElementById(id).selectedIndex = 0;

} else if (cfType == 'RADIO') {

//var el = "clientWorker.customFields[" + cfIndex + "].value";
//var cfValues = document.getElementsByName(el);
var el = "wcustomFields[" + cfIndex + "].value";
var cfValues = document.getElementsByClassName(el);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].checked = false;
}

} else if (cfType == 'MULTISELECT_CHECKBOX') {

var cfValues = document.getElementsByClassName("cfMulti-"+customFieldDefId);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].checked = false;
}

}

}

}
}
-------------
JSP:

   



Thursday, July 19, 2018

Angulat JS Conditional display of CUSTOM FIELDS
--------------------------------------------------------------------------
Angular JS Part:
------------------------
$scope.selectedCustomFieldValuesMap={};
$scope.selectedCustomFieldDefIds=[];
$scope.showHideWorkerFollowOn = function(selectedCustFieldDefId,selectedValue){
if(selectedValue != 'Select'){
if(!$scope.selectedCustomFieldDefIds.includes(selectedCustFieldDefId)){
$scope.selectedCustomFieldDefIds.push(selectedCustFieldDefId);
}
$scope.selectedCustomFieldValuesMap[selectedCustFieldDefId] = selectedValue;
angular.forEach($scope.reqResumeInfo.customFields, function(customField) {
if(selectedCustFieldDefId ==customField.parentCustomFieldDefId && customField.followOnFor !=selectedValue){
remove(selectedCustFieldDefId);
}

});
}else{
removeFromArray($scope.selectedCustomFieldDefIds,selectedCustFieldDefId);
$scope.selectedCustomFieldValuesMap[selectedCustFieldDefId] = '';
}

};
$scope.customIncludes = function(container,value){
var returnValue = false;
var pos = container.indexOf(value);
if (pos >= 0) {
returnValue = true;
}
return returnValue;

};



function removeFromArray(selectedCustomFieldDefIds,selectedCustFieldDefId) {
var index = selectedCustomFieldDefIds.indexOf(selectedCustFieldDefId);
if(index >-1)
selectedCustomFieldDefIds.splice(index,1);
}

function remove(selectedCustFieldDefId){
angular.forEach($scope.reqResumeInfo.customFields, function(customField) {

if(selectedCustFieldDefId ==customField.parentCustomFieldDefId){
removeFromArray($scope.selectedCustomFieldDefIds,selectedCustFieldDefId);
selectedCustFieldDefId=customField.customFieldDefId;
customField.value=null;
$scope.selectedCustomFieldValuesMap[selectedCustFieldDefId] = '';
}
});

}
JSP Part:
 class="row m-t-sm" ng-if="reqResumeInfo.customFields.length > 0" ng-repeat="customField in reqResumeInfo.customFields track by $index" ng-init="$customFieldIndex = $index">

ng-if="customField.parentCustomFieldDefId == 0 || (selectedCustomFieldDefIds.includes(customField.parentCustomFieldDefId) && customField.followOnFor == selectedCustomFieldValuesMap[customField.parentCustomFieldDefId])"










Wednesday, July 18, 2018

Migration of Spring MVC to Boot
-----------------------------------------------
  1. Import the configuration files of your Spring MVC App in Main class from which you initialise Spring boot application. This would ensure that you have the necessary configuration rightly initialised. Java Configurations could just be imported with @Import. With XML configurations, use @ImportXml
  2. If you are using servlet Api Version < 3 in MVC App i,e you have web.xml, then you need to put it in the webapp folder of the project which contains Spring Boot Main class. If Servlet API Version is > 3, then you just put the Spring boot MVC annotations on the class and Import it in main configuration class.
Example:
 @ComponentScan
@EnableAutoConfiguration
@Import(ScheduledTasks.class)
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}