PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ojc-core/encodersl/encoder-coco/src/com/sun/encoder/coco/model/CocoPicture.java

https://bitbucket.org/pymma/openesb-components
Java | 775 lines | 500 code | 81 blank | 194 comment | 223 complexity | 47a473a4b2bef07cca666e4c39ab28b1 MD5 | raw file
  1. /*
  2. * BEGIN_HEADER - DO NOT EDIT
  3. *
  4. * The contents of this file are subject to the terms
  5. * of the Common Development and Distribution License
  6. * (the "License"). You may not use this file except
  7. * in compliance with the License.
  8. *
  9. * You can obtain a copy of the license at
  10. * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
  11. * See the License for the specific language governing
  12. * permissions and limitations under the License.
  13. *
  14. * When distributing Covered Code, include this CDDL
  15. * HEADER in each file and include the License file at
  16. * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
  17. * If applicable add the following below this CDDL HEADER,
  18. * with the fields enclosed by brackets "[]" replaced with
  19. * your own identifying information: Portions Copyright
  20. * [year] [name of copyright owner]
  21. */
  22. /*
  23. * @(#)CocoPicture.java
  24. *
  25. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
  26. *
  27. * END_HEADER - DO NOT EDIT
  28. */
  29. package com.sun.encoder.coco.model;
  30. import com.sun.encoder.coco.runtime.messages.ErrorManager;
  31. import com.sun.encoder.coco.runtime.messages.Message;
  32. import com.sun.encoder.coco.runtime.messages.MessageCatalog;
  33. /**
  34. * Represents the information and realization of a Cobol PICTURE clause.
  35. *
  36. * @author Noel Ang
  37. *
  38. * @version $Revision: 1.2 $
  39. */
  40. public class CocoPicture {
  41. /**
  42. * Picture Data Categories
  43. */
  44. public enum Category {
  45. /*
  46. public static final int ERR = 0;
  47. public static final int ALPHABETIC = 1;
  48. public static final int NUMERIC = 2;
  49. public static final int NUMERIC_EDITED = 3;
  50. public static final int ALPHANUMERIC = 4;
  51. public static final int ALPHANUMERIC_EDITED = 5;
  52. public static final int DBCS = 6;
  53. public static final int EX_FLOAT = 7; */
  54. ERR, ALPHABETIC, NUMERIC, NUMERIC_EDITED, ALPHANUMERIC,
  55. ALPHANUMERIC_EDITED, DBCS, EX_FLOAT
  56. }
  57. private static final ErrorManager cErrorMgr =
  58. ErrorManager.getManager("STC.eWay.converter.COBOLCopybook."
  59. + CocoPicture.class.getName());
  60. private String mOriginalPicture;
  61. private String mPicture;
  62. private int mDecimalPos;
  63. private int mDecimalScalePos;
  64. private Category mDataCategory;
  65. @Override
  66. public String toString() {
  67. StringBuilder sb = new StringBuilder("CocoPicture@")
  68. .append(Integer.toHexString(hashCode()));
  69. sb.append(" picture=").append(mPicture);
  70. sb.append(" originalPicture=").append(mOriginalPicture);
  71. sb.append(" decimalPos=").append(mDecimalPos);
  72. sb.append(" decimalScalePos=").append(mDecimalScalePos);
  73. sb.append(" dataCategory=").append(mDataCategory);
  74. return sb.toString();
  75. }
  76. /**
  77. * Create a picture object from a picture character string.
  78. *
  79. * @param picStr Picture character string
  80. * @throws java.lang.IllegalArgumentException if the specified character string is
  81. * malformed or possesses unsupported and unignorable symbols.
  82. */
  83. public CocoPicture(String picStr) throws IllegalArgumentException {
  84. if (picStr == null || picStr.length() == 0) {
  85. Message msg = MessageCatalog.getMessage("CCCB4123");
  86. String text = msg.toString();
  87. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  88. throw new IllegalArgumentException(text);
  89. }
  90. mOriginalPicture = picStr;
  91. picStr = normalizePicString(picStr);
  92. validatePicString(picStr);
  93. mPicture = picStr.toUpperCase();
  94. computeCategory();
  95. computeDecimalPosition();
  96. }
  97. /**
  98. * Retrieve "raw" Picture character string.
  99. *
  100. * @return Picture character string
  101. */
  102. public String getPicture() {
  103. return mPicture;
  104. }
  105. public String getOriginalPicture() {
  106. return mOriginalPicture;
  107. }
  108. /**
  109. * Retrieve the position of the Picture's decimal.
  110. *
  111. * @return a non-negative integer equal to the number of digits to the right
  112. * of the decimal point. A picture character-string with a 'V' as the
  113. * last character computes a zero (0); a 'V' as the first character
  114. * in the picture computes the value equal to the number of digits
  115. * in the picture. A picture with trailing P symbols will return
  116. * a negative value representing the number of zeroes to append to
  117. * the number (to scale up the value). A picture which cannot have a
  118. * decimal position (either implied or explicit) returns a value of 0.
  119. */
  120. public int getDecimalPosition() {
  121. return mDecimalPos;
  122. }
  123. /**
  124. * Retrieve the number of decimal scaling positions of the Picture.
  125. *
  126. * @return a non-negative integer equal to the number of P symbols in the
  127. * picture.
  128. */
  129. public int getDecimalScalingPositions() {
  130. return mDecimalScalePos;
  131. }
  132. /**
  133. * Retrieve picture data category. See {@link CocoPicture.Category}
  134. *
  135. * @return Picture data category as a type ordinal.
  136. *
  137. * @see CocoPicture.Category
  138. */
  139. public Category getCategory() {
  140. return mDataCategory;
  141. }
  142. /**
  143. * Determine number of digits in the picture
  144. *
  145. * @return the number of digits character positions in the picture
  146. */
  147. public int countDigits() {
  148. int digitCount = 0;
  149. for (int i = 0; i < mPicture.length(); i++) {
  150. char ch = mPicture.charAt(i);
  151. if ("Z90".indexOf(ch) != -1) {
  152. digitCount++;
  153. }
  154. }
  155. return digitCount;
  156. }
  157. /**
  158. * Determine whether the picture has a sign indicator.
  159. */
  160. public boolean hasSign() {
  161. return (mPicture.indexOf('S') != -1);
  162. }
  163. /**
  164. * Determine whether the picture contains decimal point information; that is,
  165. * it contains any of the symbols P, V, and period (.).
  166. */
  167. public boolean hasDecimalPoint() {
  168. for (int i = 0; i < mPicture.length(); i++) {
  169. char ch = mPicture.charAt(i);
  170. if ("PV.".indexOf(ch) != -1) {
  171. return true;
  172. }
  173. }
  174. return false;
  175. }
  176. /**
  177. * Determine whether a string is usable as a Picture clause character-string.
  178. *
  179. * @throws java.lang.IllegalArgumentException if the string is not usable as a Picture
  180. * character-string
  181. */
  182. private static void validatePicString(String str) throws IllegalArgumentException {
  183. str = str.toUpperCase();
  184. /*
  185. * Picture character strings have many and explicit rules concerning
  186. * what characters can appear to the left of what characters.
  187. *
  188. * The full format requirements specified in the COBOL language reference
  189. * is in Part 5 of the document, figure 6.
  190. *
  191. * What I have done here is to check the symbol-specific restrictions listed
  192. * in table 11 of said document section, but not the full-blown adjacency
  193. * rules of each symbol.
  194. */
  195. /* +/-/CR/DB are mutually exclusive */
  196. {
  197. boolean foundCR = (str.indexOf("CR") != -1);
  198. boolean foundDB = (str.indexOf("DB") != -1);
  199. boolean foundPlus = (str.indexOf("+") != -1);
  200. boolean foundMinus = (str.indexOf("-") != -1);
  201. int cntFound = (foundCR || foundDB ? 1 : 0);
  202. cntFound += (foundPlus || foundMinus ? 1 : 0);
  203. if (cntFound > 1) { // 0 is valid
  204. Message msg = MessageCatalog.getMessage("CCCB4124");
  205. String text = msg.formatText(new Object[] {
  206. str
  207. });
  208. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  209. throw new IllegalArgumentException(text);
  210. }
  211. }
  212. /* V must only occur once */
  213. {
  214. int idxV1 = str.indexOf("V");
  215. int idxV2 = str.lastIndexOf("V");
  216. if (idxV1 != idxV2) {
  217. Message msg = MessageCatalog.getMessage("CCCB4125");
  218. String text = msg.formatText(new Object[] {
  219. str
  220. });
  221. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  222. throw new IllegalArgumentException(text);
  223. }
  224. }
  225. /* S must be left most character */
  226. {
  227. int idxS = str.indexOf("S");
  228. if (idxS != -1 && idxS != 0) {
  229. Message msg = MessageCatalog.getMessage("CCCB4126");
  230. String text = msg.formatText(new Object[] {
  231. str
  232. });
  233. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  234. throw new IllegalArgumentException(text);
  235. }
  236. }
  237. /*
  238. * P must be leftmost (except to S) XOR rightmost, and must be continuous
  239. * if repeating
  240. */
  241. {
  242. int idxP = str.indexOf("P");
  243. if (idxP != -1) {
  244. boolean foundStop = false;
  245. for (int i = idxP + 1; i < str.length(); i++) {
  246. if (str.charAt(i) != 'P') {
  247. foundStop = true;
  248. } else if (foundStop) {
  249. Message msg = MessageCatalog.getMessage("CCCB4127");
  250. String text = msg.formatText(new Object[] {
  251. str
  252. });
  253. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  254. throw new IllegalArgumentException(text);
  255. }
  256. }
  257. idxP = str.lastIndexOf("P");
  258. int idxS = str.indexOf("S");
  259. if ((idxS != -1) && (idxP < idxS)) {
  260. Message msg = MessageCatalog.getMessage("CCCB4128");
  261. String text = msg.formatText(new Object[] {
  262. str
  263. });
  264. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  265. throw new IllegalArgumentException(text);
  266. }
  267. if ((str.indexOf("P") != 0) && (idxP < str.length() - 1)) {
  268. Message msg = MessageCatalog.getMessage("CCCB4129");
  269. String text = msg.formatText(new Object[] {
  270. str
  271. });
  272. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  273. throw new IllegalArgumentException(text);
  274. }
  275. }
  276. }
  277. /* certain characters can only occur once in a pic string */
  278. {
  279. String msg = null;
  280. int pos;
  281. if ((pos = str.indexOf("CR")) != -1 && pos != str.lastIndexOf("CR")) {
  282. Message err = MessageCatalog.getMessage("CCCB4130");
  283. msg = err.formatText(new Object[] {str});
  284. }
  285. if ((pos = str.indexOf("DB")) != -1 && pos != str.lastIndexOf("DB")) {
  286. Message err = MessageCatalog.getMessage("CCCB4131");
  287. msg = err.formatText(new Object[] {str});
  288. }
  289. if ((pos = str.indexOf("S")) != -1 && pos != str.lastIndexOf("S")) {
  290. Message err = MessageCatalog.getMessage("CCCB4132");
  291. msg = err.formatText(new Object[] {str});
  292. }
  293. if ((pos = str.indexOf("V")) != -1 && pos != str.lastIndexOf("V")) {
  294. Message err = MessageCatalog.getMessage("CCCB4124");
  295. msg = err.formatText(new Object[] {str});
  296. }
  297. if ((pos = str.indexOf("E")) != -1 && pos != str.lastIndexOf("E")) {
  298. Message err = MessageCatalog.getMessage("CCCB4133");
  299. msg = err.formatText(new Object[] {str});
  300. }
  301. if ((pos = str.indexOf(".")) != -1 && pos != str.lastIndexOf(".")) {
  302. Message err = MessageCatalog.getMessage("CCCB4134");
  303. msg = err.formatText(new Object[] {str});
  304. }
  305. if (msg != null) {
  306. cErrorMgr.log(ErrorManager.Severity.ERROR, null, msg);
  307. throw new IllegalArgumentException(msg);
  308. }
  309. }
  310. /* if external floating point, check format */
  311. {
  312. int pos = str.indexOf('E');
  313. if (pos != -1) {
  314. String exfloat = str.trim();
  315. pos = exfloat.indexOf('E');
  316. if (pos != exfloat.length() - 4) {
  317. Message msg = MessageCatalog.getMessage("CCCB4135");
  318. String text = msg.formatText(new Object[] {str});
  319. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  320. throw new IllegalArgumentException(text);
  321. }
  322. boolean ok = true;
  323. int vCount = 0;
  324. int dotCount = 0;
  325. ok |= ("+-".indexOf(exfloat.charAt(0)) != -1);
  326. ok |= ("+-".indexOf(exfloat.charAt(pos + 1)) != -1);
  327. ok |= ((exfloat.charAt(pos + 2) == '9') && (exfloat.charAt(pos + 3) == '9'));
  328. for (int i = 1; i < pos; i++) {
  329. ok |= ("9.V".indexOf(exfloat.charAt(i)) != -1);
  330. if (exfloat.charAt(i) == '.') {
  331. dotCount++;
  332. } else if (exfloat.charAt(i) == 'V') {
  333. vCount++;
  334. }
  335. }
  336. ok |= ((dotCount + vCount) < 2);
  337. if (!ok) {
  338. Message msg = MessageCatalog.getMessage("CCCB4135");
  339. String text = msg.formatText(new Object[] {str});
  340. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  341. throw new IllegalArgumentException(text);
  342. }
  343. }
  344. }
  345. }
  346. /**
  347. * Clean up the picture string.
  348. *
  349. * @param pic Picture character-string in consideration
  350. *
  351. * @return normalized picture string
  352. *
  353. * @throws java.lang.IllegalArgumentException if any error in the picture string prevents
  354. * successful processing.
  355. */
  356. private static String normalizePicString(String pic) throws IllegalArgumentException {
  357. pic = expandOccurence(pic);
  358. return pic;
  359. }
  360. /**
  361. * Expands X(n) short-hand notations in the picture string; e.g., 9(2) becomes
  362. * 99.
  363. *
  364. * @param pic Picture character-string in consideration
  365. *
  366. * @throws java.lang.IllegalArgumentException if any error in the picture string prevents
  367. * successful processing.
  368. */
  369. private static String expandOccurence(String pic) throws IllegalArgumentException {
  370. int len = pic.length();
  371. int prevCh = -1;
  372. StringBuffer buffer = new StringBuffer(len);
  373. for (int i = 0; i < len; i++) {
  374. char ch = pic.charAt(i);
  375. if (ch == '(') {
  376. if (prevCh == -1) {
  377. Message msg = MessageCatalog.getMessage("CCCB4136");
  378. String text = msg.formatText(new Object[] {
  379. String.valueOf(ch),
  380. pic
  381. });
  382. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  383. throw new IllegalArgumentException(text);
  384. }
  385. int rparenPos = pic.indexOf(')', i);
  386. if (rparenPos == -1) {
  387. Message msg = MessageCatalog.getMessage("CCCB4137");
  388. String text = msg.formatText(new Object[] {pic});
  389. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  390. throw new IllegalArgumentException(text);
  391. }
  392. try {
  393. int times = Integer.parseInt(pic.substring(i + 1, rparenPos));
  394. times -= 1; // prevCh added the first one
  395. i = rparenPos;
  396. for (int j = 0; j < times; j++) {
  397. buffer.append((char) prevCh);
  398. }
  399. } catch (NumberFormatException nfe) {
  400. throw new IllegalArgumentException(nfe.getLocalizedMessage());
  401. }
  402. } else if (ch == ')') {
  403. Message msg = MessageCatalog.getMessage("CCCB4138");
  404. String text = msg.formatText(new Object[] {pic});
  405. cErrorMgr.log(ErrorManager.Severity.ERROR, null, text);
  406. throw new IllegalArgumentException(text);
  407. } else {
  408. prevCh = (int) ch;
  409. buffer.append(ch);
  410. }
  411. }
  412. return buffer.toString();
  413. }
  414. /**
  415. * Computes decimal position (implied or explicit) of the picture.
  416. *
  417. * Preconditions: mPicture is initialized and normalized
  418. *
  419. * Postconditions: mDecimalPos is updated
  420. */
  421. private void computeDecimalPosition() {
  422. mDecimalPos = 0;
  423. mDecimalScalePos = 0;
  424. switch (mDataCategory) {
  425. case EX_FLOAT: {
  426. int ePos = mPicture.indexOf("E");
  427. int digitCnt = 0;
  428. for (int i = ePos - 1; i >= 0; i--) {
  429. char ch = mPicture.charAt(i);
  430. if (ch == '9') {
  431. digitCnt++;
  432. } else if ("V.".indexOf(ch) != -1) {
  433. mDecimalPos = digitCnt;
  434. break;
  435. }
  436. }
  437. break;
  438. }
  439. case NUMERIC: {
  440. boolean haveV = (mPicture.indexOf('V') != -1);
  441. boolean haveP = (mPicture.indexOf('P') != -1);
  442. boolean leftP = (mPicture.lastIndexOf('P') != (mPicture.length() - 1));
  443. if (haveV) {
  444. int digitCnt = 0;
  445. for (int i = mPicture.length() - 1; i >= 0; i--) {
  446. char ch = mPicture.charAt(i);
  447. if (ch == '9') {
  448. digitCnt++;
  449. } else if (ch == 'V') {
  450. mDecimalPos = digitCnt;
  451. break;
  452. }
  453. }
  454. } else if (haveP) {
  455. mDecimalScalePos = mPicture.lastIndexOf('P') - mPicture.indexOf('P') + 1;
  456. mDecimalPos = (!leftP ? 0 : mPicture.length() - (hasSign() ? 1 : 0));
  457. } else {
  458. mDecimalPos = 0;
  459. }
  460. break;
  461. }
  462. case NUMERIC_EDITED: {
  463. boolean haveDot = (mPicture.indexOf('.') != -1);
  464. boolean haveV = (mPicture.indexOf('V') != -1);
  465. boolean haveP = (mPicture.indexOf('P') != -1);
  466. boolean leftP = (mPicture.lastIndexOf('P') != (mPicture.length() - 1));
  467. if (haveV || haveDot) {
  468. int digitCnt = 0;
  469. for (int i = mPicture.length() - 1; i >= 0; i--) {
  470. char ch = mPicture.charAt(i);
  471. if ("90Z".indexOf(ch) != -1) {
  472. digitCnt++;
  473. } else if (".V".indexOf(ch) != -1) {
  474. mDecimalPos = digitCnt;
  475. break;
  476. }
  477. }
  478. } else if (haveP) {
  479. mDecimalScalePos = mPicture.lastIndexOf('P') - mPicture.indexOf('P') + 1;
  480. mDecimalPos = (!leftP ? 0 : mPicture.length() - (hasSign() ? 1 : 0));
  481. } else {
  482. mDecimalPos = 0;
  483. }
  484. break;
  485. }
  486. default:
  487. mDecimalPos = 0;
  488. }
  489. }
  490. /**
  491. * Determine the data category of the picture.
  492. *
  493. * Preconditions: mPicture is initialized and normalized.
  494. *
  495. * Postconditions: initializes mDataCategory.
  496. */
  497. private void computeCategory() {
  498. if (checkAlphabetic()) {
  499. mDataCategory = Category.ALPHABETIC;
  500. } else if (checkNumeric()) {
  501. mDataCategory = Category.NUMERIC;
  502. } else if (checkAlphanumeric()) {
  503. mDataCategory = Category.ALPHANUMERIC;
  504. } else if (checkDbcs()) {
  505. mDataCategory = Category.DBCS;
  506. } else if (checkAlphanumericEdited()) {
  507. mDataCategory = Category.ALPHANUMERIC_EDITED;
  508. } else if (checkExFloat()) {
  509. mDataCategory = Category.EX_FLOAT;
  510. } else if (checkNumericEdited()) {
  511. mDataCategory = Category.NUMERIC_EDITED;
  512. } else {
  513. mDataCategory = Category.ERR;
  514. }
  515. }
  516. /**
  517. * Determine whether or not the picture is alphabetic.
  518. *
  519. * @return true if the pic is alphabetic, false otherwise
  520. */
  521. private boolean checkAlphabetic() {
  522. for (int i = 0; i < mPicture.length(); i++) {
  523. if (mPicture.charAt(i) != 'A') {
  524. return false;
  525. }
  526. }
  527. return true;
  528. }
  529. /**
  530. * Determine whether or not the picture is numeric
  531. *
  532. * @return true if the pic is numeric, false otherwise
  533. */
  534. private boolean checkNumeric() {
  535. int digitCount = 0;
  536. for (int i = 0; i < mPicture.length(); i++) {
  537. char ch = mPicture.charAt(i);
  538. if ("9PSV".indexOf(ch) == -1) {
  539. return false;
  540. } else if (ch == '9') {
  541. digitCount++;
  542. }
  543. }
  544. return (digitCount > 0);
  545. }
  546. /**
  547. * Determine whether or not the picture is alphanumeric.
  548. *
  549. * @return true if the pic is alphanumeric, false otherwise
  550. */
  551. private boolean checkAlphanumeric() {
  552. int countA = 0;
  553. int count9 = 0;
  554. int len = mPicture.length();
  555. for (int i = 0; i < len; i++) {
  556. char ch = mPicture.charAt(i);
  557. if ("9XA".indexOf(ch) == -1) {
  558. return false;
  559. } else if (ch == '9') {
  560. count9++;
  561. } else if (ch == 'A') {
  562. countA++;
  563. }
  564. }
  565. return ((countA != len) && (count9 != len));
  566. }
  567. /**
  568. * Determine whether or not the picture is DBCS.
  569. *
  570. * @return true if the pic is DBCS, false otherwise
  571. */
  572. private boolean checkDbcs() {
  573. boolean hasG = false;
  574. boolean hasB = false;
  575. boolean hasN = false;
  576. for (int i = 0; i < mPicture.length(); i++) {
  577. char ch = mPicture.charAt(i);
  578. if ("GBN".indexOf(ch) != -1) {
  579. switch (ch) {
  580. case 'G':
  581. hasG = true;
  582. break;
  583. case 'B':
  584. hasB = true;
  585. break;
  586. case 'N':
  587. hasN = true;
  588. break;
  589. }
  590. } else {
  591. return false;
  592. }
  593. }
  594. return ((!hasN) || (!hasG && !hasB));
  595. }
  596. /**
  597. * Determine whether or not the picture is an external floating-point.
  598. *
  599. * @return true if the pic is an external floating-point, false otherwise
  600. */
  601. private boolean checkExFloat() {
  602. if (mPicture.length() < 4) {
  603. return false;
  604. }
  605. int mantissaEndPos = -1;
  606. int exponentEndPos = -1;
  607. int exponentDelimitPos = -1;
  608. for (int i = 0; i < mPicture.length(); i++) {
  609. char ch = mPicture.charAt(i);
  610. if (ch == '+' || ch == '-') {
  611. if (i != 0) {
  612. if (mantissaEndPos == -1) {
  613. return false;
  614. } else if (i != (mantissaEndPos + 2)) {
  615. return false;
  616. }
  617. }
  618. } else if (".V".indexOf(ch) != -1) {
  619. if (exponentDelimitPos != -1) {
  620. return false;
  621. }
  622. mantissaEndPos = i;
  623. } else if (ch == 'E') {
  624. if (mantissaEndPos == -1) {
  625. return false;
  626. } else if (i != (mantissaEndPos + 1)) {
  627. return false;
  628. }
  629. exponentDelimitPos = i;
  630. } else if (ch == '9') {
  631. if (exponentDelimitPos == -1) {
  632. mantissaEndPos = i;
  633. } else {
  634. exponentEndPos = i;
  635. }
  636. } else {
  637. return false;
  638. }
  639. }
  640. if (exponentEndPos == (mPicture.length() - 1)) {
  641. return (mPicture.charAt(exponentEndPos) == '9' && mPicture.charAt(exponentEndPos - 1) == '9');
  642. } else {
  643. return false;
  644. }
  645. }
  646. /**
  647. * Determine whether or not the picture is a numeric-edited item
  648. *
  649. * @return true if the pic is numeric-edited, false otherwise
  650. */
  651. private boolean checkNumericEdited() {
  652. for (int i = 0; i < mPicture.length(); i++) {
  653. if (mPicture.indexOf("CR") != -1) {
  654. continue;
  655. } else if (mPicture.indexOf("DB") != -1) {
  656. continue;
  657. } else if ("BPVZ90/,.+-*$".indexOf(mPicture.charAt(i)) == -1) {
  658. return false;
  659. }
  660. }
  661. return true;
  662. }
  663. /**
  664. * Determine whether or not the picture is a alphanumeric-edited item
  665. *
  666. * @return true if the pic is alphanumeric-edited, false otherwise
  667. */
  668. private boolean checkAlphanumericEdited() {
  669. boolean hasA_X = false;
  670. boolean hasB_0_Slant = false;
  671. for (int i = 0; i < mPicture.length(); i++) {
  672. char ch = mPicture.charAt(i);
  673. if ("AX9B0/".indexOf(ch) != -1) {
  674. switch (ch) {
  675. /* order of cases is significant */
  676. /* has A or X */
  677. case 'A':
  678. case 'X':
  679. hasA_X = true;
  680. break;
  681. /* has B or 0 or slant */
  682. case 'B':
  683. case '0':
  684. case '/':
  685. hasB_0_Slant = true;
  686. }
  687. } else {
  688. return false;
  689. }
  690. }
  691. return (hasA_X && hasB_0_Slant);
  692. }
  693. }
  694. /* EOF $RCSfile: CocoPicture.java,v $ */