Wednesday, 7 January 2015
Tuesday, 6 January 2015
Java : HashSet
Java HashSet is very powerful Collection type when you want a collection of unique objects. HashSet doesn’t allow duplicate elements. HashSet also gives constant time performance for insertion, removal and retrieval operations. It is also important to note that HashSet doesn’t maintain any order. So, It is recommended to use HashSet if you want a collection of unique elements and order of elements is not so important. If you want your elements to be ordered in some way, you can use LinkedHashSet or TreeSet.
In this Java article, we will see one real time example of HashSet.
Let’s create one HashSet of Student records where each Student record contains three fields – name, rollNo and department. In these, rollNo will be unique for all students.
Let’s create Student class with three fields – name, rollNo and department.
You can notice that hashCode() and equals() methods are overrided in the above class so that two Students objects will be compared solely based on rollNo. That means, two Student objects having same rollNo will be considered as duplicates irrespective of other fields.
Create one HashSet object containing elements of Student type.
How to provide security to your folder with password
Step 1 : create one folder
Step 2 : create one text document with any name ( Ex: secure.txt )
Step 3 : Copy the given code and paste it in your file
@ECHO OFF
title Folder Private
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Private goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Private "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== ENTER YOUR PASSWORD HERE goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Private
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Private
echo Private created successfully
goto End
:End
Step 4 : in above code, enter your password at "ENTER YOUR PASSWORD HERE"
Step 5 : 'Save As' this with .bat extension ( Ex: secure.bat )
Step 6 : remove that original file
Step 7 : Now the file like given below img 1
| img 1 |
Step 8 : If u double click on this, it shows 'private' folder
Step 9 : in this folder,copy your documents ( Ex: data.txt )
step 10: double click on secure.bat then type 'Y' press 'Enter'. the folder disappear.
step 12: enter your password as you are given and press 'Enter'
step 13: it shows private folder. your documents are existed in it.
Advantages:
- It is hides the documents
- these type of securities used in offline war deployment
Disadvantages:
- It can be decode easily with logical effort
- It is not provided 100% security
Java Script : How to sort Javascript arraylist of objects
//How to sort Javascript arraylist of objects
The table like as shown in the figure.
<script>
$(function(){
// Intialized table id with datatable jquey
var table = $('#receiptsList').dataTable();
// ArrayList
var feeList = [];
$(table.fnGetNodes()).each(function(i){
var record = new Object();
record.receiptNo = $('button',table.fnGetData(i)[0]).text();
record.admissionNo = table.fnGetData(i)[1];
record.name = table.fnGetData(i)[2];
record.paidDate = table.fnGetData(i)[3];
record.paidAmount = table.fnGetData(i)[4];
record.paidType = table.fnGetData(i)[5];
record.userName = table.fnGetData(i)[6];
// Object added to arrayList
feeList.push(record);
});
// Sorting is called
feeList.sort(SortByField);
});
function SortByField(a, b){
var aName = a.receiptNo;
var bName = b.receiptNo;
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
}
</script>
Finally arraylist sorted receiptNo wise.
Grails : How to set default value in domain class
// How to set default value in domain class
package com.gb.vamsi
import com.gb.vamsi.common.BaseEntity
class User extends BaseEntity{
String firstName
String lastName
Long accountId
String displayName
String jobRole
String photoUrl
Date lastLogin
boolean chatStatus
static constraints = {
photoUrl nullable:true
lastLogin nullable:true
}
static mapping = {
chatStatus defaultValue:true
}
}
// Here chatStatus by default true
Subscribe to:
Posts (Atom)
