Package com.alibaba.daybits.support.odps.udf

Source Code of com.alibaba.daybits.support.odps.udf.DayBitsSet

package com.alibaba.daybits.support.odps.udf;

import com.alibaba.daybits.DayBits;
import com.alibaba.daybits.DayBitsUtils;
import com.aliyun.odps.udf.UDF;

public class DayBitsSet extends UDF {

    public DayBitsSet(){
    }

    public String evaluate(String text, String date) {
        return evaluate(text, date, true);
    }

    public String evaluate(String text, String date, Boolean value) {
        DayBits daybits;
        if (text == null || text.isEmpty()) {
            if (date == null || value == null || !value) {
                return null;
            }
            daybits = new DayBits();
        } else {
            daybits = DayBitsUtils.parse(text);
        }
       
        boolean changed = daybits.set(date, value);
        if (!changed) {
            return text;
        }

        return daybits.toString();
    }
   
    public String evaluate(String text, Long date) {
        return evaluate(text, date, true);
    }
   
    public String evaluate(String text, Long date, Boolean value) {
        DayBits daybits;
        if (text == null || text.isEmpty()) {
            if (date == null || value == null || !value) {
                return null;
            }
            daybits = new DayBits();
        } else {
            daybits = DayBitsUtils.parse(text);
        }
       
        boolean changed = daybits.set(date.intValue(), value);
        if (!changed) {
            return text;
        }

        return daybits.toString();
    }
}
TOP

Related Classes of com.alibaba.daybits.support.odps.udf.DayBitsSet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.