MISC: Code cleaning. Removed unnecessary instanceof check. 03/11903/1
authorkh5325.kim <kh5325.kim@samsung.com>
Thu, 7 Nov 2013 12:55:46 +0000 (21:55 +0900)
committerkh5325.kim <kh5325.kim@samsung.com>
Thu, 7 Nov 2013 12:55:46 +0000 (21:55 +0900)
Removed unnecessary instanceof check.
Added instanceof check before casting.

Change-Id: Ia34bf353a3a24c0600bb6f8ec584ce8c4cd482af
Signed-off-by: kh5325.kim <kh5325.kim@samsung.com>
org.tizen.common.connection/src/org/tizen/common/connection/sdblib/dnd/FileEntryTransfer.java
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/handler/GomSmartLaunchCycleHandler.java
org.tizen.common/src/org/tizen/common/rds/ui/preference/PropertyAndPreferencePage.java

index 39c6cbe..2cdf0e3 100644 (file)
@@ -32,75 +32,84 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.eclipse.swt.dnd.ByteArrayTransfer;
-import org.tizen.common.util.log.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.tizen.sdblib.service.FileEntry;
 
 public class FileEntryTransfer extends ByteArrayTransfer {
+    protected final Logger logger = LoggerFactory.getLogger(getClass());
 
-       private static FileEntryTransfer instance = new FileEntryTransfer();
-       private static final String TYPE_NAME = "sdb-transfer-format";
-       private static final int TYPE_ID = registerType(TYPE_NAME);
+    private static FileEntryTransfer instance = new FileEntryTransfer();
+    private static final String TYPE_NAME = "sdb-transfer-format";
+    private static final int TYPE_ID = registerType(TYPE_NAME);
 
-       private FileEntryTransfer() { }
-       
-       public static FileEntryTransfer getInstance() {
-               return instance;
-       }
-       @Override
-       protected int[] getTypeIds() {
-               return new int[] { TYPE_ID };
-       }
-       @Override
-       protected String[] getTypeNames() {
-               return new String[] { TYPE_NAME };
-       }
-       
-       public byte[] toByteArray(FileEntry[] entries) {
-               ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-               DataOutputStream out = new DataOutputStream(byteOut);
+    private FileEntryTransfer() {
+    }
 
-               byte[] bytes = null;
+    public static FileEntryTransfer getInstance() {
+        return instance;
+    }
 
-               try {
-                       out.writeInt(entries.length);
+    @Override
+    protected int[] getTypeIds() {
+        return new int[] { TYPE_ID };
+    }
 
-                       for (int i = 0; i < entries.length; i++) {
-                               FileEntry data = entries[i];
-                               if (data instanceof FileEntry) {
-                                       try {
-                                               out.writeUTF(((FileEntry) data).getFullPath());
-                                       } catch (IOException e1) {
-                                               // TODO Auto-generated catch block
-                                               e1.printStackTrace();
-                                       }
-                               }
-                       }
+    @Override
+    protected String[] getTypeNames() {
+        return new String[] { TYPE_NAME };
+    }
 
-                       out.close();
-                       bytes = byteOut.toByteArray();
-               } catch (IOException e) {
-                       // when in doubt send nothing
-                       Logger.error("write utf failed:" +  e);
-               }
-               return bytes;
-       }
+    public byte[] toByteArray(FileEntry[] entries) {
+        ByteArrayOutputStream byteOut = null;
+        DataOutputStream out = null;
+        byte[] bytes = null;
+        try {
+            byteOut = new ByteArrayOutputStream();
+            out = new DataOutputStream(byteOut);
+            out.writeInt(entries.length);
+            for (int i = 0; i < entries.length; i++) {
+                FileEntry data = entries[i];
+                try {
+                    out.writeUTF(((FileEntry) data).getFullPath());
+                } catch (IOException e1) {
+                    logger.error("Failed to write", e1);
+                }
+            }
+            bytes = byteOut.toByteArray();
+        } catch (IOException e) {
+            // when in doubt send nothing
+            logger.error("Failed to write", e);
+        } finally {
+            if (out != null)
+                try {
+                    out.close();
+                } catch (IOException e) {
+                }
+        }
+        return bytes;
+    }
 
-       public String[] fromByteArray(byte[] bytes) {
-               DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
-               try {
-                       int n = in.readInt();
-
-                       String[] paths = new String[n];
-                       for (int i = 0; i < n; i++) {
-                               String path = in.readUTF();
-                               paths[i] = path;
-                       }
-                       return paths;
-               } catch (IOException e) {
-                       Logger.error("read integer failed:" +  e);
-                       return null;
-               }
-       }
-
-       
+    public String[] fromByteArray(byte[] bytes) {
+        DataInputStream in = null;
+        try {
+            in = new DataInputStream(new ByteArrayInputStream(bytes));
+            int n = in.readInt();
+            String[] paths = new String[n];
+            for (int i = 0; i < n; i++) {
+                String path = in.readUTF();
+                paths[i] = path;
+            }
+            return paths;
+        } catch (IOException e) {
+            logger.error("Failed to read an int", e);
+            return null;
+        } finally {
+            if (in != null)
+                try {
+                    in.close();
+                } catch (IOException e) {
+                }
+        }
+    }
 }
index 84469e3..b403a12 100644 (file)
@@ -63,8 +63,8 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
             GomMessages.SMARTLAUNCH_CYCLE_COLUMNS_4};
     private String[] sampleColumns = {"Profile", "ProjectProject", "LaunchConfigurationLaunchConfiguration", "emulator-xxxxx"};
     
-    private final static String TIZEN_SMART_LAUNCH_UP_ID="org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.up";
-    private final static String TIZEN_SMART_LAUNCH_DOWN_ID="org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.down";
+    private final static String TIZEN_SMART_LAUNCH_UP_ID = "org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.up";
+    private final static String TIZEN_SMART_LAUNCH_DOWN_ID = "org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.down";
 
     @Override
     protected void addItems(Table table, WorkbenchPage page) {
@@ -78,8 +78,7 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
                 .getWorkbench().getService(ICommandService.class);
         final Command command = commandService
                 .getCommand(TIZEN_SMART_LAUNCH_UP_ID);
-        ParameterizedCommand commandBack = new ParameterizedCommand(command,
-                null);
+        ParameterizedCommand commandBack = new ParameterizedCommand(command, null);
         return commandBack;
     }
 
@@ -114,14 +113,12 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
         table.setHeaderVisible(true);
         table.setLinesVisible(true);
 
-        for(int i = 0 ;i < columns.length ; i++)
-        {
+        for (int i = 0 ;i < columns.length ; i++) {
             createTableColumn(table, sampleColumns[i], columns[i]);
         }
 
         addItems(table, page);
         int tableItemCount = table.getItemCount();
-
         switch (tableItemCount) {
         case 0:
             cancel(dialog);
@@ -132,13 +129,13 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
         default:
             int i;
             if (gotoDirection) {
-                i= getCurrentItemIndex() + 1;
+                i = getCurrentItemIndex() + 1;
                 if (i >= tableItemCount)
-                    i= 0;
+                    i = 0;
             } else {
-                i= getCurrentItemIndex() - 1;
+                i = getCurrentItemIndex() - 1;
                 if (i < 0)
-                    i= tableItemCount - 1;
+                    i = tableItemCount - 1;
             }
             table.setSelection(i);
         }
@@ -147,17 +144,14 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
         dialog.pack();
 
         Rectangle tableBounds = table.getBounds();
-        tableBounds.height = Math.min(tableBounds.height, table.getItemHeight()
-                * MAX_ITEMS);
+        tableBounds.height = Math.min(tableBounds.height, table.getItemHeight() * MAX_ITEMS);
         table.setBounds(tableBounds);
 
-        dialog.setBounds(dialog.computeTrim(tableBounds.x, tableBounds.y,
-                tableBounds.width, tableBounds.height));
+        dialog.setBounds(dialog.computeTrim(tableBounds.x, tableBounds.y, tableBounds.width, tableBounds.height));
 
         table.setFocus();
         table.addFocusListener(new FocusListener() {
             public void focusGained(FocusEvent e) {
-                // Do nothing
             }
 
             public void focusLost(FocusEvent e) {
@@ -170,18 +164,17 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
 
             public void mouseMove(MouseEvent e) {
                 if (table.equals(e.getSource())) {
-                    Object o = table.getItem(new Point(e.x, e.y));
+                    TableItem o = table.getItem(new Point(e.x, e.y));
                     if (lastItem == null ^ o == null) {
-                        table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(
-                                SWT.CURSOR_HAND));
+                        table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                     }
-                    if (o instanceof TableItem) {
+                    if (o == null) {
+                        lastItem = null;
+                    } else {
                         if (!o.equals(lastItem)) {
-                            lastItem = (TableItem) o;
+                            lastItem = o;
                             table.setSelection(new TableItem[] { lastItem });
                         }
-                    } else if (o == null) {
-                        lastItem = null;
                     }
                 }
             }
@@ -211,8 +204,7 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
         }
     }
     
-    private TableColumn createTableColumn(Table table, String sampleText, String text)
-    {
+    private TableColumn createTableColumn(Table table, String sampleText, String text) {
         TableColumn tc = new TableColumn(table, SWT.NONE);
         tc.setResizable(true);
         tc.setText(sampleText);
@@ -244,11 +236,7 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
     
     @Override
     protected void activate(IWorkbenchPage page, Object selectedItem) {
-        if (page == null) {
-            return;
-        }
-
-        if (selectedItem == null) {
+        if (page == null || selectedItem == null) {
             return;
         }
 
@@ -258,6 +246,5 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
                 GomSmartLauncher.smartLaunch(data);
             }
         }
-
     }
 }
index 33f5b3e..82cb1d7 100755 (executable)
@@ -93,11 +93,13 @@ public abstract class PropertyAndPreferencePage extends PreferencePage implement
 
             IDialogFieldListener listener= new IDialogFieldListener() {
                 public void dialogFieldChanged(DialogField field) {
-                    boolean enabled= ((SelectionButtonDialogField) field).isSelected();
-                    enableProjectSpecificSettings(enabled);
-
-                    if (enabled && getData() != null) {
-                        applyData(getData());
+                    if (field instanceof SelectionButtonDialogField) {
+                        boolean enabled= ((SelectionButtonDialogField) field).isSelected();
+                        enableProjectSpecificSettings(enabled);
+    
+                        if (enabled && getData() != null) {
+                            applyData(getData());
+                        }
                     }
                 }
             };