Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.corexis.calculator;
- import java.util.HashMap;
- import java.util.Map;
- public class DataValidator {
- private int a, b;
- private String op;
- private boolean roman = false;
- Expression createExpression(String checkingString) {
- if (checkForNumbers(checkingString)) {
- return new Expression(a, b, op, roman);
- } else {
- return null;
- }
- }
- private String[] splitString(String str) {
- return str.split(" ");
- }
- private boolean checkForNumbers(String str) {
- boolean mAIsRoman = false;
- boolean mBIsRoman = false;
- String[] tempArr = splitString(str);
- try {
- this.a = Integer.parseInt(tempArr[0]);
- } catch (NumberFormatException e) {
- if (checkForRoman(tempArr[0]) != 0) {
- this.a = checkForRoman(tempArr[0]);
- mAIsRoman = true;
- } else {
- throw new NumberFormatException();
- }
- }
- try {
- this.b = Integer.parseInt(tempArr[2]);
- } catch (NumberFormatException e) {
- if (checkForRoman(tempArr[2]) != 0) {
- this.b = checkForRoman(tempArr[2]);
- mBIsRoman = true;
- } else {
- throw new NumberFormatException();
- }
- }
- if(mAIsRoman == mBIsRoman) {
- return true;
- } else {
- return false;
- }
- }
- private int checkForRoman(String checkingString) {
- if (Expression.romanNumbers.containsKey(checkingString)) {
- roman = true;
- return Expression.romanNumbers.get(checkingString);
- }
- return 0;
- }
- private boolean checkForOperation(String op) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement