當前位置: 首頁>>代碼示例>>Java>>正文


Java Priority類代碼示例

本文整理匯總了Java中javax.annotation.Priority的典型用法代碼示例。如果您正苦於以下問題:Java Priority類的具體用法?Java Priority怎麽用?Java Priority使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Priority類屬於javax.annotation包,在下文中一共展示了Priority類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stopWatching

import javax.annotation.Priority; //導入依賴的package包/類
private final void stopWatching(@Observes @BeforeDestroyed(ApplicationScoped.class) @Priority(LIBRARY_BEFORE) final Object event) throws Exception {
  final Closeable watch = this.watch;
  if (watch != null) {
    KubernetesClientException closeException = this.closeException;
    try {
      watch.close();
    } catch (final Exception everything) {
      if (closeException != null) {
        closeException.addSuppressed(everything);
        throw closeException;
      } else {
        throw everything;
      }
    }
    if (closeException != null) {
      throw closeException;
    }
  }
}
 
開發者ID:microbean,項目名稱:microbean-kubernetes-client-cdi,代碼行數:20,代碼來源:KubernetesClientExtension.java

示例2: alternatives

import javax.annotation.Priority; //導入依賴的package包/類
/**
 * Activates the alternatives declared with {@code @Beans} globally for the
 * application.
 * <p/>
 * For every types and every methods of every types declared with
 * {@link Beans#alternatives()}, the {@code Priority} annotation is added
 * so that the corresponding alternatives are selected globally for the
 * entire application.
 *
 * @see Beans
 */
private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) {
    AnnotatedType<T> type = pat.getAnnotatedType();

    if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) {
        // Only select globally the alternatives that are declared with @Beans
        return;
    }

    Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
    for (AnnotatedMethod<? super T> method : type.getMethods()) {
        if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) {
            methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION)));
        }
    }

    if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) {
        pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods));
    } else if (!methods.isEmpty()) {
        pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods));
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:33,代碼來源:CamelCdiTestExtension.java

示例3: compareServices

import javax.annotation.Priority; //導入依賴的package包/類
public static int compareServices(Object o1, Object o2) {
    int prio1 = 0;
    int prio2 = 0;
    Priority prio1Annot = o1.getClass().getAnnotation(Priority.class);
    if (prio1Annot != null) {
        prio1 = prio1Annot.value();
    }
    Priority prio2Annot = o2.getClass().getAnnotation(Priority.class);
    if (prio2Annot != null) {
        prio2 = prio2Annot.value();
    }
    if (prio1 < prio2) {
        return 1;
    }
    if (prio2 < prio1) {
        return -1;
    }
    return o2.getClass().getSimpleName().compareTo(o1.getClass().getSimpleName());
}
 
開發者ID:JavaMoney,項目名稱:jsr354-ri-bp,代碼行數:20,代碼來源:PriorityAwareServiceProvider.java

示例4: beans

import javax.annotation.Priority; //導入依賴的package包/類
public <X> void beans(
        final @Observes ProcessAnnotatedType<X> processBean
) {
    if (!processBean.getAnnotatedType().isAnnotationPresent(Interceptor.class)) {
        return;
    }
    final FilteringAnnotatedTypeWrapper<X> filtered = new FilteringAnnotatedTypeWrapper<>(
            processBean.getAnnotatedType(),
            it -> it != Priority.class
    );
    processBean.setAnnotatedType(filtered);
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:13,代碼來源:MockingExtension.java

示例5: getPriority

import javax.annotation.Priority; //導入依賴的package包/類
/**
 * The priority of this mapper.  By default, it will use the {@link Priority} annotation's value as the priority.
 * If no annotation is present, it uses a default priority of {@link Priorities#USER}.
 * @return the priority of this mapper
 */
default int getPriority() {
    Priority priority = getClass().getAnnotation(Priority.class);
    if(priority == null) {
        return DEFAULT_PRIORITY;
    }
    return priority.value();
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:13,代碼來源:ResponseExceptionMapper.java

示例6: testAnnotations

import javax.annotation.Priority; //導入依賴的package包/類
@Test
public void testAnnotations() {
  // Check that the class is correctly annotated
  assertNotNull("@PreMatching annotation is required to modify headers", MediaTypeFilter.class.getAnnotation(PreMatching.class));
  Priority priority = MediaTypeFilter.class.getAnnotation(Priority.class);
  assertNotNull("@Priority annotation is required to modify headers", priority);

  assertTrue("priority should be higher than HEADER_DECORATOR", priority.value() <= Priorities.HEADER_DECORATOR);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:10,代碼來源:TestMediaTypeFilter.java

示例7: find

import javax.annotation.Priority; //導入依賴的package包/類
/**
 * Finds view engine for a viewable.
 *
 * @param viewable the viewable to be used.
 * @return selected view engine or {@code null} if none found.
 */
public ViewEngine find(Viewable viewable) {
    Optional<ViewEngine> engine;
    final String view = viewable.getView();

    // If engine specified in viewable, use it
    final Class<? extends ViewEngine> engineClass = viewable.getViewEngine();
    if (engineClass != null) {
        engine = Optional.of(cdiUtils.newBean(engineClass));
    } else {
        // Check cache first
        engine = Optional.ofNullable(cache.get(view));

        if (!engine.isPresent()) {
            List<ViewEngine> engines = CdiUtils.getApplicationBeans(ViewEngine.class);

            // Gather set of candidates
            final Set<ViewEngine> candidates = engines.stream()
                    .filter(e -> e.supports(view)).collect(toSet());

            // Find candidate with highest priority
            engine = candidates.stream().max(
                    (e1, e2) -> {
                        final Priority p1 = getAnnotation(e1.getClass(), Priority.class);
                        final int v1 = p1 != null ? p1.value() : Priorities.DEFAULT;
                        final Priority p2 = getAnnotation(e2.getClass(), Priority.class);
                        final int v2 = p2 != null ? p2.value() : Priorities.DEFAULT;
                        return v1 - v2;
                    });
            // Update cache
            if (engine.isPresent()) {
                cache.put(view, engine.get());
            }
        }
    }
    return engine.isPresent() ? engine.get() : null;
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:43,代碼來源:ViewEngineFinder.java

示例8: resolve

import javax.annotation.Priority; //導入依賴的package包/類
public Locale resolve(ContainerRequestContext requestContext) {

        // prepare context instance
        LocaleResolverContext context = new LocaleResolverContextImpl(configuration, requestContext);

        List<LocaleResolver> resolvers = CdiUtils.getApplicationBeans(LocaleResolver.class);

        // candidates as sorted list
        List<LocaleResolver> candidates = StreamSupport.stream(resolvers.spliterator(), false)
                .sorted((resolver1, resolver2) -> {
                    final Priority prio1 = getAnnotation(resolver1.getClass(), Priority.class);
                    final Priority prio2 = getAnnotation(resolver2.getClass(), Priority.class);
                    final int value1 = prio1 != null ? prio1.value() : 1000;
                    final int value2 = prio2 != null ? prio2.value() : 1000;
                    return value2 - value1;
                })
                .collect(Collectors.toList());

        // do the resolving
        for (LocaleResolver candidate : candidates) {
            Locale locale = candidate.resolveLocale(context);
            if (locale != null) {
                return locale;
            }
        }

        throw new IllegalStateException("Could not resolve locale with any of the " + candidates.size()
                + " resolver implementations");

    }
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:31,代碼來源:LocaleResolverChain.java

示例9: getPriority

import javax.annotation.Priority; //導入依賴的package包/類
private int getPriority(Converter<?> converter) {
    int priority = 100;
    Priority priorityAnnotation = converter.getClass().getAnnotation(Priority.class);
    if (priorityAnnotation != null) {
        priority = priorityAnnotation.value();
    }
    return priority;
}
 
開發者ID:struberg,項目名稱:javaConfig,代碼行數:9,代碼來源:ConfigImpl.java

示例10: returnPrimaryOrHighestPriorityBean

import javax.annotation.Priority; //導入依賴的package包/類
private Object returnPrimaryOrHighestPriorityBean(List<Bean> beans) {

            long highestPriority = Integer.MIN_VALUE;
            Object highestPrioBean = null;

            for (Bean bean : beans) {

                if (bean.isPrimary()) {
                    return bean.getInstance();
                }

                // TODO figure out to retrieve order from BeanDefinition /
                // BeanDeclaration

                Object instance = bean.getInstance();
                Order order = instance.getClass().getAnnotation(Order.class);
                if (order != null) {
                    if (order.value() > highestPriority) {
                        highestPriority = order.value();
                        highestPrioBean = instance;
                    }
                }

                Priority priority = instance.getClass().getAnnotation(Priority.class);
                if (priority != null) {
                    if (priority.value() > highestPriority) {
                        highestPriority = priority.value();
                        highestPrioBean = instance;
                    }
                }
            }

            return highestPrioBean;
        }
 
開發者ID:thomasdarimont,項目名稱:spring-boot-cdi-instance-example,代碼行數:35,代碼來源:CustomAutowireCandidateResolver.java

示例11: compareTo

import javax.annotation.Priority; //導入依賴的package包/類
@Override
public int compareTo(Object o) {
    if (!(o instanceof Filter)) return 1;
    Priority p1 = this.getClass().getAnnotation(Priority.class);
    Priority p2 = o.getClass().getAnnotation(Priority.class);
    return (p2 == null ? 0 : p2.value()) - (p1 == null ? 0 : p1.value());
}
 
開發者ID:redkale,項目名稱:redkale,代碼行數:8,代碼來源:Filter.java

示例12: getPriority

import javax.annotation.Priority; //導入依賴的package包/類
/**
   * Checks the given type optionally annotated with a @Priority. If present the annotation's value is evaluated.
   * If no such annotation is present, a default priority {@code 1} is returned.
   *
   * @param type the type, not {@code null}.
   * @return a priority, by default 1.
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public static int getPriority(Class type) {
      int prio = 1;
Priority priority = (Priority)type.getAnnotation(Priority.class);
      if (priority != null) {
          prio = priority.value();
      }
      return prio;
  }
 
開發者ID:apache,項目名稱:incubator-tamaya,代碼行數:17,代碼來源:PriorityServiceComparator.java

示例13: getPriority

import javax.annotation.Priority; //導入依賴的package包/類
/**
 * Checks the given instance for a @Priority annotation. If present the annotation's value is evaluated. If no such
 * annotation is present, a default priority of {@code 1} is returned.
 * @param o the instance, not {@code null}.
 * @return a priority, by default 1.
 */
public static int getPriority(Object o){
    int prio = 1; //X TODO discuss default priority
    Priority priority = o.getClass().getAnnotation(Priority.class);
    if (priority != null) {
        prio = priority.value();
    }
    return prio;
}
 
開發者ID:apache,項目名稱:incubator-tamaya,代碼行數:15,代碼來源:DefaultServiceContext.java

示例14: comparePropertyFilters

import javax.annotation.Priority; //導入依賴的package包/類
/**
 * Compare 2 filters for ordering the filter chain.
 *
 * @param filter1 the first filter
 * @param filter2 the second filter
 * @return the comparison result
 */
private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
    Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
    Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
    int ord1 = prio1 != null ? prio1.value() : 0;
    int ord2 = prio2 != null ? prio2.value() : 0;

    if (ord1 < ord2) {
        return -1;
    } else if (ord1 > ord2) {
        return 1;
    } else {
        return filter1.getClass().getName().compareTo(filter2.getClass().getName());
    }
}
 
開發者ID:apache,項目名稱:incubator-tamaya,代碼行數:22,代碼來源:PropertyFilterComparator.java

示例15: getPriority

import javax.annotation.Priority; //導入依賴的package包/類
/**
 * Checks the given type optionally annotated with a @Priority. If present the annotation's value is evaluated.
 * If no such annotation is present, a default priority {@code 1} is returned.
 *
 * @param type the type, not {@code null}.
 * @return a priority, by default 1.
 */
public static int getPriority(Class<? extends Object> type) {
    int prio = 1;
    Priority priority = type.getAnnotation(Priority.class);
    if (priority != null) {
        prio = priority.value();
    }
    return prio;
}
 
開發者ID:apache,項目名稱:incubator-tamaya,代碼行數:16,代碼來源:OSGIServiceComparator.java


注:本文中的javax.annotation.Priority類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。