Skip to content

Commit

Permalink
refact: eliminated complexity and warnings related to not safe generic
Browse files Browse the repository at this point in the history
actions
  • Loading branch information
batzorent committed Aug 22, 2019
1 parent 5d65490 commit 5d1ba44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
10 changes: 4 additions & 6 deletions src/main/java/org/mabb/fontverter/opentype/OpenTypeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@
import org.mabb.fontverter.io.FontDataInput;
import org.mabb.fontverter.io.FontDataInputStream;
import org.mabb.fontverter.io.DataTypeBindingDeserializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

public class OpenTypeParser {
private static final Logger log = LoggerFactory.getLogger(OpenTypeFont.class);

private OpenTypeFont font;
private FontDataInput input;

public OpenTypeFont parse(byte[] data) throws IOException, InstantiationException, IllegalAccessException {
public OpenTypeFont parse(byte[] data) throws IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
return parse(data, new OpenTypeFont());
}

public OpenTypeFont parse(byte[] data, OpenTypeFont font) throws IOException, InstantiationException, IllegalAccessException {
public OpenTypeFont parse(byte[] data, OpenTypeFont font) throws IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
this.font = font;
this.input = new FontDataInputStream(data);

Expand All @@ -50,7 +48,7 @@ public OpenTypeFont parse(byte[] data, OpenTypeFont font) throws IOException, In
}

private void readTableHeaderEntries()
throws IllegalAccessException, InstantiationException, IOException {
throws IllegalAccessException, InstantiationException, IOException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
DataTypeBindingDeserializer deserializer = new DataTypeBindingDeserializer();

for (int i = 0; i < font.sfntHeader.numTables; i++) {
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/org/mabb/fontverter/opentype/OpenTypeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

Expand All @@ -51,7 +51,7 @@ public static class OtfTableRecord {

public static final int TABLE_RECORD_SIZE = 16;

private static List<Class> tableTypes;
private static List<Class<? extends OpenTypeTable>> tableTypes;
private static final Object factoryLock = new Object();
private static Logger log = LoggerFactory.getLogger(OpenTypeTable.class);

Expand All @@ -70,12 +70,12 @@ public OpenTypeTable() {
}

public static OpenTypeTable createFromRecord(OtfTableRecord record, OpenTypeFont font)
throws IllegalAccessException, InstantiationException, IOException {
throws IllegalAccessException, InstantiationException, IOException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
initFactoryTableTypes();

OpenTypeTable createdTable = null;
for (Class typeOn : tableTypes) {
OpenTypeTable tableOn = (OpenTypeTable) typeOn.newInstance();
for (Class<? extends OpenTypeTable> typeOn : tableTypes) {
OpenTypeTable tableOn = typeOn.getDeclaredConstructor().newInstance();

if (tableOn.getTableType().equals(record.recordName)) {
createdTable = tableOn;
Expand Down Expand Up @@ -106,17 +106,14 @@ private static OpenTypeTable createUnknownTableTypeFallback(OtfTableRecord recor
private static void initFactoryTableTypes() {
synchronized (factoryLock) {
if (tableTypes == null) {
tableTypes = new ArrayList<>();
Reflections reflections = new Reflections("org.mabb.fontverter");
Set<Class<? extends OpenTypeTable>> adapterClasses = reflections.getSubTypesOf(OpenTypeTable.class);
tableTypes = Arrays.asList(adapterClasses.toArray(new Class[adapterClasses.size()]));

List<Class> filteredTables = new ArrayList<Class>();
for (Class tableTypeOn : tableTypes) {
for (Class<? extends OpenTypeTable> tableTypeOn : adapterClasses) {
if (!tableTypeOn.getCanonicalName().contains("Canned") && tableTypeOn != UnknownTableType.class)
filteredTables.add(tableTypeOn);
tableTypes.add(tableTypeOn);
}

tableTypes = filteredTables;
}
}
}
Expand Down

0 comments on commit 5d1ba44

Please sign in to comment.