use of org.springframework.core.Ordered in project BroadleafCommerce by BroadleafCommerce.
the class SortedListFactoryBean method createInstance.
@Override
protected List createInstance() {
List response = super.createInstance();
Collections.sort(response, new Comparator<Ordered>() {
@Override
public int compare(Ordered o1, Ordered o2) {
return new Integer(o1.getOrder()).compareTo(o2.getOrder());
}
});
return response;
}
use of org.springframework.core.Ordered in project grails-core by grails.
the class DefaultGrailsCodecClass method initializeCodec.
private void initializeCodec() {
if (initialized)
return;
initialized = true;
Integer orderSetting = getStaticPropertyValue("order", Integer.class);
if (orderSetting != null) {
order = orderSetting;
}
Object instance = getReferenceInstance();
if (Encoder.class.isAssignableFrom(getClazz())) {
encoder = (Encoder) instance;
encoder = (Encoder) autowireCodecBean(encoder);
if (encoder instanceof Ordered) {
order = ((Ordered) encoder).getOrder();
}
}
if (Decoder.class.isAssignableFrom(getClazz())) {
decoder = (Decoder) instance;
decoder = (Decoder) autowireCodecBean(decoder);
if (decoder instanceof Ordered) {
order = ((Ordered) decoder).getOrder();
}
}
if (encoder == null && decoder == null) {
CodecFactory codecFactory = null;
if (CodecFactory.class.isAssignableFrom(getClazz())) {
codecFactory = (CodecFactory) instance;
codecFactory = (CodecFactory) autowireCodecBean(codecFactory);
}
if (codecFactory == null) {
codecFactory = getStaticPropertyValue("codecFactory", CodecFactory.class);
codecFactory = (CodecFactory) autowireCodecBean(codecFactory);
}
if (codecFactory == null) {
codecFactory = new ClosureCodecFactory(instance);
}
encoder = codecFactory.getEncoder();
decoder = codecFactory.getDecoder();
if (codecFactory instanceof Ordered) {
order = ((Ordered) codecFactory).getOrder();
}
}
if (encoder != null) {
if (encoder instanceof StreamingEncoder) {
encoder = new StreamingStateAwareEncoderWrapper((StreamingEncoder) encoder);
} else {
encoder = new StateAwareEncoderWrapper(encoder);
}
}
}
use of org.springframework.core.Ordered in project pentaho-platform by pentaho.
the class OrderedApplicationEventMulticaster method multicastEvent.
@SuppressWarnings("unchecked")
@Override
public void multicastEvent(final ApplicationEvent event) {
List<ApplicationListener> listeners = new ArrayList<ApplicationListener>(getApplicationListeners());
// sort listeners
Collections.sort(listeners, new Comparator<ApplicationListener>() {
public int compare(final ApplicationListener o1, final ApplicationListener o2) {
if (o1 instanceof Ordered && o2 instanceof Ordered) {
return new Integer(((Ordered) o1).getOrder()).compareTo(new Integer(((Ordered) o2).getOrder()));
} else if (o1 instanceof Ordered) {
return -1;
} else if (o2 instanceof Ordered) {
return 1;
} else {
return 0;
}
}
});
// iterate over sorted listeners
for (final ApplicationListener listener : listeners) {
getTaskExecutor().execute(new Runnable() {
public void run() {
listener.onApplicationEvent(event);
}
});
}
}
Aggregations