Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 1997-2013, ( Licensed under the GPL, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.tinygroup.template.rumtime;
 import java.util.Map;

操作符工具类 之所以起一个字母,是为了生成的代码短一些 Created by luoguo on 2014/6/5.
 public final class O {
     private O() {
     private static Map<StringOperatoroperationMap = new HashMap<StringOperator>();
     private static Converter[][] converters = new Converter[7][7];
     private static Map<ClassIntegertypeMap = new HashMap<ClassInteger>();
     static {
         .put(Byte.class, 0);
         .put(Character.class, 1);
         .put(Integer.class, 2);
         .put(Long.class, 3);
         .put(Float.class, 4);
         .put(Double.class, 5);
         .put(BigDecimal.class, 6);
         addConverter(new ByteCharacter());
         addConverter(new ByteInteger());
         addConverter(new ByteFloat());
         addConverter(new ByteDouble());
         addConverter(new ByteBigDecimal());
         addConverter(new CharacterInteger());
         addConverter(new CharacterFloat());
         addConverter(new CharacterDouble());
         addConverter(new CharacterBigDecimal());
         addConverter(new IntegerLong());
         addConverter(new IntegerFloat());
         addConverter(new IntegerDouble());
         addConverter(new IntegerBigDecimal());
         addConverter(new LongFloat());
         addConverter(new LongDouble());
         addConverter(new LongBigDecimal());
         addConverter(new FloatDouble());
         addConverter(new FloatBigDecimal());
         addConverter(new DoubleBigDecimal());
         addOperator(new AddOperator());
         addOperator(new SubtractOperator());
         addOperator(new MultiplyOperator());
         addOperator(new DevideOperator());
         addOperator(new XorOperator());
         addOperator(new AdOperator());
         addOperator(new OrOperator());
         addOperator(new ModOperator());
         addOperator(new SimpleConditionOperator());
         addOperator(new LeftAddOperator());
         addOperator(new LeftSubtractOperator());
         addOperator(new LeftPlusPlusOperator());
         addOperator(new LeftSubtractSubtractOperator());
         addOperator(new RightPlusPlusOperator());
         addOperator(new RightSubtractSubtractOperator());
         addOperator(new LeftLiteralOperator());
         addOperator(new ComplementOperator());
         addOperator(new LeftNotOperator());
         addOperator(new EqualsOperator());
         addOperator(new NotEqualsOperator());
         addOperator(new LessEqualsOperator());
         addOperator(new LessOperator());
        addOperator(new BigOperator());
        addOperator(new BigEqualsOperator());
        addOperator(new ShlOperator());
        addOperator(new ShrOperator());
        addOperator(new Shr2Operator());
    public static Object convert(Object objectClass sourceTypeClass destType) {
        return [.get(sourceType)][.get(destType)].convert(object);
    public static int compare(Class type1Class type2) {
        int index1 = .get(type1);
        int index2 = .get(type2);
        if (index1 == index2) {
            return 0;
        if (index1 > index2) {
            return 1;
        } else {
            return -1;
    public static boolean isNumber(Class type) {
        return .containsKey(type);
    public static void addConverter(Converter converter) {
        [.get(converter.getSourceType())][.get(converter.getDestType())] = converter;
    public static void addOperator(Operator operator) {
        .put(operator.getOperation(), operator);
    public static void addOperator(OperatorWithContext operator) {
        .put(operator.getOperation(), operator);
    public static Object e(String opObject... parametersthrows TemplateException {
        Operator operator = .get(op);
        if (operator == null) {
            throw new TemplateException("找不对对应于:" + op + "的处理器。");
        return operator.operation(parameters);
    public static Object ce(TemplateContext contextString op,String nameObject valuethrows TemplateException {
        OperatorWithContext operator = .get(op);
        if (operator == null) {
            throw new TemplateException("找不对对应于:" + op + "的处理器。");
        return operator.operation(context,namevalue);
New to GrepCode? Check out our FAQ X