A mask factory framework that automatically builds a recursive mask. The subclass defines how to mask the primitive types and the factory builds a recursive tree of data masks that matches the schema tree.
| 30 | * builds a recursive tree of data masks that matches the schema tree. |
| 31 | */ |
| 32 | public abstract class MaskFactory { |
| 33 | |
| 34 | protected abstract DataMask buildBooleanMask(TypeDescription schema); |
| 35 | protected abstract DataMask buildLongMask(TypeDescription schema); |
| 36 | protected abstract DataMask buildDecimalMask(TypeDescription schema); |
| 37 | protected abstract DataMask buildDoubleMask(TypeDescription schema); |
| 38 | protected abstract DataMask buildStringMask(TypeDescription schema); |
| 39 | protected abstract DataMask buildDateMask(TypeDescription schema); |
| 40 | protected abstract DataMask buildTimestampMask(TypeDescription schema); |
| 41 | protected abstract DataMask buildBinaryMask(TypeDescription schema); |
| 42 | |
| 43 | public DataMask build(TypeDescription schema, |
| 44 | DataMask.MaskOverrides overrides) { |
| 45 | switch(schema.getCategory()) { |
| 46 | case BOOLEAN: |
| 47 | return buildBooleanMask(schema); |
| 48 | case BYTE: |
| 49 | case SHORT: |
| 50 | case INT: |
| 51 | case LONG: |
| 52 | return buildLongMask(schema); |
| 53 | case FLOAT: |
| 54 | case DOUBLE: |
| 55 | return buildDoubleMask(schema); |
| 56 | case DECIMAL: |
| 57 | return buildDecimalMask(schema); |
| 58 | case STRING: |
| 59 | case CHAR: |
| 60 | case VARCHAR: |
| 61 | return buildStringMask(schema); |
| 62 | case TIMESTAMP: |
| 63 | case TIMESTAMP_INSTANT: |
| 64 | return buildTimestampMask(schema); |
| 65 | case DATE: |
| 66 | return buildDateMask(schema); |
| 67 | case BINARY: |
| 68 | return buildBinaryMask(schema); |
| 69 | case UNION: |
| 70 | return buildUnionMask(schema, overrides); |
| 71 | case STRUCT: |
| 72 | return buildStructMask(schema, overrides); |
| 73 | case LIST: |
| 74 | return buildListMask(schema, overrides); |
| 75 | case MAP: |
| 76 | return buildMapMask(schema, overrides); |
| 77 | default: |
| 78 | throw new IllegalArgumentException("Unhandled type " + schema); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | protected DataMask[] buildChildren(List<TypeDescription> children, |
| 83 | DataMask.MaskOverrides overrides) { |
| 84 | DataMask[] result = new DataMask[children.size()]; |
| 85 | for(int i = 0; i < result.length; ++i) { |
| 86 | TypeDescription child = children.get(i); |
| 87 | DataMaskDescription over = overrides.hasOverride(child); |
| 88 | if (over != null) { |
| 89 | result[i] = DataMask.Factory.build(over, child, overrides); |
nothing calls this directly
no outgoing calls
no test coverage detected