jruby-scala-collections 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,8 +14,7 @@ With bundler:
14
14
  ```gem "jruby-scala-collections", ">=0.1.1", require: "jruby/scala_support"```
15
15
 
16
16
  Beware that you have to have ```scala-library.jar``` loaded before you
17
- load ```jruby/scala_support```. In Rails this generally means it loading in
18
- ```config/boot.rb```.
17
+ load ```jruby/scala_support```. In Rails this generally means it loading in ```config/boot.rb```.
19
18
 
20
19
  ## How do you use it?
21
20
 
@@ -64,5 +63,17 @@ methods:
64
63
  ## Disclaimer
65
64
 
66
65
  This library was written by Artūras 'arturaz' Šlajus for personal
67
- usage. ```#to_scala``` should work pretty well, however Ruby wrappers
66
+ usage.
67
+
68
+ ## Contributing
69
+ ```#to_scala``` should work pretty well, however Ruby wrappers
68
70
  in ```#from_scala``` may be missing methods. Patches are welcome.
71
+ jruby-scala-collections uses rubyspec and mspec to test that the behaviour
72
+ of the Ruby wrappers is correct.
73
+ Currently only a part of those tests pass. You can contribute by grabbing
74
+ any of the tests marked as `fails` in `rubyspec/tags/**/*_tags.txt`, marking it as
75
+ `focus` and implement the needed behaviour.
76
+ Guard is configured so that `bundle exec guard` runs all tests that have the focus tag.
77
+ If you want to run all tests that should be working, use `bundle exec mspec -G fails rubyspec`.
78
+ If you have implemented functionality, run `bundle exec mspec tag rubyspec` to update the list
79
+ of failing tests and check with a `git diff` that you haven't broken other functionality.
Binary file
@@ -69,13 +69,32 @@ module JRuby::ScalaSupport
69
69
  end
70
70
 
71
71
  def keys
72
- @raw.keys.toSeq.from_scala
72
+ @raw.keys.toSeq.from_scala.to_a
73
73
  end
74
74
 
75
+ def values
76
+ @raw.values.toSeq.from_scala.to_a
77
+ end
78
+
79
+ def value?(v)
80
+ values.include?(v)
81
+ end
82
+
83
+ alias_method :has_value?, :value?
84
+
75
85
  def has_key?(key)
76
86
  @raw.contains(key)
77
87
  end
78
88
 
89
+ alias_method :key?, :has_key?
90
+ alias_method :member?, :has_key?
91
+ alias_method :include?, :has_key?
92
+
93
+ def key(val)
94
+ kv = find {|_,v| v == val }
95
+ kv && kv.first
96
+ end
97
+
79
98
  def each
80
99
  if block_given?
81
100
  @raw.foreach do |tuple|
@@ -93,19 +112,57 @@ module JRuby::ScalaSupport
93
112
  end
94
113
  end
95
114
 
115
+ alias_method :each_pair, :each
116
+
96
117
  def to_s
97
118
  first = true
98
119
  each_with_object("{") do |(key, value), str|
99
120
  first ? first = false : str << ", "
100
- str << "#{key}=>#{value}"
121
+ str << "#{key.inspect}=>#{value.inspect}"
101
122
  end << "}"
102
123
  end
103
124
 
125
+ alias_method :inspect, :to_s
126
+
104
127
  def as_json(options=nil)
105
128
  each_with_object({}) do |(key, value), hash|
106
129
  hash[key.as_json(options)] = value.as_json(options)
107
130
  end
108
131
  end
132
+
133
+ def eql?(other)
134
+ return true if self.equal? other
135
+
136
+ unless other.kind_of? Hash
137
+ return false unless other.respond_to? :to_hash
138
+ return other.eql?(self)
139
+ end
140
+
141
+ return false unless other.size == size
142
+
143
+ other.each do |k,v|
144
+
145
+ return false unless (entry = real_map.send(:findEntry,k)) && (entry.key.from_scala.eql?(k)) && (item = entry.value)
146
+
147
+ # Order of the comparison matters! We must compare our value with
148
+ # the other Hash's value and not the other way around.
149
+ return false unless item.eql?(v)
150
+ end
151
+
152
+ true
153
+ end
154
+
155
+ alias_method :==, :eql?
156
+
157
+ alias_method :length, :size
158
+
159
+ private
160
+ def real_map
161
+ case @raw
162
+ when scala.collection.Map::WithDefault then @raw.send(:underlying)
163
+ else @raw
164
+ end
165
+ end
109
166
  end
110
167
 
111
168
  class Immutable
@@ -122,6 +179,49 @@ module JRuby::ScalaSupport
122
179
  include Common
123
180
  JRuby::ScalaSupport::Common.fake_identity self, Hash
124
181
 
182
+ class << self
183
+ alias_method :previous_new, :new
184
+
185
+ def [](*args)
186
+ hash = new
187
+ if args.size == 1
188
+ obj = args.first
189
+ case obj
190
+ when Array, Hash then obj.each {|k,v| hash[k] = v}
191
+ else
192
+ raise "Don't yet know what to do with a #{obj.inspect}"
193
+ end
194
+ return hash
195
+ end
196
+
197
+ return new if args.empty?
198
+
199
+ if args.size & 1 == 1
200
+ raise ArgumentError, "Expected an even number, got #{args.length}"
201
+ end
202
+
203
+ i = 0
204
+ total = args.size
205
+
206
+ while i < total
207
+ hash[args[i]] = args[i+1]
208
+ i += 2
209
+ end
210
+
211
+ hash
212
+ end
213
+
214
+ def new(default_value=nil, &default_block)
215
+ raise ArgumentError, "You can only provide either a default value or a block" if default_value && default_block
216
+ h = scala.collection.mutable.HashMap.new
217
+ if default_block
218
+ h = h.with_default {|k| default_block.call(h,k) }
219
+ end
220
+ h = h.with_default_value(default_value) if default_value
221
+ previous_new(h)
222
+ end
223
+ end
224
+
125
225
  def []=(key, value)
126
226
  @raw.update(key, value.to_scala)
127
227
  end
@@ -365,6 +465,8 @@ class Object
365
465
  JRuby::ScalaSupport::Set::Mutable.new(self)
366
466
  when Java::scala.collection.Set, Java::scala.collection.immutable.Set,
367
467
  JRuby::ScalaSupport::Set::Immutable.new(self)
468
+ when Java::scala.Symbol
469
+ self.name.to_sym
368
470
  else
369
471
  self
370
472
  end
metadata CHANGED
@@ -1,18 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-scala-collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Artūras Šlajus
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-24 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Interoperability layer for passing JRuby & Scala collections back and
15
- forth. See README.md for more info.
12
+ date: 2013-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: mspec
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ none: false
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec-jruby
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ none: false
76
+ prerelease: false
77
+ type: :development
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-bundler
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ none: false
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ none: false
92
+ prerelease: false
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-shell
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ none: false
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ none: false
108
+ prerelease: false
109
+ type: :development
110
+ description: Interoperability layer for passing JRuby & Scala collections back and forth. See README.md for more info.
16
111
  email: arturas.slajus@gmail.com
17
112
  executables: []
18
113
  extensions: []
@@ -23,26 +118,26 @@ files:
23
118
  - ext/dist/collections.jar
24
119
  homepage: http://github.com/arturaz/jruby-scala-collections
25
120
  licenses: []
26
- post_install_message:
121
+ post_install_message:
27
122
  rdoc_options: []
28
123
  require_paths:
29
124
  - lib
30
125
  required_ruby_version: !ruby/object:Gem::Requirement
31
- none: false
32
126
  requirements:
33
- - - ! '>='
127
+ - - '>='
34
128
  - !ruby/object:Gem::Version
35
129
  version: '0'
36
- required_rubygems_version: !ruby/object:Gem::Requirement
37
130
  none: false
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
132
  requirements:
39
- - - ! '>='
133
+ - - '>='
40
134
  - !ruby/object:Gem::Version
41
135
  version: '0'
136
+ none: false
42
137
  requirements: []
43
- rubyforge_project:
44
- rubygems_version: 1.8.21
45
- signing_key:
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.24
140
+ signing_key:
46
141
  specification_version: 3
47
- summary: Compiled against JRuby 1.6.7/Scala 2.9.2
142
+ summary: Compiled against JRuby 1.6.7/Scala 2.10.2
48
143
  test_files: []