Skip to content

Commit d339814

Browse files
authored
Merge pull request #23 from microsphere-projects/dev
Release v0.0.8
2 parents cdd2531 + 1670e7c commit d339814

File tree

15 files changed

+1444
-20
lines changed

15 files changed

+1444
-20
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.microsphere.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
/**
26+
* The marker annotation indicates a feature is experimental, it could be changed or even be removed in the future.
27+
*
28+
* @author <a href="mailto:[email protected]">Mercy<a/>
29+
* @since 1.0.0
30+
*/
31+
@Retention(RetentionPolicy.SOURCE)
32+
@Target({
33+
ElementType.ANNOTATION_TYPE,
34+
ElementType.CONSTRUCTOR,
35+
ElementType.FIELD,
36+
ElementType.METHOD,
37+
ElementType.TYPE
38+
})
39+
@Documented
40+
public @interface Experimental {
41+
42+
/**
43+
* The description of the experimental feature
44+
*/
45+
String description() default "";
46+
47+
}

microsphere-java-core/src/main/java/io/microsphere/beans/BeanProperty.java

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
*/
1717
package io.microsphere.beans;
1818

19+
import javax.annotation.Nonnull;
1920
import java.beans.PropertyDescriptor;
21+
import java.lang.reflect.Method;
2022
import java.util.Objects;
2123

24+
import static io.microsphere.lang.function.ThrowableSupplier.execute;
25+
import static io.microsphere.reflect.MethodUtils.invokeMethod;
26+
import static io.microsphere.util.Assert.assertNotNull;
27+
2228
/**
2329
* The class presenting the Property of Bean
2430
*
@@ -27,20 +33,25 @@
2733
*/
2834
public class BeanProperty {
2935

30-
private String name;
36+
@Nonnull
37+
private final String name;
3138

3239
private Object value;
3340

34-
private Class<?> declaringClass;
41+
@Nonnull
42+
private final Class<?> beanClass;
3543

36-
private PropertyDescriptor descriptor;
44+
@Nonnull
45+
private final PropertyDescriptor descriptor;
3746

38-
public String getName() {
39-
return name;
47+
public BeanProperty(@Nonnull String name, Class<?> beanClass, PropertyDescriptor descriptor) {
48+
this.name = name;
49+
this.beanClass = beanClass;
50+
this.descriptor = descriptor;
4051
}
4152

42-
public void setName(String name) {
43-
this.name = name;
53+
public String getName() {
54+
return name;
4455
}
4556

4657
public Object getValue() {
@@ -51,22 +62,14 @@ public void setValue(Object value) {
5162
this.value = value;
5263
}
5364

54-
public Class<?> getDeclaringClass() {
55-
return declaringClass;
56-
}
57-
58-
public void setDeclaringClass(Class<?> declaringClass) {
59-
this.declaringClass = declaringClass;
65+
public Class<?> getBeanClass() {
66+
return beanClass;
6067
}
6168

6269
public PropertyDescriptor getDescriptor() {
6370
return descriptor;
6471
}
6572

66-
public void setDescriptor(PropertyDescriptor descriptor) {
67-
this.descriptor = descriptor;
68-
}
69-
7073
@Override
7174
public boolean equals(Object o) {
7275
if (this == o) return true;
@@ -76,7 +79,7 @@ public boolean equals(Object o) {
7679

7780
if (!Objects.equals(name, that.name)) return false;
7881
if (!Objects.equals(value, that.value)) return false;
79-
if (!Objects.equals(declaringClass, that.declaringClass))
82+
if (!Objects.equals(beanClass, that.beanClass))
8083
return false;
8184
return Objects.equals(descriptor, that.descriptor);
8285
}
@@ -85,7 +88,7 @@ public boolean equals(Object o) {
8588
public int hashCode() {
8689
int result = name != null ? name.hashCode() : 0;
8790
result = 31 * result + (value != null ? value.hashCode() : 0);
88-
result = 31 * result + (declaringClass != null ? declaringClass.hashCode() : 0);
91+
result = 31 * result + (beanClass != null ? beanClass.hashCode() : 0);
8992
result = 31 * result + (descriptor != null ? descriptor.hashCode() : 0);
9093
return result;
9194
}
@@ -94,9 +97,31 @@ public int hashCode() {
9497
public String toString() {
9598
String sb = "BeanProperty{" + "name='" + name + '\'' +
9699
", value=" + value +
97-
", declaringClass=" + declaringClass +
100+
", declaringClass=" + beanClass +
98101
", descriptor=" + descriptor +
99102
'}';
100103
return sb;
101104
}
105+
106+
/**
107+
* Create a {@link BeanProperty} instance
108+
*
109+
* @param bean bean instance
110+
* @param propertyName the name of bean property
111+
* @return a {@link BeanProperty} instance
112+
*/
113+
public static BeanProperty of(@Nonnull Object bean, @Nonnull String propertyName) {
114+
assertNotNull(bean, "The 'bean' argument must not be null");
115+
assertNotNull(propertyName, "The 'propertyName' argument must not be null");
116+
Class<?> beanClass = bean.getClass();
117+
118+
return execute(() -> {
119+
PropertyDescriptor descriptor = new PropertyDescriptor(propertyName, beanClass);
120+
BeanProperty beanProperty = new BeanProperty(propertyName, beanClass, descriptor);
121+
Method getterMethod = descriptor.getReadMethod();
122+
Object propertyValue = invokeMethod(bean, getterMethod);
123+
beanProperty.value = (propertyValue);
124+
return beanProperty;
125+
});
126+
}
102127
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.microsphere.concurrent;
18+
19+
import java.util.Collection;
20+
import java.util.Iterator;
21+
import java.util.Spliterator;
22+
import java.util.concurrent.BlockingQueue;
23+
import java.util.concurrent.TimeUnit;
24+
import java.util.function.Consumer;
25+
import java.util.function.Predicate;
26+
import java.util.stream.Stream;
27+
28+
/**
29+
* Delegating {@link BlockingQueue}
30+
*
31+
* @param <E> – the type of elements held in this queue
32+
* @author <a href="mailto:[email protected]">Mercy</a>
33+
* @since 1.0.0
34+
*/
35+
public class DelegatingBlockingQueue<E> implements BlockingQueue<E> {
36+
37+
private final BlockingQueue<E> delegate;
38+
39+
public DelegatingBlockingQueue(BlockingQueue<E> delegate) {
40+
this.delegate = delegate;
41+
}
42+
43+
@Override
44+
public Iterator<E> iterator() {
45+
return delegate.iterator();
46+
}
47+
48+
@Override
49+
public Object[] toArray() {
50+
return delegate.toArray();
51+
}
52+
53+
@Override
54+
public <T> T[] toArray(T[] a) {
55+
return delegate.toArray(a);
56+
}
57+
58+
@Override
59+
public boolean containsAll(Collection<?> c) {
60+
return delegate.containsAll(c);
61+
}
62+
63+
@Override
64+
public boolean addAll(Collection<? extends E> c) {
65+
return delegate.addAll(c);
66+
}
67+
68+
@Override
69+
public boolean removeAll(Collection<?> c) {
70+
return delegate.removeAll(c);
71+
}
72+
73+
@Override
74+
public boolean removeIf(Predicate<? super E> filter) {
75+
return delegate.removeIf(filter);
76+
}
77+
78+
@Override
79+
public boolean retainAll(Collection<?> c) {
80+
return delegate.retainAll(c);
81+
}
82+
83+
@Override
84+
public void clear() {
85+
delegate.clear();
86+
}
87+
88+
@Override
89+
public boolean equals(Object o) {
90+
return delegate.equals(o);
91+
}
92+
93+
@Override
94+
public int hashCode() {
95+
return delegate.hashCode();
96+
}
97+
98+
@Override
99+
public Spliterator<E> spliterator() {
100+
return delegate.spliterator();
101+
}
102+
103+
@Override
104+
public Stream<E> stream() {
105+
return delegate.stream();
106+
}
107+
108+
@Override
109+
public Stream<E> parallelStream() {
110+
return delegate.parallelStream();
111+
}
112+
113+
@Override
114+
public boolean add(E e) {
115+
return delegate.add(e);
116+
}
117+
118+
@Override
119+
public boolean offer(E e) {
120+
return delegate.offer(e);
121+
}
122+
123+
@Override
124+
public void put(E e) throws InterruptedException {
125+
delegate.put(e);
126+
}
127+
128+
@Override
129+
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
130+
return delegate.offer(e, timeout, unit);
131+
}
132+
133+
@Override
134+
public E take() throws InterruptedException {
135+
return delegate.take();
136+
}
137+
138+
@Override
139+
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
140+
return delegate.poll(timeout, unit);
141+
}
142+
143+
@Override
144+
public int remainingCapacity() {
145+
return delegate.remainingCapacity();
146+
}
147+
148+
@Override
149+
public boolean remove(Object o) {
150+
return delegate.remove(o);
151+
}
152+
153+
@Override
154+
public boolean contains(Object o) {
155+
return delegate.contains(o);
156+
}
157+
158+
@Override
159+
public int drainTo(Collection<? super E> c) {
160+
return delegate.drainTo(c);
161+
}
162+
163+
@Override
164+
public int drainTo(Collection<? super E> c, int maxElements) {
165+
return delegate.drainTo(c, maxElements);
166+
}
167+
168+
@Override
169+
public E remove() {
170+
return delegate.remove();
171+
}
172+
173+
@Override
174+
public E poll() {
175+
return delegate.poll();
176+
}
177+
178+
@Override
179+
public E element() {
180+
return delegate.element();
181+
}
182+
183+
@Override
184+
public E peek() {
185+
return delegate.peek();
186+
}
187+
188+
@Override
189+
public int size() {
190+
return delegate.size();
191+
}
192+
193+
@Override
194+
public boolean isEmpty() {
195+
return delegate.isEmpty();
196+
}
197+
198+
@Override
199+
public void forEach(Consumer<? super E> action) {
200+
delegate.forEach(action);
201+
}
202+
}

0 commit comments

Comments
 (0)