cleanup
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / ExportDataWrapper.java
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 private ExportDataWrapper(){
30 }
31
32 public ExportResultType getType() {
33 return type;
34 }
35
36 public void setType(ExportResultType type) {
37 this.type = type;
38 }
39
40 public static final ExportDataWrapper<List<byte[]>> NewListByteArrayInstance(){
41 ExportDataWrapper<List<byte[]>> result = new ExportDataWrapper<>();
42 result.type = ExportResultType.LIST_BYTE_ARRAY;
43 result.exportData = new ArrayList<>();
44 return result;
45 }
46
47 public static final ExportDataWrapper<Map<String,byte[]>> NewMapByteArrayInstance(){
48 ExportDataWrapper<Map<String, byte[]>> result = new ExportDataWrapper<>();
49 result.type = ExportResultType.MAP_BYTE_ARRAY;
50 result.exportData = new HashMap<>();
51 return result;
52 }
53
54 public static final ExportDataWrapper<byte[]> NewByteArrayInstance(){
55 ExportDataWrapper<byte[]> result = new ExportDataWrapper<>();
56 result.type = ExportResultType.BYTE_ARRAY;
57
58 return result;
59 }
60
61 public void setValue(T value){this.exportData = value;}
62
63 public T getExportData(){return this.exportData;}
64
65 public void addExportData(byte[] data){
66 if (type.equals(ExportResultType.BYTE_ARRAY)){
67 exportData = (T)data;
68 } else if (type.equals(ExportResultType.LIST_BYTE_ARRAY)){
69 ((List<byte[]>)exportData).add(data);
70 }
71 }
72
73 public void putExportData(String key, byte[] data){
74 if (type.equals(ExportResultType.MAP_BYTE_ARRAY)){
75 ((Map<String, byte[]>)exportData).put(key,data);
76 }
77 }
78
79 }