Public synchronized int incContador (int val)

Classified in Computers

Written at on English with a size of 2.34 KB.

MEMENTO
public class MementoDemo {
    public static void main(String[] args) {
        Caretaker caretaker = new Caretaker();
Originator originator = new Originator(); Originator.SetState("State1"); Caretaker.AddMemento( originator.Save() ); Originator.Restore( caretaker.GetMemento() ); } }


COMPOSITE
public class CompositeDemo {
    public static void main(String[] args) {
        Box root = initialize();
        int[] levels = new int[args.Length];
        For (int i=0; i < args.Length; i++) {
            Levels[i] = Integer.ParseInt(args[i]);
        }
        Root.Traverse( levels );   
}
private static Box initialize() { Box[] nodes = new Box[7]; Nodes[1] = new Box( 1 ); Int[] waves = {1, 4, 7}; For (int i=0; i < 3; i++) { Nodes[2] = new Box(21+i); Nodes[1].Add(nodes[2]); Int level = 3; For (int j=0; j < 4; j++) { Nodes[level-1].Add(new Product(level*10 + waves[i])); Nodes[level] = new Box(level*10 + waves[i]+1); Nodes[level-1].Add(nodes[level]); Nodes[level-1].Add(new Product(level*10 + waves[i]+2)); Level++; } } Return nodes[1]; } }




FACTORY
public class FactoryMethodDemo { Public static void main(String[] args) { DecodedImage decodedImage; ImageReader reader = null; String image = args[0]; String format = image.Substring(image.IndexOf('.') + 1
, (image.Length())); If (format.Equals("gif")) { Reader = new GifReader(image); } If (format.Equals("jpeg")) { Reader = new JpegReader(image); } Assert reader != null; DecodedImage = reader.GetDecodeImage(); System.Out.Println(decodedImage); } }

SINGLETON
public final class Singleton { Private static volatile Singleton instance; Private Singleton() {} Public static Singleton getInstance(String value) { If (instance == null) { Synchronized (Singleton.Class) { If (instance == null) { Instance = new Singleton(); } } } Return instance; } }

Entradas relacionadas: