Javarsenal y Scala-tore Briatore
Tuesday, April 14, 2015
Pattern match with match-case on lists
val a = ((1 to 3) :\ List[Int]())(_ :: _)
a match {
case x::Nil => println(a)
case _ => println("kk")
}
Monday, January 10, 2011
Ejemplo simple y buenisimo de Spring Framework
package org.me;
class CompoundInterestBean {
float years;
float principle;
float rate;
CompoundInterestBean(){
}
public void setYears(float years){
this.years=years;
}
public float getYears(){
return years;
}
public void setPrinciple(float principle){
this. principle = principle;
}
public float getPrinciple(){
return principle;
}
public void setRate(float rate){
this. rate=rate;
}
public float calculate(){
return (float)((principle*(Math.pow(1+(rate/100)),time))-1);
}
public float getInterest(){
return calculate();
}
}
Next comes the beans.xml. It contains the declarations for the constructor injection. Since there is more than one argument, there are multiple
class=org.me. CompoundInterestBean
Next is the client class that calls the bean to calculate the interest.
import java.io.*;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
import org.springframework.core.io.*;
public class Client
{
public static void main(String args[]) throws Exception
{
try
{
System.out.println("please Wait.");
Resource res = new ClassPathResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(res);
CompoundInterestBean interest=
(CompoundInterestBean)factory.getBean(“CompoundInterestBean”);
System.out.println(interest.getInterest());
}
catch(Exception e1)
{
System.out.println(""+e1);
}
}
}