Java Code Examples for java.lang.reflect.Method#hashCode()

The following examples show how to use java.lang.reflect.Method#hashCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventProducer.java    From divide with Apache License 2.0 6 votes vote down vote up
EventProducer(Object target, Method method) {
  if (target == null) {
    throw new NullPointerException("EventProducer target cannot be null.");
  }
  if (method == null) {
    throw new NullPointerException("EventProducer method cannot be null.");
  }

  this.target = target;
  this.method = method;
  method.setAccessible(true);

  // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
  // target's hashCode call.
  final int prime = 31;
  hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 2
Source File: ProducerEvent.java    From RxBus with Apache License 2.0 6 votes vote down vote up
public ProducerEvent(Object target, Method method, EventThread thread) {
    if (target == null) {
        throw new NullPointerException("EventProducer target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("EventProducer method cannot be null.");
    }

    this.target = target;
    this.thread = thread;
    this.method = method;
    method.setAccessible(true);

    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 3
Source File: SubscriberEvent.java    From SweetMusicPlayer with Apache License 2.0 6 votes vote down vote up
public SubscriberEvent(Object target, Method method, EventThread thread) {
    if (target == null) {
        throw new NullPointerException("SubscriberEvent target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("SubscriberEvent method cannot be null.");
    }
    if (thread == null) {
        throw new NullPointerException("SubscriberEvent thread cannot be null.");
    }

    this.target = target;
    this.method = method;
    this.thread = thread;
    method.setAccessible(true);
    initObservable();

    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 4
Source File: ProducerEvent.java    From SweetMusicPlayer with Apache License 2.0 6 votes vote down vote up
public ProducerEvent(Object target, Method method, EventThread thread) {
    if (target == null) {
        throw new NullPointerException("EventProducer target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("EventProducer method cannot be null.");
    }

    this.target = target;
    this.thread = thread;
    this.method = method;
    method.setAccessible(true);

    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 5
Source File: EventHandler.java    From Noyze with Apache License 2.0 6 votes vote down vote up
EventHandler(Object target, Method method) {
  if (target == null) {
    throw new NullPointerException("EventHandler target cannot be null.");
  }
  if (method == null) {
    throw new NullPointerException("EventHandler method cannot be null.");
  }

  this.target = target;
  this.method = method;
  method.setAccessible(true);

  // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
  // target's hashCode call.
  final int prime = 31;
  hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 6
Source File: EventProducer.java    From SaveAndroidResources with MIT License 6 votes vote down vote up
EventProducer(Object target, Method method) {
    if (target == null) {
        throw new NullPointerException("EventProducer target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("EventProducer method cannot be null.");
    }

    this.target = target;
    this.method = method;

    /**
     * 取消 Java语言访问检查,提高反射速度
     */
    method.setAccessible(true);

    /**
     * 计算hashCode
     */
    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 7
Source File: EventHandler.java    From SaveAndroidResources with MIT License 6 votes vote down vote up
EventHandler(Object target, Method method) {
    if (target == null) {
        throw new NullPointerException("EventHandler target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("EventHandler method cannot be null.");
    }

    this.target = target;
    this.method = method;

    /**
     * 取消 Java语言访问检查,提高反射速度
     */
    method.setAccessible(true);

    /**
     * 计算hashCode
     */
    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 8
Source File: ProducerEvent.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
public ProducerEvent(Object target, Method method, EventThread thread) {
    if (target == null) {
        throw new NullPointerException("EventProducer target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("EventProducer method cannot be null.");
    }

    this.target = target;
    this.thread = thread;
    this.method = method;
    method.setAccessible(true);

    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 9
Source File: SubscriberEvent.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
public SubscriberEvent(Object target, Method method, EventThread thread) {
    if (target == null) {
        throw new NullPointerException("SubscriberEvent target cannot be null.");
    }
    if (method == null) {
        throw new NullPointerException("SubscriberEvent method cannot be null.");
    }
    if (thread == null) {
        throw new NullPointerException("SubscriberEvent thread cannot be null.");
    }

    this.target = target;
    this.method = method;
    this.thread = thread;
    method.setAccessible(true);
    initObservable();

    // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
    // target's hashCode call.
    final int prime = 31;
    hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 10
Source File: EventHandler.java    From divide with Apache License 2.0 6 votes vote down vote up
public EventHandler(Object target, Method method) {
  if (target == null) {
    throw new NullPointerException("EventHandler target cannot be null.");
  }
  if (method == null) {
    throw new NullPointerException("EventHandler method cannot be null.");
  }

  this.target = target;
  this.method = method;
  method.setAccessible(true);

  // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
  // target's hashCode call.
  final int prime = 31;
  hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 11
Source File: EventProducer.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
EventProducer(Object target, Method method) {
  if (target == null) {
    throw new NullPointerException("EventProducer target cannot be null.");
  }
  if (method == null) {
    throw new NullPointerException("EventProducer method cannot be null.");
  }

  this.target = target;
  this.method = method;
  method.setAccessible(true);

  // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
  // target's hashCode call.
  final int prime = 31;
  hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 12
Source File: EventHandler.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
EventHandler(Object target, Method method) {
  if (target == null) {
    throw new NullPointerException("EventHandler target cannot be null.");
  }
  if (method == null) {
    throw new NullPointerException("EventHandler method cannot be null.");
  }

  this.target = target;
  this.method = method;
  method.setAccessible(true);

  // Compute hash code eagerly since we know it will be used frequently and we cannot estimate the runtime of the
  // target's hashCode call.
  final int prime = 31;
  hashCode = (prime + method.hashCode()) * prime + target.hashCode();
}
 
Example 13
Source File: AnyProperty.java    From spearal-java with Apache License 2.0 6 votes vote down vote up
public AnyProperty(String name, Field field, Method getter, Method setter) {
	if (name == null || name.length() == 0)
		throw new IllegalArgumentException("Illegal property name: " + name);
	
	if (field != null)
		field.setAccessible(true);
	else if (getter == null)
		throw new IllegalArgumentException("Property '" + name + "' must have at least a field or a getter");

	this.name = name;
	this.field = field;
	this.getter = getter;
	this.setter = setter;
	
	this.type = typeOf(field, getter);
	this.genericType = genericTypeOf(field, getter);
	
	int hash = name.hashCode();
	hash += (31 * hash) + (field != null ? field.hashCode() : 0);
	hash += (31 * hash) + (getter != null ? getter.hashCode() : 0);
	hash += (31 * hash) + (setter != null ? setter.hashCode() : 0);
	this.hash = hash;
}
 
Example 14
Source File: EventHandler.java    From gimBUS with MIT License 5 votes vote down vote up
EventHandler(@NonNull Object subscriber, @NonNull Method method, @NonNull Dispatcher.DispatchingMethod dispatchingMethodd) {
    mSubscriber = new WeakReference<>(subscriber);
    mMethod = method;
    mDispatchingMethod = dispatchingMethodd;
    method.setAccessible(true);

    //Compute hash now, it will never change anyway, and it will be used frequently.
    //Plus it will not crash the app if GC clear the mSubscriber
    mHash = (31 + method.hashCode()) * 31 + System.identityHashCode(subscriber);
}
 
Example 15
Source File: EjbMethodInvoker.java    From tomee with Apache License 2.0 5 votes vote down vote up
public MostSpecificMethodKey(final Class<?> ejbInterface, final Method method) {
    this.ejbInterface = ejbInterface;
    this.method = method;

    // this class exists for map usage so simply precalculate hashcode
    hashCode = ejbInterface != null ? ejbInterface.hashCode() : 0;
    hashCode = 31 * hashCode + (method != null ? method.hashCode() : 0);
}
 
Example 16
Source File: TeaSpoonProcessor.java    From teaspoon with Apache License 2.0 5 votes vote down vote up
@Around("methodWithOnUiAnnotation()")
public void methodWithOnUiAnnotation(final ProceedingJoinPoint joinPoint) {
    Runnable runnableJoinPoint = new Runnable() {
        @Override public void run() {
            try {
                joinPoint.proceed();
            } catch (Throwable throwable) {
                throw new IllegalStateException(throwable);
            }
        }
    };

    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    Method method = methodSignature.getMethod();
    int methodHashCode = method.hashCode();

    int delay;

    if (processedMap.containsKey(methodHashCode)) {
        delay = processedMap.get(methodHashCode);
    } else {
        delay = processMethodAndGetDelay(method);
        processedMap.put(methodHashCode, delay);
    }

    TeaSpoon.getInstance().onUi(runnableJoinPoint, delay);
}
 
Example 17
Source File: AdvisedSupport.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public MethodCacheKey(Method method) {
	this.method = method;
	this.hashCode = method.hashCode();
}
 
Example 18
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
private MethodKey(final Class<?> base, final Method delegate)
{
    this.base = base; // we need a class to ensure inheritance don't fall in the same key
    this.delegate = delegate;
    this.hash = 31 * delegate.hashCode() + (base == null ? 0 : base.hashCode());
}
 
Example 19
Source File: AdvisedSupport.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public MethodCacheKey(Method method) {
	this.method = method;
	this.hashCode = method.hashCode();
}
 
Example 20
Source File: AdvisedSupport.java    From java-technology-stack with MIT License 4 votes vote down vote up
public MethodCacheKey(Method method) {
	this.method = method;
	this.hashCode = method.hashCode();
}