aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main/java/com/yahoo/document/fieldset/FieldCollection.java
blob: b73b630f03892223cab38d5246888cf90f717662 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.fieldset;

import com.yahoo.document.DocumentType;
import com.yahoo.document.Field;

import java.util.ArrayList;

public class FieldCollection extends ArrayList<Field> implements FieldSet {
    DocumentType docType;

    public FieldCollection(DocumentType type) {
        docType = type;
    }

    public DocumentType getDocumentType() {
        return docType;
    }

    @Override
    public boolean contains(FieldSet o) {
        if (o instanceof DocIdOnly || o instanceof NoFields) {
            return true;
        }

        if (o instanceof Field) {
            return super.contains(o);
        } else if (o instanceof FieldCollection) {
            FieldCollection c = (FieldCollection)o;

            for (Field f : c) {
                if (!super.contains(f)) {
                    return false;
                }
            }

            return true;
        } else {
            return false;
        }
    }

    @Override
    public FieldSet clone() {
        FieldCollection c = new FieldCollection(docType);
        c.addAll(this);
        return c;
    }
}