当前访客身份:游客 [ 登录 | 加入 OSCHINA ]

代码分享

当前位置:
代码分享 » Java  » 编程基础
stephansun

test

stephansun 发布于 2016年08月18日 18时, 0评/266阅
分享到: 
收藏 +0
0
test
标签: <无>

代码片段(5) [全屏查看所有代码]

1. [代码][Java]代码     跳至 [1] [2] [3] [4] [5] [全屏预览]

public class FieldOfMoc {

    private String name;
    private String type;
    private String dbtype;
    private String minvalue;
    private String maxvalue;
    private String defaultValue;
    private String isnull;
    private String isfinal;
    private String isarray;
    private String structName;
    private String fieldProperty;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDbtype() {
        return dbtype;
    }

    public void setDbtype(String dbtype) {
        this.dbtype = dbtype;
    }

    public String getMinvalue() {
        return minvalue;
    }

    public void setMinvalue(String minvalue) {
        this.minvalue = minvalue;
    }

    public String getMaxvalue() {
        return maxvalue;
    }

    public void setMaxvalue(String maxvalue) {
        this.maxvalue = maxvalue;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getIsnull() {
        return isnull;
    }

    public void setIsnull(String isnull) {
        this.isnull = isnull;
    }

    public String getIsfinal() {
        return isfinal;
    }

    public void setIsfinal(String isfinal) {
        this.isfinal = isfinal;
    }

    public String getIsarray() {
        return isarray;
    }

    public void setIsarray(String isarray) {
        this.isarray = isarray;
    }

    public void setStructName(String structName) {
        this.structName = structName;
    }

    public String getStructName() {
        return structName;
    }

    public void setFieldProperty(String fieldProperty) {
        this.fieldProperty = fieldProperty;
    }

    public String getFieldProperty() {
        return fieldProperty;
    }
}

2. [代码][Java]代码     跳至 [1] [2] [3] [4] [5] [全屏预览]

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FieldOfMocAction {
    public static final String SDRMEID = "MEID";
    @SuppressWarnings("unchecked")
    public List<FieldOfMoc> getNewFieldOfMocList(MocInfoOfOss mocInfoOfOss, String primaryKey, String product) {
        List<FieldOfMoc> fieldsOfMoc = new ArrayList<FieldOfMoc>();
        // TODO: fieldsOfOss变量,两行可以合并为一行
        List<FieldOfOss> fieldsOfOss = null;
        fieldsOfOss = mocInfoOfOss.getFields();
        Iterator itOfFields = fieldsOfOss.iterator();

        // TODO: Iterator这种迭代器模式可以用 增强型for 循环替代
        while (itOfFields.hasNext()) {
            FieldOfOss fieldOfOss = (FieldOfOss) itOfFields.next();
            try{
                // TODO: 空指针异常要不要考虑?
                if (fieldOfOss.getName().equalsIgnoreCase("SYNCSTATUS")
                        || fieldOfOss.getName().equalsIgnoreCase("SYNCSTATUS1")) {
                    continue;
                }
                if ((mocInfoOfOss.getName().equalsIgnoreCase("NEManagedElement")
                        && fieldOfOss.getName().equalsIgnoreCase("TOPONAME"))
                        || fieldOfOss.getName().equalsIgnoreCase("ratMode")) {
                    continue;
                }
                if (fieldOfOss.getIsDBAttr().equalsIgnoreCase("false")) {
                    continue;
                }
                FieldOfMoc fieldOfMoc = new FieldOfMoc();

                // TODO: 下面这个 if 可以移到上面这行的前面
                // field列表中不添加configset字段
                // 不添加lastModifedTime(11.23 王雅芳 by jun)
                if (fieldOfOss.getName().equalsIgnoreCase("configset")
                        || fieldOfOss.getName().equalsIgnoreCase("lastModifedTime")) {
                    continue;
                }
                // 利用fieldOfOss对FieldList进行实例化
                fieldOfMoc.setName(fieldOfOss.getName());
                fieldOfMoc.setType(fieldOfOss.getType());

                // TODO: 下面这个 if 可以移到上面这两行的前面
                String icmFlag = fieldOfOss.getIcmFlag();
                if (null != icmFlag && !"".equals(icmFlag)) {
                    if (isNumeric(icmFlag)) {
                        BigInteger src = new BigInteger(icmFlag);//转换为BigInteger类型
                        if ("1".equals(src.toString(2))) {
                            continue;
                        }
                    }
                }

                // TODO: 下面的代码可以移动到一个方法中
                // dbtype还待确定,String类型的数据直接取其长度
                if (fieldOfOss.getType().equals("long")) {
                    fieldOfMoc.setDbtype("NUMBER("
                            + getLongNumOfField(RangeValueAction.getMaxValueStr(fieldOfOss.getRange())) + ")");
                } else if (fieldOfOss.getType().equalsIgnoreCase("double")) {
                    fieldOfMoc.setDbtype("BINARY_DOUBLE");
                } else if (fieldOfOss.getType().equals("string")) {
                    fieldOfMoc.setDbtype("VARCHAR2("
                            + getStringNumOfField(RangeValueAction.getMaxValueStr(fieldOfOss.getRange())) + ")");
                } else {
                    fieldOfMoc.setDbtype("VARCHAR2(4000)");
                }

                fieldOfMoc.setMinvalue(fieldOfOss.getMinimum());
                fieldOfMoc.setMaxvalue(fieldOfOss.getMaximum());

                // TODO: defaultvalue 和 isnull 的赋值可以分开
                // *********这个DEFAULT值要注意,在要生成的XML文件中变量值为DEFAULT,而在程序中
                // *********定义的是DEFAULTVALUE
                String defaultvalue = "";
                String isnull = "";
                defaultvalue = fieldOfOss.getDefaultValue();
                isnull = fieldOfOss.getIsNull();
                if (defaultvalue.startsWith("{")) {
                    defaultvalue = "";
                }
                fieldOfMoc.setDefaultValue(defaultvalue);
                fieldOfMoc.setIsnull(isnull);
                if (primaryKey.contains(fieldOfOss.getName())) {
                    fieldOfMoc.setIsfinal("true");
                } else {
                    fieldOfMoc.setIsfinal("false");
                }
                fieldOfMoc.setIsarray(fieldOfOss.getIsarray());
                String structname = fieldOfOss.getStructName();
                //此处专门为tdd的结构体类型增加后缀,为避免与fdd的结构体mo名称相同,此问题应该在ommb上彻底改此问题
                //暂时在oss上进行处理以规避此问题,后期ommb将此问题解决后,此部分必须删除掉
                if (fieldOfOss.getType().equalsIgnoreCase("struct")) {
                    if (product.equalsIgnoreCase("TDD")) {
                        structname = structname + "TDD";
                    } else if ("".equalsIgnoreCase(product)) {
                        structname = structname + "PLAT";
                    } else if ("FDD".equalsIgnoreCase(product)) {
                        structname = structname + "FDD";
                    } else if ("TD".equalsIgnoreCase(product)) {
                        structname = structname + "TD";
                    } else if ("GSM".equalsIgnoreCase(product)) {
                        structname = structname + "GSM";
                    } else if ("UMTS".equalsIgnoreCase(product)) {
                        structname = structname + "UMTS";
                    } else if ("CDMA".equalsIgnoreCase(product)) {
                        structname = structname + "CDMA";
                    } else if ("LTE".equalsIgnoreCase(product)) {
                        structname = structname + "LTE";
                    } else if ("NB-IoT".equalsIgnoreCase(product)) {
                        structname = structname + "NBI";
                    }
                }

                // TODO: 在下面这种if的场景下才取 structname ,那么前面这部分预先算出 structname 就没必要了,可以移到到下面
                // 添加structName,但是字段MOI、SMOI、SubNetwork、SDRMEID、ConfigSet中不添加structName
                if (!(fieldOfOss.getName().equalsIgnoreCase("MOI") || fieldOfOss.getName().equalsIgnoreCase("SMOI")
                        || fieldOfOss.getName().equalsIgnoreCase("SubNetwork")
                        || fieldOfOss.getName().equalsIgnoreCase(SDRMEID) || fieldOfOss.getName()
                        .equalsIgnoreCase("ConfigSet"))) {
                    fieldOfMoc.setStructName(structname);
                }
                // 将创建好的FieldOfMoc对象添加到fieldsOfMoc中
                fieldsOfMoc.add(fieldOfMoc);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return fieldsOfMoc;
    }

    public int getLongNumOfField(String maxValueStr) {
        int num = 10;
        if (maxValueStr != null && (!maxValueStr.equals(""))) {
            num = maxValueStr.length() + 2;
        }
        return num;
    }

    public int getStringNumOfField(String maxValueStr) {
        int num = 512;
        if (maxValueStr != null && (!maxValueStr.equals(""))) {
            num = Integer.valueOf(maxValueStr);
        }
        return num;
    }

    private static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        // TODO: 可以优化if语句
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}

3. [代码][Java]代码     跳至 [1] [2] [3] [4] [5] [全屏预览]

import java.io.Serializable;

/**
 * Created by Administrator on 16-7-26.
 */
public class FieldOfOss implements Serializable {
    private String name;
    private String type;
    private String isarray;
    private String labelKey;
    private String neField;
    private String syncState;
    private String wsfComponent;
    private String wsfFormat;
    private String isEdit;
    private String isVisible;
    private String defaultValue;
    private String wsfListener;
    private String explanationInfo;
    private String maximum;
    private String minimum;
    private String isDBAttr;
    private String wsfStepsize;
    private String isNull;
    private String isStatic;
    private String valueMap;
    private String recommendValueGettor;
    private String sequenceLabel;
    private String isReportMDEventAttr;
    private String range;
    private String deleteEventExtAttr;
    private String arrayLength;
    private String structName;
    private String isExport;
    private String businessDesc;
    private String uniqueKey;
    private String isBase;
    private String isSetBySystem;
    private String fieldProperty;
    private String isGuiModify;
    private String icmFlag;
    private String rwn;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getIsarray() {
        return isarray;
    }

    public void setIsarray(String isarray) {
        this.isarray = isarray;
    }

    public String getLabelKey() {
        return labelKey;
    }

    public void setLabelKey(String labelKey) {
        this.labelKey = labelKey;
    }

    public String getNeField() {
        return neField;
    }

    public void setNeField(String neField) {
        this.neField = neField;
    }

    public String getWsfComponent() {
        return wsfComponent;
    }

    public void setWsfComponent(String wsfComponent) {
        this.wsfComponent = wsfComponent;
    }

    public String getWsfFormat() {
        return wsfFormat;
    }

    public void setWsfFormat(String wsfFormat) {
        this.wsfFormat = wsfFormat;
    }

    public String getIsEdit() {
        return isEdit;
    }

    public void setIsEdit(String isEdit) {
        this.isEdit = isEdit;
    }

    public String getIsVisible() {
        return isVisible;
    }

    public void setIsVisible(String isVisible) {
        this.isVisible = isVisible;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getWsfListener() {
        return wsfListener;
    }

    public void setWsfListener(String wsfListener) {
        this.wsfListener = wsfListener;
    }

    public String getExplanationInfo() {
        return explanationInfo;
    }

    public void setExplanationInfo(String explanationInfo) {
        this.explanationInfo = explanationInfo;
    }

    public String getMaximum() {
        return maximum;
    }

    public void setMaximum(String maximum) {
        this.maximum = maximum;
    }

    public String getMinimum() {
        return minimum;
    }

    public void setMinimum(String minimum) {
        this.minimum = minimum;
    }

    public String getIsDBAttr() {
        return isDBAttr;
    }

    public void setIsDBAttr(String isDBAttr) {
        this.isDBAttr = isDBAttr;
    }

    public String getWsfStepsize() {
        return wsfStepsize;
    }

    public void setWsfStepsize(String wsfStepsize) {
        this.wsfStepsize = wsfStepsize;
    }

    public String getIsNull() {
        return isNull;
    }

    public void setIsNull(String isNull) {
        this.isNull = isNull;
    }

    public String getIsStatic() {
        return isStatic;
    }

    public void setIsStatic(String isStatic) {
        this.isStatic = isStatic;
    }

    public String getValueMap() {
        return valueMap;
    }

    public void setValueMap(String valueMap) {
        this.valueMap = valueMap;
    }

    public String getRecommendValueGettor() {
        return recommendValueGettor;
    }

    public void setRecommendValueGettor(String recommendValueGettor) {
        this.recommendValueGettor = recommendValueGettor;
    }

    public String getSequenceLabel() {
        return sequenceLabel;
    }

    public void setSequenceLabel(String sequenceLabel) {
        this.sequenceLabel = sequenceLabel;
    }

    public String getIsReportMDEventAttr() {
        return isReportMDEventAttr;
    }

    public void setIsReportMDEventAttr(String isReportMDEventAttr) {
        this.isReportMDEventAttr = isReportMDEventAttr;
    }

    public String getRange() {
        return range;
    }

    public void setRange(String range) {
        this.range = range;
    }

    public String getDeleteEventExtAttr() {
        return deleteEventExtAttr;
    }

    public void setDeleteEventExtAttr(String deleteEventExtAttr) {
        this.deleteEventExtAttr = deleteEventExtAttr;
    }

    public String getArrayLength() {
        return arrayLength;
    }

    public void setArrayLength(String arrayLength) {
        this.arrayLength = arrayLength;
    }

    public String getStructName() {
        return structName;
    }

    public void setStructName(String structName) {
        this.structName = structName;
    }

    public void setIsExport(String isExport) {
        this.isExport = isExport;
    }

    public String getIsExport() {
        return isExport;
    }

    public void setBusinessDesc(String businessDesc) {
        this.businessDesc = businessDesc;
    }

    public String getBusinessDesc() {
        return businessDesc;
    }

    public void setUniqueKey(String uniqueKey) {
        this.uniqueKey = uniqueKey;
    }

    public String getUniqueKey() {
        return uniqueKey;
    }

    public void setIsBase(String isBase) {
        this.isBase = isBase;
    }

    public String getIsBase() {
        return isBase;
    }

    public void setIsSetBySystem(String isSetBySystem) {
        this.isSetBySystem = isSetBySystem;
    }

    public String getIsSetBySystem() {
        return isSetBySystem;
    }

    public String getFieldProperty() {
        return fieldProperty;
    }

    public void setFieldProperty(String fieldProperty) {
        this.fieldProperty = fieldProperty;
    }

    public void setSyncState(String syncState) {
        this.syncState = syncState;
    }

    public String getSyncState() {
        return syncState;
    }

    public void setIsGuiModify(String isGuiModify) {
        this.isGuiModify = isGuiModify;
    }

    public String getIsGuiModify() {
        return isGuiModify;
    }

    public void setIcmFlag(String icmFlag) {
        this.icmFlag = icmFlag;
    }

    public String getIcmFlag() {
        return icmFlag;
    }

    public String getRwn() {
        return rwn;
    }

    public void setRwn(String rwn) {
        this.rwn = rwn;
    }
}

4. [代码][Java]代码     跳至 [1] [2] [3] [4] [5] [全屏预览]

import java.io.Serializable;
import java.util.List;

public class MocInfoOfOss implements Serializable {
    private String name;
    private String parent;
    private String rdn;
    private String tableName;
    private String labelKey;
    private String i18nFile;
    private String neTableName;
    private String maxCount;
    private String minCount;
    private String explanationInfo;
    private String level;
    private String deleteConfirmTip;
    private String isVisible;
    private String isPureVirtual;
    private String virtualParent;
    private String virtualLevel;
    private String needDeleteEventExtAttr;
    private String isStruct;
    private String reportResourceType;
    private String transNo;
    private String moProperty;
    private List<FieldOfOss> fields;
    private String gMaxCount;
    private String maxAllCount;
    private String minAllCount;
    private String fieldProperty;
    private String icmFlag;
    private String rwn;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParent() {
        return parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public String getRdn() {
        return rdn;
    }

    public void setRdn(String rdn) {
        this.rdn = rdn;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getLabelKey() {
        return labelKey;
    }

    public void setLabelKey(String labelKey) {
        this.labelKey = labelKey;
    }

    public String getI18nFile() {
        return i18nFile;
    }

    public void setI18nFile(String file) {
        i18nFile = file;
    }

    public String getNeTableName() {
        return neTableName;
    }

    public void setNeTableName(String neTableName) {
        this.neTableName = neTableName;
    }

    public String getMaxCount() {
        return maxCount;
    }

    public void setMaxCount(String maxCount) {
        this.maxCount = maxCount;
    }

    public String getMinCount() {
        return minCount;
    }

    public void setMinCount(String minCount) {
        this.minCount = minCount;
    }

    public String getExplanationInfo() {
        return explanationInfo;
    }

    public void setExplanationInfo(String explanationInfo) {
        this.explanationInfo = explanationInfo;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getDeleteConfirmTip() {
        return deleteConfirmTip;
    }

    public void setDeleteConfirmTip(String deleteConfirmTip) {
        this.deleteConfirmTip = deleteConfirmTip;
    }

    public String getIsVisible() {
        return isVisible;
    }

    public void setIsVisible(String isVisible) {
        this.isVisible = isVisible;
    }

    public String getIsPureVirtual() {
        return isPureVirtual;
    }

    public void setIsPureVirtual(String isPureVirtual) {
        this.isPureVirtual = isPureVirtual;
    }

    public String getVirtualParent() {
        return virtualParent;
    }

    public void setVirtualParent(String virtualParent) {
        this.virtualParent = virtualParent;
    }

    public String getVirtualLevel() {
        return virtualLevel;
    }

    public void setVirtualLevel(String virtualLevel) {
        this.virtualLevel = virtualLevel;
    }

    public String getNeedDeleteEventExtAttr() {
        return needDeleteEventExtAttr;
    }

    public void setNeedDeleteEventExtAttr(String needDeleteEventExtAttr) {
        this.needDeleteEventExtAttr = needDeleteEventExtAttr;
    }

    public String getIsStruct() {
        return isStruct;
    }

    public void setIsStruct(String isStruct) {
        this.isStruct = isStruct;
    }

    public String getReportResourceType() {
        return reportResourceType;
    }

    public void setReportResourceType(String reportResourceType) {
        this.reportResourceType = reportResourceType;
    }

    public String getTransNo() {
        return transNo;
    }

    public void setTransNo(String transNo) {
        this.transNo = transNo;
    }

    public String getMOProperty() {
        return moProperty;
    }

    public void setMOProperty(String property) {
        this.moProperty = property;
    }

    public List<FieldOfOss> getFields() {
        return fields;
    }

    public void setFields(List<FieldOfOss> fields) {
        this.fields = fields;
    }

    public String getGMaxCount() {
        return gMaxCount;
    }

    public void setGMaxCount(String gMaxCount) {
        this.gMaxCount = gMaxCount;
    }

    public String getMaxAllCount() {
        return maxAllCount;
    }

    public void setMaxAllCount(String maxAllCount) {
        this.maxAllCount = maxAllCount;
    }

    public String getMinAllCount() {
        return minAllCount;
    }

    public void setMinAllCount(String minAllCount) {
        this.minAllCount = minAllCount;
    }


    public String getFieldProperty() {
        return fieldProperty;
    }

    public void setFieldProperty(String fieldProperty) {
        this.fieldProperty = fieldProperty;
    }

    public void setIcmFlag(String icmFlag) {
        this.icmFlag = icmFlag;
    }

    public String getIcmFlag() {
        return icmFlag;
    }

    public String getRwn() {
        return rwn;
    }

    public void setRwn(String rwn) {
        this.rwn = rwn;
    }
}

5. [代码][Java]代码     跳至 [1] [2] [3] [4] [5] [全屏预览]

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class RangeValueAction {
    public static String getMaxValueStr(String rangeValueStr) {
        String maxValueStr = "";
        if (rangeValueStr == null || (rangeValueStr.equalsIgnoreCase(""))
                || (rangeValueStr.equalsIgnoreCase("groovy"))) {
            return maxValueStr;
        }

        List<Double> rangeValueList = getRangeValueList(rangeValueStr);
        Double maxValue = 0.0;
        for (Double aRangeValueList : rangeValueList) {
            if (aRangeValueList > maxValue) {
                maxValue = aRangeValueList;
            }
        }
        maxValueStr = new BigDecimal(maxValue).toString();
        if (maxValueStr.endsWith(".0")) {
            maxValueStr = maxValueStr.substring(0, maxValueStr.length() - 2);
        }

        return maxValueStr;
    }
    public static List<Double> getRangeValueList(String rangeValueStr) {
        List<Double> rangeValueList = new ArrayList<Double>();
        String value[] = rangeValueStr.split(",");
        String temp = "";
        char c;
        for (String aValue : value) {
            String oneValue = aValue.contains("{") ? aValue.substring(aValue.indexOf('[')) : aValue;
            char[] charArray = oneValue.toCharArray();
            long num = charArray.length;
            for (int i = 0; i < num; i++) {
                c = charArray[i];
                if (c == '-' || c >= '0' && c <= '9') {
                    temp += c;
                } else {
                    if (!temp.equals("")) {
                        if (temp.startsWith("--")) {
                            temp = temp.substring(2, temp.length());
                        }
                        rangeValueList.add(Double.parseDouble(temp));
                        temp = "";
                    }
                }
            }
            if (!"".equalsIgnoreCase(temp)) {
                rangeValueList.add(Double.parseDouble(temp));
                temp = "";
            }
        }
        return rangeValueList;
    }
}


开源中国-程序员在线工具:Git代码托管 API文档大全(120+) JS在线编辑演示 二维码 更多»

开源从代码分享开始 分享代码
stephansun的其它代码
  • test(0评/266阅,3年前)
全部(1)...