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

The following examples show how to use java.lang.reflect.Method#hashCode() . These examples are extracted from open source projects. 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 Project: SaveAndroidResources   File: EventProducer.java    License: 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 2
Source Project: SaveAndroidResources   File: EventHandler.java    License: 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 3
Source Project: AndroidBase   File: ProducerEvent.java    License: 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 4
Source Project: AndroidBase   File: SubscriberEvent.java    License: 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 5
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 6
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 7
Source Project: spearal-java   File: AnyProperty.java    License: 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 8
Source Project: divide   File: EventHandler.java    License: 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 9
Source Project: Noyze   File: EventHandler.java    License: 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 10
Source Project: SweetMusicPlayer   File: ProducerEvent.java    License: 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 11
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 12
Source Project: RxBus   File: ProducerEvent.java    License: 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 13
Source Project: divide   File: EventProducer.java    License: 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 14
Source Project: teaspoon   File: TeaSpoonProcessor.java    License: 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 15
Source Project: tomee   File: EjbMethodInvoker.java    License: 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 Project: gimBUS   File: EventHandler.java    License: 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 17
Source Project: spring-analysis-note   File: AdvisedSupport.java    License: MIT License 4 votes vote down vote up
public MethodCacheKey(Method method) {
	this.method = method;
	this.hashCode = method.hashCode();
}
 
Example 18
Source Project: java-technology-stack   File: AdvisedSupport.java    License: MIT License 4 votes vote down vote up
public MethodCacheKey(Method method) {
	this.method = method;
	this.hashCode = method.hashCode();
}
 
Example 19
public MethodCacheKey(Method method) {
	this.method = method;
	this.hashCode = method.hashCode();
}
 
Example 20
Source Project: commons-jcs   File: CDIJCacheHelper.java    License: 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());
}