Tuesday, October 1, 2013

The Kong Dillema, Indentity the Monkey -> Government shutdown: 800,000 workers go without pay, and it doesn't stop there

A


"Britney Spears isn't one of the most brilliant scientists in the world but certainly is one of the most rich."l


Original isn't a bad idea.


package org.nanotek;

import java.io.Serializable;

import org.nanotek.util.Base;

public interface Kong<K extends Serializable> extends Base<K> , Serializable {
}
package org.nanotek.cms.domain;
import java.util.Date; import java.io.Serializable;
import org.nanotek.util.Base;
@SuppressWarnings("serial")
public abstract class AbstractBase<K extends Serializable> implements Base<K> {


        public Date dateUpdate;
        public Date dateInsert;
        public Date getDateUpdate() {
                return dateUpdate;
        }
        public void setDateUpdate(Date dateUpdate) {
                this.dateUpdate = dateUpdate;
        }
        public Date getDateInsert() {
                return dateInsert;
        }
        public void setDateInsert(Date dateInsert) {
                this.dateInsert = dateInsert;
        }
}
Small Kong ID ready to use.

package org.nanotek.cms.domain.base;

import org.nanotek.Kong;
import org.nanotek.util.Base;
import org.nanotek.cms.domain.AbstractBase;
@SuppressWarnings({ "serial", "hiding" })
public class KongIdentity<E extends Kong<String>> extends AbstractBase<Kong<String>>{

    private Kong<String> kong;

//    public KongIdentity(Kong<String> string){
//      this.kong = string;
//    }

        public KongIdentity(Kong<String> string) {

                this.kong = string;
        }


        public void setId(Kong<String> id)
    {
        this.kong = id;
    }


        @Override
        public Kong<String> getId() {
                return kong.getId(); // the kong delegate case; or return kong; //if you want to hide the "string id key".-> showing the kong 'cover' hashcode.
        }

@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((kong == null) ? 0 : kong.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; KongIdentity other = (KongIdentity) obj; if (kong == null) { if (other.kong != null) return false; } else if (!kong.equals(other.kong)) return false; return true; }

}

lol -> The Identity cannot implement equals using the String ID method. Otherwise will show that they are "equal" since they aren't. points to same string but are 2 distincts entities (who hold the unicity test is the KongIdentity instead of the StringKong implementation). 




package org.nanotek;

@SuppressWarnings("serial")
public class StringKong implements Kong<String> {

        private String id;

        public StringKong(String id) {
                super();
                this.id = id;
        }

        @Override
        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }

}


package org.nanotek;

import org.nanotek.cms.domain.base.KongIdentity;

public class KongIndentityTest {

        /**
         * @param args
         */
        public static void main(String[] args) {
                        KongIdentity<?> kongIdentity = new KongIdentity(new StringKong("id"));
                        System.out.println(kongIdentity.getId());
        }

}