1 16 package org.apache.commons.collections.functors; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.collections.Transformer; 21 22 34 public class ConstantTransformer implements Transformer, Serializable { 35 36 37 static final long serialVersionUID = 6374440726369055124L; 38 39 40 public static final Transformer NULL_INSTANCE = new ConstantTransformer(null); 41 42 43 private final Object iConstant; 44 45 51 public static Transformer getInstance(Object constantToReturn) { 52 if (constantToReturn == null) { 53 return NULL_INSTANCE; 54 } 55 return new ConstantTransformer(constantToReturn); 56 } 57 58 64 public ConstantTransformer(Object constantToReturn) { 65 super(); 66 iConstant = constantToReturn; 67 } 68 69 75 public Object transform(Object input) { 76 return iConstant; 77 } 78 79 85 public Object getConstant() { 86 return iConstant; 87 } 88 89 } 90 | Popular Tags |