Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 the original author or authors. Licensed 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 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.
Annotated fields and entities will be indexed and available for retrieval using an indexing API.
public @interface Indexed {
Name of the index to use.
    String indexName() default "";
    String fieldName() default "";
    boolean unique() default false;
    boolean numeric() default false;
    // FQN is a fix for javac compiler bug
    static class Name {
        public static String getDefault(Field field) {
            return get(field.getDeclaringClass());
        public static String get(Class<?> type) {
            return getIndexName(typetype.getSimpleName());
        private static String getIndexName(AnnotatedElement elementString defaultIndexName) {
            Indexed indexed = element.getAnnotation(Indexed.class);
            if (indexed == null || indexed.indexName() == null || indexed.indexName().isEmpty()) {
                return defaultIndexName;
            return indexed.indexName();
        public static String get(Field field) {
            return getIndexName(fieldgetDefault(field));
        public static String get(Level levelClass<?> typeString providedIndexNameClass<?> instanceType) {
            if (providedIndexName!=nullreturn providedIndexName;
            switch (level) {
                case return "nodes";
                case return get(type);
                case return get(instanceType);
                default : return get(type);
    enum Level { @Deprecated GLOBAL, CLASS, INSTANCE}
New to GrepCode? Check out our FAQ X