001/*- 002 ******************************************************************************* 003 * Copyright (c) 2016 Diamond Light Source Ltd. 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Peter Chang - initial API and implementation and/or initial documentation 011 *******************************************************************************/ 012 013package org.eclipse.january.dataset; 014 015/** 016 * Interface to represent a binary operation for implementations over different output domains 017 */ 018public interface BinaryOperation extends IOperation { 019 020 /** 021 * @param a first operand 022 * @param b second operand 023 * @return a op b 024 */ 025 boolean booleanOperate(long a, long b); 026 027 /** 028 * @param a first operand 029 * @param b second operand 030 * @return a op b 031 */ 032 long longOperate(long a, long b); 033 034 /** 035 * @param a first operand 036 * @param b second operand 037 * @return a op b 038 */ 039 double doubleOperate(double a, double b); 040 041 /** 042 * @param out holds (ra, ia) op (rb, ib) 043 * @param ra real part of first operand 044 * @param ia imaginary part of first operand 045 * @param rb real part of second operand 046 * @param ib imaginary part of second operand 047 */ 048 void complexOperate(double[] out, double ra, double ia, double rb, double ib); 049 050 /** 051 * @param a first operand 052 * @param b second operand 053 * @return string to represent output 054 * @since 2.0 055 */ 056 String toString(String a, String b); 057 058 /** 059 * Stub class where only three methods need to be overridden: 060 * {@link #complexOperate(double[], double, double, double, double)}, 061 * {@link #toString(String, String)} 062 */ 063 public static class Stub implements BinaryOperation { 064 double[] z = new double[2]; 065 066 @Override 067 public double doubleOperate(double a, double b) { 068 complexOperate(z, a, 0, b, 0); 069 return z[0]; 070 } 071 072 @Override 073 public boolean booleanOperate(long a, long b) { 074 return doubleOperate(a, b) != 0; 075 } 076 077 @Override 078 public long longOperate(long a, long b) { 079 return DTypeUtils.toLong(doubleOperate(a, b)); 080 } 081 082 @Override 083 public void complexOperate(double[] out, double ra, double ia, double rb, double ib) { 084 } 085 086 @Override 087 public String toString(String string, String string2) { 088 return null; 089 } 090 } 091}