From 05f96ce812594a4dd212c7b0ebd977d5789f0720 Mon Sep 17 00:00:00 2001 From: kamhung <22250530@qq.com> Date: Mon, 30 Nov 2015 17:55:54 +0800 Subject: [PATCH] --- .../convert/bson/BsonByteBufferWriter.java | 2 +- .../redkale/convert/bson/BsonConvert.java | 3 +- .../redkale/convert/bson/BsonReader.java | 1 + .../redkale/convert/bson/BsonWriter.java | 1 + .../convert/json/JsonByteBufferWriter.java | 2 +- .../redkale/convert/json/JsonConvert.java | 1 + .../redkale/convert/json/JsonReader.java | 3 +- .../redkale/convert/json/JsonWriter.java | 1 + .../com/wentch/redkale/util/BiPredicate.java | 27 ---------- .../src/com/wentch/redkale/util/Consumer.java | 22 -------- .../com/wentch/redkale/util/ObjectPool.java | 7 ++- .../com/wentch/redkale/util/Predicate.java | 24 --------- .../src/com/wentch/redkale/util/Supplier.java | 22 -------- .../src/java/util/function/BiPredicate.java | 54 +++++++++++++++++++ .../src/java/util/function/Consumer.java | 49 +++++++++++++++++ .../src/java/util/function/Predicate.java | 49 +++++++++++++++++ .../src/java/util/function/Supplier.java | 49 +++++++++++++++++ 17 files changed, 217 insertions(+), 100 deletions(-) delete mode 100644 android-jdk6-redkale/src/com/wentch/redkale/util/BiPredicate.java delete mode 100644 android-jdk6-redkale/src/com/wentch/redkale/util/Consumer.java delete mode 100644 android-jdk6-redkale/src/com/wentch/redkale/util/Predicate.java delete mode 100644 android-jdk6-redkale/src/com/wentch/redkale/util/Supplier.java create mode 100644 android-jdk6-redkale/src/java/util/function/BiPredicate.java create mode 100644 android-jdk6-redkale/src/java/util/function/Consumer.java create mode 100644 android-jdk6-redkale/src/java/util/function/Predicate.java create mode 100644 android-jdk6-redkale/src/java/util/function/Supplier.java diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonByteBufferWriter.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonByteBufferWriter.java index 1a9f392f4..8d4a40062 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonByteBufferWriter.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonByteBufferWriter.java @@ -5,8 +5,8 @@ */ package com.wentch.redkale.convert.bson; -import com.wentch.redkale.util.*; import java.nio.*; +import java.util.function.*; /** * diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonConvert.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonConvert.java index 3312c0b31..5fd4c1bb0 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonConvert.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonConvert.java @@ -9,6 +9,7 @@ import com.wentch.redkale.convert.*; import com.wentch.redkale.util.*; import java.lang.reflect.*; import java.nio.*; +import java.util.function.*; /** * BSON协议格式: @@ -44,7 +45,7 @@ public final class BsonConvert extends Convert { } public BsonByteBufferWriter pollBsonWriter(final Supplier supplier) { - return new BsonByteBufferWriter(supplier).setTiny(tiny); + return new BsonByteBufferWriter(supplier).setTiny(tiny); } public BsonWriter pollBsonWriter() { diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonReader.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonReader.java index 69e2a2b79..749fd139d 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonReader.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonReader.java @@ -9,6 +9,7 @@ import com.wentch.redkale.convert.*; import com.wentch.redkale.convert.ext.*; import com.wentch.redkale.util.*; import java.util.concurrent.atomic.*; +import java.util.function.*; /** * diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonWriter.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonWriter.java index 4b185d5a6..d4c06220c 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonWriter.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/bson/BsonWriter.java @@ -8,6 +8,7 @@ package com.wentch.redkale.convert.bson; import com.wentch.redkale.convert.*; import com.wentch.redkale.util.*; import java.nio.*; +import java.util.function.*; /** * diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonByteBufferWriter.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonByteBufferWriter.java index f135d9525..6482e3a0f 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonByteBufferWriter.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonByteBufferWriter.java @@ -6,10 +6,10 @@ package com.wentch.redkale.convert.json; import com.wentch.redkale.util.*; -import com.wentch.redkale.util.Supplier; import java.nio.*; import java.nio.charset.*; import java.util.*; +import java.util.function.*; /** * diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonConvert.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonConvert.java index 6201938d5..2fd8b709c 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonConvert.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonConvert.java @@ -10,6 +10,7 @@ import com.wentch.redkale.util.*; import java.lang.reflect.*; import java.nio.*; import java.nio.charset.*; +import java.util.function.*; /** * diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonReader.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonReader.java index 2e399e3bb..407f50e12 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonReader.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonReader.java @@ -8,6 +8,7 @@ package com.wentch.redkale.convert.json; import com.wentch.redkale.convert.*; import com.wentch.redkale.util.*; import java.util.concurrent.atomic.*; +import java.util.function.*; /** * @@ -22,7 +23,7 @@ public final class JsonReader implements Reader { private int limit; public static ObjectPool createPool(int max) { - return new ObjectPool(max, new Creator() { + return new ObjectPool(max, new Creator() { //为了兼容 JDK 6 @Override public JsonReader create(Object... params) { diff --git a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonWriter.java b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonWriter.java index 111d3484b..8c08296e9 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonWriter.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/convert/json/JsonWriter.java @@ -8,6 +8,7 @@ package com.wentch.redkale.convert.json; import com.wentch.redkale.convert.*; import com.wentch.redkale.util.*; import java.nio.*; +import java.util.function.*; /** * diff --git a/android-jdk6-redkale/src/com/wentch/redkale/util/BiPredicate.java b/android-jdk6-redkale/src/com/wentch/redkale/util/BiPredicate.java deleted file mode 100644 index 20624a6c4..000000000 --- a/android-jdk6-redkale/src/com/wentch/redkale/util/BiPredicate.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.wentch.redkale.util; - -/** - * JDK 8 java.util.function.BiPredicate - * - * @author zhangjx - * @param - * @param - */ -public interface BiPredicate { - - /** - * Evaluates this predicate on the given arguments. - * - * @param t the first input argument - * @param u the second input argument - * @return {@code true} if the input arguments match the predicate, - * otherwise {@code false} - */ - boolean test(T t, U u); - -} diff --git a/android-jdk6-redkale/src/com/wentch/redkale/util/Consumer.java b/android-jdk6-redkale/src/com/wentch/redkale/util/Consumer.java deleted file mode 100644 index 2ae5f6af6..000000000 --- a/android-jdk6-redkale/src/com/wentch/redkale/util/Consumer.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.wentch.redkale.util; - -/** - * JDK 8 java.util.function.Consumer - * - * @author zhangjx - * @param - */ -public interface Consumer { - - /** - * Performs this operation on the given argument. - * - * @param t the input argument - */ - void accept(T t); -} diff --git a/android-jdk6-redkale/src/com/wentch/redkale/util/ObjectPool.java b/android-jdk6-redkale/src/com/wentch/redkale/util/ObjectPool.java index de3815f71..6b05cbb74 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/util/ObjectPool.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/util/ObjectPool.java @@ -8,6 +8,7 @@ import com.wentch.redkale.util.Creator.Creators; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; +import java.util.function.*; import java.util.logging.*; /** @@ -63,6 +64,7 @@ public final class ObjectPool implements Supplier { this.creator = creator; } + @Override public T get() { T result = queue.poll(); if (result == null) { @@ -78,7 +80,10 @@ public final class ObjectPool implements Supplier { if (cycleCounter != null) cycleCounter.incrementAndGet(); if (debug) { for (T t : queue) { - if (t == e) logger.log(Level.WARNING, "[" + Thread.currentThread().getName() + "] repeat offer the same object(" + e + ")", new Exception()); + if (t == e) { + logger.log(Level.WARNING, "[" + Thread.currentThread().getName() + "] repeat offer the same object(" + e + ")", new Exception()); + return; + } } } queue.offer(e); diff --git a/android-jdk6-redkale/src/com/wentch/redkale/util/Predicate.java b/android-jdk6-redkale/src/com/wentch/redkale/util/Predicate.java deleted file mode 100644 index 9bf0b0639..000000000 --- a/android-jdk6-redkale/src/com/wentch/redkale/util/Predicate.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.wentch.redkale.util; - -/** - * JDK 8 java.util.function.Predicate - * - * @author zhangjx - * @param - */ -public interface Predicate { - - /** - * Evaluates this predicate on the given argument. - * - * @param t the input argument - * @return {@code true} if the input argument matches the predicate, - * otherwise {@code false} - */ - boolean test(T t); -} diff --git a/android-jdk6-redkale/src/com/wentch/redkale/util/Supplier.java b/android-jdk6-redkale/src/com/wentch/redkale/util/Supplier.java deleted file mode 100644 index 619e02d57..000000000 --- a/android-jdk6-redkale/src/com/wentch/redkale/util/Supplier.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.wentch.redkale.util; - -/** - * JDK 8 java.util.function.Supplier - * - * @author zhangjx - * @param - */ -public interface Supplier { - - /** - * Gets a result. - * - * @return a result - */ - T get(); -} diff --git a/android-jdk6-redkale/src/java/util/function/BiPredicate.java b/android-jdk6-redkale/src/java/util/function/BiPredicate.java new file mode 100644 index 000000000..848c8ebf2 --- /dev/null +++ b/android-jdk6-redkale/src/java/util/function/BiPredicate.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + + +/** + * Represents a predicate (boolean-valued function) of two arguments. This is + * the two-arity specialization of {@link Predicate}. + * + *

This is a functional interface + * whose functional method is {@link #test(Object, Object)}. + * + * @param the type of the first argument to the predicate + * @param the type of the second argument the predicate + * + * @see Predicate + * @since 1.8 + */ +@FunctionalInterface +public interface BiPredicate { + + /** + * Evaluates this predicate on the given arguments. + * + * @param t the first input argument + * @param u the second input argument + * @return {@code true} if the input arguments match the predicate, + * otherwise {@code false} + */ + boolean test(T t, U u); + +} diff --git a/android-jdk6-redkale/src/java/util/function/Consumer.java b/android-jdk6-redkale/src/java/util/function/Consumer.java new file mode 100644 index 000000000..4031d4e0f --- /dev/null +++ b/android-jdk6-redkale/src/java/util/function/Consumer.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Represents an operation that accepts a single input argument and returns no + * result. Unlike most other functional interfaces, {@code Consumer} is expected + * to operate via side-effects. + * + *

This is a functional interface + * whose functional method is {@link #accept(Object)}. + * + * @param the type of the input to the operation + * + * @since 1.8 + */ +@FunctionalInterface +public interface Consumer { + + /** + * Performs this operation on the given argument. + * + * @param t the input argument + */ + void accept(T t); + +} diff --git a/android-jdk6-redkale/src/java/util/function/Predicate.java b/android-jdk6-redkale/src/java/util/function/Predicate.java new file mode 100644 index 000000000..b76a5a24d --- /dev/null +++ b/android-jdk6-redkale/src/java/util/function/Predicate.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Represents a predicate (boolean-valued function) of one argument. + * + *

This is a functional interface + * whose functional method is {@link #test(Object)}. + * + * @param the type of the input to the predicate + * + * @since 1.8 + */ +@FunctionalInterface +public interface Predicate { + + /** + * Evaluates this predicate on the given argument. + * + * @param t the input argument + * @return {@code true} if the input argument matches the predicate, + * otherwise {@code false} + */ + boolean test(T t); + +} diff --git a/android-jdk6-redkale/src/java/util/function/Supplier.java b/android-jdk6-redkale/src/java/util/function/Supplier.java new file mode 100644 index 000000000..b87777e88 --- /dev/null +++ b/android-jdk6-redkale/src/java/util/function/Supplier.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.function; + +/** + * Represents a supplier of results. + * + *

There is no requirement that a new or distinct result be returned each + * time the supplier is invoked. + * + *

This is a functional interface + * whose functional method is {@link #get()}. + * + * @param the type of results supplied by this supplier + * + * @since 1.8 + */ +@FunctionalInterface +public interface Supplier { + + /** + * Gets a result. + * + * @return a result + */ + T get(); +}