package com.javapatterns.immutable.complex;
final public class Complex1 extends Number
implements java.io.Serializable, Cloneable, Comparable
{
/**
* The imaginary unit.
*/
static final public Complex1 i = new Complex1(0.0, 1.0);
/**
* Real part of the Complex.
*/
private double re;
/**
* Imaginary part of the Complex.
*/
private double im;
/**
* String used in converting Complex to String.
*/
public static String suffix = "i";
/**
* Constructs a Complex equal to the argument.
* @param z A Complex object
* If z is null then a NullPointerException is thrown.
*/
public Complex1(Complex1 z)
{
re = z.re;
im = z.im;
}
/**
* Constructs a Complex with real and imaginary parts given
* by the input arguments.
* @param re A double value equal to the real part of the Complex object.
* @param im A double value equal to the imaginary part of the Complex object.
*/
public Complex1(double re, double im)
{
this.re = re;
this.im = im;
}
/**
* Constructs a Complex with a zero imaginary part.
* @param re A double value equal to the real part of the Complex object.
*/
public Complex1(double re)
{
this.re = re;
this.im = 0.0;
}
/**
* Constructs a Complex equal to zero.
*/
public Complex1()
{
re = 0.0;
im = 0.0;
}
/**
* Compares with another Complex.
* <p><em>Note: To be useful in hashtables this method
* considers two NaN double values to be equal. This
* is not according to IEEE specification.</em>
* @param z A Complex object.
* @return True if the real and imaginary parts of this object
* are equal to their counterparts in the argument; false, otherwise.
*/
public boolean equals(Complex1 z)
{
return (re == z.re && im == z.im);
}
/**
* Compares this object against the specified object.
* @param obj The object to compare with.
* @return True if the objects are the same; false otherwise.
*/
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
else if (obj instanceof Complex)
{
return equals((Complex)obj);
}
else
{
return false;
}
}
/**
* Returns a hashcode for this Complex.
* @return A hash code value for this object.
*/
public int hashCode()
{
long re_bits = Double.doubleToLongBits(re);
long im_bits = Double.doubleToLongBits(im);
return (int)((re_bits^im_bits)^((re_bits^im_bits)>>32));
}
/**
* Returns the value of the real part as a short.
*/
public short shortValue()
{
return (short)re;
}
/**
* Returns the real part of a Complex object.
* @return The real part of z.
*/
public double real()
{
return re;
}
/**
* Returns the imaginary part of a Complex object.
* @param z A Complex object.
* @return The imaginary part of z.
*/
public double imag()
{
return im;
}
/**
* Returns the value of the real part as an int.
*/
public int intValue()
{
return (int)re;
}
/**
* Returns the value of the real part as a byte.
*/
public byte byteValue()
{
return (byte)re;
}
/**
* Returns the value of the real part as a long.
*/
public long longValue()
{
return (long)re;
}
/**
* Returns the value of the real part as a float.
*/
public float floatValue()
{
return (float)re;
}
/**
* Returns the value of the real part as a double.
*/
public double doubleValue()
{
return re;
}
/**
* Compares this Complex to another Object. If the Object is a Complex,
* this function behaves like compareTo(Complex). Otherwise, it throws
* a ClassCastException (as Complex objects are comparable only to other
* Complex objects).
*/
public int compareTo(Object obj)
{
return compareTo((Complex)obj);
}
/**
* Compares two Complex objects.
* <P>A lexagraphical ordering is used. First the real parts are compared
* in the sense of Double.compareTo. If the real parts are unequal this
* is the return value. If the return parts are equal then the comparison
* of the imaginary parts is returned.
* @return The value 0 if z is equal to this Complex;
* a value less than 0 if this Complex is less than z;
* and a value greater than 0 if this Complex is greater
* than z.
*/
public int compareTo(Complex1 z)
{
int compare = new Double(re).compareTo(new Double(z.re));
if (compare == 0)
{
compare = new Double(im).compareTo(new Double(z.im));
}
return compare;
}
/**
* Returns the real part of a Complex object.
* @param z A Complex object.
* @return The real part of z.
*/
public static double real(Complex1 z)
{
return z.re;
}
/**
* Returns the imaginary part of a Complex object.
* @param z A Complex object.
* @return The imaginary part of z.
*/
public static double imag(Complex1 z)
{
return z.im;
}
/**
* Returns the negative of a Complex object, -z.
* @param z A Complex object.
* @return A newly constructed Complex initialized to
* the negative of the argument.
*/
public static Complex1 negate(Complex1 z)
{
return new Complex1(-z.re, -z.im);
}
/**
* Returns the complex conjugate of a Complex object.
* @param z A Complex object.
* @return A newly constructed Complex initialized to complex conjugate of z.
*/
public static Complex1 conjugate(Complex1 z)
{
return new Complex1(z.re, -z.im);
}
/**
* Returns the sum of two Complex objects, x+y.
* @param x A Complex object.
* @param y A Complex object.
* @return A newly constructed Complex initialized to x+y.
*/
public static Complex1 add(Complex1 x, Complex1 y)
{
return new Complex1(x.re+y.re, x.im+y.im);
}
/**
* Returns the sum of a Complex and a double, x+y.
* @param x A Complex object.
* @param y A double value.
* @return A newly constructed Complex initialized to x+y.
*/
public static Complex1 add(Complex1 x, double y)
{
return new Complex1(x.re+y, x.im);
}
/**
* Returns the sum of a double and a Complex, x+y.
* @param x A double value.
* @param y A Complex object.
* @return A newly constructed Complex initialized to x+y.
*/
public static Complex1 add(double x, Complex1 y)
{
return new Complex1(x+y.re, y.im);
}
/**
* Returns the difference of two Complex objects, x-y.
* @param x A Complex object.
* @param y A Complex object.
* @return A newly constructed Complex initialized to x-y.
*/
public static Complex1 subtract(Complex1 x, Complex1 y)
{
return new Complex1(x.re-y.re, x.im-y.im);
}
/**
* Returns the difference of a Complex object and a double, x-y.
* @param x A Complex object.
* @param y A double value.
* @return A newly constructed Complex initialized to x-y.
*/
public static Complex1 subtract(Complex1 x, double y)
{
return new Complex1(x.re-y, x.im);
}
/**
* Returns the difference of a double and a Complex object, x-y.
* @param x A double value.
* @param y A Complex object.
* @return A newly constructed Complex initialized to x-y..
*/
public static Complex1 subtract(double x, Complex1 y)
{
return new Complex1(x-y.re, -y.im);
}
/**
* Returns the product of two Complex objects, x*y.
* @param x A Complex object.
* @param y A Complex object.
* @return A newly constructed Complex initialized to x*y.
*/
public static Complex1 multiply(Complex1 x, Complex1 y)
{
return new Complex1(x.re*y.re-x.im*y.im, x.re*y.im+x.im*y.re);
}
/**
* Returns the product of a Complex object and a double, x*y.
* @param x A Complex object.
* @param y A double value.
* @return A newly con
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
full source code of java design patterns (792个子文件)
Complex1.java 11KB
XMLProperties.java 6KB
ButtonMaker.java 5KB
Complex.java 5KB
Point.java 5KB
PickleMaker.java 4KB
UndoableTextArea.java 4KB
AdvUndoTextClass.java 4KB
XMLParser.java 4KB
UndoableTextArea.java 4KB
MXList1.java 4KB
MXList.java 4KB
MXList.java 3KB
ShowButtons.java 3KB
ShowPickle.java 3KB
ConcreteObserver.java 3KB
ObserverApp.java 2KB
MonkTang.java 2KB
MIMEParser.java 2KB
ImageIconProxy.java 2KB
AutoMessage.java 2KB
LazySingleton1.java 2KB
Drawing.java 2KB
Drawing.java 2KB
Monkey.java 2KB
Grep.java 2KB
FlyweightFactorySingleton.java 2KB
ConfigManager.java 2KB
SimpleDraw.java 2KB
SimpleDraw.java 2KB
ContextServlet.java 2KB
RegSingleton.java 2KB
SwingUI.java 2KB
Professional.java 2KB
Itr.java 2KB
LingualResource.java 2KB
FlyweightFactory.java 2KB
Order.java 2KB
OCBox.java 2KB
Client.java 1KB
Client.java 1KB
RotatingCursorCompact.java 1KB
TextAreaUndoDemoPanel.java 1KB
UserValidatorServlet.java 1KB
MyHandler.java 1KB
ExcelReader.java 1KB
ObjectKeeper.java 1KB
FlyweightFactorySingleton.java 1KB
MessageBuilder.java 1KB
SessionFacadeBean.java 1KB
TheWorld.java 1KB
Monkey.java 1KB
CadSymbol.java 1KB
VectorProxy.java 1KB
MXTest.java 1KB
Interrogation.java 1KB
Julia.java 1KB
ClientSingleton.java 1KB
ItsukyuQuotation.java 1KB
Expression.java 1KB
KeyInfo.java 1KB
KeyInfo.java 1KB
Clock.java 1KB
Itsukyu.java 1KB
TimerAction.java 1KB
FlyweightFactory.java 1KB
DrumBeater.java 1KB
Client.java 1KB
helloServlet.java 1KB
MailSender.java 1KB
CommandList.java 1KB
Proxy.java 1KB
ClientSingleton.java 1KB
OrderLine.java 1KB
Grep.java 1KB
Business2Bean.java 1KB
Business1Bean.java 1KB
CommandList.java 1KB
TextAreaUndoDemo.java 1KB
TheGreatestSage.java 1KB
SwingClock.java 1KB
MagicFinger.java 1KB
Client1.java 1KB
Client.java 1KB
Client.java 1KB
ObjectKeeperTest.java 1KB
LogoutState.java 1KB
KeyInfo.java 1KB
FlavorFactorySingleton.java 1KB
FlavorFactorySingleton.java 1KB
SimpleMail.java 1KB
TestServlet.java 1KB
Composite.java 997B
Scheduler.java 996B
Originator.java 982B
Subject.java 978B
Client.java 976B
Composite.java 976B
CloneableBike.java 970B
Composite.java 964B
共 792 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
zhangwonderful
- 粉丝: 35
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功