class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor {
    /** Fields sorted by order number. */
    private final Collection<T2<String, Integer>> fields = new TreeSet<>(
        new Comparator<T2<String, Integer>>() {
            @Override public int compare(T2<String, Integer> o1, T2<String, Integer> o2) {
                if (o1.get2().equals(o2.get2())) // Order is equal, compare field names to avoid replace in Set.
                    return o1.get1().compareTo(o2.get1());

                return o1.get2() < o2.get2() ? -1 : 1;
            }
        });

    /** Fields which should be indexed in descending order. */
    private Collection<String> descendings;

    /** Type descriptor. */
    @GridToStringExclude
    private final QueryTypeDescriptorImpl typDesc;

    /** Index name. */
    private final String name;

    /** */
    private final QueryIndexType type;

    /** */
    private final int inlineSize;

    /**
     * Constructor.
     *
     * @param typDesc Type descriptor.
     * @param name Index name.
     * @param type Type.
     * @param inlineSize Inline size.
     */
    public QueryIndexDescriptorImpl(QueryTypeDescriptorImpl typDesc, String name, QueryIndexType type, int inlineSize) {
        assert type != null;

        this.typDesc = typDesc;
        this.name = name;
        this.type = type;
        this.inlineSize = inlineSize;
    }

    /**
     * @return Type descriptor.
     */
    public QueryTypeDescriptorImpl typeDescriptor() {
        return typDesc;
    }

    /** {@inheritDoc} */
    @Override public String name() {
        return name;
    }

    /** {@inheritDoc} */
    @Override public Collection<String> fields() {
        Collection<String> res = new ArrayList<>(fields.size());

        for (T2<String, Integer> t : fields)
            res.add(t.get1());

        return res;
    }

    /** {@inheritDoc} */
    @Override public int inlineSize() {
        return inlineSize;
    }

    /** {@inheritDoc} */
    @Override public boolean descending(String field) {
        return descendings != null && descendings.contains(field);
    }

    /**
     * Adds field to this index.
     *
     * @param field Field name.
     * @param orderNum Field order number in this index.
     * @param descending Sort order.
     * @return This instance for chaining.
     * @throws IgniteCheckedException If failed.
     */
    public QueryIndexDescriptorImpl addField(String field, int orderNum, boolean descending)
        throws IgniteCheckedException {<FILL_FUNCTION_BODY>}

    /** {@inheritDoc} */
    @Override public QueryIndexType type() {
        return type;
    }

    /** {@inheritDoc} */
    @Override public String toString() {
        return S.toString(QueryIndexDescriptorImpl.class, this);
    }
}

        if (!typDesc.hasField(field))
            throw new IgniteCheckedException("Field not found: " + field);

        fields.add(new T2<>(field, orderNum));

        if (descending) {
            if (descendings == null)
                descendings = new HashSet<>();

            descendings.add(field);
        }

        return this;
    
<no_super_class>