| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MetadataContainerFactory |
|
| 1.6;1.6 |
| 1 | package org.jaudiotagger.audio.asf.data; | |
| 2 | ||
| 3 | import java.math.BigInteger; | |
| 4 | ||
| 5 | /** | |
| 6 | * A factory for creating appropriate {@link MetadataContainer} objects upon | |
| 7 | * specified {@linkplain ContainerType container types}.<br> | |
| 8 | * | |
| 9 | * @author Christian Laireiter | |
| 10 | */ | |
| 11 | 4 | public final class MetadataContainerFactory { |
| 12 | ||
| 13 | /** | |
| 14 | * Factory instance. | |
| 15 | */ | |
| 16 | 4 | private final static MetadataContainerFactory INSTANCE = new MetadataContainerFactory(); |
| 17 | ||
| 18 | /** | |
| 19 | * Returns an instance. | |
| 20 | * | |
| 21 | * @return an instance. | |
| 22 | */ | |
| 23 | public static MetadataContainerFactory getInstance() { | |
| 24 | 153 | return INSTANCE; |
| 25 | } | |
| 26 | ||
| 27 | /** | |
| 28 | * Hidden utility class constructor. | |
| 29 | */ | |
| 30 | 4 | private MetadataContainerFactory() { |
| 31 | // Hidden | |
| 32 | 4 | } |
| 33 | ||
| 34 | /** | |
| 35 | * Creates an appropriate {@linkplain MetadataContainer container | |
| 36 | * implementation} for the given container type. | |
| 37 | * | |
| 38 | * @param type | |
| 39 | * the type of container to get a container instance for. | |
| 40 | * @return appropriate container implementation. | |
| 41 | */ | |
| 42 | public MetadataContainer createContainer(final ContainerType type) { | |
| 43 | 765 | return createContainer(type, 0, BigInteger.ZERO); |
| 44 | } | |
| 45 | ||
| 46 | /** | |
| 47 | * Convenience Method for I/O. Same as | |
| 48 | * {@link #createContainer(ContainerType)}, but additionally assigns | |
| 49 | * position and size. (since a {@link MetadataContainer} is actually a | |
| 50 | * {@link Chunk}). | |
| 51 | * | |
| 52 | * @param type | |
| 53 | * The containers type. | |
| 54 | * @param pos | |
| 55 | * the position within the stream. | |
| 56 | * @param chunkSize | |
| 57 | * the size of the container. | |
| 58 | * @return an appropriate container implementation with assigned size and | |
| 59 | * position. | |
| 60 | */ | |
| 61 | public MetadataContainer createContainer(final ContainerType type, | |
| 62 | final long pos, final BigInteger chunkSize) { | |
| 63 | MetadataContainer result; | |
| 64 | 765 | if (type == ContainerType.CONTENT_DESCRIPTION) { |
| 65 | 153 | result = new ContentDescription(pos, chunkSize); |
| 66 | 612 | } else if (type == ContainerType.CONTENT_BRANDING) { |
| 67 | 153 | result = new ContentBranding(pos, chunkSize); |
| 68 | } else { | |
| 69 | 459 | result = new MetadataContainer(type, pos, chunkSize); |
| 70 | } | |
| 71 | 765 | return result; |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * Convenience method which calls {@link #createContainer(ContainerType)} | |
| 76 | * for each given container type. | |
| 77 | * | |
| 78 | * @param types | |
| 79 | * types of the container which are to be created. | |
| 80 | * @return appropriate container implementations. | |
| 81 | */ | |
| 82 | public MetadataContainer[] createContainers(final ContainerType[] types) { | |
| 83 | 153 | assert types != null; |
| 84 | 153 | final MetadataContainer[] result = new MetadataContainer[types.length]; |
| 85 | 918 | for (int i = 0; i < result.length; i++) { |
| 86 | 765 | result[i] = createContainer(types[i]); |
| 87 | } | |
| 88 | 153 | return result; |
| 89 | } | |
| 90 | ||
| 91 | } |