@@ -0,0 +1,1643 @@
+package com.ning.serialization;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.Comparator;%0Aimport java.util.HashMap;%0A%0A/**%0A * A Schema is a collection of SchemaFields.%0A *%0A * @see com.ning.serialization.SchemaField%0A */%0Apublic class Schema%0A%7B%0A    private String name;%0A    private HashMap%3CShort, SchemaField%3E schemaFields = new HashMap%3CShort, SchemaField%3E();%0A%0A    public Schema(String name)%0A    %7B%0A        this.name = name;%0A    %7D%0A%0A    public String getName()%0A    %7B%0A        return name;%0A    %7D%0A%0A    public void addSchemaField(SchemaField schemaField)%0A    %7B%0A        schemaFields.put(schemaField.getId(), schemaField);%0A    %7D%0A%0A    public SchemaField getFieldByPosition(short id)%0A    %7B%0A        return schemaFields.get(id);%0A    %7D%0A%0A    public SchemaField getFieldByName(String name)%0A    %7B%0A        for (SchemaField field : schemaFields.values()) %7B%0A            if (field.getName().equals(name)) %7B%0A                return field;%0A            %7D%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    /**%0A     * Get the schema as a collection of fields.%0A     * We guarantee the ordering by field id.%0A     *%0A     * @return the sorted collection of fields%0A     */%0A    @SuppressWarnings(%22unused%22)%0A    public ArrayList%3CSchemaField%3E getSchema()%0A    %7B%0A        ArrayList%3CSchemaField%3E items = new ArrayList%3CSchemaField%3E(schemaFields.values());%0A%0A        Collections.sort(items, new Comparator%3CSchemaField%3E()%0A        %7B%0A            @Override%0A            public int compare(SchemaField left, SchemaField right)%0A            %7B%0A                return Short.valueOf(left.getId()).compareTo(right.getId());%0A            %7D%0A        %7D);%0A%0A        return items;%0A    %7D%0A%7D%0A

introduce the Schema abstraction