Project

General

Profile

« Previous | Next » 

Revision f905a388

Added by Andreas Müller almost 2 years ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/mapping/berlinModel/CdmOneToManyMapper.java
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.io.common.mapping.berlinModel;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
18
import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20

  
21
/**
22
 * @author a.mueller
23
 * @since 20.03.2008
24
 * @version 1.0
25
 */
26
public class CdmOneToManyMapper<ONE extends CdmBase, MANY extends CdmBase, SINGLE_MAPPER extends CdmSingleAttributeMapperBase> extends MultipleAttributeMapperBase<SINGLE_MAPPER> {
27
	@SuppressWarnings("unused")
28
	private static Logger logger = LogManager.getLogger(CdmOneToManyMapper.class);
29

  
30
	private Class<MANY> manyClass;
31
	private Class<ONE> oneClass;
32
	private String singleAttributeName;
33

  
34
	public CdmOneToManyMapper(Class<ONE> oneClass, Class<MANY> manyClass, String singleAttributeName, SINGLE_MAPPER[] singleAttributesMappers) {
35
		if (singleAttributesMappers == null){
36
			throw new NullPointerException("singleAttributesMapper and cdmAttributeStrings must not be null");
37
		}
38
		for (SINGLE_MAPPER singleMapper : singleAttributesMappers){
39
			singleMappers.add(singleMapper);
40
		}
41
		this.manyClass = manyClass;
42
		this.oneClass = oneClass;
43
		this.singleAttributeName = singleAttributeName;
44
	}
45

  
46
//	@Override
47
//	public Set<String> getSourceAttributes(){
48
//		Set<String> result = new HashSet<>();
49
//		result.addAll(getSourceAttributeList());
50
//		return result;
51
//	}
52

  
53
	@Override
54
	public List<String> getSourceAttributeList(){
55
		List<String> result = new ArrayList<String>();
56
		for (SINGLE_MAPPER singleMapper : singleMappers){
57
			result.add(singleMapper.getSourceAttribute());
58
		}
59
		return result;
60
	}
61

  
62
//	@Override
63
//	public Set<String> getDestinationAttributes(){
64
//		Set<String> result = new HashSet<>();
65
//		result.addAll(getDestinationAttributeList());
66
//		return result;
67
//	}
68

  
69
	@Override
70
	public List<String> getDestinationAttributeList(){
71
		List<String> result = new ArrayList<String>();
72
		for (SINGLE_MAPPER singleMapper : singleMappers){
73
			result.add(singleMapper.getDestinationAttribute());
74
		}
75
		return result;
76
	}
77

  
78

  
79
	public Class<MANY> getManyClass(){
80
		return manyClass;
81
	}
82

  
83
	public Class<ONE> getOneClass(){
84
		return oneClass;
85
	}
86

  
87
	public String getDestinationAttribute(String sourceAttribute){
88
		if (sourceAttribute == null){
89
			return null;
90
		}
91
		for (SINGLE_MAPPER singleMapper : singleMappers){
92
			if (sourceAttribute.equals(singleMapper.getSourceAttribute())){
93
				return singleMapper.getDestinationAttribute();
94
			}
95
		}
96
		return null;
97
	}
98

  
99
	public List<SINGLE_MAPPER> getSingleMappers(){
100
		return singleMappers;
101
	}
102

  
103
	/**
104
	 * @return the singleAttributeName
105
	 */
106
	public String getSingleAttributeName() {
107
		return singleAttributeName;
108
	}
109

  
110
}
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.io.common.mapping.berlinModel;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17

  
18
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
19
import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21

  
22
/**
23
 * @author a.mueller
24
 * @since 20.03.2008
25
 */
26
public class CdmOneToManyMapper<ONE extends CdmBase, MANY extends CdmBase, SINGLE_MAPPER extends CdmSingleAttributeMapperBase> extends MultipleAttributeMapperBase<SINGLE_MAPPER> {
27

  
28
    @SuppressWarnings("unused")
29
	private static Logger logger = LogManager.getLogger();
30

  
31
	private Class<MANY> manyClass;
32
	private Class<ONE> oneClass;
33
	private String singleAttributeName;
34

  
35
	public CdmOneToManyMapper(Class<ONE> oneClass, Class<MANY> manyClass, String singleAttributeName, SINGLE_MAPPER[] singleAttributesMappers) {
36
		if (singleAttributesMappers == null){
37
			throw new NullPointerException("singleAttributesMapper and cdmAttributeStrings must not be null");
38
		}
39
		for (SINGLE_MAPPER singleMapper : singleAttributesMappers){
40
			singleMappers.add(singleMapper);
41
		}
42
		this.manyClass = manyClass;
43
		this.oneClass = oneClass;
44
		this.singleAttributeName = singleAttributeName;
45
	}
46

  
47
//	@Override
48
//	public Set<String> getSourceAttributes(){
49
//		Set<String> result = new HashSet<>();
50
//		result.addAll(getSourceAttributeList());
51
//		return result;
52
//	}
53

  
54
	@Override
55
	public List<String> getSourceAttributeList(){
56
		List<String> result = new ArrayList<String>();
57
		for (SINGLE_MAPPER singleMapper : singleMappers){
58
			result.add(singleMapper.getSourceAttribute());
59
		}
60
		return result;
61
	}
62

  
63
//	@Override
64
//	public Set<String> getDestinationAttributes(){
65
//		Set<String> result = new HashSet<>();
66
//		result.addAll(getDestinationAttributeList());
67
//		return result;
68
//	}
69

  
70
	@Override
71
	public List<String> getDestinationAttributeList(){
72
		List<String> result = new ArrayList<String>();
73
		for (SINGLE_MAPPER singleMapper : singleMappers){
74
			result.add(singleMapper.getDestinationAttribute());
75
		}
76
		return result;
77
	}
78

  
79

  
80
	public Class<MANY> getManyClass(){
81
		return manyClass;
82
	}
83

  
84
	public Class<ONE> getOneClass(){
85
		return oneClass;
86
	}
87

  
88
	public String getDestinationAttribute(String sourceAttribute){
89
		if (sourceAttribute == null){
90
			return null;
91
		}
92
		for (SINGLE_MAPPER singleMapper : singleMappers){
93
			if (sourceAttribute.equals(singleMapper.getSourceAttribute())){
94
				return singleMapper.getDestinationAttribute();
95
			}
96
		}
97
		return null;
98
	}
99

  
100
	public List<SINGLE_MAPPER> getSingleMappers(){
101
		return singleMappers;
102
	}
103

  
104
	/**
105
	 * @return the singleAttributeName
106
	 */
107
	public String getSingleAttributeName() {
108
		return singleAttributeName;
109
	}
110

  
111
}

Also available in: Unified diff