1 | unit UObjectInteger;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | SysUtils, Classes, UObjectTypeBase, UObjectBoolean;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TInteger = class(TInterfacedObject, IAssignable, IOrderable)
|
---|
10 | public
|
---|
11 | Value: Integer;
|
---|
12 | function Predecessor: IOrderable;
|
---|
13 | function Successor: IOrderable;
|
---|
14 | function Low: IOrderable;
|
---|
15 | function High: IOrderable;
|
---|
16 | procedure Assign(Source: TInterfacedObject);
|
---|
17 | function EqualTo(Operand: TInterfacedObject): TBoolean;
|
---|
18 | function HigherThen(Operand: IOrderable): TBoolean;
|
---|
19 | function LowerThan(Operand: IOrderable): TBoolean;
|
---|
20 | function Max(Operand1, Operand2: IOrderable): IOrderable;
|
---|
21 | function Min(Operand1, Operand2: IOrderable): IOrderable;
|
---|
22 | end;
|
---|
23 |
|
---|
24 | implementation
|
---|
25 |
|
---|
26 | uses
|
---|
27 | UObjectString;
|
---|
28 |
|
---|
29 | { TInteger }
|
---|
30 |
|
---|
31 | procedure TInteger.Assign(Source: TInterfacedObject);
|
---|
32 | begin
|
---|
33 | if Source is TInteger then Value := (Source as TInteger).Value
|
---|
34 | else if Source is TString then Value := StrToInt((Source as TString).Value)
|
---|
35 | else raise EConvertError.Create('');
|
---|
36 | end;
|
---|
37 |
|
---|
38 | function TInteger.EqualTo(Operand: TInterfacedObject): TBoolean;
|
---|
39 | begin
|
---|
40 | if Operand is TInteger then begin
|
---|
41 | Result := TBoolean.Create;
|
---|
42 | Result.Value := Value = TInteger(Operand).Value;
|
---|
43 | end else raise EInvalidCast.Create('Typecast error.');
|
---|
44 | end;
|
---|
45 |
|
---|
46 | function TInteger.High: IOrderable;
|
---|
47 | begin
|
---|
48 |
|
---|
49 | end;
|
---|
50 |
|
---|
51 | function TInteger.HigherThen(Operand: IOrderable): TBoolean;
|
---|
52 | begin
|
---|
53 | if TInterfacedObject(Operand) is TInteger then begin
|
---|
54 | Result := TBoolean.Create;
|
---|
55 | Result.Value := Value > TInteger(Operand).Value;
|
---|
56 | end else raise EInvalidCast.Create('Typecast error.');
|
---|
57 | end;
|
---|
58 |
|
---|
59 | function TInteger.Low: IOrderable;
|
---|
60 | begin
|
---|
61 |
|
---|
62 | end;
|
---|
63 |
|
---|
64 | function TInteger.LowerThan(Operand: IOrderable): TBoolean;
|
---|
65 | begin
|
---|
66 | if TInterfacedObject(Operand) is TInteger then begin
|
---|
67 | Result := TBoolean.Create;
|
---|
68 | Result.Value := Value < TInteger(Operand).Value;
|
---|
69 | end else raise EInvalidCast.Create('Typecast error.');
|
---|
70 | end;
|
---|
71 |
|
---|
72 | function TInteger.Max(Operand1, Operand2: IOrderable): IOrderable;
|
---|
73 | begin
|
---|
74 |
|
---|
75 | end;
|
---|
76 |
|
---|
77 | function TInteger.Min(Operand1, Operand2: IOrderable): IOrderable;
|
---|
78 | begin
|
---|
79 |
|
---|
80 | end;
|
---|
81 |
|
---|
82 | function TInteger.Predecessor: IOrderable;
|
---|
83 | begin
|
---|
84 | Result := TInteger.Create;
|
---|
85 | TInteger(Result).Value := Pred(Value);
|
---|
86 | end;
|
---|
87 |
|
---|
88 | function TInteger.Successor: IOrderable;
|
---|
89 | begin
|
---|
90 | Result := TInteger.Create;
|
---|
91 | TInteger(Result).Value := Succ(Value);
|
---|
92 | end;
|
---|
93 |
|
---|
94 | end.
|
---|