Wednesday 30 May 2012

How to construct a queue data structure using stacks


Stacks and queues.

  
Each is defined by two basic operations: insert a new item, and remove an item. When we insert an item, our intent is clear. But when we remove an item, which one do we choose? The rule used for a queue is to always remove the item that has been in the collection the mostamount of time. This policy is known as first-in-first-out or FIFO. The rule used for a stack is to always remove the item that has been in the collection the least amount of time. This policy is known as last-in first-out or LIFO.


construct a queue data structure using only the Single stacks


public class SimulatedQueue<E> { 
    private java.util.Stack<E> stack = new java.util.Stack<E>(); 

    public void insert(E elem) { 
        if (!stack.empty()) { 
            E topElem = stack.pop(); 
            insert(elem); 
            stack.push(topElem); 
        } 
        else 
            stack.push(elem); 
    } 

    public E remove() { 
        return stack.pop(); 
    } 
}


construct a queue data structure using only the two stacks


public class Queue<E> 


    private Stack<E> inbox = new Stack<E>(); 
    private Stack<E> outbox = new Stack<E>(); 

    public void queue(E item) { 
        inbox.push(item); 
    } 

    public E dequeue() { 
        if (outbox.isEmpty()) { 
            while (!inbox.isEmpty()) { 
               outbox.push(inbox.pop()); 
            } 
        } 
        return outbox.pop(); 
    } 

}

Friday 18 May 2012

Extjs 4.x Tips and Tricks

I will try to add few points  based on my experience in extjs 4.x.
  • Communication between different controller.(use fireEvent on application)
this.fireEvent('expand', this, cmp, e);
  • Lazy initialization of controller.
someAction: function() {
    var controller = this.getController('AnotherController');
 
    // Remember to call the init method manually
    controller.init();
}
  • Avoid "Id" in coding for reusable component
Don't put id to components, Add id to where it use in your code 
{
  xtype:'customercombo',
  id:'cust-project-field-cust-name'
}
  • Avoid using Ext.getCmp()..use Ext.ComponentQuery  
  • Minimize no of panel in application.
  • Avoid using ownerCt proprety
  • Reduce container nesting
  • Reduce border layout nesting
  • Try to reuse the code
  • Make a cleaner separation between model,view and controller
Only put static code in view and event code in controller and model to store the data
  • Replace Panels with Containers
Panel is more expensive than contaier. Declare   xtype: 'container'  to avoid default panel.
{
 xtype: 'container', // defaultType is 'panel'
 items: [ ... ]
}

Tuesday 15 May 2012

Ant task to deploy ear file to weblogic server from IDE(Jdeveloper/Eclipse).


Please find steps to deploy ear file weblogic server from IDE.

  • Changes in build.properties file.
    weblogic Deployment properties - Modify as per your weblogic environment
    • weblgoic.deployer.uri=t3://localhost:7001
    • weblogic.admin.user=weblogic
    • weblogic.admin.password=welcome1
    • weblogic.server=SWserver
  • Changes in build.xml file.
  • <property environment="env"/>
    <target name="deploy-weblogic" depends="dist">
    
    <taskdef name="wldeploy"
            classname="weblogic.ant.taskdefs.management.WLDeploy">
      <classpath
      <pathelement location="${env.WL_HOME}\server\lib\weblogic.jar"/> 
      </classpath>
    </taskdef>
    <wldeploy action="deploy" verbose="true" debug="true"
    name="${ear.deployment.name}" source="${deploy.dir}/${ear.file}"
    user="${weblogic.admin.user}" password="${weblogic.admin.password}"
    adminurl="${weblgoic.deployer.uri}" targets="${weblogic.server}"  />
    </target>


How to set up DB2 datasource in weblogic server 11g

Before you create datasource in weblogic server you need to follow few steps .

Get the following jar files

  • db2java.zip
  • db2jcc.jar
  • db2jcc_javax.jar
  • db2jcc_license_cisuz.jar
  • db2jcc_license_cu.jar
  • db2cc_javax.jar
change the setDomainEnv.cmd. file with below changes.

set DB2_DRIVER=../sqllib/java/db2java.zip;../sqllib/java/db2jcc.jar;../sqllib/java/db2jcc_javax.jar;.../sqllib/java/db2jcc_license_cisuz.jar;../sqllib/java/db2jcc_license_cu.jar;../sqllib/java/db2cc_javax.jar;
set CLASSPATH=%CLASSPATH%;%DB2_DRIVER%

How to pass extra parameter to extjs combo

I have to one scenario, Suppose there are two combo ,I need to pass first one value as parameter of second combo query param.
Let say i have two combos in form
items:[
{
 fieldLabel: 'Customer Name',
 xtype:'customerlovcombo',
 width:550,
 id:'form-field-custproj-cust-name'
},
{
 fieldLabel: 'Project Name',
 xtype:'projectlovcombo',
 width:550,
 id:'form-field-custproj-proj-name'
}
]

Here i want to pass customerId as part of  proejctlovcombo.
What we need to do is in controller user beforequery to pass extra param as part of  proejctlovcombo

init: function() {
    '#form-field-custproj-proj-name':{
    beforequery:this.formatQuery
    }
},

formatQuery: function(queryEvent) {
var custName = Ext.getCmp('form-filed-cust-name').getRawValue();
 if(custName !=null && custName != ""){
  queryEvent.combo.getStore().getProxy().extraParams.custName=custName;
  }
}

Thursday 10 May 2012

How to change grid column header name in extjs



Suppose I have below grid. I want to change header 2 to  "Inst" from "Instance".

    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [new Ext.grid.RowNumberer({width: 30}),
            {header: "Date", width: 50, dataIndex: 'timestamp', sortable: true},
            {header: "Instance", width: 120, dataIndex: 'olt', sortable: true},
            {header: "DL", width: 50, dataIndex: 'dl', sortable: true}
        ], ...

In extjs 3.x :

   Use the code like this
  grid.getColumnModel().setColumnHeader(2,'Inst');


In extjs 4.x :

   Use the code like this.
   grid.columns[1].setText('Inst');