Project

General

Profile

Download (2.3 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.common;
10

    
11
import java.io.Serializable;
12
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16

    
17
/**
18
 * @author k.luther
19
 * @since 17.03.2017
20
 *
21
 */
22
public class ExportDataWrapper<T> implements Serializable{
23

    
24
    private static final long serialVersionUID = 4500184563547082579L;
25

    
26
    private T exportData;
27
    private ExportResultType type;
28

    
29
    /**
30
     * @return the type
31
     */
32
    public ExportResultType getType() {
33
        return type;
34
    }
35

    
36
    /**
37
     * @param type the type to set
38
     */
39
    public void setType(ExportResultType type) {
40
        this.type = type;
41
    }
42

    
43
    private ExportDataWrapper(){
44

    
45
    }
46

    
47
    public static final ExportDataWrapper<List<byte[]>> NewListByteArrayInstance(){
48
        ExportDataWrapper<List<byte[]>> result = new ExportDataWrapper<>();
49
        result.type = ExportResultType.LIST_BYTE_ARRAY;
50
        result.exportData = new ArrayList<>();
51
        return result;
52
    }
53

    
54
    public static final ExportDataWrapper<Map<String,byte[]>> NewMapByteArrayInstance(){
55
        ExportDataWrapper<Map<String, byte[]>> result = new ExportDataWrapper<>();
56
        result.type = ExportResultType.MAP_BYTE_ARRAY;
57
        result.exportData = new HashMap<>();
58
        return result;
59
    }
60

    
61
    public static final ExportDataWrapper<byte[]> NewByteArrayInstance(){
62
        ExportDataWrapper<byte[]> result = new ExportDataWrapper<>();
63
        result.type = ExportResultType.BYTE_ARRAY;
64

    
65
        return result;
66
    }
67

    
68
    public void setValue(T value){this.exportData = value;}
69

    
70
    public T getExportData(){return this.exportData;}
71

    
72
    public void addExportData(byte[] data){
73
        if (type.equals(ExportResultType.BYTE_ARRAY)){
74
            exportData = (T)data;
75
        } else if (type.equals(ExportResultType.LIST_BYTE_ARRAY)){
76
            ((List<byte[]>)exportData).add(data);
77
        }
78
    }
79

    
80
    public void putExportData(String key, byte[] data){
81
        if (type.equals(ExportResultType.MAP_BYTE_ARRAY)){
82
            ((Map<String, byte[]>)exportData).put(key,data);
83
        }
84
    }
85

    
86
}
(19-19/65)