当前位置: 首页>>代码示例>>Java>>正文


Java Tag类代码示例

本文整理汇总了Java中io.protostuff.Tag的典型用法代码示例。如果您正苦于以下问题:Java Tag类的具体用法?Java Tag怎么用?Java Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Tag类属于io.protostuff包,在下文中一共展示了Tag类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RuntimeDerivativeField

import io.protostuff.Tag; //导入依赖的package包/类
public RuntimeDerivativeField(Class<Object> typeClass, FieldType type,
        int number, String name, boolean repeated, Tag tag,
        IdStrategy strategy)
{
    super(type, number, name, repeated, tag);
    this.typeClass = typeClass;

    schema = new DerivativeSchema(strategy)
    {
        @Override
        protected void doMergeFrom(Input input,
                Schema<Object> derivedSchema, Object owner)
                throws IOException
        {
            RuntimeDerivativeField.this.doMergeFrom(input, derivedSchema,
                    owner);
        }
    };
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:20,代码来源:RuntimeDerivativeField.java

示例2: EnumIO

import io.protostuff.Tag; //导入依赖的package包/类
public EnumIO(Class<E> enumClass)
{
    this.enumClass = enumClass;
    Field[] fields = enumClass.getFields();
    int n = fields.length;
    alias = new String[n];
    tag = new int[n];
    valueByAliasMap = new HashMap<>(n * 2);
    valueByTagMap = new HashMap<>(n * 2);
    for (E instance : enumClass.getEnumConstants())
    {
        int ordinal = instance.ordinal();
        try
        {
            Field field = enumClass.getField(instance.name());
            if (field.isAnnotationPresent(Tag.class))
            {
                Tag annotation = field.getAnnotation(Tag.class);
                tag[ordinal] = annotation.value();
                alias[ordinal] = annotation.alias();
                valueByTagMap.put(annotation.value(), instance);
                valueByAliasMap.put(annotation.alias(), instance);
            }
            else
            {
                tag[ordinal] = ordinal;
                alias[ordinal] = field.getName();
                valueByTagMap.put(ordinal, instance);
                valueByAliasMap.put(field.getName(), instance);
            }
        }
        catch (NoSuchFieldException e)
        {
            throw new IllegalStateException(e);
        }
    }
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:38,代码来源:EnumIO.java

示例3: Field

import io.protostuff.Tag; //导入依赖的package包/类
public Field(WireFormat.FieldType type, int number, String name, boolean repeated,
        Tag tag)
{
    this.type = type;
    this.number = number;
    this.name = name;
    this.repeated = repeated;
    this.groupFilter = tag == null ? 0 : tag.groupFilter();
    // this.tag = tag;
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:11,代码来源:Field.java

示例4: RuntimeMessageField

import io.protostuff.Tag; //导入依赖的package包/类
public RuntimeMessageField(Class<P> typeClass, HasSchema<P> hasSchema,
        FieldType type, int number, String name, boolean repeated, Tag tag)
{
    super(type, number, name, repeated, tag);
    this.typeClass = typeClass;
    this.hasSchema = hasSchema;
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:8,代码来源:RuntimeMessageField.java

示例5: RuntimeCollectionField

import io.protostuff.Tag; //导入依赖的package包/类
public RuntimeCollectionField(FieldType type, int number, String name,
        Tag tag, MessageFactory messageFactory)
{
    super(type, number, name, false, tag);
    schema = new CollectionSchema<V>(messageFactory)
    {
        @Override
        protected void addValueFrom(Input input, Collection<V> collection)
                throws IOException
        {
            RuntimeCollectionField.this.addValueFrom(input, collection);
        }

        @Override
        protected void writeValueTo(Output output, int fieldNumber,
                V value, boolean repeated) throws IOException
        {
            RuntimeCollectionField.this.writeValueTo(output, fieldNumber,
                    value, repeated);
        }

        @Override
        protected void transferValue(Pipe pipe, Input input, Output output,
                int number, boolean repeated) throws IOException
        {
            RuntimeCollectionField.this.transferValue(pipe, input, output,
                    number, repeated);
        }
    };
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:31,代码来源:RuntimeCollectionField.java

示例6: RuntimeObjectField

import io.protostuff.Tag; //导入依赖的package包/类
public RuntimeObjectField(Class<?> typeClass, FieldType type, int number,
        String name, boolean repeated, Tag tag,
        PolymorphicSchema.Factory factory, IdStrategy strategy)
{
    super(type, number, name, repeated, tag);

    schema = factory.newSchema(typeClass, strategy, this);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:9,代码来源:RuntimeObjectField.java

示例7: EnumIO

import io.protostuff.Tag; //导入依赖的package包/类
public EnumIO(Class<E> enumClass, IdStrategy strategy)
{
    this.enumClass = enumClass;
    this.strategy = strategy;
    genericElementSchema = new ArraySchemas.EnumArray(strategy, null, this);
    
    Field[] fields = enumClass.getFields();
    int n = fields.length;
    alias = new String[n];
    tag = new int[n];
    valueByAliasMap = new HashMap<String, E>(n * 2);
    valueByTagMap = new HashMap<Integer, E>(n * 2);
    for (E instance : enumClass.getEnumConstants())
    {
        int ordinal = instance.ordinal();
        try
        {
            Field field = enumClass.getField(instance.name());
            if (field.isAnnotationPresent(Tag.class))
            {
                Tag annotation = field.getAnnotation(Tag.class);
                tag[ordinal] = annotation.value();
                alias[ordinal] = annotation.alias();
                valueByTagMap.put(annotation.value(), instance);
                valueByAliasMap.put(annotation.alias(), instance);
            }
            else
            {
                tag[ordinal] = ordinal;
                alias[ordinal] = field.getName();
                valueByTagMap.put(ordinal, instance);
                valueByAliasMap.put(field.getName(), instance);
            }
        }
        catch (NoSuchFieldException e)
        {
            throw new IllegalStateException(e);
        }
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:41,代码来源:EnumIO.java

示例8: RuntimeMapField

import io.protostuff.Tag; //导入依赖的package包/类
public RuntimeMapField(FieldType type, int number, String name, Tag tag,
        MessageFactory messageFactory)
{
    super(type, number, name, false, tag);
    schema = new MapSchema<K, V>(messageFactory)
    {
        @Override
        protected K readKeyFrom(Input input, MapWrapper<K, V> wrapper)
                throws IOException
        {
            return kFrom(input, wrapper);
        }

        @Override
        protected void putValueFrom(Input input, MapWrapper<K, V> wrapper,
                K key) throws IOException
        {
            vPutFrom(input, wrapper, key);
        }

        @Override
        protected void writeKeyTo(Output output, int fieldNumber, K key,
                boolean repeated) throws IOException
        {
            kTo(output, fieldNumber, key, repeated);
        }

        @Override
        protected void writeValueTo(Output output, int fieldNumber, V val,
                boolean repeated) throws IOException
        {
            vTo(output, fieldNumber, val, repeated);
        }

        @Override
        protected void transferKey(Pipe pipe, Input input, Output output,
                int number, boolean repeated) throws IOException
        {
            kTransfer(pipe, input, output, number, repeated);
        }

        @Override
        protected void transferValue(Pipe pipe, Input input, Output output,
                int number, boolean repeated) throws IOException
        {
            vTransfer(pipe, input, output, number, repeated);
        }
    };
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:50,代码来源:RuntimeMapField.java

示例9: createFrom

import io.protostuff.Tag; //导入依赖的package包/类
/**
 * Generates a schema from the given class with the exclusion of certain fields.
 */
public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass,
        Set<String> exclusions, IdStrategy strategy)
{
    if (typeClass.isInterface()
            || Modifier.isAbstract(typeClass.getModifiers()))
    {
        throw new RuntimeException(
                "The root object can neither be an abstract "
                        + "class nor interface: \"" + typeClass.getName());
    }

    final Map<String, java.lang.reflect.Field> fieldMap = findInstanceFields(typeClass);
    final ArrayList<Field<T>> fields = new ArrayList<>(
            fieldMap.size());
    int i = 0;
    boolean annotated = false;
    for (java.lang.reflect.Field f : fieldMap.values())
    {
        if (!exclusions.contains(f.getName()))
        {
            if (f.getAnnotation(Deprecated.class) != null)
            {
                // this field should be ignored by ProtoStuff.
                // preserve its field number for backward-forward compat
                i++;
                continue;
            }

            final Tag tag = f.getAnnotation(Tag.class);
            final int fieldMapping;
            final String name;
            if (tag == null)
            {
                // Fields gets assigned mapping tags according to their
                // definition order
                if (annotated)
                {
                    throw new RuntimeException(
                            "When using annotation-based mapping, "
                                    + "all fields must be annotated with @"
                                    + Tag.class.getSimpleName());
                }
                fieldMapping = ++i;

                name = f.getName();
            }
            else
            {
                // Fields gets assigned mapping tags according to their
                // annotation
                if (!annotated && !fields.isEmpty())
                {
                    throw new RuntimeException(
                            "When using annotation-based mapping, "
                                    + "all fields must be annotated with @"
                                    + Tag.class.getSimpleName());
                }
                annotated = true;
                fieldMapping = tag.value();

                if (fieldMapping < MIN_TAG_VALUE || fieldMapping > MAX_TAG_VALUE)
                {
                    throw new IllegalArgumentException(ERROR_TAG_VALUE + ": " + fieldMapping + " on " + typeClass);
                }

                name = tag.alias().isEmpty() ? f.getName() : tag.alias();
            }

            final Field<T> field = RuntimeFieldFactory.getFieldFactory(
                    f.getType(), strategy).create(fieldMapping, name, f,
                    strategy);
            fields.add(field);
        }
    }

    return new RuntimeSchema<>(typeClass, fields, RuntimeEnv.newInstantiator(typeClass));
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:81,代码来源:RuntimeSchema.java

示例10: createFrom

import io.protostuff.Tag; //导入依赖的package包/类
/**
 * Generates a schema from the given class with the exclusion of certain fields.
 */
public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass,
        Set<String> exclusions, IdStrategy strategy)
{
    if (typeClass.isInterface()
            || Modifier.isAbstract(typeClass.getModifiers()))
    {
        throw new RuntimeException(
                "The root object can neither be an abstract "
                        + "class nor interface: \"" + typeClass.getName());
    }

    final Map<String, java.lang.reflect.Field> fieldMap = findInstanceFields(typeClass);
    final ArrayList<Field<T>> fields = new ArrayList<Field<T>>(
            fieldMap.size());
    int i = 0;
    boolean annotated = false;
    for (java.lang.reflect.Field f : fieldMap.values())
    {
        if (!exclusions.contains(f.getName()))
        {
            if (f.getAnnotation(Deprecated.class) != null)
            {
                // this field should be ignored by ProtoStuff.
                // preserve its field number for backward-forward compat
                i++;
                continue;
            }

            final Tag tag = f.getAnnotation(Tag.class);
            final int fieldMapping;
            final String name;
            if (tag == null)
            {
                // Fields gets assigned mapping tags according to their
                // definition order
                if (annotated)
                {
                    String className = typeClass.getCanonicalName();
                    String fieldName = f.getName();
                    String message = String.format("%s#%s is not annotated with @Tag", className, fieldName);
                    throw new RuntimeException(message);
                }
                fieldMapping = ++i;

                name = f.getName();
            }
            else
            {
                // Fields gets assigned mapping tags according to their
                // annotation
                if (!annotated && !fields.isEmpty())
                {
                    throw new RuntimeException(
                            "When using annotation-based mapping, "
                                    + "all fields must be annotated with @"
                                    + Tag.class.getSimpleName());
                }
                annotated = true;
                fieldMapping = tag.value();

                if (fieldMapping < MIN_TAG_VALUE || fieldMapping > MAX_TAG_VALUE)
                {
                    throw new IllegalArgumentException(ERROR_TAG_VALUE + ": " + fieldMapping + " on " + typeClass);
                }

                name = tag.alias().isEmpty() ? f.getName() : tag.alias();
            }

            final Field<T> field = RuntimeFieldFactory.getFieldFactory(
                    f.getType(), strategy).create(fieldMapping, name, f,
                    strategy);
            fields.add(field);
        }
    }

    return new RuntimeSchema<T>(typeClass, fields,
            RuntimeEnv.newInstantiator(typeClass));
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:82,代码来源:RuntimeSchema.java


注:本文中的io.protostuff.Tag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。