public void resultClicked() { try { addOperand(currentNumber); currentNumber = ""; if (operator.equals("+")) { add(); increaseCalculations(); } else if (operator.equals("-")) { subtract(); increaseCalculations(); } else if (operator.equals("x")) { multiply(); increaseCalculations(); } else if (operator.equals("/")) { divide(); increaseCalculations(); } setPrintText(""); setPrintText(secondOperand()); processEvent(new ActionEvent(this, ActionEvent.NULL_SOURCE_TARGET)); operator = ""; System.out.println(firstOperand()); System.out.println(secondOperand()); } catch (FormatException e) { e.printStackTrace(); } }
/** Reads the next key/value pair from the input for processing. */ public boolean next(Text key, SequencedFragment value) throws IOException { if (pos >= end) return false; // past end of slice int bytesRead = 0; boolean goodRecord; do { bytesRead = lowLevelQseqRead(key, value); // if bytesRead <= 0 EOF has been reached goodRecord = (bytesRead > 0) && (!filterFailedQC || value.getFilterPassed() == null || value.getFilterPassed()); } while (bytesRead > 0 && !goodRecord); if (goodRecord) // post process the record only if it's going to be used { try { postProcessSequencedFragment(value); } catch (FormatException e) { throw new FormatException( e.getMessage() + " Position: " + makePositionMessage(this.pos - bytesRead) + "; line: " + buffer); // last line read is still in the buffer } } return goodRecord; }
// YUVオブジェクトのバイナリデータを読み込み、マーカーを検知 public void readYUV( final byte[] data, int dataWidth, int dataHeight, int left, int top, int width, int height, boolean reserversion) { final LuminanceSource source = new PlanarYUVLuminanceSource( data, dataWidth, dataHeight, left, top, width, height, reserversion); final BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); // final Reader reader = new MultiFormatReader(); final Reader reader = new QRCodeReader(); try { // 結果をゲット mQRResult.setResultData(reader.decode(binaryBitmap)); mFoundFlag = true; } // 見つからなかった! catch (NotFoundException ex) { ex.printStackTrace(); mFoundFlag = false; } catch (ChecksumException ex) { ex.printStackTrace(); mFoundFlag = false; } catch (FormatException ex) { ex.printStackTrace(); mFoundFlag = false; } }
public void operatorClicked(String op) { try { if (currentNumber.equals("")) { currentNumber = secondOperand(); } addOperand(currentNumber); currentNumber = ""; operator = op; setPrintText(op); processEvent(new ActionEvent(this, ActionEvent.NULL_SOURCE_TARGET)); } catch (FormatException e) { e.printStackTrace(); } }
public void changeBase(String base) { try { addOperand(currentNumber); System.out.println(operator); } catch (FormatException e1) { e1.printStackTrace(); } if (base.equals("Oct")) { setBase(new OctalBase()); } else if (base.equals("Hex")) { setBase(new HexBase()); } setPrintText(""); if (operator.equals("") || operator.equals("#")) { setPrintText(secondOperand()); } else { setPrintText(firstOperand() + operator + secondOperand()); } System.out.println(getPrintText()); processEvent(new ActionEvent(this, ActionEvent.NULL_SOURCE_TARGET)); }
public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws FormatException, NotFoundException { // Find out where the Middle section (payload) starts & ends int[] startRange = decodeStart(row); int[] endRange = decodeEnd(row); StringBuffer result = new StringBuffer(20); decodeMiddle(row, startRange[1], endRange[0], result); String resultString = result.toString(); int[] allowedLengths = null; if (hints != null) { allowedLengths = (int[]) hints.get(DecodeHintType.ALLOWED_LENGTHS); } if (allowedLengths == null) { allowedLengths = DEFAULT_ALLOWED_LENGTHS; } // To avoid false positives with 2D barcodes (and other patterns), make // an assumption that the decoded string must be 6, 10 or 14 digits. int length = resultString.length(); boolean lengthOK = false; for (int i = 0; i < allowedLengths.length; i++) { if (length == allowedLengths[i]) { lengthOK = true; break; } } if (!lengthOK) { throw FormatException.getFormatInstance(); } return new Result( resultString, null, // no natural byte representation for these barcodes new ResultPoint[] { new ResultPoint(startRange[1], (float) rowNumber), new ResultPoint(endRange[0], (float) rowNumber) }, BarcodeFormat.ITF); }
static { INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless }
/** * @param value character set ECI value * @return {@code CharacterSetECI} representing ECI of given value, or null if it is legal but * unsupported * @throws FormatException if ECI value is invalid */ public static CharacterSetECI getCharacterSetECIByValue(int value) throws FormatException { if (value < 0 || value >= 900) { throw FormatException.getFormatInstance(); } return VALUE_TO_ECI.get(value); }
boolean nextCommand() { System.out.print( "\n[" + calc.getBase().getName() + "," + calc.getFormat().getName() + "," + calc.firstOperand() + ", " + calc.secondOperand() + "] >"); // Print huidige waarden van calc. try { // reads the command from the keyboard String command = lineReader.readLine(); // Lees input. while (command == null) { // if (prevReader != null) { lineReader = prevReader; prevReader = null; command = lineReader.readLine(); } else { return false; } } /* * Acties die uitgevoerd worden bij herkenning van een operator. */ if (command.equals("+")) calc.add(); else if (command.equals("-")) calc.subtract(); else if (command.equals("*")) calc.multiply(); else if (command.equals("/")) calc.divide(); else if (command.equals("dec")) calc.setBase(new DecimalBase()); else if (command.equals("bin")) calc.setBase(new BinaryBase()); else if (command.equals("oct")) calc.setBase(new OctalBase()); else if (command.equals("hex")) calc.setBase(new HexBase()); else if (command.equals("rat")) calc.setFormat(new RationalFormat()); else if (command.equals("fixed")) calc.setFormat(new FixedPointFormat()); else if (command.equals("float")) calc.setFormat(new FloatingPointFormat()); else if (command.equals("del")) calc.delete(); else if (command.indexOf("op") >= 0) { command = command.substring(2).trim(); try { calc.addOperand(command); } catch (FormatException e) { System.out.println("Wrong operand: " + e.getMessage()); } } else if (command.indexOf("read") >= 0) { try { BufferedReader file = new BufferedReader(new FileReader(command.substring(4).trim())); prevReader = lineReader; lineReader = file; System.out.println("Reading from file " + command.substring(4).trim()); } catch (Exception e) { System.out.println("Cannot open file " + command.substring(4).trim()); } } else if (command.equals("help")) { printHelp(); } else if (command.equals("exit")) return false; else { System.out.println("Error! Not a valid command"); } } catch (IOException ioe) { ioe.printStackTrace(); } return true; }