martes, 31 de marzo de 2015

SVN: How to revert last change on a file?

¿Cómo revertir el último cambio en solo un archivo con SVN?

¿Cuál es la mejor manera de volver a una revisión anterior de un solo archivo en SVN?

svn log -l 2
------------------------------------------------------------------------
r537635 | coco | 2015-03-30 20:58:55 +0000 (Mon, 30 Mar 2015) | 1 line

[Ticket]: Fix bug
------------------------------------------------------------------------
r536022 | coco | 2015-02-20 20:33:51 +0000 (Fri, 20 Feb 2015) | 70 lines

svn merge -c -537635 t/unit/test_01.t

svn merge -c -537635 t/unit/test_01.t
--- Reverse-merging r537635 into 't/unit/test_01.t':
U    t/unit/test_01.t
--- Recording mergeinfo for reverse merge of r537635 into 't/unit/test_01.t':
 G   t/unit/test_01.t
--- Eliding mergeinfo from 't/unit/test_01.t':
 U   t/unit/test_01.t

svn commit -m "[Ticket]: REVERT cambios en unit test"


svn up --ignore-externals
svn log -l 2

------------------------------------------------------------------------
r537657 | coco | 2015-03-31 14:02:24 +0000 (Tue, 31 Mar 2015) | 1 line

[Ticket]: REVERT ultimo cambio en unit test
------------------------------------------------------------------------
r537635 | coco | 2015-03-30 20:58:55 +0000 (Mon, 30 Mar 2015) | 1 line

[Ticket]: Fix bug
------------------------------------------------------------------------



Referencias:

domingo, 1 de marzo de 2015

Java: How to use Generic Types to create a generics class

Java: How to use Generic Types to create a generics class


A generic type is a generic class or interface that is parameterized over types.

Las clases genéricas (con tipos genéricos) permiten, entre otras cosas, forzar la seguridad de los tipos creados por nosostros, en tiempo de compilación. También permiten abstraer comportamiento independientemente de tipo de objeto que se manipule.

Esto se puede apreciar con un ejemplo:

Example diagram




Example code


//........................................................
//File name: IMyGenericClass.java

package com.daro.generic.example.generic;

import java.util.List;

public interface IMyGenericClass<T> {

public void printClassName(T p);
public List<T> list(Class<T> clazz);

}

//........................................................
//File name: MyGenericClass.java

package com.daro.generic.example.generic;

import com.daro.generic.example.generic.IMyGenericClass;
import java.util.ArrayList;
import java.util.List;

public abstract class MyGenericClass<T> 
                implements IMyGenericClass<T> {

private final Class<T> type; public MyGenericClass(Class<T> type) { this.type = type; } public Class<T> getMyType() { return this.type; }

@Override
public void printClassName(T p) {
System.out.println ("Class name: " + p.getClass().getName());
}

@SuppressWarnings("unchecked")
@Override
public List<T> list(Class<T> clazz) {
@SuppressWarnings("rawtypes")
Object object = null;
try {
object = clazz.newInstance(); 
                         //equal to this.getMyType().newInstance()
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
List<T> list = new ArrayList<T>();
list.add((T)object);
return list;
}

}

//........................................................
//File name: MyGenericClassImpl.java

package com.daro.generic.example.generic;

import java.util.List;
import com.daro.generic.example.generic.MyGenericClass;
import com.daro.generic.example.generic.MyClass;


public class MyGenericClassImpl extends MyGenericClass<MyClass> {

public MyGenericClassImpl() {
super(MyClass.class);
}

public void doSomething() {
   MyClass myClass = new MyClass();
List<MyClass> myList = this.list(MyClass.class);
this.printClassName(myClass);
System.out.println("To string my object: " + myList.get(0).toString()); 
}
   
public static void main(String[] args) {
        System.out.println("Running test!"); // Display the string.
MyGenericClassImpl myGenericClassImpl = new MyGenericClassImpl();
myGenericClassImpl.doSomething();
}

}

//........................................................
//File name: MyClass.java

package com.daro.generic.example.generic;

import java.io.Serializable;

public class MyClass {

public String toString(){
return "MyClass Example";
}

}


Running Example


Result of run MyGenericClassImpl:

Running test!
Class name: com.daro.generic.example.generic.MyClass

To string my object: MyClass Example



References:

http://docs.oracle.com/javase/tutorial/java/generics/types.html
http://www.arquitecturajava.com/uso-de-java-generics/
http://jonsegador.com/2012/10/clases-y-tipos-genericos-en-java/