Permalink
Browse files

Init에 포함된 Intervar 주기 설정값을 Property로 분리

  • Loading branch information...
gomsun2 committed Feb 13, 2014
1 parent 2e9cebd commit 55908b399f920387626812a7c38bd92db2f5c52d
Showing with 26 additions and 8 deletions.
  1. +26 −8 source/utils/mIntervalCounter.pas
@@ -13,13 +13,16 @@ interface
function GetStrIdx(Interval: Integer): Integer;
function GetEndIdx(Interval: Integer): Integer;
function GetIntervalRange(Interval: Integer): Integer;
+ function GetInterval: Integer;
+ procedure SetInterval(const Value: Integer);
- procedure Init(const ABegin, AEnd, AInterval: Integer);
+ procedure Init(const ABegin, AEnd: Integer);
property Range: Integer read GetRange;
property Count: Integer read GetCount;
property StrIdx[Interval: Integer]: Integer read GetStrIdx;
property EndIdx[Interval: Integer]: Integer read GetEndIdx;
+ property Interval: Integer read GetInterval write SetInterval;
property IntervalRange[Interval: Integer]: Integer read GetIntervalRange;
end;
@@ -39,14 +42,17 @@ TIntervalCounter = class(TInterfacedObject, IIntervalCounter)
function GetStrIdx(Interval: Integer): Integer;
function GetEndIdx(Interval: Integer): Integer;
function GetIntervalRange(Interval: Integer): Integer;
+ function GetInterval: Integer;
+ procedure SetInterval(const Value: Integer);
public
- procedure Init(const ABegin, AEnd, AInterval: Integer);
+ procedure Init(const ABegin, AEnd: Integer);
property Range: Integer read GetRange;
property Count: Integer read GetCount;
property StrIdx[Interval: Integer]: Integer read GetStrIdx;
property EndIdx[Interval: Integer]: Integer read GetEndIdx;
property IntervalRange[Interval: Integer]: Integer read GetIntervalRange;
+ property Interval: Integer read GetInterval write SetInterval;
end;
implementation
@@ -56,6 +62,11 @@ implementation
{ TIntervalIndexer }
+function TIntervalCounter.GetInterval: Integer;
+begin
+ Result := FInterval;
+end;
+
function TIntervalCounter.GetIntervalRange(Interval: Integer): Integer;
begin
Result := EndIdx[Interval] - StrIdx[Interval];
@@ -89,23 +100,30 @@ function TIntervalCounter.GetStrIdx(Interval: Integer): Integer;
Result := FMin + (FInterval * Interval);
end;
-procedure TIntervalCounter.Init(const ABegin, AEnd, AInterval: Integer);
+procedure TIntervalCounter.Init(const ABegin, AEnd: Integer);
begin
if (ABegin = 0) or (AEnd = 0) then
raise ERangeParamsAssignedByZero.Create('ABegin or AEnd params can not assigned by zero');
if (ABegin < 0) or (AEnd < 0) then
raise ERangeParamsAssignedByNegative.Create('ABegin or AEnd params can not assigned by negative');
if ABegin > AEnd then
raise ERangeParamsOutOfRange.Create('AEnd parameter is always greater then or equal to ABegin parameter');
- if AInterval = 0 then
+ if FInterval = 0 then
raise EIntervalAssignedByZero.Create('AInterval can not assigned by zero');
- if AInterval < 0 then
- raise EIntervalAssignedByNegative.Create('AInterval cannot assigned by negative');
- FInterval := AInterval;
FMin := ABegin;
FMax := AEnd;
- FGetIntervalCnt := MinimumCount(AEnd - ABegin + 1, AInterval);
+ FGetIntervalCnt := MinimumCount(AEnd - ABegin + 1, FInterval);
+end;
+
+procedure TIntervalCounter.SetInterval(const Value: Integer);
+begin
+ if Value = 0 then
+ raise EIntervalAssignedByZero.Create('AInterval can not assigned by zero');
+ if Value < 0 then
+ raise EIntervalAssignedByNegative.Create('AInterval cannot assigned by negative');
+
+ FInterval := Value;
end;
end.

0 comments on commit 55908b3

Please sign in to comment.