tmf.core: Make TmfTimestampFormat#toPattern NonNull
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 2 Feb 2017 15:03:42 +0000 (10:03 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 2 Feb 2017 18:16:17 +0000 (13:16 -0500)
And all the changes required for this to work.

Change-Id: Ie07326346cf187f37011d5c624665186440f4517
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/90189
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.chart.ui/src/org/eclipse/tracecompass/internal/tmf/chart/ui/format/ChartTimeStampFormat.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimePreferences.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestampFormat.java

index ff4712cb3c9158101fdebd26093a03a21aaf75ab..1a7188b0566768dcecf4fd6f80bde9c96fa832f5 100644 (file)
@@ -17,7 +17,6 @@ import java.text.Format;
 import java.text.ParsePosition;
 
 import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRangeMap;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
 
@@ -90,7 +89,7 @@ public class ChartTimeStampFormat extends Format {
      * @return the pattern string.
      */
     public String getPattern() {
-        return NonNullUtils.checkNotNull(fFormat.toPattern());
+        return fFormat.toPattern();
     }
 
     // ------------------------------------------------------------------------
index 3dc7e7817868c68f4e3df6975a128f0e7a4d9da9..06405aa65c928e896ad6ab08b3d59b824c963de6 100644 (file)
@@ -25,6 +25,7 @@ import org.eclipse.core.runtime.preferences.DefaultScope;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.core.runtime.preferences.IPreferencesService;
 import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 
 /**
@@ -79,7 +80,7 @@ public final class TmfTimePreferences {
      *
      * @return the timestamp pattern
      */
-    public static String getTimePattern() {
+    public static @NonNull String getTimePattern() {
         return computeTimePattern(getPreferenceMap(false));
     }
 
@@ -88,7 +89,7 @@ public final class TmfTimePreferences {
      *
      * @return the interval pattern
      */
-    public static String getIntervalPattern() {
+    public static @NonNull String getIntervalPattern() {
         return computeIntervalPattern(getPreferenceMap(false));
     }
 
@@ -154,7 +155,7 @@ public final class TmfTimePreferences {
     // Operations
     // ------------------------------------------------------------------------
 
-    private static String computeIntervalPattern(Map<String, String> prefsMap) {
+    private static @NonNull String computeIntervalPattern(Map<String, String> prefsMap) {
         String ssecFmt = computeSubSecFormat(prefsMap);
         return ITmfTimePreferencesConstants.TIME_ELAPSED_FMT + "." + ssecFmt; //$NON-NLS-1$
     }
@@ -176,7 +177,7 @@ public final class TmfTimePreferences {
      * @param prefsMap the preferences to apply when computing the time pattern
      * @return the time pattern resulting in applying the preferences
      */
-    public static String computeTimePattern(Map<String, String> prefsMap) {
+    public static @NonNull String computeTimePattern(Map<String, String> prefsMap) {
         String dateTimeFormat = prefsMap.get(ITmfTimePreferencesConstants.DATIME);
         if (dateTimeFormat == null) {
             dateTimeFormat = ITmfTimePreferencesConstants.DEFAULT_TIME_PATTERN;
index 66b042bbb7c1542f9545c1012246cf8f36a88105..5281421262640745c4a4ec0355c4a617da3cb791 100644 (file)
@@ -26,6 +26,8 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * A formatting and parsing facility that can handle timestamps that span the
  * epoch with a precision down to the nanosecond. It can be understood as an
@@ -222,7 +224,7 @@ public class TmfTimestampFormat extends SimpleDateFormat {
     private static TmfTimestampFormat fDefaultIntervalFormat = null;
 
     // The timestamp pattern
-    private String fPattern;
+    private @NonNull String fPattern;
 
     // The index of the decimal separator in the pattern
     private int fPatternDecimalSeparatorIndex;
@@ -302,8 +304,9 @@ public class TmfTimestampFormat extends SimpleDateFormat {
      *
      * @param pattern the format pattern
      */
-    public TmfTimestampFormat(String pattern) {
+    public TmfTimestampFormat(@NonNull String pattern) {
         fLocale = Locale.getDefault();
+        fPattern = pattern;
         applyPattern(pattern);
     }
 
@@ -313,9 +316,10 @@ public class TmfTimestampFormat extends SimpleDateFormat {
      * @param pattern the format pattern
      * @param timeZone the time zone
      */
-    public TmfTimestampFormat(String pattern, TimeZone timeZone) {
+    public TmfTimestampFormat(@NonNull String pattern, TimeZone timeZone) {
         fLocale = Locale.getDefault();
         setTimeZone(timeZone);
+        fPattern = pattern;
         applyPattern(pattern);
     }
 
@@ -326,11 +330,12 @@ public class TmfTimestampFormat extends SimpleDateFormat {
      * @param timeZone the time zone
      * @param locale the locale
      */
-    public TmfTimestampFormat(String pattern, TimeZone timeZone, Locale locale) {
+    public TmfTimestampFormat(@NonNull String pattern, TimeZone timeZone, Locale locale) {
         super("", locale); //$NON-NLS-1$
         fLocale = locale;
         setTimeZone(timeZone);
         setCalendar(Calendar.getInstance(timeZone, locale));
+        fPattern = pattern;
         applyPattern(pattern);
     }
 
@@ -383,6 +388,9 @@ public class TmfTimestampFormat extends SimpleDateFormat {
 
     @Override
     public void applyPattern(String pattern) {
+        if (pattern == null) {
+            throw new NullPointerException("TmfTimestampFormat: pattern should not be null"); //$NON-NLS-1$
+        }
         fPattern = pattern;
         fPatternDecimalSeparatorIndex = indexOfPatternDecimalSeparator(pattern);
         fDateTimePattern = unquotePattern(pattern.substring(0, fPatternDecimalSeparatorIndex));
@@ -401,7 +409,7 @@ public class TmfTimestampFormat extends SimpleDateFormat {
     }
 
     @Override
-    public String toPattern() {
+    public @NonNull String toPattern() {
         return fPattern;
     }
 
This page took 0.02807 seconds and 5 git commands to generate.