wirispluginengine 3.62.0.1322 → 7.14.0.1422
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +34 -34
- data/app/assets/javascripts/wirispluginengine/WIRISplugins.js +1040 -64
- data/app/controllers/wirispluginengine/application_controller.rb +84 -75
- data/app/helpers/wirispluginengine/application_helper.rb +4 -4
- data/config/routes.rb +4 -4
- data/lib/com/wiris/common/WInteger.rb +52 -51
- data/lib/com/wiris/plugin/api/Cas.rb +5 -5
- data/lib/com/wiris/plugin/api/CleanCache.rb +5 -5
- data/lib/com/wiris/plugin/api/Configuration.rb +5 -5
- data/lib/com/wiris/plugin/api/ConfigurationKeys.rb +94 -91
- data/lib/com/wiris/plugin/api/Editor.rb +5 -5
- data/lib/com/wiris/plugin/api/Filter.rb +5 -5
- data/lib/com/wiris/plugin/api/ImageFormatController.rb +5 -5
- data/lib/com/wiris/plugin/api/ParamsProvider.rb +5 -5
- data/lib/com/wiris/plugin/api/PluginBuilder.rb +88 -74
- data/lib/com/wiris/plugin/api/Render.rb +5 -5
- data/lib/com/wiris/plugin/api/ServiceResourceLoader.rb +5 -5
- data/lib/com/wiris/plugin/api/Test.rb +5 -5
- data/lib/com/wiris/plugin/api/TextService.rb +5 -5
- data/lib/com/wiris/plugin/configuration/ConfigurationUpdater.rb +5 -5
- data/lib/com/wiris/plugin/impl/CacheFormulaImpl.rb +15 -0
- data/lib/com/wiris/plugin/impl/CacheImpl.rb +124 -0
- data/lib/com/wiris/plugin/impl/CasImpl.rb +140 -138
- data/lib/com/wiris/plugin/impl/CleanCacheImpl.rb +103 -101
- data/lib/com/wiris/plugin/impl/ConfigurationImpl.rb +165 -166
- data/lib/com/wiris/plugin/impl/CustomConfigurationUpdater.rb +32 -30
- data/lib/com/wiris/plugin/impl/DefaultConfigurationUpdater.rb +24 -22
- data/lib/com/wiris/plugin/impl/EditorImpl.rb +80 -78
- data/lib/com/wiris/plugin/impl/FileConfigurationUpdater.rb +29 -27
- data/lib/com/wiris/plugin/impl/FileStorageAndCache.rb +55 -53
- data/lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb +65 -134
- data/lib/com/wiris/plugin/impl/GenericParamsProviderImpl.rb +50 -48
- data/lib/com/wiris/plugin/impl/HttpImpl.rb +49 -48
- data/lib/com/wiris/plugin/impl/HttpListener.rb +5 -5
- data/lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb +71 -63
- data/lib/com/wiris/plugin/impl/ImageFormatControllerSvg.rb +37 -28
- data/lib/com/wiris/plugin/impl/PluginBuilderImpl.rb +280 -248
- data/lib/com/wiris/plugin/impl/RenderImpl.rb +303 -257
- data/lib/com/wiris/plugin/impl/ServiceResourceLoaderImpl.rb +41 -39
- data/lib/com/wiris/plugin/impl/TestImpl.rb +177 -157
- data/lib/com/wiris/plugin/impl/TextFilter.rb +210 -194
- data/lib/com/wiris/plugin/impl/TextFilterTags.rb +57 -50
- data/lib/com/wiris/plugin/impl/TextServiceImpl.rb +158 -107
- data/lib/com/wiris/plugin/storage/StorageAndCache.rb +5 -5
- data/lib/com/wiris/util/json/JSon.rb +505 -493
- data/lib/com/wiris/util/json/JSonIntegerFormat.rb +17 -16
- data/lib/com/wiris/util/json/JsonAPIResponse.rb +70 -0
- data/lib/com/wiris/util/json/StringParser.rb +57 -56
- data/lib/com/wiris/util/sys/AccessProvider.rb +8 -0
- data/lib/com/wiris/util/sys/Cache.rb +8 -0
- data/lib/com/wiris/util/sys/HttpConnection.rb +14 -13
- data/lib/com/wiris/util/sys/HttpConnectionListener.rb +5 -5
- data/lib/com/wiris/util/sys/HttpSync.rb +28 -0
- data/lib/com/wiris/util/sys/IniFile.rb +132 -131
- data/lib/com/wiris/util/sys/Lock.rb +8 -0
- data/lib/com/wiris/util/sys/LockProvider.rb +8 -0
- data/lib/com/wiris/util/sys/Store.rb +126 -101
- data/lib/com/wiris/util/sys/StoreCache.rb +63 -0
- data/lib/com/wiris/util/sys/TimerProxy.rb +21 -0
- data/lib/com/wiris/util/sys/TimerTask.rb +8 -0
- data/lib/com/wiris/util/type/Arrays.rb +275 -0
- data/lib/com/wiris/util/type/ByteBuffer.rb +69 -0
- data/lib/com/wiris/util/type/Comparator.rb +8 -0
- data/lib/com/wiris/util/type/DataUtils.rb +24 -0
- data/lib/com/wiris/util/type/DoubleTools.rb +14 -0
- data/lib/com/wiris/util/type/HashCache.rb +43 -0
- data/lib/com/wiris/util/type/IntegerTools.rb +32 -0
- data/lib/com/wiris/util/type/Queue.rb +31 -0
- data/lib/com/wiris/util/type/SortArrayByStringLength.rb +26 -0
- data/lib/com/wiris/util/type/SortStringByLength.rb +26 -0
- data/lib/com/wiris/util/type/SortedHash.rb +45 -0
- data/lib/com/wiris/util/type/Stack.rb +31 -0
- data/lib/com/wiris/util/type/StringUtils.rb +56 -0
- data/lib/com/wiris/util/type/Tokenizer.rb +40 -0
- data/lib/com/wiris/util/type/UrlUtils.rb +78 -0
- data/lib/com/wiris/util/xml/ContentHandler.rb +8 -0
- data/lib/com/wiris/util/xml/DefaultHandler.rb +25 -0
- data/lib/com/wiris/util/xml/EntityResolver.rb +8 -0
- data/lib/com/wiris/util/xml/MathMLEntityResolver.rb +19 -0
- data/lib/com/wiris/util/xml/SAXParser.rb +470 -0
- data/lib/com/wiris/util/xml/SerializableImpl.rb +16 -15
- data/lib/com/wiris/util/xml/WCharacterBase.rb +968 -627
- data/lib/com/wiris/util/xml/WEntities.rb +11 -9
- data/lib/com/wiris/util/xml/WXmlUtils.rb +660 -490
- data/lib/com/wiris/util/xml/XmlSerializer.rb +517 -471
- data/lib/com/wiris/util/xml/XmlWriter.rb +260 -262
- data/lib/loader.rb +15 -12
- data/lib/src-generic/Array.rb +22 -22
- data/lib/src-generic/ArrayInt.rb +31 -31
- data/lib/src-generic/Base64.rb +14 -14
- data/lib/src-generic/BaseCode.rb +93 -93
- data/lib/src-generic/Boolean.rb +27 -0
- data/lib/src-generic/Bytes.rb +50 -50
- data/lib/src-generic/BytesInput.rb +37 -37
- data/lib/src-generic/EReg.rb +55 -55
- data/lib/src-generic/File.rb +35 -35
- data/lib/src-generic/FileLock.rb +26 -26
- data/lib/src-generic/FileSystem.rb +37 -37
- data/lib/src-generic/Hash.rb +42 -42
- data/lib/src-generic/Http.rb +111 -107
- data/lib/src-generic/HttpRequest.rb +25 -25
- data/lib/src-generic/HttpResponse.rb +70 -70
- data/lib/src-generic/Iterator.rb +20 -19
- data/lib/src-generic/Math.rb +14 -14
- data/lib/src-generic/Md5.rb +8 -8
- data/lib/src-generic/Md5Tools.rb +11 -11
- data/lib/src-generic/PropertiesTools.rb +32 -32
- data/lib/src-generic/Reflect.rb +16 -16
- data/lib/src-generic/RubyConfigurationUpdater.rb +49 -45
- data/lib/src-generic/Serializer.rb +84 -84
- data/lib/src-generic/Std.rb +74 -74
- data/lib/src-generic/Storage.rb +152 -152
- data/lib/src-generic/StringBuf.rb +40 -40
- data/lib/src-generic/StringTools.rb +44 -46
- data/lib/src-generic/Timer.rb +6 -6
- data/lib/src-generic/Type.rb +18 -18
- data/lib/src-generic/TypeTools.rb +31 -31
- data/lib/src-generic/Unserializer.rb +72 -72
- data/lib/src-generic/Utf8.rb +26 -26
- data/lib/src-generic/Xml.rb +199 -198
- data/lib/src-generic/extended/Integer.rb +5 -5
- data/lib/src-generic/extended/Math.rb +6 -6
- data/lib/src-generic/extended/Properties.rb +11 -11
- data/lib/src-generic/extended/String.rb +38 -38
- data/lib/src-generic/settings/PlatformSettings.rb +18 -18
- data/lib/src-generic/system/HttpProxy.rb +23 -0
- data/lib/src-generic/system/HttpProxyAuth.rb +10 -0
- data/lib/wirispluginengine.rb +5 -5
- data/lib/wirispluginengine/engine.rb +5 -5
- data/lib/wirispluginengine/integration/cleancache.rb +8 -8
- data/lib/wirispluginengine/integration/configurationjs.rb +8 -15
- data/lib/wirispluginengine/integration/configurationjson.rb +6 -6
- data/lib/wirispluginengine/integration/createimage.rb +7 -7
- data/lib/wirispluginengine/integration/getmathml.rb +18 -18
- data/lib/wirispluginengine/integration/resource.rb +8 -8
- data/lib/wirispluginengine/integration/service.rb +5 -5
- data/lib/wirispluginengine/integration/showimage.rb +28 -21
- data/lib/wirispluginengine/integration/test.rb +5 -5
- data/lib/wirispluginengine/integration/testfilter.rb +10 -0
- data/lib/wirispluginengine/version.rb +2 -2
- data/resources/VERSION +1 -1
- data/resources/WEB-INF/web.xml +25 -0
- data/resources/WIRISplugins.js +3809 -0
- data/resources/default-configuration.ini +47 -45
- data/resources/tech.txt +1 -1
- data/resources/wirisplugin.css +43 -42
- metadata +40 -4
- data/configuration.ini.dist +0 -104
@@ -1,109 +1,134 @@
|
|
1
1
|
module WirisPlugin
|
2
2
|
include Wiris
|
3
|
-
require('com/wiris/common/WInteger.rb')
|
4
|
-
|
5
|
-
|
3
|
+
require('com/wiris/common/WInteger.rb')
|
4
|
+
class Store
|
5
|
+
include Wiris
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
path = FileSystem::fullPath(folder)
|
82
|
-
files = FileSystem::readDirectory(folder)
|
83
|
-
i = 0
|
84
|
-
for i in 0..files::length-1
|
85
|
-
file = files[i]
|
86
|
-
file = (path+'/'.to_s)+file
|
87
|
-
if FileSystem::isDirectory(file)
|
88
|
-
deleteDirectory(file,included)
|
89
|
-
else
|
90
|
-
includedIterator = included::iterator()
|
91
|
-
if included!=nil
|
92
|
-
while includedIterator::hasNext()
|
93
|
-
if StringTools::endsWith(file,includedIterator::next())
|
94
|
-
FileSystem::deleteFile(file)
|
95
|
-
end
|
96
|
-
end
|
7
|
+
attr_accessor :file
|
8
|
+
def initialize()
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
def self.newStore(folder)
|
12
|
+
s = Store.new()
|
13
|
+
s::file = folder
|
14
|
+
return s
|
15
|
+
end
|
16
|
+
def list()
|
17
|
+
return FileSystem::readDirectory(@file)
|
18
|
+
end
|
19
|
+
def mkdirs()
|
20
|
+
parent = getParent()
|
21
|
+
if !parent::exists() && !((parent::getFile() == self.file))
|
22
|
+
parent::mkdirs()
|
23
|
+
end
|
24
|
+
if !exists()
|
25
|
+
FileSystem::createDirectory(@file)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def write(str)
|
29
|
+
File::saveContent(@file,str)
|
30
|
+
end
|
31
|
+
def writeBinary(bs)
|
32
|
+
File::saveBytes(@file,bs)
|
33
|
+
end
|
34
|
+
def readBinary()
|
35
|
+
return File::getBytes(@file)
|
36
|
+
end
|
37
|
+
def append(str)
|
38
|
+
output = File::append(@file,true)
|
39
|
+
output::writeString(str)
|
40
|
+
output::flush()
|
41
|
+
output::close()
|
42
|
+
end
|
43
|
+
def read()
|
44
|
+
return File::getContent(@file)
|
45
|
+
end
|
46
|
+
def self.newStoreWithParent(store, str)
|
47
|
+
return Store.newStore((store::getFile() + "/") + str)
|
48
|
+
end
|
49
|
+
def getFile()
|
50
|
+
return @file
|
51
|
+
end
|
52
|
+
def exists()
|
53
|
+
return FileSystem::exists(@file)
|
54
|
+
end
|
55
|
+
def self.getCurrentPath()
|
56
|
+
return FileSystem::fullPath(".")
|
57
|
+
end
|
58
|
+
def getParent()
|
59
|
+
parent = FileSystem::fullPath(@file)
|
60
|
+
if parent == nil
|
61
|
+
parent = @file
|
62
|
+
end
|
63
|
+
i = WInteger::max(parent::lastIndexOf("/"),parent::lastIndexOf("\\"))
|
64
|
+
if i < 0
|
65
|
+
return Store.newStore(".")
|
66
|
+
end
|
67
|
+
parent = Std::substr(parent,0,i)
|
68
|
+
return Store.newStore(parent)
|
69
|
+
end
|
70
|
+
def copyTo(dest)
|
71
|
+
b = readBinary()
|
72
|
+
dest::writeBinary(b)
|
73
|
+
end
|
74
|
+
def moveTo(dest)
|
75
|
+
FileSystem::rename(self.file,dest::getFile())
|
76
|
+
end
|
77
|
+
def delete()
|
78
|
+
if FileSystem::isDirectory(self.file)
|
79
|
+
FileSystem::deleteDirectory(self.file)
|
97
80
|
else
|
98
|
-
|
81
|
+
FileSystem::deleteFile(self.file)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
def deleteFolderContents()
|
85
|
+
if self.exists() && FileSystem::isDirectory(self.getFile())
|
86
|
+
files = self.list()
|
87
|
+
for i in 0..files::length - 1
|
88
|
+
if !((files[i] == ".") || (files[i] == ".."))
|
89
|
+
f = Store::newStoreWithParent(self,files[i])
|
90
|
+
if FileSystem::isDirectory(f::getFile())
|
91
|
+
f::deleteFolderContents()
|
92
|
+
FileSystem::deleteDirectory(f::getFile())
|
93
|
+
else
|
94
|
+
FileSystem::deleteFile(f::getFile())
|
95
|
+
end
|
96
|
+
end
|
97
|
+
i+=1
|
98
|
+
end
|
99
99
|
end
|
100
|
-
end
|
101
|
-
i+=1
|
102
100
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
101
|
+
def self.deleteDirectory(folder, included)
|
102
|
+
if (folder == nil) || !FileSystem::exists(folder)
|
103
|
+
return
|
104
|
+
end
|
105
|
+
path = FileSystem::fullPath(folder)
|
106
|
+
files = FileSystem::readDirectory(folder)
|
107
|
+
i = 0
|
108
|
+
for i in 0..files::length - 1
|
109
|
+
file = files[i]
|
110
|
+
file = (path + '/'.to_s) + file
|
111
|
+
if FileSystem::isDirectory(file)
|
112
|
+
Store.deleteDirectory(file,included)
|
113
|
+
else
|
114
|
+
includedIterator = included::iterator()
|
115
|
+
if included != nil
|
116
|
+
while includedIterator::hasNext()
|
117
|
+
if StringTools::endsWith(file,includedIterator::next())
|
118
|
+
FileSystem::deleteFile(file)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
else
|
122
|
+
FileSystem::deleteFile(file)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
i+=1
|
126
|
+
end
|
127
|
+
files = FileSystem::readDirectory(folder)
|
128
|
+
if files::length == 0
|
129
|
+
FileSystem::deleteDirectory(folder)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
107
133
|
end
|
108
|
-
end
|
109
134
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
require('com/wiris/util/sys/Cache.rb')
|
4
|
+
require('com/wiris/util/sys/Cache.rb')
|
5
|
+
class StoreCache
|
6
|
+
extend CacheInterface
|
7
|
+
|
8
|
+
include Wiris
|
9
|
+
|
10
|
+
attr_accessor :cachedir
|
11
|
+
def initialize(cachedir)
|
12
|
+
super()
|
13
|
+
self.cachedir = Storage::newStorage(cachedir)
|
14
|
+
if !self.cachedir::exists()
|
15
|
+
self.cachedir::mkdirs()
|
16
|
+
end
|
17
|
+
if !(self.cachedir::exists())
|
18
|
+
raise Exception,("Variable folder \"" + self.cachedir::toString().to_s) + "\" does not exist and can\'t be automatically created. Please create it with write permissions."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def set(key, value)
|
22
|
+
s = self.getItemStore(key)
|
23
|
+
begin
|
24
|
+
s::writeBinary(value::getData())
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def get(key)
|
28
|
+
s = self.getItemStore(key)
|
29
|
+
if s::exists()
|
30
|
+
begin
|
31
|
+
return Bytes::ofData(s::readBinary())
|
32
|
+
end
|
33
|
+
else
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def deleteAll()
|
38
|
+
self.deleteStorageDir(self.cachedir)
|
39
|
+
end
|
40
|
+
def deleteStorageDir(s)
|
41
|
+
if s::exists() && s::isDirectory()
|
42
|
+
files = s::list()
|
43
|
+
for i in 0..files::length - 1
|
44
|
+
if !((files[i] == ".") || (files[i] == ".."))
|
45
|
+
f = Storage::newStorageWithParent(s,files[i])
|
46
|
+
if f::isDirectory()
|
47
|
+
deleteStorageDir(f)
|
48
|
+
end
|
49
|
+
f::delete()
|
50
|
+
end
|
51
|
+
i+=1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def delete(key)
|
56
|
+
self.getItemStore(key)::delete()
|
57
|
+
end
|
58
|
+
def getItemStore(key)
|
59
|
+
return Storage::newStorageWithParent(self.cachedir,key)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
class TimerProxy < Timer
|
4
|
+
include Wiris
|
5
|
+
|
6
|
+
attr_accessor :timerTask
|
7
|
+
attr_accessor :isTimeout
|
8
|
+
def initialize(ms, runOnce, task)
|
9
|
+
super(ms)
|
10
|
+
@isTimeout = runOnce
|
11
|
+
@timerTask = task
|
12
|
+
end
|
13
|
+
def run()
|
14
|
+
if @isTimeout
|
15
|
+
stop()
|
16
|
+
end
|
17
|
+
@timerTask::run(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
module WirisPlugin
|
2
|
+
include Wiris
|
3
|
+
class Arrays
|
4
|
+
include Wiris
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
super()
|
8
|
+
end
|
9
|
+
def self.newIntArray(length, initValue)
|
10
|
+
data = []
|
11
|
+
length-=1
|
12
|
+
while length >= 0
|
13
|
+
data[length] = initValue
|
14
|
+
length-=1
|
15
|
+
end
|
16
|
+
return data
|
17
|
+
end
|
18
|
+
def self.isNotEmpty(array)
|
19
|
+
return (array != nil) && (array::length > 0)
|
20
|
+
end
|
21
|
+
def self.getOrDefault(array, index, defaultValue)
|
22
|
+
if ((array != nil) && (index >= 0)) && (index < array::length)
|
23
|
+
return array[index]
|
24
|
+
else
|
25
|
+
return defaultValue
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def self.indexOfElement(array, element)
|
29
|
+
i = 0
|
30
|
+
n = array::length()
|
31
|
+
while i < n
|
32
|
+
if (array::_(i) != nil) && ((array::_(i) == element))
|
33
|
+
return i
|
34
|
+
end
|
35
|
+
i+=1
|
36
|
+
end
|
37
|
+
return -1
|
38
|
+
end
|
39
|
+
def self.fromIterator(iterator)
|
40
|
+
array = Array.new()
|
41
|
+
while iterator::hasNext()
|
42
|
+
array::push(iterator::next())
|
43
|
+
end
|
44
|
+
return array
|
45
|
+
end
|
46
|
+
def self.fromCSV(s)
|
47
|
+
words = Std::split(s,",")
|
48
|
+
i = 0
|
49
|
+
while i < words::length()
|
50
|
+
w = words::_(i)::trim()
|
51
|
+
if w::length() > 0
|
52
|
+
words::_(i,w)
|
53
|
+
i+=1
|
54
|
+
else
|
55
|
+
words::splice(i,1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return words
|
59
|
+
end
|
60
|
+
def self.toIntArray(array)
|
61
|
+
result = ArrayInt.new()
|
62
|
+
it = array::iterator()
|
63
|
+
while it::hasNext()
|
64
|
+
value = Std::parseInt(it::next())
|
65
|
+
result::push(value)
|
66
|
+
end
|
67
|
+
return result
|
68
|
+
end
|
69
|
+
def self.contains(array, element)
|
70
|
+
return Arrays.indexOfElement(array,element) >= 0
|
71
|
+
end
|
72
|
+
def self.indexOfElementArray(array, element)
|
73
|
+
for i in 0..array::length - 1
|
74
|
+
if (array[i] != nil) && (array[i] == element)
|
75
|
+
return i
|
76
|
+
end
|
77
|
+
i+=1
|
78
|
+
end
|
79
|
+
return -1
|
80
|
+
end
|
81
|
+
def self.indexOfElementInt(array, element)
|
82
|
+
for i in 0..array::length - 1
|
83
|
+
if array[i] == element
|
84
|
+
return i
|
85
|
+
end
|
86
|
+
i+=1
|
87
|
+
end
|
88
|
+
return -1
|
89
|
+
end
|
90
|
+
def self.containsArray(array, element)
|
91
|
+
return Arrays.indexOfElementArray(array,element) >= 0
|
92
|
+
end
|
93
|
+
def self.containsInt(array, element)
|
94
|
+
return Arrays.indexOfElementInt(array,element) >= 0
|
95
|
+
end
|
96
|
+
def self.clear(a)
|
97
|
+
i = a::length() - 1
|
98
|
+
while i >= 0
|
99
|
+
a::remove(a::_(i))
|
100
|
+
i-=1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
def self.sort(elements, comparator)
|
104
|
+
Arrays::quicksort(elements,0,elements::length() - 1,comparator)
|
105
|
+
end
|
106
|
+
def self.insertSorted(a, e)
|
107
|
+
Arrays.insertSortedImpl(a,e,false)
|
108
|
+
end
|
109
|
+
def self.insertSortedSet(a, e)
|
110
|
+
Arrays.insertSortedImpl(a,e,true)
|
111
|
+
end
|
112
|
+
def self.insertSortedImpl(a, e, set)
|
113
|
+
imin = 0
|
114
|
+
imax = a::length()
|
115
|
+
while imin < imax
|
116
|
+
imid = ((imax + imin)/2)
|
117
|
+
cmp = Reflect::compare(a::_(imid),e)
|
118
|
+
if cmp == 0
|
119
|
+
if set
|
120
|
+
return
|
121
|
+
else
|
122
|
+
imin = imid
|
123
|
+
imax = imid
|
124
|
+
end
|
125
|
+
else
|
126
|
+
if cmp < 0
|
127
|
+
imin = imid + 1
|
128
|
+
else
|
129
|
+
imax = imid
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
a::insert(imin,e)
|
134
|
+
end
|
135
|
+
def self.binarySearch(array, key)
|
136
|
+
imin = 0
|
137
|
+
imax = array::length()
|
138
|
+
while imin < imax
|
139
|
+
imid = ((imin + imax)/2)
|
140
|
+
cmp = Reflect::compare(array::_(imid),key)
|
141
|
+
if cmp == 0
|
142
|
+
return imid
|
143
|
+
else
|
144
|
+
if cmp < 0
|
145
|
+
imin = imid + 1
|
146
|
+
else
|
147
|
+
imax = imid
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
return -1
|
152
|
+
end
|
153
|
+
def self.copyArray(a)
|
154
|
+
b = Array.new()
|
155
|
+
i = a::iterator()
|
156
|
+
while i::hasNext()
|
157
|
+
b::push(i::next())
|
158
|
+
end
|
159
|
+
return b
|
160
|
+
end
|
161
|
+
def self.addAll(baseArray, additionArray)
|
162
|
+
i = additionArray::iterator()
|
163
|
+
while i::hasNext()
|
164
|
+
baseArray::push(i::next())
|
165
|
+
end
|
166
|
+
end
|
167
|
+
def self.quicksort(elements, lower, higher, comparator)
|
168
|
+
if lower < higher
|
169
|
+
p = Arrays::partition(elements,lower,higher,comparator)
|
170
|
+
Arrays::quicksort(elements,lower,p - 1,comparator)
|
171
|
+
Arrays::quicksort(elements,p + 1,higher,comparator)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
def self.partition(elements, lower, higher, comparator)
|
175
|
+
pivot = elements::_(higher)
|
176
|
+
i = lower - 1
|
177
|
+
j = lower
|
178
|
+
while j < higher
|
179
|
+
if comparator::compare(pivot,elements::_(j)) > 0
|
180
|
+
i+=1
|
181
|
+
if i != j
|
182
|
+
swapper = elements::_(i)
|
183
|
+
elements::_(i,elements::_(j))
|
184
|
+
elements::_(j,swapper)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
j+=1
|
188
|
+
end
|
189
|
+
if comparator::compare(elements::_(i + 1),elements::_(higher)) > 0
|
190
|
+
finalSwap = elements::_(i + 1)
|
191
|
+
elements::_(i + 1,elements::_(higher))
|
192
|
+
elements::_(higher,finalSwap)
|
193
|
+
end
|
194
|
+
return i + 1
|
195
|
+
end
|
196
|
+
def self.firstElement(elements)
|
197
|
+
return elements::_(0)
|
198
|
+
end
|
199
|
+
def self.lastElement(elements)
|
200
|
+
return elements::_(elements::length() - 1)
|
201
|
+
end
|
202
|
+
def self.intersectSorted(a, b)
|
203
|
+
if a == nil
|
204
|
+
return b == nil ? nil : Arrays.copyArray(b)
|
205
|
+
else
|
206
|
+
if b == nil
|
207
|
+
return Arrays.copyArray(a)
|
208
|
+
else
|
209
|
+
v = Array.new()
|
210
|
+
i = 0
|
211
|
+
j = 0
|
212
|
+
while (i < a::length()) && (j < b::length())
|
213
|
+
cmp = Reflect::compare(a::_(i),b::_(j))
|
214
|
+
if cmp == 0
|
215
|
+
v::push(a::_(i))
|
216
|
+
i+=1
|
217
|
+
j+=1
|
218
|
+
else
|
219
|
+
if cmp < 0
|
220
|
+
i+=1
|
221
|
+
else
|
222
|
+
j+=1
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
return v
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
def self.difference(a, b)
|
231
|
+
v = Array.new()
|
232
|
+
if a == nil
|
233
|
+
return v
|
234
|
+
else
|
235
|
+
if b == nil
|
236
|
+
return Arrays.copyArray(a)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
it = a::iterator()
|
240
|
+
while it::hasNext()
|
241
|
+
e = it::next()
|
242
|
+
if Arrays.indexOfElement(b,e) < 0
|
243
|
+
v::push(e)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
return v
|
247
|
+
end
|
248
|
+
def self.arrayUnion(baseArray, unionArray)
|
249
|
+
it = unionArray::iterator()
|
250
|
+
while it::hasNext()
|
251
|
+
n = it::next()
|
252
|
+
if !baseArray::contains_(n)
|
253
|
+
baseArray::push(n)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
def self.equalAsSets(a, b)
|
258
|
+
if (a == nil) || (b == nil)
|
259
|
+
return a == b
|
260
|
+
end
|
261
|
+
if a::length() == b::length()
|
262
|
+
it = b::iterator()
|
263
|
+
while it::hasNext()
|
264
|
+
t = it::next()
|
265
|
+
if !a::contains_(t)
|
266
|
+
return false
|
267
|
+
end
|
268
|
+
end
|
269
|
+
return true
|
270
|
+
end
|
271
|
+
return false
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
end
|