Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.microsphere.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The marker annotation indicates a feature is experimental, it could be changed or even be removed in the future.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
* @since 1.0.0
*/
@Retention(RetentionPolicy.SOURCE)
@Target({
ElementType.ANNOTATION_TYPE,
ElementType.CONSTRUCTOR,
ElementType.FIELD,
ElementType.METHOD,
ElementType.TYPE
})
@Documented
public @interface Experimental {

/**
* The description of the experimental feature
*/
String description() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
*/
package io.microsphere.beans;

import javax.annotation.Nonnull;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Objects;

import static io.microsphere.lang.function.ThrowableSupplier.execute;
import static io.microsphere.reflect.MethodUtils.invokeMethod;
import static io.microsphere.util.Assert.assertNotNull;

/**
* The class presenting the Property of Bean
*
Expand All @@ -27,20 +33,25 @@
*/
public class BeanProperty {

private String name;
@Nonnull
private final String name;

private Object value;

private Class<?> declaringClass;
@Nonnull
private final Class<?> beanClass;

private PropertyDescriptor descriptor;
@Nonnull
private final PropertyDescriptor descriptor;

public String getName() {
return name;
public BeanProperty(@Nonnull String name, Class<?> beanClass, PropertyDescriptor descriptor) {
this.name = name;
this.beanClass = beanClass;
this.descriptor = descriptor;
}

public void setName(String name) {
this.name = name;
public String getName() {
return name;
}

public Object getValue() {
Expand All @@ -51,22 +62,14 @@ public void setValue(Object value) {
this.value = value;
}

public Class<?> getDeclaringClass() {
return declaringClass;
}

public void setDeclaringClass(Class<?> declaringClass) {
this.declaringClass = declaringClass;
public Class<?> getBeanClass() {
return beanClass;
}

public PropertyDescriptor getDescriptor() {
return descriptor;
}

public void setDescriptor(PropertyDescriptor descriptor) {
this.descriptor = descriptor;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -76,7 +79,7 @@ public boolean equals(Object o) {

if (!Objects.equals(name, that.name)) return false;
if (!Objects.equals(value, that.value)) return false;
if (!Objects.equals(declaringClass, that.declaringClass))
if (!Objects.equals(beanClass, that.beanClass))
return false;
return Objects.equals(descriptor, that.descriptor);
}
Expand All @@ -85,7 +88,7 @@ public boolean equals(Object o) {
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
result = 31 * result + (declaringClass != null ? declaringClass.hashCode() : 0);
result = 31 * result + (beanClass != null ? beanClass.hashCode() : 0);
result = 31 * result + (descriptor != null ? descriptor.hashCode() : 0);
return result;
}
Expand All @@ -94,9 +97,31 @@ public int hashCode() {
public String toString() {
String sb = "BeanProperty{" + "name='" + name + '\'' +
", value=" + value +
", declaringClass=" + declaringClass +
", declaringClass=" + beanClass +
", descriptor=" + descriptor +
'}';
return sb;
}

/**
* Create a {@link BeanProperty} instance
*
* @param bean bean instance
* @param propertyName the name of bean property
* @return a {@link BeanProperty} instance
*/
public static BeanProperty of(@Nonnull Object bean, @Nonnull String propertyName) {
assertNotNull(bean, "The 'bean' argument must not be null");
assertNotNull(propertyName, "The 'propertyName' argument must not be null");
Class<?> beanClass = bean.getClass();

return execute(() -> {
PropertyDescriptor descriptor = new PropertyDescriptor(propertyName, beanClass);
BeanProperty beanProperty = new BeanProperty(propertyName, beanClass, descriptor);
Method getterMethod = descriptor.getReadMethod();
Object propertyValue = invokeMethod(bean, getterMethod);
beanProperty.value = (propertyValue);
return beanProperty;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.microsphere.concurrent;

import java.util.Collection;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
* Delegating {@link BlockingQueue}
*
* @param <E> – the type of elements held in this queue
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
public class DelegatingBlockingQueue<E> implements BlockingQueue<E> {

private final BlockingQueue<E> delegate;

public DelegatingBlockingQueue(BlockingQueue<E> delegate) {
this.delegate = delegate;
}

@Override
public Iterator<E> iterator() {
return delegate.iterator();
}

@Override
public Object[] toArray() {
return delegate.toArray();
}

@Override
public <T> T[] toArray(T[] a) {
return delegate.toArray(a);
}

@Override
public boolean containsAll(Collection<?> c) {
return delegate.containsAll(c);
}

@Override
public boolean addAll(Collection<? extends E> c) {
return delegate.addAll(c);
}

@Override
public boolean removeAll(Collection<?> c) {
return delegate.removeAll(c);
}

@Override
public boolean removeIf(Predicate<? super E> filter) {
return delegate.removeIf(filter);
}

@Override
public boolean retainAll(Collection<?> c) {
return delegate.retainAll(c);
}

@Override
public void clear() {
delegate.clear();
}

@Override
public boolean equals(Object o) {
return delegate.equals(o);
}

@Override
public int hashCode() {
return delegate.hashCode();
}

@Override
public Spliterator<E> spliterator() {
return delegate.spliterator();
}

@Override
public Stream<E> stream() {
return delegate.stream();
}

@Override
public Stream<E> parallelStream() {
return delegate.parallelStream();
}

@Override
public boolean add(E e) {
return delegate.add(e);
}

@Override
public boolean offer(E e) {
return delegate.offer(e);
}

@Override
public void put(E e) throws InterruptedException {
delegate.put(e);
}

@Override
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
return delegate.offer(e, timeout, unit);
}

@Override
public E take() throws InterruptedException {
return delegate.take();
}

@Override
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
return delegate.poll(timeout, unit);
}

@Override
public int remainingCapacity() {
return delegate.remainingCapacity();
}

@Override
public boolean remove(Object o) {
return delegate.remove(o);
}

@Override
public boolean contains(Object o) {
return delegate.contains(o);
}

@Override
public int drainTo(Collection<? super E> c) {
return delegate.drainTo(c);
}

@Override
public int drainTo(Collection<? super E> c, int maxElements) {
return delegate.drainTo(c, maxElements);
}

@Override
public E remove() {
return delegate.remove();
}

@Override
public E poll() {
return delegate.poll();
}

@Override
public E element() {
return delegate.element();
}

@Override
public E peek() {
return delegate.peek();
}

@Override
public int size() {
return delegate.size();
}

@Override
public boolean isEmpty() {
return delegate.isEmpty();
}

@Override
public void forEach(Consumer<? super E> action) {
delegate.forEach(action);
}
}
Loading