Skip to content

Commit

Permalink
#6 common api via IMetadataDirectory and IMetadataTag: reduced redund…
Browse files Browse the repository at this point in the history
…ant code
  • Loading branch information
k3b committed Jun 16, 2016
1 parent c2db9f5 commit 790143a
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 394 deletions.
33 changes: 32 additions & 1 deletion pixymeta-lib/src/main/java/pixy/meta/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,5 +521,36 @@ public void write(OutputStream out) throws IOException {
byte[] data = getData();
if(data != null)
out.write(data);
}
}


/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}

/** may generate the IMetadataDirectory on demand */
abstract protected IMetadataDirectory get();

}
30 changes: 3 additions & 27 deletions pixymeta-lib/src/main/java/pixy/meta/adobe/DDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import pixy.io.ReadStrategy;
import pixy.util.ArrayUtils;

public class DDB extends Metadata implements IMetadataDirectory {
public class DDB extends Metadata {
private static final String MODUL_NAME = "Adobe-DDB";
private ReadStrategy readStrategy;
private Map<Integer, DDBEntry> entries = new HashMap<Integer, DDBEntry>();
Expand Down Expand Up @@ -125,7 +125,8 @@ public void showMetadata() {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand All @@ -139,29 +140,4 @@ private MetadataDirectoryImpl get() {
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}
}
32 changes: 3 additions & 29 deletions pixymeta-lib/src/main/java/pixy/meta/adobe/IRB.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import pixy.util.ArrayUtils;
import pixy.io.IOUtils;

public class IRB extends Metadata implements IMetadataDirectory {
public class IRB extends Metadata {
private static final String MODUL_NAME = "Adobe-IRB";
private boolean containsThumbnail;
private ThumbnailResource thumbnail;
Expand Down Expand Up @@ -189,7 +189,8 @@ public void showMetadata() {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand All @@ -202,31 +203,4 @@ private MetadataDirectoryImpl get() {
}
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}

}
32 changes: 3 additions & 29 deletions pixymeta-lib/src/main/java/pixy/meta/exif/Exif.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @author Wen Yu, [email protected]
* @version 1.0 03/13/2014
*/
public abstract class Exif extends Metadata implements IMetadataDirectory {
public abstract class Exif extends Metadata {
private final String MODUL_NAME;

protected IFD imageIFD;
Expand Down Expand Up @@ -273,7 +273,8 @@ public void showMetadata() {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand All @@ -295,31 +296,4 @@ private MetadataDirectoryImpl get() {
}
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}

}
31 changes: 3 additions & 28 deletions pixymeta-lib/src/main/java/pixy/meta/icc/ICCProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Wen Yu, [email protected]
* @version 1.0 07/02/2013
*/
public class ICCProfile extends Metadata implements IMetadataDirectory {
public class ICCProfile extends Metadata {

private static final String MODUL_NAME = "ICC";

Expand Down Expand Up @@ -340,7 +340,8 @@ private void showTagTable() {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand All @@ -354,30 +355,4 @@ private MetadataDirectoryImpl get() {
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}

}
31 changes: 3 additions & 28 deletions pixymeta-lib/src/main/java/pixy/meta/image/Comments.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import pixy.meta.MetadataDirectoryImpl;
import pixy.meta.MetadataType;

public class Comments extends Metadata implements IMetadataDirectory {
public class Comments extends Metadata {
// Obtain a logger instance
private static final Logger LOGGER = LoggerFactory.getLogger(Comments.class);
private static final String MODUL_NAME = "Image-Comments";
Expand Down Expand Up @@ -99,7 +99,8 @@ public void showMetadata() {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand All @@ -113,30 +114,4 @@ private MetadataDirectoryImpl get() {
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}

}
32 changes: 3 additions & 29 deletions pixymeta-lib/src/main/java/pixy/meta/image/ImageMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import pixy.meta.Thumbnail;
import pixy.string.XMLUtils;

public class ImageMetadata extends Metadata implements IMetadataDirectory {
public class ImageMetadata extends Metadata {
private static final String MODUL_NAME = "Image";
private Document document;
private Map<String, Thumbnail> thumbnails;
Expand Down Expand Up @@ -96,7 +96,8 @@ public void showMetadata() {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand Down Expand Up @@ -126,31 +127,4 @@ private MetadataDirectoryImpl get() {
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}


}
31 changes: 3 additions & 28 deletions pixymeta-lib/src/main/java/pixy/meta/iptc/IPTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import pixy.meta.MetadataType;
import pixy.io.IOUtils;

public class IPTC extends Metadata implements IMetadataDirectory {
public class IPTC extends Metadata {

private static final String MODUL_NAME = "Iptc";

Expand Down Expand Up @@ -192,7 +192,8 @@ public void write(OutputStream os) throws IOException {
private MetadataDirectoryImpl metaData = null;

// calculate metaData on demand
private MetadataDirectoryImpl get() {
@Override
protected IMetadataDirectory get() {
if ((metaData == null)) {
metaData = new MetadataDirectoryImpl().setName(MODUL_NAME);

Expand All @@ -206,30 +207,4 @@ private MetadataDirectoryImpl get() {
return metaData;
}

/**
* Provides the name of the directory, for display purposes. E.g. <code>Exif</code>
*
* @return the name of the directory
*/
@Override
public String getName() {
return get().getName();
}

/**
* @return sub-directories that belong to this Directory or null if there are no sub-directories
*/
@Override
public List<IMetadataDirectory> getSubdirectories() {
return get().getSubdirectories();
}

/**
* @return Tags that belong to this Directory or null if there are no tags
*/
@Override
public List<IMetadataTag> getTags() {
return get().getTags();
}

}
Loading

0 comments on commit 790143a

Please sign in to comment.