Java класс для сортировки массива строк

hosm

* so what *
18.05.2009
2 442
6
#1
Спасибо говорим lmike

джава класс для сортировки массива строк (либа SortList):
<!--shcode--><pre><code class='java'>import java.util.*;
public class SortList {
private ArrayList arrList=new ArrayList();
public void add(String s){
arrList.add(s);
}
public String[] sort(){
Collections.sort(arrList);
String[] sorted=new String[arrList.size()];
arrList.toArray(sorted);
return sorted;
}

}[/CODE]

Ниже приведен пример использования класса.
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">его заюзывание в бридже:</div></div><div class="sp-body"><div class="sp-content">
Код:
Option Public
Option Declare
Use "ErrorHandling"
Uselsx "*lsxlc"
Use "SortList"
Const ERRBASE_SORT=1130
Private Const ERRLS2JINIT=ERRBASE_SORT+1, CS_ERRLS2JINIT={ошибка инициализации класса Java}

Class SortObj As ErrorHandlerWJ
Private SortListObj As JavaObject
Private SortListClass As JavaClass
Private fCount As Integer
'********************************
Sub New()
On Error Goto errorhandler
Set SortListClass = jSession.GetClass("SortList")
Set SortListObj = SortListClass.CreateObject
ExitFunction:
Exit Sub
errorhandler:
Call Me.RaiseError()
Error ERRLS2JINIT, CS_ERRLS2JINIT
End Sub
Sub Delete()
If Not SortListObj Is Nothing Then
Delete SortListObj
End If
End Sub
Sub Add(s As String)
SortListObj.add(s)
End Sub
Function Sort() As Variant
On Error Goto errorhandler
Sort=SortListObj.sort()
ExitFunction:
Exit Function
errorhandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
End Class
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">используемый в примере код класса обработчика ошибок (либа ErrorHandling):</div></div><div class="sp-body"><div class="sp-content">
Код:
Option Public
Option Declare
%INCLUDE "lserr.lss"
'Uselsx "*lsxlc"
Uselsx "*javacon"
%INCLUDE "lsconst.lss"
Class ErrorHandler

Sub ClrError()
End Sub
Sub New()
Call Me.ClrError()
End Sub
Function GetModuleInfo() As String
Dim thisType As String, modInfo As String	
thisType= Typename(Me)
' Not a class, use the calling module instead
If (thisType = "") Then thisType = Getthreadinfo(11)
modInfo = thisType & "::" & Getthreadinfo(10) & ": "
GetModuleInfo=modInfo
End Function
Function RaiseError() As String
Dim es As String
es=GetModuleInfo()
If (Err = 0) Then
es = es + "Manually raised an error"
Else
es = es + "Run time error: (" + Trim(Str(Err)) + ") " + Error$ + " at line: "+ Trim(Str(Erl))
End If
Print es
Me.RaiseError=es
Call Me.ClrError()
End Function
End Class

Class ErrorHandlerWJ As ErrorHandler
Private jSession As JavaSession	
Private jError As JavaError	
Sub New()
On Error Goto errorhandler
Set jSession= New JAVASESSION
ExitFunction:
Exit Sub
errorhandler:
Call ErrorHandler..RaiseError()
Resume ExitFunction
End Sub
Function RaiseError() As String
Set jError = jSession.getLastJavaError()
Dim es As String
If (jError.errorMsg = "") Then		
es=ErrorHandler..RaiseError()
Else
es=GetModuleInfo()+"Error at line " & Erl & ": " & jError.errorMsg
Print es
jSession.ClearJavaError			
End If
RaiseError=es
End Function
End Class
Взято [post="165930"]отсюда[/post].