将数字转化成数量

package flow;
 
import java.util.Collection;
import java.util.Iterator;
 
import com.avaya.sce.runtime.Goto;
import com.avaya.sce.runtimecommon.IComplexVariable;
import com.avaya.sce.runtimecommon.IVariable;
import com.avaya.sce.runtimecommon.IVariableField;
import com.avaya.sce.runtimecommon.SCESession;
 
/**
 * A basic servlet which allows a user to define their code, generate
 * any output, and to select where to transition to next.
 * Last generated by Dialog Designer at: 2011年2月16日 下午02时32分08秒
 */
public class ProcNum extends com.avaya.sce.runtime.BasicServlet {
 
//{{START:CLASS:FIELDS
String sAnnounce = "";
String sFlowName = "";
//}}END:CLASS:FIELDS
 
/**
 * Default constructor
 * Last generated by Dialog Designer at: 2011年2月16日 下午02时32分08秒
 */
public ProcNum() {
//{{START:CLASS:CONSTRUCTOR
super();
//}}END:CLASS:CONSTRUCTOR
}
 
/**
 * This method allows for custom integration with other Java components.
 * You may use Java for sophisticated logic or to integrate with custom
 * connectors (i.e. JMS, custom web services, sockets, XML, JAXB, etc.)
 *
 * Any custom code added here should work as efficiently as possible to prevent delays.
 * It's important to design your callflow so that the voice browser (Voice Portal/IR)
 * is not waiting too long for a response as this can lead to a poor caller experience.
 * Additionally, if the response to the client voice browser exceeds the configured
 * timeout, the platform may throw an "error.badfetch".
 *
 * Using this method, you have access to all session variables through the
 * SCESession object.
 *
 * The code generator will *** NOT *** overwrite this method in the future.
 * Last generated by Dialog Designer at: 2011年2月16日 下午02时32分08秒
 */
public void servletImplementation(com.avaya.sce.runtimecommon.SCESession mySession) {
 
IVariable  iv1 = mySession.getVariable(IProjectVariables.READ_NUMBER);
IComplexVariable icv1 = iv1.getComplexVariable();
IVariableField ivf1_1 = icv1.getField(IProjectVariables.READ_NUMBER_FIELD_CYCLE);
IVariableField ivf1_2 = icv1.getField(IProjectVariables.READ_NUMBER_FIELD_NUM);
IVariableField ivf1_3 = icv1.getField(IProjectVariables.READ_NUMBER_FIELD_READ);
IVariableField ivf1_4 = icv1.getField(IProjectVariables.READ_NUMBER_FIELD_SINGLE_READ);
IVariableField ivf1_5 = icv1.getField(IProjectVariables.READ_NUMBER_FIELD_MODE);
 
String sTotalNum = ivf1_2.getStringValue();
 
if (!"".equals(sTotalNum)){
 
//检验是否是数字,包括小数
try {
double dTotalNum = Double.parseDouble(sTotalNum);
} catch (NumberFormatException e) {
ivf1_1.setValue("");
}
 
ivf1_1.setValue(0);
String[] sIntegerAndFraction = sTotalNum.split("\\.");
if (sIntegerAndFraction.length == 1){
if (ivf1_5.getIntValue() == 1){
transToQuantity(sIntegerAndFraction[0]);
} else
sAnnounce = sTotalNum;
} else {
if (ivf1_5.getIntValue() == 1){
transToQuantity(sIntegerAndFraction[0]);
sAnnounce = sAnnounce.concat("d" + sIntegerAndFraction[1]);
} else
sAnnounce = sIntegerAndFraction[0] + "d" + sIntegerAndFraction[1];
}
 
ivf1_2.setValue("");
ivf1_3.setValue(sAnnounce);
}
 
String sRead = ivf1_3.getStringValue();
String sCycle = ivf1_1.getStringValue();
 
//sCycle为空是因为数字为空,不会读任何信息
if ("".equals(sCycle)) {
sFlowName = "end";
return;
}
 
int nCycle = Integer.parseInt(sCycle);
 
if (nCycle < sRead.length()){
ivf1_4.setValue(sRead.substring(nCycle, ++nCycle));
ivf1_1.setValue(nCycle);
sFlowName = "next_read";
} else {
ivf1_1.setValue("");
ivf1_3.setValue("");
sFlowName = "end";
}
}
/**
 * Builds the list of branches that are defined for this servlet object.
 * This list is built automatically by defining Goto nodes in the call flow editor.
 * It is the programmer's responsibilty to provide at least one enabled Goto.<BR>
 *
 * The user should override updateBranches() to determine which Goto that the
 * framework will activate.  If there is not at least one enabled Goto item,
 * the framework will throw a runtime exception.<BR>
 *
 * This method is generated automatically and changes to it may
 * be overwritten next time code is generated.  To modify the list
 * of branches for the flow item, override:
 *     <code>updateBranches(Collection branches, SCESession mySession)</code>
 *
 * @return a Collection of <code>com.avaya.sce.runtime.Goto</code>
 * objects that will be evaluated at runtime.  If there are no gotos
 * defined in the Servlet node, then this returns null.
 * Last generated by Dialog Designer at: 2011年2月24日 上午09时00分24秒
 */
public java.util.Collection getBranches(com.avaya.sce.runtimecommon.SCESession mySession) {
java.util.List list = null;
com.avaya.sce.runtime.Goto aGoto = null;
list = new java.util.ArrayList(2);
 
aGoto = new com.avaya.sce.runtime.Goto("Read", 0, true, "next_read");
list.add(aGoto);
 
aGoto = new com.avaya.sce.runtime.Goto("Return", 0, true, "end");
list.add(aGoto);
 
return list;
}
 
public void transToQuantity (String sTotalNum){
String sNum = "";
int nNumLast = 9;
int nNumCurrent = 0;
boolean bAllZero = true;
boolean b5To8AllZero = true;
final int nNUM_TOTAL_LENGTH = sTotalNum.length();
final int nMod8 = nNUM_TOTAL_LENGTH % 8;
final int nDevide8 = nNUM_TOTAL_LENGTH / 8;
int nNum_Length = 0;
 
for (int n8Times = 0 ; n8Times <= nDevide8 ; n8Times++){
if (n8Times == 0)
sNum = sTotalNum.substring(0, nMod8);
else
sNum = sTotalNum.substring(nMod8+(n8Times-1)*8, nMod8+n8Times*8);
nNum_Length = sNum.length();
nNumLast = 9;
nNumCurrent = 0;
bAllZero = true;
b5To8AllZero = true;
 
for (int nNumIterator = nNum_Length; nNumIterator > 0; nNumIterator--) {
nNumCurrent = Integer.parseInt(sNum.substring(nNum_Length
- nNumIterator, nNum_Length - nNumIterator + 1));
 
if (nNumLast == 0) {
nNumLast = nNumCurrent;
if (nNumCurrent != 0) {
 
if (b5To8AllZero == true && nNumIterator >= 5 && nNumIterator < 9) b5To8AllZero = false;
if (sAnnounce != "" && bAllZero == true){
if (bAllZero == true) bAllZero = false;
appendZero(nNumCurrent, nNumIterator);
} else if (bAllZero != true){
if (nNumIterator != 8 && nNumIterator != 4){
if (bAllZero == true) bAllZero = false;
appendZero(nNumCurrent, nNumIterator);
} else {
if (bAllZero == true) bAllZero = false;
appendNum(nNumCurrent, nNumIterator);
}
} else {
if (bAllZero == true) bAllZero = false;
appendNum(nNumCurrent, nNumIterator);
}
} else {
if (bAllZero == true && nNumIterator == 1 && sAnnounce == ""){
appendZero(nNumCurrent, nNumIterator);
} else {
if (nNumIterator == 9){
appendParameter(nNumIterator);
} else if (nNumIterator == 5 && b5To8AllZero == false){
appendParameter(nNumIterator);
}
}
}
} else if (nNumCurrent == 0) {
nNumLast = nNumCurrent;
if (bAllZero == true) {
if (nNumIterator == 1)
appendZero(nNumCurrent, nNumIterator);
} else {
if (nNumIterator == 9 || nNumIterator == 5) {
appendParameter(nNumIterator);
}
}
} else {
nNumLast = nNumCurrent;
if (bAllZero == true) bAllZero = false;
if (b5To8AllZero == true && nNumIterator >= 5 && nNumIterator < 9) b5To8AllZero = false;
appendNum(nNumCurrent, nNumIterator);
}
}
if (n8Times == 0 && nMod8 == 0);
else if (n8Times != nDevide8)
sAnnounce = sAnnounce.concat("E");
}
}
 
public void appendZero (int nNum, int nIterator){
sAnnounce = sAnnounce.concat("0");
appendNum(nNum,nIterator);
}
 
public void appendNum (int nNum, int nIterator){
if (nNum == 1 && (nIterator == 2 || nIterator == 6 || nIterator == 10)) {
appendParameter(nIterator);
} else if (nNum != 0){
sAnnounce = sAnnounce.concat(Integer.toString(nNum));
appendParameter(nIterator);
}
}
 
public void appendParameter (int nIterator){
String sPara = "";
if (nIterator == 2 || nIterator == 6 || nIterator == 10)
sPara = "A";//十
else if (nIterator == 3 || nIterator == 7 || nIterator == 11)
sPara = "B";//百
else if (nIterator == 4 || nIterator == 8 || nIterator == 12)
sPara = "C";//千
else if (nIterator == 5)
sPara = "D";//万
sAnnounce = sAnnounce.concat(sPara);
}
 
@Override
public void updateBranchesPost(Collection branches, SCESession mySession) {
for (Iterator it = branches.iterator(); it.hasNext();){
Goto branch = (Goto) it.next();
if (branch.getName().equals(sFlowName)){
branch.setEnabled(true);
break;
} else
branch.setEnabled(false);
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值