jactive_support 1.0.2
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.
- data/.gitignore +4 -0
- data/.rvmrc +63 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +45 -0
- data/jactive_support.gemspec +24 -0
- data/lib/jactive_support.rb +6 -0
- data/lib/jactive_support/constantize.rb +19 -0
- data/lib/jactive_support/core_ext.rb +4 -0
- data/lib/jactive_support/core_ext/enum.rb +43 -0
- data/lib/jactive_support/core_ext/hash.rb +2 -0
- data/lib/jactive_support/core_ext/hash/assert_valid_params.rb +19 -0
- data/lib/jactive_support/core_ext/hash/with_keys_values.rb +9 -0
- data/lib/jactive_support/core_ext/locale.rb +28 -0
- data/lib/jactive_support/core_ext/module.rb +9 -0
- data/lib/jactive_support/core_ext/numeric.rb +7 -0
- data/lib/jactive_support/core_ext/ordering.rb +17 -0
- data/lib/jactive_support/core_ext/to_java.rb +9 -0
- data/lib/jactive_support/core_ext/to_java_date.rb +25 -0
- data/lib/jactive_support/core_ext/to_java_list.rb +11 -0
- data/lib/jactive_support/core_ext/to_java_map.rb +11 -0
- data/lib/jactive_support/java_ext.rb +4 -0
- data/lib/jactive_support/java_ext/date.rb +37 -0
- data/lib/jactive_support/java_ext/date/calculations.rb +43 -0
- data/lib/jactive_support/java_ext/date/conversions.rb +135 -0
- data/lib/jactive_support/java_ext/enum.rb +19 -0
- data/lib/jactive_support/java_ext/iterable.rb +74 -0
- data/lib/jactive_support/java_ext/iterator.rb +8 -0
- data/lib/jactive_support/java_ext/list.rb +65 -0
- data/lib/jactive_support/java_ext/list_iterator.rb +8 -0
- data/lib/jactive_support/java_ext/locale.rb +32 -0
- data/lib/jactive_support/java_ext/map.rb +6 -0
- data/lib/jactive_support/java_ext/map/constructor.rb +35 -0
- data/lib/jactive_support/java_ext/map/hash.rb +166 -0
- data/lib/jactive_support/java_ext/number.rb +91 -0
- data/lib/jactive_support/java_ext/sql_date.rb +7 -0
- data/lib/jactive_support/java_ext/sql_date/conversions.rb +33 -0
- data/lib/jactive_support/json.rb +1 -0
- data/lib/jactive_support/json/encoders/collection.rb +12 -0
- data/lib/jactive_support/json/encoders/locale.rb +6 -0
- data/lib/jactive_support/json/encoders/map.rb +55 -0
- data/lib/jactive_support/json/encoding.rb +5 -0
- data/lib/jactive_support/rescuable.rb +62 -0
- data/lib/jactive_support/version.rb +3 -0
- data/spec/constantize_spec.rb +57 -0
- data/spec/core_ext/hash_spec.rb +34 -0
- data/spec/core_ext/module_spec.rb +19 -0
- data/spec/core_ext/ordering_spec.rb +12 -0
- data/spec/enum_spec.rb +67 -0
- data/spec/java_ext/iterable/clear_spec.rb +56 -0
- data/spec/java_ext/iterable/delete_if_spec.rb +71 -0
- data/spec/java_ext/iterable/empty_spec.rb +10 -0
- data/spec/java_ext/iterable/reject_spec.rb +76 -0
- data/spec/java_ext/iterable/shared/enumeratorize.rb +12 -0
- data/spec/java_ext/iterable/shared/fixtures.rb +90 -0
- data/spec/java_ext/iterable/shift_spec.rb +160 -0
- data/spec/java_ext/list/clear_spec.rb +56 -0
- data/spec/java_ext/list/collect_spec.rb +11 -0
- data/spec/java_ext/list/last_spec.rb +87 -0
- data/spec/java_ext/list/map_spec.rb +11 -0
- data/spec/java_ext/list/push_spec.rb +44 -0
- data/spec/java_ext/list/shared/collect.rb +133 -0
- data/spec/java_ext/list/shared/fixtures.rb +34 -0
- data/spec/java_ext/map/assoc_spec.rb +43 -0
- data/spec/java_ext/map/clear_spec.rb +49 -0
- data/spec/java_ext/map/clone_spec.rb +13 -0
- data/spec/java_ext/map/compare_by_identity_spec.rb +111 -0
- data/spec/java_ext/map/constructor_spec.rb +54 -0
- data/spec/java_ext/map/delete_if_spec.rb +54 -0
- data/spec/java_ext/map/delete_spec.rb +38 -0
- data/spec/java_ext/map/each_key_spec.rb +29 -0
- data/spec/java_ext/map/each_pair_spec.rb +38 -0
- data/spec/java_ext/map/each_spec.rb +9 -0
- data/spec/java_ext/map/each_value_spec.rb +28 -0
- data/spec/java_ext/map/element_reference_spec.rb +119 -0
- data/spec/java_ext/map/element_set_spec.rb +7 -0
- data/spec/java_ext/map/empty_spec.rb +15 -0
- data/spec/java_ext/map/eql_spec.rb +19 -0
- data/spec/java_ext/map/equal_value_spec.rb +18 -0
- data/spec/java_ext/map/fetch_spec.rb +35 -0
- data/spec/java_ext/map/fixtures/classes.rb +36 -0
- data/spec/java_ext/map/flatten_spec.rb +64 -0
- data/spec/java_ext/map/has_key_spec.rb +8 -0
- data/spec/java_ext/map/has_value_spec.rb +8 -0
- data/spec/java_ext/map/hash_spec.rb +53 -0
- data/spec/java_ext/map/include_spec.rb +7 -0
- data/spec/java_ext/map/index_spec.rb +7 -0
- data/spec/java_ext/map/indexes_spec.rb +9 -0
- data/spec/java_ext/map/indices_spec.rb +9 -0
- data/spec/java_ext/map/initialize_copy_spec.rb +13 -0
- data/spec/java_ext/map/initialize_spec.rb +64 -0
- data/spec/java_ext/map/inspect_spec.rb +9 -0
- data/spec/java_ext/map/invert_spec.rb +27 -0
- data/spec/java_ext/map/keep_if_spec.rb +33 -0
- data/spec/java_ext/map/key_spec.rb +14 -0
- data/spec/java_ext/map/keys_spec.rb +39 -0
- data/spec/java_ext/map/length_spec.rb +7 -0
- data/spec/java_ext/map/member_spec.rb +7 -0
- data/spec/java_ext/map/merge_spec.rb +69 -0
- data/spec/java_ext/map/rassoc_spec.rb +39 -0
- data/spec/java_ext/map/reject_spec.rb +123 -0
- data/spec/java_ext/map/replace_spec.rb +7 -0
- data/spec/java_ext/map/select_spec.rb +98 -0
- data/spec/java_ext/map/shared/each.rb +77 -0
- data/spec/java_ext/map/shared/eql.rb +224 -0
- data/spec/java_ext/map/shared/equal.rb +94 -0
- data/spec/java_ext/map/shared/index.rb +29 -0
- data/spec/java_ext/map/shared/iteration.rb +28 -0
- data/spec/java_ext/map/shared/key.rb +43 -0
- data/spec/java_ext/map/shared/length.rb +12 -0
- data/spec/java_ext/map/shared/replace.rb +82 -0
- data/spec/java_ext/map/shared/store.rb +68 -0
- data/spec/java_ext/map/shared/to_s.rb +68 -0
- data/spec/java_ext/map/shared/update.rb +95 -0
- data/spec/java_ext/map/shared/value.rb +16 -0
- data/spec/java_ext/map/shared/values_at.rb +12 -0
- data/spec/java_ext/map/shift_spec.rb +44 -0
- data/spec/java_ext/map/size_spec.rb +7 -0
- data/spec/java_ext/map/sort_spec.rb +17 -0
- data/spec/java_ext/map/store_spec.rb +7 -0
- data/spec/java_ext/map/to_a_spec.rb +29 -0
- data/spec/java_ext/map/to_hash_spec.rb +11 -0
- data/spec/java_ext/map/to_s_spec.rb +20 -0
- data/spec/java_ext/map/try_convert_spec.rb +32 -0
- data/spec/java_ext/map/update_spec.rb +7 -0
- data/spec/java_ext/map/value_spec.rb +8 -0
- data/spec/java_ext/map/values_at_spec.rb +7 -0
- data/spec/java_ext/map/values_spec.rb +10 -0
- data/spec/locale_spec.rb +77 -0
- data/spec/shared/fixtures.rb +7 -0
- data/spec/shared/version.rb +123 -0
- data/spec/spec_helper.rb +50 -0
- metadata +332 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use jruby" > .rvmrc
|
9
|
+
environment_id="jruby-1.6.7@jactive_support"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# Uncomment following line if you want options to be set only for given project.
|
19
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
20
|
+
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
|
21
|
+
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
|
22
|
+
|
23
|
+
# First we attempt to load the desired environment directly from the environment
|
24
|
+
# file. This is very fast and efficient compared to running through the entire
|
25
|
+
# CLI and selector. If you want feedback on which environment was used then
|
26
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
27
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
28
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
29
|
+
then
|
30
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
31
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
32
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
33
|
+
else
|
34
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
35
|
+
rvm --create "$environment_id" || {
|
36
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
37
|
+
return 1
|
38
|
+
}
|
39
|
+
fi
|
40
|
+
|
41
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
42
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
43
|
+
# necessary.
|
44
|
+
#
|
45
|
+
# filename=".gems"
|
46
|
+
# if [[ -s "$filename" ]]
|
47
|
+
# then
|
48
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
49
|
+
# fi
|
50
|
+
|
51
|
+
# If you use bundler, this might be useful to you:
|
52
|
+
# if [[ -s Gemfile ]] && {
|
53
|
+
# ! builtin command -v bundle >/dev/null ||
|
54
|
+
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
|
55
|
+
# }
|
56
|
+
# then
|
57
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
58
|
+
# gem install bundler
|
59
|
+
# fi
|
60
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
61
|
+
# then
|
62
|
+
# bundle install | grep -vE '^Using|Your bundle is complete'
|
63
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Brian Olsen <brian@maven-group.org>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
def install_tasks(opts = nil)
|
5
|
+
dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
|
6
|
+
h = Bundler::GemHelper.new(dir, opts && opts[:name])
|
7
|
+
h.install
|
8
|
+
h
|
9
|
+
end
|
10
|
+
helper = install_tasks
|
11
|
+
spec = helper.gemspec
|
12
|
+
|
13
|
+
require 'rake/clean'
|
14
|
+
CLEAN.include 'pkg'
|
15
|
+
|
16
|
+
task :git_local_check do
|
17
|
+
sh "git diff --no-ext-diff --ignore-submodules --quiet --exit-code" do |ok, _|
|
18
|
+
raise "working directory is unclean" if !ok
|
19
|
+
sh "git diff-index --cached --quiet --ignore-submodules HEAD --" do |ok, _|
|
20
|
+
raise "git index is unclean" if !ok
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
task :release => :git_local_check
|
25
|
+
task :build => :git_local_check
|
26
|
+
|
27
|
+
class MyRSpec < RSpec::Core::RakeTask
|
28
|
+
def task(*args,&block)
|
29
|
+
super(*args) do
|
30
|
+
old, ENV['RUBYOPT'] = ENV['RUBYOPT'], "#{ENV['RUBYOPT']} #{ruby_opts}"
|
31
|
+
yield
|
32
|
+
ENV['RUBYOPT'] = old
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
MyRSpec.new("spec:1.8") do |t|
|
38
|
+
t.ruby_opts = '--1.8'
|
39
|
+
end
|
40
|
+
MyRSpec.new("spec:1.9") do |t|
|
41
|
+
t.ruby_opts = '--1.9'
|
42
|
+
end
|
43
|
+
task :spec => ["spec:1.8", "spec:1.9"]
|
44
|
+
task :test => :spec
|
45
|
+
task :default => :spec
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jactive_support/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jactive_support"
|
7
|
+
s.version = JActiveSupport::VERSION
|
8
|
+
s.author = "Brian Olsen"
|
9
|
+
s.email = "brian@maven-group.org"
|
10
|
+
s.homepage = "http://github.com/griff/jactive_support"
|
11
|
+
s.summary = "Extensions to add some activesupport flavor to java classes"
|
12
|
+
s.description = %q{Extensions to add some activesupport flavor to java classes}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency 'activesupport', "~> 2.3.8"
|
20
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
s.add_development_dependency "rspec", "~> 2.6.0"
|
22
|
+
s.add_development_dependency "rake", ">= 0.9.2"
|
23
|
+
s.add_development_dependency "jruby-openssl", ">= 0"
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Inflector
|
5
|
+
def constantize_with_jruby(camel_cased_word)
|
6
|
+
names = camel_cased_word.split('::')
|
7
|
+
names.shift if names.empty? || names.first.empty?
|
8
|
+
|
9
|
+
if names.first == "Java" && names.size == 3
|
10
|
+
last = names.pop
|
11
|
+
constantize_without_jruby(names.join('::')).__send__ last
|
12
|
+
else
|
13
|
+
constantize_without_jruby(camel_cased_word)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
alias :constantize_without_jruby :constantize
|
17
|
+
alias :constantize :constantize_with_jruby
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'jactive_support/java_ext/enum'
|
2
|
+
|
3
|
+
module JactiveSupport #:nodoc:
|
4
|
+
module CoreExtensions #:nodoc:
|
5
|
+
module Enum
|
6
|
+
def self.included(other_mod)
|
7
|
+
other_mod.send :alias_method, :flash_without_enum, :===
|
8
|
+
other_mod.send :alias_method, :===, :flash_with_enum
|
9
|
+
|
10
|
+
other_mod.send :alias_method, :to_java_without_enum, :to_java
|
11
|
+
other_mod.send :alias_method, :to_java, :to_java_with_enum
|
12
|
+
end
|
13
|
+
|
14
|
+
def flash_with_enum(other)
|
15
|
+
if other.java_kind_of? java::lang::Enum
|
16
|
+
other.name == self.to_s || other.name == self.to_s.camelize
|
17
|
+
else
|
18
|
+
flash_without_enum(other)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_java_with_enum(other=nil)
|
23
|
+
if other.superclass == java::lang::Enum
|
24
|
+
begin
|
25
|
+
other.find_value_of(self)
|
26
|
+
rescue java::lang::IllegalArgumentException => e
|
27
|
+
raise TypeError, e.cause.message
|
28
|
+
end
|
29
|
+
else
|
30
|
+
to_java_without_enum(other)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Symbol
|
38
|
+
include ::JactiveSupport::CoreExtensions::Enum
|
39
|
+
end
|
40
|
+
|
41
|
+
class String
|
42
|
+
include ::JactiveSupport::CoreExtensions::Enum
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module JactiveSupport
|
2
|
+
class InvalidParameter < ArgumentError
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
class Hash
|
7
|
+
# Validate all keys in a hash match *valid keys, raising JactiveSupport::InvalidParameter on a mismatch.
|
8
|
+
# Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
|
9
|
+
# as keys, this will fail.
|
10
|
+
#
|
11
|
+
# ==== Examples
|
12
|
+
# { :name => "Rob", :years => "28" }.assert_valid_params(:name, :age) # => raises "InvalidParameter: Unknown key(s): years"
|
13
|
+
# { :name => "Rob", :age => "28" }.assert_valid_params("name", "age") # => raises "InvalidParameter: Unknown key(s): name, age"
|
14
|
+
# { :name => "Rob", :age => "28" }.assert_valid_params(:name, :age) # => passes, raises nothing
|
15
|
+
def assert_valid_params(*valid_keys)
|
16
|
+
unknown_keys = keys.map{|key| key.to_sym} - [valid_keys].flatten
|
17
|
+
raise(::JactiveSupport::InvalidParameter, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Hash
|
2
|
+
def Hash.with_keys_values(keys, values)
|
3
|
+
raise ArgumentError, "Unmatching sizes #{keys.size} != #{values.size}" unless keys.size == values.size
|
4
|
+
#Hash[keys.zip(values).flatten]
|
5
|
+
ret = Hash.new
|
6
|
+
keys.each_with_index{|key, idx| ret[key] = values[idx]}
|
7
|
+
ret
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'jactive_support/java_ext/locale'
|
2
|
+
|
3
|
+
Locale = java::util::Locale
|
4
|
+
|
5
|
+
class NilClass
|
6
|
+
def to_locale
|
7
|
+
java::util::Locale.current_locale
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class String
|
12
|
+
# Returns the java.util.Locale that maches this string
|
13
|
+
def to_locale
|
14
|
+
if self =~ /^(.+)[-_](.+)[-_](.+)$/
|
15
|
+
java::util::Locale.new($1, $2, $3)
|
16
|
+
elsif self =~ /^(.+)[-_](.+)$/
|
17
|
+
java::util::Locale.new($1, $2)
|
18
|
+
else
|
19
|
+
java::util::Locale.new(self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Symbol
|
25
|
+
def to_locale
|
26
|
+
to_s.to_locale
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Date
|
2
|
+
def to_java_date
|
3
|
+
java::util::Date.new((to_time.tv_sec*1000).to_i)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
class Time
|
7
|
+
def to_java_date
|
8
|
+
java::util::Date.new((tv_sec*1000).to_i)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
class ActiveSupport::TimeWithZone
|
12
|
+
def to_java_date
|
13
|
+
java::util::Date.new((tv_sec*1000).to_i)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class java::util::Date
|
17
|
+
def to_java_date
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
class String
|
22
|
+
def to_java_date
|
23
|
+
to_datetime.to_java_date
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'jactive_support/java_ext/date/calculations'
|
2
|
+
require 'jactive_support/java_ext/date/conversions'
|
3
|
+
|
4
|
+
class java::util::Date
|
5
|
+
include JactiveSupport::JavaExtensions::Date::Calculations
|
6
|
+
include JactiveSupport::JavaExtensions::Date::Conversions
|
7
|
+
|
8
|
+
FULL_STYLE = java::text::DateFormat::FULL
|
9
|
+
LONG_STYLE = java::text::DateFormat::LONG
|
10
|
+
MEDIUM_STYLE = java::text::DateFormat::MEDIUM
|
11
|
+
SHORT_STYLE = java::text::DateFormat::SHORT
|
12
|
+
DEFAULT_STYLE = java::text::DateFormat::DEFAULT
|
13
|
+
|
14
|
+
STYLE = {
|
15
|
+
:full => FULL_STYLE,
|
16
|
+
:long => LONG_STYLE,
|
17
|
+
:medium => MEDIUM_STYLE,
|
18
|
+
:short => SHORT_STYLE,
|
19
|
+
:default => DEFAULT_STYLE
|
20
|
+
}
|
21
|
+
|
22
|
+
def acts_like_time?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.date_time_instance(date_style=:default, time_style=:default, locale=nil)
|
27
|
+
java::text::DateFormat.getDateTimeInstance(STYLE[date_style], STYLE[time_style], locale.to_locale)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.time_instance(time_style=:default, locale=nil)
|
31
|
+
java::text::DateFormat.getTimeInstance(STYLE[time_style], locale.to_locale)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.date_instance(date_style=:default, locale=nil)
|
35
|
+
java::text::DateFormat.getDateInstance(STYLE[date_style], locale.to_locale)
|
36
|
+
end
|
37
|
+
end
|