[Bedework-commit] calendarapi r844 - in trunk/calFacade/src/org/bedework/calfacade: . util

svnadmin at bedework.org svnadmin at bedework.org
Thu Mar 12 09:39:42 EDT 2009


Author: douglm
Date: 2009-03-12 09:39:42 -0400 (Thu, 12 Mar 2009)
New Revision: 844

Modified:
   trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java
   trunk/calFacade/src/org/bedework/calfacade/BwEvent.java
   trunk/calFacade/src/org/bedework/calfacade/util/CalFacadeUtil.java
Log:
A little more refactoring - no functional changes

Modified: trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java	2009-03-11 04:45:59 UTC (rev 843)
+++ trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java	2009-03-12 13:39:42 UTC (rev 844)
@@ -71,6 +71,7 @@
 import net.fortuna.ical4j.model.Dur;
 import net.fortuna.ical4j.model.Parameter;
 import net.fortuna.ical4j.model.ParameterList;
+import net.fortuna.ical4j.model.Property;
 import net.fortuna.ical4j.model.TimeZone;
 import net.fortuna.ical4j.model.parameter.Value;
 import net.fortuna.ical4j.model.property.DateProperty;
@@ -394,13 +395,13 @@
     DtEnd dtEnd;
     java.util.Date endDt = dur.getTime(dtStart.getDate());
 
-    Parameter tzid = CalFacadeUtil.getIcalParameter(dtStart, "TZID");
+    Parameter tzid = getIcalParameter(dtStart, "TZID");
 
     if (dateOnly) {
       dtEnd = new DtEnd(new Date(endDt));
-      CalFacadeUtil.addIcalParameter(dtEnd, Value.DATE);
+      addIcalParameter(dtEnd, Value.DATE);
       if (tzid != null) {
-        CalFacadeUtil.addIcalParameter(dtEnd, tzid);
+        addIcalParameter(dtEnd, tzid);
       }
     } else {
       DateTime d = new DateTime(endDt);
@@ -412,7 +413,7 @@
 //          dtEnd = new DtEnd(d, dtStart.isUtc());
       dtEnd = new DtEnd(d);
       if (tzid != null) {
-        CalFacadeUtil.addIcalParameter(dtEnd, tzid);
+        addIcalParameter(dtEnd, tzid);
       } else if (dtStart.isUtc()) {
         dtEnd.setUtc(true);
       }
@@ -435,11 +436,11 @@
 
     if (getDateType()) {
       dtEnd = new DtEnd(new Date(endDt));
-      CalFacadeUtil.addIcalParameter(dtEnd, Value.DATE);
+      addIcalParameter(dtEnd, Value.DATE);
     } else {
       DateTime d = new DateTime(endDt);
 
-      Parameter tzid = CalFacadeUtil.getIcalParameter(dtStart, "TZID");
+      Parameter tzid = getIcalParameter(dtStart, "TZID");
       if (tzid != null) {
         DateTime sd = (DateTime)dtStart.getDate();
 
@@ -448,7 +449,7 @@
 //          dtEnd = new DtEnd(d, dtStart.isUtc());
       dtEnd = new DtEnd(d);
       if (tzid != null) {
-        CalFacadeUtil.addIcalParameter(dtEnd, tzid);
+        addIcalParameter(dtEnd, tzid);
       } else if (dtStart.isUtc()) {
         dtEnd.setUtc(true);
       }
@@ -475,11 +476,11 @@
    * @throws CalFacadeException
    */
   public void initFromDateTime(DateProperty val) throws CalFacadeException {
-    Parameter par = CalFacadeUtil.getIcalParameter(val, "VALUE");
+    Parameter par = getIcalParameter(val, "VALUE");
 
     init((par != null) && (par.equals(Value.DATE)),
          val.getValue(),
-         CalFacadeUtil.getTzid(val));
+         getTzid(val));
   }
 
   /** Set utc time
@@ -588,6 +589,53 @@
   }
 
   /* ====================================================================
+   *                        private methods
+   * ==================================================================== */
+
+  /** Add val to prop
+   *
+   * @param prop
+   * @param val
+   */
+  private static void addIcalParameter(Property prop, Parameter val) {
+    ParameterList parl =  prop.getParameters();
+
+    parl.add(val);
+  }
+
+  /** Get named parameter from prop
+   *
+   * @param prop
+   * @param name
+   * @return Parameter
+   */
+  private static Parameter getIcalParameter(Property prop, String name) {
+    ParameterList parl =  prop.getParameters();
+
+    if (parl == null) {
+      return null;
+    }
+
+    return parl.getParameter(name);
+  }
+
+  /** Return the timezone id if it is set for the property.
+   *
+   * @param val
+   * @return String tzid or null.
+   */
+  private static String getTzid(DateProperty val) {
+    Parameter tzidPar = getIcalParameter(val, "TZID");
+
+    String tzid = null;
+    if (tzidPar != null) {
+      tzid = tzidPar.getValue();
+    }
+
+    return tzid;
+  }
+
+  /* ====================================================================
    *                        Object methods
    * ==================================================================== */
 

Modified: trunk/calFacade/src/org/bedework/calfacade/BwEvent.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwEvent.java	2009-03-11 04:45:59 UTC (rev 843)
+++ trunk/calFacade/src/org/bedework/calfacade/BwEvent.java	2009-03-12 13:39:42 UTC (rev 844)
@@ -3489,6 +3489,26 @@
     setScheduleState(ev.getScheduleState());
   }
 
+  /** Check for a valid transparency - null is invalid
+   *
+   * @param val
+   * @return boolean true = it's OK
+   */
+  public static boolean validTransparency(String val) {
+    if (val == null) {
+      /* We could argue that's valid as the default but I think that leads to
+       * problems.
+       */
+      return false;
+    }
+
+    if (transparencyOpaque.equals(val)) {
+      return true;
+    }
+
+    return transparencyTransparent.equals(val);
+  }
+
   /* ====================================================================
    *                   Object methods
    * ==================================================================== */

Modified: trunk/calFacade/src/org/bedework/calfacade/util/CalFacadeUtil.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/util/CalFacadeUtil.java	2009-03-11 04:45:59 UTC (rev 843)
+++ trunk/calFacade/src/org/bedework/calfacade/util/CalFacadeUtil.java	2009-03-12 13:39:42 UTC (rev 844)
@@ -53,18 +53,9 @@
 */
 package org.bedework.calfacade.util;
 
-import org.bedework.calfacade.BwEvent;
 import org.bedework.calfacade.exc.CalFacadeException;
 
-import net.fortuna.ical4j.model.Parameter;
-import net.fortuna.ical4j.model.ParameterList;
-import net.fortuna.ical4j.model.Property;
-import net.fortuna.ical4j.model.property.DateProperty;
-
 import java.io.Serializable;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Locale;
@@ -98,40 +89,6 @@
   private CalFacadeUtil() {
   }
 
-  /** From hibernate.util
-   *
-   * @param bytes
-   * @return int
-   */
-  public static int toInt(byte[] bytes ) {
-    int result = 0;
-    for (int i = 0; i < 4; i++) {
-      result = (result << 8) - Byte.MIN_VALUE + (int)bytes[i];
-    }
-
-    return result;
-  }
-
-  /** Check for a valid transparency - null is invalid
-   *
-   * @param val
-   * @return boolean true = it's OK
-   */
-  public static boolean validTransparency(String val) {
-    if (val == null) {
-      /* We could argue that's valid as the default but I think that leads to
-       * problems.
-       */
-      return false;
-    }
-
-    if (BwEvent.transparencyOpaque.equals(val)) {
-      return true;
-    }
-
-    return BwEvent.transparencyTransparent.equals(val);
-  }
-
   /** Update the to Collection with from elements. This is used to
    * add or remove members from a Collection managed by hibernate for example
    * where a replacement of the Collection is not allowed.
@@ -314,93 +271,6 @@
     return 1;
   }
 
-  /** Return a String representing the given String array, achieved by
-   * URLEncoding the individual String elements then concatenating with
-   *intervening blanks.
-   *
-   * @param  val    String[] value to encode
-   * @return String encoded value
-   */
-  public static String encodeArray(String[] val){
-    if (val == null) {
-      return null;
-    }
-
-    int len = val.length;
-
-    if (len == 0) {
-      return "";
-    }
-
-    StringBuffer sb = new StringBuffer();
-
-    for (int i = 0; i < len; i++) {
-      if (i > 0) {
-        sb.append(" ");
-      }
-
-      String s = val[i];
-
-      try {
-        if (s == null) {
-          sb.append("\t");
-        } else {
-          sb.append(URLEncoder.encode(s, "UTF-8"));
-        }
-      } catch (Throwable t) {
-        throw new RuntimeException(t);
-      }
-    }
-
-    return sb.toString();
-  }
-
-  /** Return a StringArray resulting from decoding the given String which
-   * should have been encoded by encodeArray
-   *
-   * @param  val      String value encoded by encodeArray
-   * @return String[] decoded value
-   */
-  public static String[] decodeArray(String val){
-    if (val == null) {
-      return null;
-    }
-
-    int len = val.length();
-
-    if (len == 0) {
-      return new String[0];
-    }
-
-    ArrayList<String> al = new ArrayList<String>();
-    int i = 0;
-
-    while (i < len) {
-      int end = val.indexOf(" ", i);
-
-      String s;
-      if (end < 0) {
-        s = val.substring(i);
-        i = len;
-      } else {
-        s = val.substring(i, end);
-        i = end + 1;
-      }
-
-      try {
-        if (s.equals("\t")) {
-          al.add(null);
-        } else {
-          al.add(URLDecoder.decode(s, "UTF-8"));
-        }
-      } catch (Throwable t) {
-        throw new RuntimeException(t);
-      }
-    }
-
-    return al.toArray(new String[al.size()]);
-  }
-
   /** Given a class name return an object of that class.
    * The class parameter is used to check that the
    * named class is an instance of that class.
@@ -432,53 +302,6 @@
     }
   }
 
-  /* ====================================================================
-             ical utilities
-     ==================================================================== */
-
-  /** Add val to prop
-   *
-   * @param prop
-   * @param val
-   */
-  public static void addIcalParameter(Property prop, Parameter val) {
-    ParameterList parl =  prop.getParameters();
-
-    parl.add(val);
-  }
-
-  /** Get named parameter from prop
-   *
-   * @param prop
-   * @param name
-   * @return Parameter
-   */
-  public static Parameter getIcalParameter(Property prop, String name) {
-    ParameterList parl =  prop.getParameters();
-
-    if (parl == null) {
-      return null;
-    }
-
-    return parl.getParameter(name);
-  }
-
-  /** Return the timezone id if it is set for the property.
-   *
-   * @param val
-   * @return String tzid or null.
-   */
-  public static String getTzid(DateProperty val) {
-    Parameter tzidPar = getIcalParameter(val, "TZID");
-
-    String tzid = null;
-    if (tzidPar != null) {
-      tzid = tzidPar.getValue();
-    }
-
-    return tzid;
-  }
-
   /** Turn the int minutes into a 4 digit String hours and minutes value
    *
    * @param minutes  int
@@ -492,7 +315,7 @@
    * @param val
    * @return String
    */
-  public static String pad2(int val) {
+  private static String pad2(int val) {
     if (val > 9) {
       return String.valueOf(val);
     }



More information about the Bedework-commit mailing list