Commits

P_W999 committed 13ce5a0

- small refactoring + less visibility of internal stuff

Comments (0)

Files changed (13)

+<?xml version="1.0" encoding="UTF-8"?>
+
+<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
+  <fileset name="all" enabled="true" check-config-name="J-ExifTool" local="false">
+    <file-match-pattern match-pattern="src/.*java" include-pattern="true"/>
+  </fileset>
+</fileset-config>

.settings/org.eclipse.jdt.ui.prefs

+cleanup.add_default_serial_version_id=false
+cleanup.add_generated_serial_version_id=true
+cleanup.add_missing_annotations=true
+cleanup.add_missing_deprecated_annotations=true
+cleanup.add_missing_methods=false
+cleanup.add_missing_nls_tags=false
+cleanup.add_missing_override_annotations=true
+cleanup.add_missing_override_annotations_interface_methods=true
+cleanup.add_serial_version_id=true
+cleanup.always_use_blocks=true
+cleanup.always_use_parentheses_in_expressions=true
+cleanup.always_use_this_for_non_static_field_access=true
+cleanup.always_use_this_for_non_static_method_access=false
+cleanup.convert_to_enhanced_for_loop=false
+cleanup.correct_indentation=true
+cleanup.format_source_code=true
+cleanup.format_source_code_changes_only=false
+cleanup.make_local_variable_final=false
+cleanup.make_parameters_final=true
+cleanup.make_private_fields_final=false
+cleanup.make_type_abstract_if_missing_method=false
+cleanup.make_variable_declarations_final=true
+cleanup.never_use_blocks=false
+cleanup.never_use_parentheses_in_expressions=false
+cleanup.organize_imports=true
+cleanup.qualify_static_field_accesses_with_declaring_class=false
+cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+cleanup.qualify_static_member_accesses_with_declaring_class=true
+cleanup.qualify_static_method_accesses_with_declaring_class=false
+cleanup.remove_private_constructors=true
+cleanup.remove_trailing_whitespaces=true
+cleanup.remove_trailing_whitespaces_all=true
+cleanup.remove_trailing_whitespaces_ignore_empty=false
+cleanup.remove_unnecessary_casts=true
+cleanup.remove_unnecessary_nls_tags=true
+cleanup.remove_unused_imports=true
+cleanup.remove_unused_local_variables=false
+cleanup.remove_unused_private_fields=true
+cleanup.remove_unused_private_members=false
+cleanup.remove_unused_private_methods=true
+cleanup.remove_unused_private_types=true
+cleanup.sort_members=false
+cleanup.sort_members_all=false
+cleanup.use_blocks=true
+cleanup.use_blocks_only_for_return_and_throw=false
+cleanup.use_parentheses_in_expressions=false
+cleanup.use_this_for_non_static_field_access=false
+cleanup.use_this_for_non_static_field_access_only_if_necessary=false
+cleanup.use_this_for_non_static_method_access=false
+cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+cleanup_profile=_eclipse-cs J-ExifTool
+cleanup_settings_version=2
+eclipse.preferences.version=1
+formatter_profile=_Phillip
+formatter_settings_version=12

src/be/pw/jexif/JExifTool.java

 	 * @throws ExifError if there was a problem in ExifTool
 	 */
 	String readTagInfo(final File file, final Tag tag, final boolean exact) throws JExifException, ExifError {
-		startIfNecessary();
 		LOG.trace("Starting readTagInfo");
-		int i = 0;
 		IAction action;
-		EventHandler handler;
+		EventHandler handler = new EventHandler();
 		try {
 			if (exact) {
 				action = ActionFactory.createExactReadAction(file, tag);
 			} else {
 				action = ActionFactory.createReadAction(file, tag);
 			}
-			handler = new EventHandler();
-			bus.register(handler);
-
-			String[] arguments = action.buildArguments();
-			for (String argument : arguments) {
-				argsWriter.append(argument).append("\r\n");
-			}
-			argsWriter.flush();
-			while (!handler.isFinished() && i <= deadLock) {
-				Thread.sleep(50);
-				i += 50;
-			}
-			if (!handler.isFinished()) {
-				LOG.error(Cal10nUtil.get(Errors.DEADLOCK, i));
-				throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
-			}
-			bus.unregister(handler);
+			executeAction(handler, action);
 		} catch (IOException e) {
 			throw new JExifException(Cal10nUtil.get(Errors.IO_ARGSFILE), e);
 		} catch (InterruptedException e) {
 	 * @throws ExifError if there was a problem in ExifTool
 	 */
 	void writeTagInfo(final File file, final Tag tag, final String value) throws ExifError, JExifException {
-		startIfNecessary();
 		LOG.trace("Starting readTagInfo");
-		int i = 0;
 		IAction action;
-		EventHandler handler;
+		EventHandler handler = new EventHandler();
 		try {
 			Map<Tag, String> valuesToWrite = new HashMap<>(1);
 			valuesToWrite.put(tag, value);
 			action = ActionFactory.createTagWriteAction(file, valuesToWrite);
-			handler = new EventHandler();
-			bus.register(handler);
-
-			String[] arguments = action.buildArguments();
-			for (String argument : arguments) {
-				argsWriter.append(argument).append("\r\n");
-			}
-			argsWriter.flush();
-			while (!handler.isFinished() && i <= deadLock) {
-				Thread.sleep(50);
-				i += 50;
-			}
-			if (!handler.isFinished()) {
-				LOG.error(Cal10nUtil.get(Errors.DEADLOCK, i));
-				throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
-			}
-			bus.unregister(handler);
+			executeAction(handler, action);
 		} catch (IOException e) {
 			throw new JExifException(Cal10nUtil.get(Errors.IO_ARGSFILE), e);
 		} catch (InterruptedException e) {
 	 * @throws ExifError if there was a problem in ExifTool
 	 */
 	void writeGPSTagInfo(final File file, final Map<Tag, String> valuesToWrite) throws ExifError, JExifException {
-		startIfNecessary();
 		LOG.trace("Starting readTagInfo");
-		int i = 0;
 		IAction action;
-		EventHandler handler;
+		EventHandler handler = new EventHandler();
 		try {
 			GPSUtil.validateGPSValues(valuesToWrite);
 			GPSUtil.formatGPSValues(valuesToWrite);
 			action = ActionFactory.createTagWriteAction(file, valuesToWrite);
-			String[] arguments = action.buildArguments();
 			handler = new EventHandler();
-			bus.register(handler);
-
-			for (String argument : arguments) {
-				argsWriter.append(argument).append("\r\n");
-			}
-			argsWriter.flush();
-			while (!handler.isFinished() && i <= deadLock * 1.2) { // slightly (random) longer delay because of multiple values to write
-				Thread.sleep(50);
-				i += 50;
-			}
-			if (!handler.isFinished()) {
-				throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
-			}
-			bus.unregister(handler);
+			executeAction(handler, action);
 		} catch (IOException e) {
 			throw new JExifException(Cal10nUtil.get(Errors.IO_ARGSFILE), e);
 		} catch (InterruptedException e) {
 	}
 
 	void timeShift(final File file, final String shift, final DateTag tag) throws JExifException, ExifError {
-		startIfNecessary();
 		LOG.trace("Starting timeShift");
-		int i = 0;
 		IAction action;
-		EventHandler handler;
+		EventHandler handler = new EventHandler();
 		try {
 			action = ActionFactory.createDateTimeShiftAction(file, shift, tag);
-			handler = new EventHandler();
-			bus.register(handler);
-
-			String[] arguments = action.buildArguments();
-			for (String argument : arguments) {
-				argsWriter.append(argument).append("\r\n");
-			}
-			argsWriter.flush();
-			while (!handler.isFinished() && i <= deadLock) {
-				Thread.sleep(50);
-				i += 50;
-			}
-			if (!handler.isFinished()) {
-				LOG.error(Cal10nUtil.get(Errors.DEADLOCK, i));
-				throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
-			}
-			bus.unregister(handler);
+			executeAction(handler, action);
 		} catch (IOException e) {
 			throw new JExifException(Cal10nUtil.get(Errors.IO_ARGSFILE), e);
 		} catch (InterruptedException e) {
 	}
 
 	void copyFrom(final File to, final File from, final Tag... tags) throws JExifException, ExifError {
-		startIfNecessary();
 		LOG.trace("Starting copyFrom");
-		int i = 0;
 		IAction action;
-		EventHandler handler;
+		EventHandler handler = new EventHandler();
 		try {
 			action = ActionFactory.createCopyFromAction(from, to, tags);
-			handler = new EventHandler();
-			bus.register(handler);
-
-			String[] arguments = action.buildArguments();
-			for (String argument : arguments) {
-				argsWriter.append(argument).append("\r\n");
-			}
-			argsWriter.flush();
-			while (!handler.isFinished() && i <= deadLock) {
-				Thread.sleep(50);
-				i += 50;
-			}
-			if (!handler.isFinished()) {
-				LOG.error(Cal10nUtil.get(Errors.DEADLOCK, i));
-				throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
-			}
-			bus.unregister(handler);
+			executeAction(handler, action);
 		} catch (IOException e) {
 			throw new JExifException(Cal10nUtil.get(Errors.IO_ARGSFILE), e);
 		} catch (InterruptedException e) {
 	}
 
 	private Map<? extends Object, String> getAllTagInfo(final File file, final boolean exact, final boolean onlySupported) throws ExifError, JExifException {
-		startIfNecessary();
 		LOG.trace("Starting readTagInfo");
-		int i = 0;
 		IAction action;
-		EventHandler handler;
+		EventHandler handler = new EventHandler();
 		try {
 			if (exact) {
 				action = ActionFactory.createTagReadExactAllAction(file);
 			} else {
 				action = ActionFactory.createTagReadAllAction(file);
 			}
-			handler = new EventHandler();
-			bus.register(handler);
-
-			String[] arguments = action.buildArguments();
-			for (String argument : arguments) {
-				argsWriter.append(argument).append("\r\n");
-			}
-			argsWriter.flush();
-			while (!handler.isFinished() && i <= deadLock) {
-				Thread.sleep(50);
-				i += 50;
-			}
-			if (!handler.isFinished()) {
-				LOG.error(Cal10nUtil.get(Errors.DEADLOCK, i));
-				throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
-			}
-			bus.unregister(handler);
+			executeAction(handler, action);
 		} catch (IOException e) {
 			throw new JExifException(Cal10nUtil.get(Errors.IO_ARGSFILE), e);
 		} catch (InterruptedException e) {
 		}
 	}
 
+	private void executeAction(EventHandler handler, IAction action) throws InterruptedException, JExifException, IOException {
+		startIfNecessary();
+		int i = 0;
+		bus.register(handler);
+
+		String[] arguments = action.buildArguments();
+		for (String argument : arguments) {
+			argsWriter.append(argument).append("\r\n");
+		}
+		argsWriter.flush();
+		while (!handler.isFinished() && i <= deadLock) {
+			Thread.sleep(50);
+			i += 50;
+		}
+		if (!handler.isFinished()) {
+			LOG.error(Cal10nUtil.get(Errors.DEADLOCK, i));
+			throw new JExifException(Cal10nUtil.get(Errors.DEADLOCK, i));
+		}
+		bus.unregister(handler);
+	}
+
 }

src/be/pw/jexif/internal/action/AbstractAction.java

-/*******************************************************************************
- * Copyright 2012 P_W999
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package be.pw.jexif.internal.action;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import be.pw.jexif.enums.tag.Tag;
-
-/**
- * An abstract implementation of the IAction interface.
- * 
- * @author phillip
- */
-public abstract class AbstractAction implements IAction {
-
-	private static final Logger LOG = LoggerFactory.getLogger(AbstractAction.class);
-
-	protected File file = null;
-	protected Set<Tag> tags = null;
-	private final Map<Tag, String> results;
-	private Map<String, String> unsupportedTags;
-	private UUID id = null;
-
-	protected AbstractAction() {
-		this.tags = new HashSet<>();
-		this.results = new HashMap<>();
-		this.unsupportedTags = new HashMap<>();
-		this.id = UUID.randomUUID();
-		LOG.trace("New action created with UUID {}", id);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public String getId() {
-		return id.toString();
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public Map<Tag, String> getResult() {
-		return results;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	@Override
-	public void addResult(final Tag tag, final String result) {
-		results.put(tag, result);
-	}
-
-	@Override
-	public void addUnsupportedResult(final String tag, final String result) {
-		unsupportedTags.put(tag, result);
-	}
-
-	/**
-	 * @return the unsupportedTags
-	 */
-	@Override
-	public final Map<String, String> getUnsupportedTags() {
-		return unsupportedTags;
-	}
-
-}

src/be/pw/jexif/internal/action/impl/AbstractAction.java

+/*******************************************************************************
+ * Copyright 2012 P_W999
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package be.pw.jexif.internal.action.impl;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import be.pw.jexif.enums.tag.Tag;
+import be.pw.jexif.internal.action.IAction;
+
+/**
+ * An abstract implementation of the IAction interface.
+ * 
+ * @author phillip
+ */
+abstract class AbstractAction implements IAction {
+
+	private static final Logger LOG = LoggerFactory.getLogger(AbstractAction.class);
+
+	protected File file = null;
+	protected Set<Tag> tags = null;
+	private final Map<Tag, String> results;
+	private Map<String, String> unsupportedTags;
+	private UUID id = null;
+
+	protected AbstractAction() {
+		this.tags = new HashSet<>();
+		this.results = new HashMap<>();
+		this.unsupportedTags = new HashMap<>();
+		this.id = UUID.randomUUID();
+		LOG.trace("New action created with UUID {}", id);
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public String getId() {
+		return id.toString();
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public Map<Tag, String> getResult() {
+		return results;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void addResult(final Tag tag, final String result) {
+		results.put(tag, result);
+	}
+
+	@Override
+	public void addUnsupportedResult(final String tag, final String result) {
+		unsupportedTags.put(tag, result);
+	}
+
+	/**
+	 * @return the unsupportedTags
+	 */
+	@Override
+	public final Map<String, String> getUnsupportedTags() {
+		return unsupportedTags;
+	}
+
+}

src/be/pw/jexif/internal/action/impl/CopyFromAction.java

 import be.pw.jexif.enums.tag.Tag;
 import be.pw.jexif.exception.JExifException;
 import be.pw.jexif.exception.JExifValidationException;
-import be.pw.jexif.internal.action.AbstractAction;
 import be.pw.jexif.internal.action.ICopyFromAction;
 import be.pw.jexif.internal.constants.ExecutionConstant;
 import be.pw.jexif.internal.util.ArrayUtil;

src/be/pw/jexif/internal/action/impl/DateTimeShiftAction.java

 import be.pw.jexif.enums.DateTag;
 import be.pw.jexif.enums.Errors;
 import be.pw.jexif.exception.JExifException;
-import be.pw.jexif.internal.action.AbstractAction;
 import be.pw.jexif.internal.action.IDateTimeShiftAction;
 import be.pw.jexif.internal.constants.ExecutionConstant;
 import be.pw.jexif.internal.util.ArrayUtil;

src/be/pw/jexif/internal/action/impl/TagReadAction.java

 import be.pw.jexif.enums.Errors;
 import be.pw.jexif.enums.tag.Tag;
 import be.pw.jexif.exception.JExifException;
-import be.pw.jexif.internal.action.AbstractAction;
 import be.pw.jexif.internal.action.ITagReadAction;
 import be.pw.jexif.internal.constants.ExecutionConstant;
 import be.pw.jexif.internal.util.ArrayUtil;

src/be/pw/jexif/internal/action/impl/TagReadAllAction.java

 
 import be.pw.jexif.enums.Errors;
 import be.pw.jexif.exception.JExifException;
-import be.pw.jexif.internal.action.AbstractAction;
 import be.pw.jexif.internal.action.ITagReadAllAction;
 import be.pw.jexif.internal.constants.ExecutionConstant;
 import be.pw.jexif.internal.util.ArrayUtil;

src/be/pw/jexif/internal/action/impl/TagWriteAction.java

 import be.pw.jexif.enums.tag.Tag;
 import be.pw.jexif.exception.JExifException;
 import be.pw.jexif.exception.JExifValidationException;
-import be.pw.jexif.internal.action.AbstractAction;
 import be.pw.jexif.internal.action.ITagWriteAction;
 import be.pw.jexif.internal.constants.ExecutionConstant;
 import be.pw.jexif.internal.util.ArrayUtil;

src/be/pw/jexif/internal/result/impl/CopyFromResultParser.java

  * @author phillip
  * @since v0.0.6
  */
-public class CopyFromResultParser implements IResultParser {
+class CopyFromResultParser implements IResultParser {
 
 	/**
 	 * Logger for this class.

src/be/pw/jexif/internal/thread/event/ErrorEvent.java

 	 * 
 	 * @return the message.
 	 */
-	public String getMsg() {
+	protected String getMsg() {
 		return msg;
 	}
 

src/be/pw/jexif/internal/thread/event/InputEvent.java

 	 * 
 	 * @return the message.
 	 */
-	public String getMsg() {
+	protected String getMsg() {
 		return msg;
 	}