Java tutorial
/** * [module] * LengthCheck.java * * Copyright (c) 2014 M.Tsubaki * This software is released under the MIT License. * http://opensource.org/licenses/mit-license.php */ package org.hac.service.impl; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.math.NumberUtils; import org.hac.exception.HACBusinessException; import org.hac.exception.HACSystemException; import org.tsrvfw.common.util.LogicUtils; import org.tsrvfw.constant.ActionCommonConst; import org.tsrvfw.exception.TsrvfwBusinessException; import org.tsrvfw.exception.TsrvfwSystemException; import org.tsrvfw.service.AbstractService; /** * * * @author tsubaki * */ public class LengthCheck extends AbstractService { /** * ?? */ @SuppressWarnings("unchecked") @Override protected Map<String, Object> executeService(Map<String, Object> inputData) throws TsrvfwSystemException, TsrvfwBusinessException { // ??? if (!LogicUtils.isNotEmptyMap(inputData)) { throw new HACSystemException("?????"); } // ?? for (Map.Entry<String, ?> e : inputData.entrySet()) { Map<String, Object> valueMap = (Map<String, Object>) inputData.get(e.getKey()); // ??? if (!LogicUtils.isNotEmptyMap(valueMap)) { throw new HACSystemException("?????"); } String data = LogicUtils.getMapValueToString(valueMap, "data"); String length = LogicUtils.getMapValueToString(valueMap, "length"); if (!NumberUtils.isNumber(length)) { throw new HACSystemException("?????"); } if (LogicUtils.isNotEmptyString(data)) { if (data.length() >= Integer.parseInt(length)) { throw new HACBusinessException(this.getClass().getName() + ":00001", "", (String[]) valueMap.get("name")); } } } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(ActionCommonConst.RESULT_CODE, ActionCommonConst.RESULT_SUCCESS); return resultMap; } }