namespace ServerApp
{
public class MaxDataSizeRecorder
{
private const int numberOfPoints = 10;
class NamedPoint : IComparable
{
public string Name = "NoName";
public int Point = 0;
public int CompareTo( object obj )
{
return ((NamedPoint)obj).Point - Point;
}
public NamedPoint( string name, int point )
{
this.Name = name;
this.Point = point;
}
}
private ArrayList points;
public string Name
{
get { return ((NamedPoint)points[0]).Name; }
}
public int Point
{
get { return ((NamedPoint)points[0]).Point; }
}
public void SetPoint( string name, int point )
{
if( ((NamedPoint)points[numberOfPoints-1]).Point >= point ) return;
points.Add( new NamedPoint( name, point) );
points.Sort();
points.RemoveAt(numberOfPoints-1);
}
public bool IsHighest( int point )
{
return this.Point < point;
}
public MaxDataSizeRecorder()
{
points = new ArrayList();
for( int i=0; i<numberOfPoints; i++ )
{
points.Add( new NamedPoint("NoName", 0 ) );
}
}
}
}
10個のデータを記録するようにしたMaxDataSizeRecorderクラス(C#版)
Imports System.Collections
Public Class MaxDataSizeRecorder
Private Const numberOfPoints As Integer = 10
Class NamedPoint
Implements IComparable
Public Name As String = "NoName"
Public Point As Integer = 0
Public Function CompareTo(ByVal obj As Object) As Integer Implements IComparable.CompareTo
Return obj.Point - Point
End Function
Public Sub New(ByVal name As String, ByVal point As Integer)
Me.Name = name
Me.Point = point
End Sub
End Class
Private points As ArrayList
Public ReadOnly Property Name() As String
Get
Return points(0).Name
End Get
End Property
Public ReadOnly Property Point() As Integer
Get
Return points(0).Point
End Get
End Property
Public Sub SetPoint(ByVal _name As String, ByVal _point As Integer)
If points(numberOfPoints - 1).Point >= _point Then Exit Sub
points.Add(New NamedPoint(_name, _point))
points.Sort()
points.RemoveAt(numberOfPoints - 1)
End Sub
Public Function IsHighest(ByVal _point As Integer) As Boolean
Return Me.Point < _point
End Function
Public Sub New()
points = New ArrayList()
Dim i As Integer
For i = 0 To numberOfPoints - 1
points.Add(New NamedPoint("NoName", 0))
Next
End Sub
End Class
namespace ServerApp
{
public class MaxDataSizeRecorder
{
private const int numberOfPoints = 10;
class NamedPoint : IComparable
{
private string name = "NoName";
private int point = 0;
public string Name
{
get { return name; }
}
public int Point
{
get { return point; }
}
public int CompareTo( object obj )
{
return ((NamedPoint)obj).point - point;
}
public NamedPoint( string name, int point )
{
this.name = name;
this.point = point;
}
}
private NamedPoint [] points;
public string Name
{
get { return points[0].Name; }
}
public int Point
{
get { return points[0].Point; }
}
public void SetPoint( string name, int point )
{
if( points[numberOfPoints-1].Point >= point ) return;
points[numberOfPoints-1] = new NamedPoint( name, point);
Array.Sort( points );
}
public bool IsHighest( int point )
{
return this.Point < point;
}
public MaxDataSizeRecorder()
{
points = new NamedPoint[numberOfPoints];
for( int i=0; i<numberOfPoints; i++ )
{
points[i] = new NamedPoint("NoName", 0 );
}
}
}
}
Public Class MaxDataSizeRecorder
Private Const numberOfPoints As Integer = 10
Class NamedPoint
Implements IComparable
Private _name As String = "NoName"
Private _point As Integer = 0
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
Public ReadOnly Property Point() As Integer
Get
Return _point
End Get
End Property
Public Function CompareTo(ByVal obj As Object) As Integer Implements IComparable.CompareTo
Return obj.Point - _point
End Function
Public Sub New(ByVal name As String, ByVal point As Integer)
Me._name = name
Me._point = point
End Sub
End Class
Private points(numberOfPoints - 1) As NamedPoint
Public ReadOnly Property Name() As String
Get
Return points(0).Name
End Get
End Property
Public ReadOnly Property Point() As Integer
Get
Return points(0).Point
End Get
End Property
Public Sub SetPoint(ByVal _name As String, ByVal _point As Integer)
If points(numberOfPoints - 1).Point >= _point Then Exit Sub
points(numberOfPoints - 1) = New NamedPoint(_name, _point)
Array.Sort(points)
End Sub
Public Function IsHighest(ByVal _point As Integer) As Boolean
Return Me.Point < _point
End Function
Public Sub New()
Dim i As Integer
For i = 0 To numberOfPoints - 1
points(i) = New NamedPoint("NoName", 0)
Next
End Sub
End Class