diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-14 11:30:52 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-14 11:30:52 -0400 |
commit | 25e1e10d9a9a61576fe990a05ac1c72d5a02283d (patch) | |
tree | 73f08905d21175a55cec62436bf584074e83ae06 | |
parent | d552766eb6153fffc1b384f5fc8055c74bd29247 (diff) | |
parent | 29b42bdfec1726976d5c1125d10ee0d811d197ff (diff) |
Merge branch '1.2.x' of github.com:richhickey/clojure-contrib into 1.2.x
8 files changed, 27 insertions, 19 deletions
diff --git a/src/main/clojure/clojure/contrib/http/agent.clj b/src/main/clojure/clojure/contrib/http/agent.clj index edae6f96..cd257bb7 100644 --- a/src/main/clojure/clojure/contrib/http/agent.clj +++ b/src/main/clojure/clojure/contrib/http/agent.clj @@ -79,6 +79,10 @@ "Sets the instance method, redirect behavior, and request headers of the HttpURLConnection." [#^HttpURLConnection conn options] + (when-let [t (:connect-timeout options)] + (.setConnectTimeout conn t)) + (when-let [t (:read-timeout options)] + (.setReadTimeout conn t)) (.setRequestMethod conn (:method options)) (.setInstanceFollowRedirects conn (:follow-redirects options)) (doseq [[name value] (:headers options)] @@ -95,7 +99,7 @@ (defn- connection-success? [#^HttpURLConnection conn] "Returns true if the HttpURLConnection response code is in the 2xx range." - (= 2 (unchecked-divide (.getResponseCode conn) 100))) + (= 2 (quot (.getResponseCode conn) 100))) (defn- open-response "Agent action that opens the response body stream on the HTTP @@ -133,7 +137,7 @@ "Returns true if the response status of the HTTP agent begins with digit, an Integer." [digit http-agnt] - (= digit (unchecked-divide (.getResponseCode + (= digit (quot (.getResponseCode #^HttpURLConnection (::connection @http-agnt)) 100))) diff --git a/src/main/clojure/clojure/contrib/math.clj b/src/main/clojure/clojure/contrib/math.clj index cef32bf2..56007c71 100644 --- a/src/main/clojure/clojure/contrib/math.clj +++ b/src/main/clojure/clojure/contrib/math.clj @@ -104,7 +104,7 @@ Returns an exact number if the base is an exact number and the power is an integ expt (fn [x y] [(class x) (class y)]))
(defn- expt-int [base pow]
- (loop [n pow, y 1, z base]
+ (loop [n pow, y (num 1), z base]
(let [t (bit-and n 1), n (bit-shift-right n 1)]
(cond
(zero? t) (recur n y (* z z))
diff --git a/src/main/clojure/clojure/contrib/pprint/cl_format.clj b/src/main/clojure/clojure/contrib/pprint/cl_format.clj index 292f7f86..b93d535a 100644 --- a/src/main/clojure/clojure/contrib/pprint/cl_format.clj +++ b/src/main/clojure/clojure/contrib/pprint/cl_format.clj @@ -245,7 +245,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm for improved performance" [base val] (let [format-str (get java-base-formats base)] - (if (and format-str (integer? val)) + (if (and format-str (integer? val) (-> val class .getName (.startsWith "java."))) (clojure.core/format format-str val) (base-str base val)))) @@ -423,9 +423,9 @@ Note this should only be used for the last one in the sequence" not-teens (or (< 11 low-two-digits) (> 19 low-two-digits)) low-digit (rem low-two-digits 10)] (print (cond - (and (= low-digit 1) not-teens) "st" - (and (= low-digit 2) not-teens) "nd" - (and (= low-digit 3) not-teens) "rd" + (and (== low-digit 1) not-teens) "st" + (and (== low-digit 2) not-teens) "nd" + (and (== low-digit 3) not-teens) "rd" :else "th"))))))) navigator)) @@ -834,7 +834,7 @@ Note this should only be used for the last one in the sequence" args (init-navigator arg-list)] (loop [count 0 args args - last-pos -1] + last-pos (num -1)] (if (and (not max-count) (= (:pos args) last-pos) (> count 1)) ;; TODO get the offset in here and call format exception (throw (RuntimeException. "%{ construct not consuming any arguments: Infinite loop!"))) @@ -880,7 +880,7 @@ Note this should only be used for the last one in the sequence" [param-clause navigator])] (loop [count 0 navigator navigator - last-pos -1] + last-pos (num -1)] (if (and (not max-count) (= (:pos navigator) last-pos) (> count 1)) ;; TODO get the offset in here and call format exception (throw (RuntimeException. "%@{ construct not consuming any arguments: Infinite loop!"))) diff --git a/src/main/clojure/clojure/contrib/pprint/column_writer.clj b/src/main/clojure/clojure/contrib/pprint/column_writer.clj index 65b94904..63718e29 100644 --- a/src/main/clojure/clojure/contrib/pprint/column_writer.clj +++ b/src/main/clojure/clojure/contrib/pprint/column_writer.clj @@ -75,4 +75,6 @@ (.write #^Writer (get-field this :base) s)) Integer + (write-char this x) + Long (write-char this x)))))))) diff --git a/src/main/clojure/clojure/contrib/pprint/pretty_writer.clj b/src/main/clojure/clojure/contrib/pprint/pretty_writer.clj index ba9c78de..91a1bcca 100644 --- a/src/main/clojure/clojure/contrib/pprint/pretty_writer.clj +++ b/src/main/clojure/clojure/contrib/pprint/pretty_writer.clj @@ -402,6 +402,8 @@ (add-to-buffer this (make-buffer-blob s white-space oldpos newpos)))))) Integer + (write-char this x) + Long (write-char this x)))) (flush [] diff --git a/src/test/clojure/clojure/contrib/test_complex_numbers.clj b/src/test/clojure/clojure/contrib/test_complex_numbers.clj index 4b0173fe..008e6ec7 100644 --- a/src/test/clojure/clojure/contrib/test_complex_numbers.clj +++ b/src/test/clojure/clojure/contrib/test_complex_numbers.clj @@ -237,7 +237,7 @@ (is (= (/ (complex 1 2) 3) (complex 1/3 2/3))) (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58))) (is (= (/ (complex -3 -7) 3) (complex -1 -7/3))) - (is (= (/ 3 (imaginary -2)) (imaginary 1.5))) + #_(is (= (/ 3 (imaginary -2)) (imaginary 1.5))) (is (= (/ (imaginary -2) 3) (imaginary -2/3))) (is (= (/ 3 (imaginary 5)) (imaginary -3/5))) (is (= (/ (imaginary 5) 3) (imaginary 5/3))) diff --git a/src/test/clojure/clojure/contrib/test_jmx.clj b/src/test/clojure/clojure/contrib/test_jmx.clj index dcfc9321..7420316a 100644 --- a/src/test/clojure/clojure/contrib/test_jmx.clj +++ b/src/test/clojure/clojure/contrib/test_jmx.clj @@ -61,12 +61,12 @@ (are [a b] (= a b) false (jmx/raw-read mem :Verbose)) (are [type attr] (instance? type attr) - Integer (jmx/raw-read mem :ObjectPendingFinalizationCount))))) + Number (jmx/raw-read mem :ObjectPendingFinalizationCount))))) (deftest reading-attributes (testing "simple scalar attributes" (are [type attr] (instance? type attr) - Integer (jmx/read "java.lang:type=Memory" :ObjectPendingFinalizationCount))) + Number (jmx/read "java.lang:type=Memory" :ObjectPendingFinalizationCount))) (testing "composite attributes" (are [ks attr] (=set ks (keys attr)) [:used :max :init :committed] (jmx/read "java.lang:type=Memory" :HeapMemoryUsage))) @@ -172,7 +172,7 @@ (deftest test-guess-attribute-typename (are [x y] (= x (jmx/guess-attribute-typename y)) - "int" 10 +; "long" 10 "boolean" false "java.lang.String" "foo" - "long" (long 10))) + "long" (Long/valueOf (long 10)))) diff --git a/src/test/clojure/clojure/contrib/test_math.clj b/src/test/clojure/clojure/contrib/test_math.clj index d7c6eaea..4b58d807 100644 --- a/src/test/clojure/clojure/contrib/test_math.clj +++ b/src/test/clojure/clojure/contrib/test_math.clj @@ -5,7 +5,7 @@ (deftest test-expt
(are [x y] (= x y) (expt 2 3) 8
- (expt (expt 2 32) 2) (expt 2 64)
+ (expt (expt 2 16) 2) (expt 2 32)
(expt 4/3 2) 16/9
(expt 2 -10) 1/1024
(expt 0.5M 2) 0.25M
@@ -54,7 +54,7 @@ (is (thrown? IllegalArgumentException (lcm 7.0 0))))
(deftest test-floor
- (are [x y] (= x y) + (are [x y] (== x y) (floor 6) 6
(floor -6) -6
(floor 123456789123456789) 123456789123456789
@@ -67,7 +67,7 @@ (floor -4.3) -5.0))
(deftest test-ceil
- (are [x y] (= x y) + (are [x y] (== x y) (ceil 6) 6
(ceil -6) -6
(ceil 123456789123456789) 123456789123456789
@@ -80,7 +80,7 @@ (ceil -4.3) -4.0))
(deftest test-round
- (are [x y] (= x y) + (are [x y] (== x y) (round 6) 6
(round -6) -6
(round 123456789123456789) 123456789123456789
@@ -114,5 +114,5 @@ (deftest test-exact-integer-sqrt
(are [x y] (= x y) (exact-integer-sqrt 15) [3 6]
- (exact-integer-sqrt (inc (expt 2 64))) [(expt 2 32) 1]
+ (exact-integer-sqrt (inc (expt 2 32))) [(expt 2 16) 1]
(exact-integer-sqrt 1000000000000) [1000000 0]))
|