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


Java MapSchema類代碼示例

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


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

示例1: newEnumMapFactory

import io.protostuff.MapSchema; //導入依賴的package包/類
private static <E extends Enum<E>> MapSchema.MessageFactory newEnumMapFactory(
        final EnumIO<E> eio)
{
    return new MapSchema.MessageFactory()
    {
        @Override
        @SuppressWarnings("unchecked")
        public <K, V> Map<K, V> newMessage()
        {
            return (Map<K, V>) eio.newEnumMap();
        }

        @Override
        public Class<?> typeClass()
        {
            return EnumMap.class;
        }
    };
}
 
開發者ID:BFergerson,項目名稱:Beam,代碼行數:20,代碼來源:EnumIO.java

示例2: getMapFactory

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
protected MapSchema.MessageFactory getMapFactory(Class<?> clazz)
{
    final String className = clazz.getName();
    MapSchema.MessageFactory factory = mapMapping.get(className);
    if (factory == null)
    {
        if (className.startsWith("java.util"))
        {
            factory = MapSchema.MessageFactories.valueOf(clazz
                    .getSimpleName());
        }
        else
        {
            factory = new RuntimeMapFactory(clazz);
            MapSchema.MessageFactory f = mapMapping.putIfAbsent(className,
                    factory);
            if (f != null)
                factory = f;
        }
    }

    return factory;
}
 
開發者ID:BFergerson,項目名稱:Beam,代碼行數:25,代碼來源:DefaultIdStrategy.java

示例3: writeMapIdTo

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
protected void writeMapIdTo(Output output, int fieldNumber, Class<?> clazz)
        throws IOException
{
    final MapSchema.MessageFactory factory = mapMapping.get(clazz);
    if (factory == null && clazz.getName().startsWith("java.util"))
    {
        // jdk map
        // better not to register the jdk map if using this strategy
        // as it saves space by not writing the full package
        output.writeString(fieldNumber, clazz.getSimpleName(), false);
    }
    else
    {
        output.writeString(fieldNumber, clazz.getName(), false);
    }
}
 
開發者ID:BFergerson,項目名稱:Beam,代碼行數:18,代碼來源:DefaultIdStrategy.java

示例4: resolveMapFrom

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
protected MapSchema.MessageFactory resolveMapFrom(Input input)
        throws IOException
{
    final String className = input.readString();
    MapSchema.MessageFactory factory = mapMapping.get(className);
    if (factory == null)
    {
        if (className.indexOf('.') == -1)
        {
            factory = MapSchema.MessageFactories.valueOf(className);
        }
        else
        {
            factory = new RuntimeMapFactory(RuntimeEnv.loadClass(className));
            MapSchema.MessageFactory f = mapMapping.putIfAbsent(className,
                    factory);
            if (f != null)
                factory = f;
        }
    }

    return factory;
}
 
開發者ID:BFergerson,項目名稱:Beam,代碼行數:25,代碼來源:DefaultIdStrategy.java

示例5: registerMap

import io.protostuff.MapSchema; //導入依賴的package包/類
/**
 * Map ids start at 1.
 */
@Override
public <T extends Map<?, ?>> Registry registerMap(
        MapSchema.MessageFactory factory, int id)
{
    if (id < 1)
        throw new IllegalArgumentException("map ids start at 1.");

    if (id >= strategy.mapIdStart)
        throw new IllegalArgumentException("map ids must be lesser than " + strategy.mapIdStart);
    else if (strategy.maps.get(id) != null)
    {
        throw new IllegalArgumentException("Duplicate id registration: " + id +
                " (" + factory.typeClass() + ")");
    }

    RuntimeMapFactory rf = new RuntimeMapFactory();
    rf.id = id;
    rf.factory = factory;
    strategy.maps.set(id, rf);
    // just in case
    if (strategy.mapMapping.put(factory.typeClass(), rf) != null)
        throw new IllegalArgumentException("Duplicate registration for: " + factory.typeClass());

    return this;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:29,代碼來源:IncrementalIdStrategy.java

示例6: registerMap

import io.protostuff.MapSchema; //導入依賴的package包/類
/**
 * Map ids start at 1.
 */
@Override
public <T extends Map<?, ?>> Registry registerMap(
        MapSchema.MessageFactory factory, int id)
{
    if (id < 1)
        throw new IllegalArgumentException("map ids start at 1.");

    if (id >= strategy.maps.size())
        grow(strategy.maps, id + 1);
    else if (strategy.maps.get(id) != null)
    {
        throw new IllegalArgumentException("Duplicate id registration: " + id +
                " (" + factory.typeClass() + ")");
    }

    RegisteredMapFactory rf = new RegisteredMapFactory(id, factory);
    strategy.maps.set(id, rf);
    // just in case
    if (strategy.mapMapping.put(factory.typeClass(), rf) != null)
        throw new IllegalArgumentException("Duplicate registration for: " + factory.typeClass());

    return this;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:27,代碼來源:ExplicitIdStrategy.java

示例7: getEnumMapFactory

import io.protostuff.MapSchema; //導入依賴的package包/類
/**
 * Returns the factory for an EnumMap (lazy).
 */
public MapSchema.MessageFactory getEnumMapFactory()
{
    MapSchema.MessageFactory enumMapFactory = this.enumMapFactory;
    if (enumMapFactory == null)
    {
        synchronized (this)
        {
            if ((enumMapFactory = this.enumMapFactory) == null)
                this.enumMapFactory = enumMapFactory = newEnumMapFactory(this);
        }
    }
    return enumMapFactory;
}
 
開發者ID:BFergerson,項目名稱:Beam,代碼行數:17,代碼來源:EnumIO.java

示例8: create

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
public IdStrategy create()
{
    return new IncrementalIdStrategy(
            CollectionSchema.MessageFactories.values().length, 1,
            MapSchema.MessageFactories.values().length, 1,
            16, 1, // enums
            64, 1); // pojos
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:10,代碼來源:IncrementalIdStrategy.java

示例9: getRuntimeMapFactory

import io.protostuff.MapSchema; //導入依賴的package包/類
private RuntimeMapFactory getRuntimeMapFactory(Class<?> clazz)
{
    RuntimeMapFactory rfactory = mapMapping.get(clazz);
    if (rfactory == null)
    {
        rfactory = new RuntimeMapFactory();
        RuntimeMapFactory f = mapMapping.putIfAbsent(
                clazz, rfactory);
        if (f != null)
            rfactory = f;
        else
        {
            if (clazz.getName().startsWith("java.util"))
            {
                rfactory.factory = MapSchema.MessageFactories.valueOf(
                        clazz.getSimpleName());
            }
            else
            {
                rfactory.instantiator = RuntimeEnv.newInstantiator(clazz);
                rfactory.mapClass = clazz;
            }

            int id = mapId.getAndIncrement();
            maps.set(id, rfactory);

            // commit
            rfactory.id = id;
        }
    }

    return rfactory;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:34,代碼來源:IncrementalIdStrategy.java

示例10: resolveMapFrom

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
protected MapSchema.MessageFactory resolveMapFrom(Input input)
        throws IOException
{
    final int id = input.readUInt32();

    final RuntimeMapFactory factory = id < maps.size() ? maps.get(id) : null;
    if (factory == null)
        throw new UnknownTypeException("Unknown map id: " + id);

    return factory;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:13,代碼來源:IncrementalIdStrategy.java

示例11: getMapFactory

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
protected MapSchema.MessageFactory getMapFactory(Class<?> clazz)
{
    final RegisteredMapFactory rf = mapMapping.get(clazz);
    if (rf == null)
    {
        if (clazz.getName().startsWith("java.util"))
            return MapSchema.MessageFactories.valueOf(clazz.getSimpleName());

        throw new UnknownTypeException("map: " + clazz);
    }

    return rf;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:15,代碼來源:ExplicitIdStrategy.java

示例12: resolveMapFrom

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
protected MapSchema.MessageFactory resolveMapFrom(Input input)
        throws IOException
{
    final int id = input.readUInt32();

    final MapSchema.MessageFactory factory = id < maps.size() ? maps.get(id) : null;
    if (factory == null)
        throw new UnknownTypeException("map id: " + id + " (Outdated registry)");

    return factory;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:13,代碼來源:ExplicitIdStrategy.java

示例13: postCreate

import io.protostuff.MapSchema; //導入依賴的package包/類
@Override
public void postCreate()
{
    r.registerCollection(CollectionSchema.MessageFactories.ArrayList, 1)
            .registerCollection(CollectionSchema.MessageFactories.HashSet, 2)
            .registerCollection(CustomArrayList.MESSAGE_FACTORY, 3);

    r.registerMap(MapSchema.MessageFactories.HashMap, 1)
            .registerMap(MapSchema.MessageFactories.LinkedHashMap, 2)
            .registerMap(CustomHashMap.MESSAGE_FACTORY, 3);

    r.registerEnum(Size.class, 1)
            .registerEnum(GuitarPickup.class, 2);

    r.registerPojo(AcousticGuitar.class, 1)
            .registerPojo(BassGuitar.class, 2)
            .registerPojo(Pojo.class, 3)
            .registerPojo(PojoWithArray.class, 4)
            .registerPojo(PojoWithArray2D.class, 5)
            .registerPojo(PojoWithCollection.class, 6)
            .registerPojo(PojoWithMap.class, 7)
            .registerPojo(Bat.SCHEMA, Bat.PIPE_SCHEMA, 8)
            .registerPojo(WrapsBat.class, 9)
            .registerPojo(PojoWithCustomArrayListAndHashMap.class, 10);

    r.registerDelegate(new ShortArrayDelegate(), 1);
    r.registerDelegate(SINGLETON_DELEGATE, 2);

    r = null;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:31,代碼來源:IncrementalRuntimeObjectSchemaTest.java

示例14: RuntimeMapField

import io.protostuff.MapSchema; //導入依賴的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

示例15: resolveMapFrom

import io.protostuff.MapSchema; //導入依賴的package包/類
protected abstract MapSchema.MessageFactory resolveMapFrom(Input input)
throws IOException;
 
開發者ID:BFergerson,項目名稱:Beam,代碼行數:3,代碼來源:IdStrategy.java


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