incubator-oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smccl...@apache.org
Subject svn commit: r917722 [1/3] - in /incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons: database/ date/ exec/ filter/ io/ option/ option/handler/ option/parser/ option/required/ option/util/ option/validator/ pagination/ spring/ s...
Date Mon, 01 Mar 2010 21:17:27 GMT
Author: smcclees
Date: Mon Mar  1 21:17:24 2010
New Revision: 917722

URL: http://svn.apache.org/viewvc?rev=917722&view=rev
Log:
Working towards OODT-3, prepending the necessary files with HEADER.txt RE:mattmann's commits. 

Modified:
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/DatabaseConnectionBuilder.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/SqlScript.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/date/DateUtils.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/EnvUtilities.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecHelper.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecUtils.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/StreamGobbler.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/ObjectTimeEvent.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEvent.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEventWeightedHash.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/io/LoggerOutputStream.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOption.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/CmdLineOptionInstance.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/BeanInfo.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionBeanHandler.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/CmdLineOptionHandler.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/handler/StdCmdLineOptionHandler.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/parser/CmdLineOptionParser.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/required/RequiredOption.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionUtils.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/util/CmdLineOptionsUsagePrinter.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/AllowedArgsCmdLineOptionValidator.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/ArgRegExpCmdLineOptionValidator.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/ClassExistsCmdLineOptionValidator.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/CmdLineOptionValidator.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/FileExistCmdLineOptionValidator.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/option/validator/NoRestrictionsCmdLineOptionValidator.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/pagination/PaginationUtils.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/spring/SpringSetIdInjectionType.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/spring/postprocessor/SetIdBeanPostProcessor.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/xml/DOMUtil.java
    incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/xml/XMLUtils.java

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/DatabaseConnectionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/DatabaseConnectionBuilder.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/DatabaseConnectionBuilder.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/DatabaseConnectionBuilder.java Mon Mar  1 21:17:24 2010
@@ -1,7 +1,20 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.database;
 

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/SqlScript.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/SqlScript.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/SqlScript.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/database/SqlScript.java Mon Mar  1 21:17:24 2010
@@ -1,7 +1,20 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.database;
 
@@ -235,4 +248,4 @@
         }
     }
 
-}
\ No newline at end of file
+}

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/date/DateUtils.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/date/DateUtils.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/date/DateUtils.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/date/DateUtils.java Mon Mar  1 21:17:24 2010
@@ -1,219 +1,232 @@
-//Copyright (c) 2007, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.date;
-
-//JDK imports
-import java.text.DecimalFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.SimpleTimeZone;
-import java.util.TimeZone;
-
-/**
- * 
- * @author bfoster
- * @version $Revision$
- * 
- */
-public class DateUtils {
-
-    public static enum FormatType { UTC_FORMAT, LOCAL_FORMAT, TAI_FORMAT };
-    
-    public static Calendar tai93epoch = new GregorianCalendar(1993, GregorianCalendar.JANUARY, 1);
-    
-    public static Calendar julianEpoch = new GregorianCalendar(1970, GregorianCalendar.JANUARY, 1);
-    
-    private static SimpleDateFormat utcFormat = new SimpleDateFormat(
-            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
-    private static SimpleDateFormat taiFormat = new SimpleDateFormat(
-            "yyyy-MM-dd'T'HH:mm:ss.SSS");
-    private static SimpleDateFormat localFormat = new SimpleDateFormat(
-            "yyyy-MM-dd'T'HH:mm:ss.SSSZ");    
-    
-    static {
-        utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-        taiFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-    }
-    
-    static enum IndexType {
-        DATE(0),
-        LEAP_SECS(1);
-        
-        public int index;
-        
-        IndexType(int index) {
-            this.index = index;
-        }
-    }
-    
-    //Info taken from ftp://oceans.gsfc.nasa.gov/COMMON/leapsec.dat
-    static long[][] dateAndLeapSecs = {
-        { 0 , 10 },
-        { new GregorianCalendar(1972, GregorianCalendar.JULY,    1).getTimeInMillis() , 11 },
-        { new GregorianCalendar(1973, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 12 },
-        { new GregorianCalendar(1974, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 13 },
-        { new GregorianCalendar(1975, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 14 },
-        { new GregorianCalendar(1976, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 15 },
-        { new GregorianCalendar(1977, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 16 },
-        { new GregorianCalendar(1978, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 17 },
-        { new GregorianCalendar(1979, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 18 },
-        { new GregorianCalendar(1980, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 19 },
-        { new GregorianCalendar(1981, GregorianCalendar.JULY,    1).getTimeInMillis() , 20 },
-        { new GregorianCalendar(1982, GregorianCalendar.JULY,    1).getTimeInMillis() , 21 },
-        { new GregorianCalendar(1983, GregorianCalendar.JULY,    1).getTimeInMillis() , 22 },
-        { new GregorianCalendar(1985, GregorianCalendar.JULY,    1).getTimeInMillis() , 23 },
-        { new GregorianCalendar(1988, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 24 },
-        { new GregorianCalendar(1990, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 25 },
-        { new GregorianCalendar(1991, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 26 },
-        { new GregorianCalendar(1992, GregorianCalendar.JULY,    1).getTimeInMillis() , 27 },
-        { new GregorianCalendar(1993, GregorianCalendar.JULY,    1).getTimeInMillis() , 28 },
-        { new GregorianCalendar(1994, GregorianCalendar.JULY,    1).getTimeInMillis() , 29 },
-        { new GregorianCalendar(1996, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 30 },
-        { new GregorianCalendar(1997, GregorianCalendar.JULY,    1).getTimeInMillis() , 31 },
-        { new GregorianCalendar(1999, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 32 },
-        { new GregorianCalendar(2006, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 33 },
-        { new GregorianCalendar(2009, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 34 },
-    };
-    
-    private DateUtils() {}
-    
-    public static int getLeapSecsForDate(Calendar utcCal) throws Exception {
-        long timeInMillis = utcCal.getTimeInMillis();
-        for (int i = dateAndLeapSecs.length - 1; i >= 0; i--) {
-            if (dateAndLeapSecs[i][IndexType.DATE.index] < timeInMillis)
-                return (int) dateAndLeapSecs[i][IndexType.LEAP_SECS.index];
-        }
-        throw new Exception("No Leap Second found for given date!");
-    }
-    
-    public static synchronized Calendar toTai(Calendar cal) throws Exception {
-        Calendar taiCal = Calendar.getInstance(createTaiTimeZone(getLeapSecsForDate(cal)));
-        taiCal.setTimeInMillis(cal.getTimeInMillis() + getLeapSecsForDate(cal) * 1000);
-        return taiCal;
-    }
-    
-    private static synchronized Calendar taiToUtc(Calendar taiCal) throws Exception {
-        Calendar calUtc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
-        calUtc.setTimeInMillis(taiCal.getTimeInMillis() - taiCal.getTimeZone().getRawOffset());
-        return calUtc;
-    }
-    
-    private static Calendar taiToLocal(Calendar taiCal) throws Exception {
-        return toLocal(taiToUtc(taiCal));
-    }
-
-    public static synchronized Calendar toLocal(Calendar cal) throws Exception {
-        if (cal.getTimeZone().getID().equals("TAI")) {
-            return taiToLocal(cal);
-        } else {
-            Calendar calLocal = Calendar.getInstance();
-            calLocal.setTimeInMillis(cal.getTimeInMillis());
-            return calLocal;
-        }
-    }
-
-    public static synchronized Calendar toUtc(Calendar cal) throws Exception {
-        if (cal.getTimeZone().getID().equals("TAI")) {
-            return taiToUtc(cal);
-        } else {
-            Calendar calUtc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
-            calUtc.setTimeInMillis(cal.getTimeInMillis());
-            return calUtc;   
-        }
-    }
-    
-    public static Calendar getCurrentUtcTime() throws Exception {
-        return toUtc(getCurrentLocalTime());
-    }
-    
-    public static Calendar getCurrentLocalTime() throws Exception {
-        return Calendar.getInstance();
-    }
-    
-    public static Calendar getCurrentTaiTime() throws Exception {
-        return toTai(getCurrentUtcTime());
-    }
-    
-    public static String toCustomLocalFormat(Calendar cal, String format) {
-        return new SimpleDateFormat(format).format(cal.getTime());
-    }
-    
-    public static String toString(Calendar cal) {
-        String timeZoneId = cal.getTimeZone().getID();
-        if (timeZoneId.equals("UTC")) {
-            return utcFormat.format(cal.getTime());
-        }else if (timeZoneId.equals("TAI")) {
-            return taiFormat.format(cal.getTime()) + "-0000" 
-                + (cal.getTimeZone().getRawOffset() / 1000);
-        }else {
-            return localFormat.format(cal.getTime());
-        }
-    }
-    
-    public static synchronized Calendar toLocalCustomFormatCalendar(String calString, String format) throws ParseException {
-        Calendar localCal = Calendar.getInstance();
-        localCal.setTime(new SimpleDateFormat(format).parse(calString));
-        return localCal;
-    }
-    
-    public static synchronized Calendar toCalendar(String calString, FormatType formatType)
-            throws ParseException {
-        Calendar cal = Calendar.getInstance();
-        switch (formatType) {
-            case LOCAL_FORMAT:
-                cal.setTimeInMillis(localFormat.parse(calString).getTime());
-                break;
-            case TAI_FORMAT:
-                cal.setTimeZone(createTaiTimeZone(Integer.parseInt(calString
-                    .substring(calString.length() - 2))));
-                calString = calString.substring(0, calString.length() - 5);
-                cal.setTimeInMillis(taiFormat.parse(calString).getTime());
-                break;
-            case UTC_FORMAT:
-                cal.setTimeZone(TimeZone.getTimeZone("UTC"));
-                cal.setTimeInMillis(utcFormat.parse(calString).getTime());
-                break;
-            default:
-                cal.setTimeInMillis(localFormat.parse(calString).getTime());
-        }
-        return cal;
-    }
-    
-    public static double getTimeInSecs(Calendar cal, Calendar epoch) throws Exception {
-        return getTimeInMillis(cal, epoch) / 1000.0;
-    }
-    
-    public static String toString(double seconds) {
-        return new DecimalFormat("#.000").format(seconds);
-    }
-    
-    public static long getTimeInMillis(Calendar cal, Calendar epoch) throws Exception {
-        long epochDiffInMilli = epoch.getTimeInMillis() - julianEpoch.getTimeInMillis() ;
-        if (cal.getTimeZone().getID().equals("TAI"))
-            epochDiffInMilli += getLeapSecsForDate(epoch) * 1000;
-        long milliseconds = cal.getTimeInMillis();
-        return milliseconds - epochDiffInMilli;
-    }
-    
-    private static TimeZone createTaiTimeZone(int leapSecs) {
-        return new SimpleTimeZone(leapSecs * 1000, "TAI");
-    }
-    
-    public static void main(String[] args) throws Exception {
-        Calendar curTime = getCurrentLocalTime();
-        System.out.println("Test Time: " + toString(toCalendar(toString(toTai(toCalendar("2008-01-20T16:29:55.000Z", 
-                FormatType.UTC_FORMAT))), FormatType.TAI_FORMAT)));
-        System.out.println("Current Local Time: " + toString(curTime) + " " + curTime.getTimeInMillis());
-        System.out.println("Current UTC Time: " + toString((curTime = toCalendar("2008-01-20T16:29:55.000Z", 
-                FormatType.UTC_FORMAT))) + " " + toString(getTimeInSecs(curTime, tai93epoch)));
-        System.out.println("Current TAI Time: " + toString((curTime = toTai(toCalendar("2008-01-20T16:29:55.000Z", 
-                FormatType.UTC_FORMAT)))) + " " + toString(getTimeInSecs(curTime, tai93epoch)));
-        System.out.println("Current UTC Time: " + toString(taiToUtc(curTime)));
-    }
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.date;
+
+//JDK imports
+import java.text.DecimalFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ * 
+ */
+public class DateUtils {
+
+    public static enum FormatType { UTC_FORMAT, LOCAL_FORMAT, TAI_FORMAT };
+    
+    public static Calendar tai93epoch = new GregorianCalendar(1993, GregorianCalendar.JANUARY, 1);
+    
+    public static Calendar julianEpoch = new GregorianCalendar(1970, GregorianCalendar.JANUARY, 1);
+    
+    private static SimpleDateFormat utcFormat = new SimpleDateFormat(
+            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+    private static SimpleDateFormat taiFormat = new SimpleDateFormat(
+            "yyyy-MM-dd'T'HH:mm:ss.SSS");
+    private static SimpleDateFormat localFormat = new SimpleDateFormat(
+            "yyyy-MM-dd'T'HH:mm:ss.SSSZ");    
+    
+    static {
+        utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+        taiFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+    }
+    
+    static enum IndexType {
+        DATE(0),
+        LEAP_SECS(1);
+        
+        public int index;
+        
+        IndexType(int index) {
+            this.index = index;
+        }
+    }
+    
+    //Info taken from ftp://oceans.gsfc.nasa.gov/COMMON/leapsec.dat
+    static long[][] dateAndLeapSecs = {
+        { 0 , 10 },
+        { new GregorianCalendar(1972, GregorianCalendar.JULY,    1).getTimeInMillis() , 11 },
+        { new GregorianCalendar(1973, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 12 },
+        { new GregorianCalendar(1974, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 13 },
+        { new GregorianCalendar(1975, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 14 },
+        { new GregorianCalendar(1976, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 15 },
+        { new GregorianCalendar(1977, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 16 },
+        { new GregorianCalendar(1978, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 17 },
+        { new GregorianCalendar(1979, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 18 },
+        { new GregorianCalendar(1980, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 19 },
+        { new GregorianCalendar(1981, GregorianCalendar.JULY,    1).getTimeInMillis() , 20 },
+        { new GregorianCalendar(1982, GregorianCalendar.JULY,    1).getTimeInMillis() , 21 },
+        { new GregorianCalendar(1983, GregorianCalendar.JULY,    1).getTimeInMillis() , 22 },
+        { new GregorianCalendar(1985, GregorianCalendar.JULY,    1).getTimeInMillis() , 23 },
+        { new GregorianCalendar(1988, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 24 },
+        { new GregorianCalendar(1990, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 25 },
+        { new GregorianCalendar(1991, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 26 },
+        { new GregorianCalendar(1992, GregorianCalendar.JULY,    1).getTimeInMillis() , 27 },
+        { new GregorianCalendar(1993, GregorianCalendar.JULY,    1).getTimeInMillis() , 28 },
+        { new GregorianCalendar(1994, GregorianCalendar.JULY,    1).getTimeInMillis() , 29 },
+        { new GregorianCalendar(1996, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 30 },
+        { new GregorianCalendar(1997, GregorianCalendar.JULY,    1).getTimeInMillis() , 31 },
+        { new GregorianCalendar(1999, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 32 },
+        { new GregorianCalendar(2006, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 33 },
+        { new GregorianCalendar(2009, GregorianCalendar.JANUARY, 1).getTimeInMillis() , 34 },
+    };
+    
+    private DateUtils() {}
+    
+    public static int getLeapSecsForDate(Calendar utcCal) throws Exception {
+        long timeInMillis = utcCal.getTimeInMillis();
+        for (int i = dateAndLeapSecs.length - 1; i >= 0; i--) {
+            if (dateAndLeapSecs[i][IndexType.DATE.index] < timeInMillis)
+                return (int) dateAndLeapSecs[i][IndexType.LEAP_SECS.index];
+        }
+        throw new Exception("No Leap Second found for given date!");
+    }
+    
+    public static synchronized Calendar toTai(Calendar cal) throws Exception {
+        Calendar taiCal = Calendar.getInstance(createTaiTimeZone(getLeapSecsForDate(cal)));
+        taiCal.setTimeInMillis(cal.getTimeInMillis() + getLeapSecsForDate(cal) * 1000);
+        return taiCal;
+    }
+    
+    private static synchronized Calendar taiToUtc(Calendar taiCal) throws Exception {
+        Calendar calUtc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+        calUtc.setTimeInMillis(taiCal.getTimeInMillis() - taiCal.getTimeZone().getRawOffset());
+        return calUtc;
+    }
+    
+    private static Calendar taiToLocal(Calendar taiCal) throws Exception {
+        return toLocal(taiToUtc(taiCal));
+    }
+
+    public static synchronized Calendar toLocal(Calendar cal) throws Exception {
+        if (cal.getTimeZone().getID().equals("TAI")) {
+            return taiToLocal(cal);
+        } else {
+            Calendar calLocal = Calendar.getInstance();
+            calLocal.setTimeInMillis(cal.getTimeInMillis());
+            return calLocal;
+        }
+    }
+
+    public static synchronized Calendar toUtc(Calendar cal) throws Exception {
+        if (cal.getTimeZone().getID().equals("TAI")) {
+            return taiToUtc(cal);
+        } else {
+            Calendar calUtc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+            calUtc.setTimeInMillis(cal.getTimeInMillis());
+            return calUtc;   
+        }
+    }
+    
+    public static Calendar getCurrentUtcTime() throws Exception {
+        return toUtc(getCurrentLocalTime());
+    }
+    
+    public static Calendar getCurrentLocalTime() throws Exception {
+        return Calendar.getInstance();
+    }
+    
+    public static Calendar getCurrentTaiTime() throws Exception {
+        return toTai(getCurrentUtcTime());
+    }
+    
+    public static String toCustomLocalFormat(Calendar cal, String format) {
+        return new SimpleDateFormat(format).format(cal.getTime());
+    }
+    
+    public static String toString(Calendar cal) {
+        String timeZoneId = cal.getTimeZone().getID();
+        if (timeZoneId.equals("UTC")) {
+            return utcFormat.format(cal.getTime());
+        }else if (timeZoneId.equals("TAI")) {
+            return taiFormat.format(cal.getTime()) + "-0000" 
+                + (cal.getTimeZone().getRawOffset() / 1000);
+        }else {
+            return localFormat.format(cal.getTime());
+        }
+    }
+    
+    public static synchronized Calendar toLocalCustomFormatCalendar(String calString, String format) throws ParseException {
+        Calendar localCal = Calendar.getInstance();
+        localCal.setTime(new SimpleDateFormat(format).parse(calString));
+        return localCal;
+    }
+    
+    public static synchronized Calendar toCalendar(String calString, FormatType formatType)
+            throws ParseException {
+        Calendar cal = Calendar.getInstance();
+        switch (formatType) {
+            case LOCAL_FORMAT:
+                cal.setTimeInMillis(localFormat.parse(calString).getTime());
+                break;
+            case TAI_FORMAT:
+                cal.setTimeZone(createTaiTimeZone(Integer.parseInt(calString
+                    .substring(calString.length() - 2))));
+                calString = calString.substring(0, calString.length() - 5);
+                cal.setTimeInMillis(taiFormat.parse(calString).getTime());
+                break;
+            case UTC_FORMAT:
+                cal.setTimeZone(TimeZone.getTimeZone("UTC"));
+                cal.setTimeInMillis(utcFormat.parse(calString).getTime());
+                break;
+            default:
+                cal.setTimeInMillis(localFormat.parse(calString).getTime());
+        }
+        return cal;
+    }
+    
+    public static double getTimeInSecs(Calendar cal, Calendar epoch) throws Exception {
+        return getTimeInMillis(cal, epoch) / 1000.0;
+    }
+    
+    public static String toString(double seconds) {
+        return new DecimalFormat("#.000").format(seconds);
+    }
+    
+    public static long getTimeInMillis(Calendar cal, Calendar epoch) throws Exception {
+        long epochDiffInMilli = epoch.getTimeInMillis() - julianEpoch.getTimeInMillis() ;
+        if (cal.getTimeZone().getID().equals("TAI"))
+            epochDiffInMilli += getLeapSecsForDate(epoch) * 1000;
+        long milliseconds = cal.getTimeInMillis();
+        return milliseconds - epochDiffInMilli;
+    }
+    
+    private static TimeZone createTaiTimeZone(int leapSecs) {
+        return new SimpleTimeZone(leapSecs * 1000, "TAI");
+    }
+    
+    public static void main(String[] args) throws Exception {
+        Calendar curTime = getCurrentLocalTime();
+        System.out.println("Test Time: " + toString(toCalendar(toString(toTai(toCalendar("2008-01-20T16:29:55.000Z", 
+                FormatType.UTC_FORMAT))), FormatType.TAI_FORMAT)));
+        System.out.println("Current Local Time: " + toString(curTime) + " " + curTime.getTimeInMillis());
+        System.out.println("Current UTC Time: " + toString((curTime = toCalendar("2008-01-20T16:29:55.000Z", 
+                FormatType.UTC_FORMAT))) + " " + toString(getTimeInSecs(curTime, tai93epoch)));
+        System.out.println("Current TAI Time: " + toString((curTime = toTai(toCalendar("2008-01-20T16:29:55.000Z", 
+                FormatType.UTC_FORMAT)))) + " " + toString(getTimeInSecs(curTime, tai93epoch)));
+        System.out.println("Current UTC Time: " + toString(taiToUtc(curTime)));
+    }
+    
+}

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/EnvUtilities.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/EnvUtilities.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/EnvUtilities.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/EnvUtilities.java Mon Mar  1 21:17:24 2010
@@ -1,177 +1,190 @@
-//Copyright (c) 2007, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.exec;
-
-//JDK imports
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * @author mattmann
- * @author bfoster
- * @version $Revision$
- * 
- * <p>
- * Environment Utilities for reading variables and setting them and such.
- * </p>.
- */
-public final class EnvUtilities {
-
-    private static final Logger LOG = Logger.getLogger(EnvUtilities.class
-            .getName());
-
-    private EnvUtilities() throws InstantiationException {
-        throw new InstantiationException("Don't construct utility classes!");
-    }
-
-    /**
-     * This method returns a particular named environment variable from the user's
-     * working environment using the {@link #getEnv()} method to grab that environment.
-     * 
-     * @param envVarName The named environment variable to return.
-     * @return The environment variable value, as a String.
-     */
-    public static String getEnv(String envVarName) {
-        Properties props = getEnv();
-
-        return (props != null) ? props.getProperty(envVarName) : null;
-    }
-
-    /**
-     * This method does exactly the same thing as {@link #getEnvUsingWaitFor()},
-     * except it uses {@link ExecHelper} rather than traditional Java
-     * {@link Process} creation ( and
-     * 
-     * @link {@link Process#waitFor()}) and termination.
-     * 
-     * 
-     * @return The user's current environment, in a {@link Properties} object.
-     */
-    public static Properties getEnv() {
-        String commandLine = "env";
-
-        Properties envProps = null;
-        ExecHelper exec;
-        try {
-            exec = ExecHelper.exec(new String[] { commandLine });
-            envProps = new Properties();
-            envProps.load(preProcessInputStream(new ByteArrayInputStream(exec
-                    .getOutput().getBytes())));
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING, "Error executing env command: Message: "
-                    + e.getMessage());
-        }
-
-        return envProps;
-    }
-
-    /**
-     * This method grabs the current environment using the Linux shell program
-     * called <code>env</code>. Unfortunately, this method also uses
-     * {@link Process#waitFor()}, which seems to hang when folks have weird
-     * environment variables and such.
-     * 
-     * A more appropriate method to call is {@link #getEnv()} because it uses
-     * the {@link ExecHelper} class, which seems to handle process termination a
-     * bit more elegantly.
-     * 
-     * @deprecated
-     * @return A {@link Properites} object containing the user's current
-     *         environment variables.
-     */
-    public static Properties getEnvUsingWaitFor() {
-        String commandLine = "env";
-
-        Process p = null;
-        Properties envProps = null;
-
-        try {
-            p = Runtime.getRuntime().exec(commandLine);
-            int retVal = p.waitFor();
-            envProps = new Properties();
-            envProps.load(preProcessInputStream(p.getInputStream()));
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING, "Error executing env command: Message: "
-                    + e.getMessage());
-        } finally {
-            try {
-                if (p.getErrorStream() != null)
-                    p.getErrorStream().close();
-            } catch (Exception e) {
-            }
-            try {
-                if (p.getInputStream() != null)
-                    p.getInputStream().close();
-            } catch (Exception e) {
-            }
-            try {
-                if (p.getOutputStream() != null)
-                    p.getOutputStream().close();
-            } catch (Exception e) {
-            }
-        }
-
-        return envProps;
-    }
-
-    /**
-     * This method turns an {@link InputStream} into a String. Method taken
-     * from:<br>
-     * 
-     * <a
-     * href="http://snippets.dzone.com/posts/show/555">http://snippets.dzone.com/posts/show/555</a>.
-     * 
-     * @param in
-     *            The {@link InputStream} to Stringify.
-     * @return A String constructed from the given {@link InputStream}.
-     * @throws IOException
-     *             If any error occurs.
-     */
-    public static String slurp(InputStream in) throws IOException {
-        StringBuffer out = new StringBuffer();
-        byte[] b = new byte[4096];
-        for (int n; (n = in.read(b)) != -1;) {
-            out.append(new String(b, 0, n));
-        }
-        return out.toString();
-    }
-
-    protected static InputStream preProcessInputStream(InputStream is)
-            throws Exception {
-        // basically read this sucker into a BufferedReader
-        // line by line, and replaceAll on \ with \\
-        // so \\\\ with \\\\\\\\
-        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
-        String line = null;
-        StringBuffer buf = new StringBuffer();
-
-        while ((line = reader.readLine()) != null) {
-            // fix the line
-            line = line.replaceAll("\\\\", "\\\\\\\\");
-            buf.append(line + "\n");
-        }
-
-        if (reader != null) {
-            try {
-                reader.close();
-            } catch (Exception ignore) {
-            }
-
-            reader = null;
-        }
-
-        return new ByteArrayInputStream(buf.toString().getBytes());
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.exec;
+
+//JDK imports
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @version $Revision$
+ * 
+ * <p>
+ * Environment Utilities for reading variables and setting them and such.
+ * </p>.
+ */
+public final class EnvUtilities {
+
+    private static final Logger LOG = Logger.getLogger(EnvUtilities.class
+            .getName());
+
+    private EnvUtilities() throws InstantiationException {
+        throw new InstantiationException("Don't construct utility classes!");
+    }
+
+    /**
+     * This method returns a particular named environment variable from the user's
+     * working environment using the {@link #getEnv()} method to grab that environment.
+     * 
+     * @param envVarName The named environment variable to return.
+     * @return The environment variable value, as a String.
+     */
+    public static String getEnv(String envVarName) {
+        Properties props = getEnv();
+
+        return (props != null) ? props.getProperty(envVarName) : null;
+    }
+
+    /**
+     * This method does exactly the same thing as {@link #getEnvUsingWaitFor()},
+     * except it uses {@link ExecHelper} rather than traditional Java
+     * {@link Process} creation ( and
+     * 
+     * @link {@link Process#waitFor()}) and termination.
+     * 
+     * 
+     * @return The user's current environment, in a {@link Properties} object.
+     */
+    public static Properties getEnv() {
+        String commandLine = "env";
+
+        Properties envProps = null;
+        ExecHelper exec;
+        try {
+            exec = ExecHelper.exec(new String[] { commandLine });
+            envProps = new Properties();
+            envProps.load(preProcessInputStream(new ByteArrayInputStream(exec
+                    .getOutput().getBytes())));
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Error executing env command: Message: "
+                    + e.getMessage());
+        }
+
+        return envProps;
+    }
+
+    /**
+     * This method grabs the current environment using the Linux shell program
+     * called <code>env</code>. Unfortunately, this method also uses
+     * {@link Process#waitFor()}, which seems to hang when folks have weird
+     * environment variables and such.
+     * 
+     * A more appropriate method to call is {@link #getEnv()} because it uses
+     * the {@link ExecHelper} class, which seems to handle process termination a
+     * bit more elegantly.
+     * 
+     * @deprecated
+     * @return A {@link Properites} object containing the user's current
+     *         environment variables.
+     */
+    public static Properties getEnvUsingWaitFor() {
+        String commandLine = "env";
+
+        Process p = null;
+        Properties envProps = null;
+
+        try {
+            p = Runtime.getRuntime().exec(commandLine);
+            int retVal = p.waitFor();
+            envProps = new Properties();
+            envProps.load(preProcessInputStream(p.getInputStream()));
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOG.log(Level.WARNING, "Error executing env command: Message: "
+                    + e.getMessage());
+        } finally {
+            try {
+                if (p.getErrorStream() != null)
+                    p.getErrorStream().close();
+            } catch (Exception e) {
+            }
+            try {
+                if (p.getInputStream() != null)
+                    p.getInputStream().close();
+            } catch (Exception e) {
+            }
+            try {
+                if (p.getOutputStream() != null)
+                    p.getOutputStream().close();
+            } catch (Exception e) {
+            }
+        }
+
+        return envProps;
+    }
+
+    /**
+     * This method turns an {@link InputStream} into a String. Method taken
+     * from:<br>
+     * 
+     * <a
+     * href="http://snippets.dzone.com/posts/show/555">http://snippets.dzone.com/posts/show/555</a>.
+     * 
+     * @param in
+     *            The {@link InputStream} to Stringify.
+     * @return A String constructed from the given {@link InputStream}.
+     * @throws IOException
+     *             If any error occurs.
+     */
+    public static String slurp(InputStream in) throws IOException {
+        StringBuffer out = new StringBuffer();
+        byte[] b = new byte[4096];
+        for (int n; (n = in.read(b)) != -1;) {
+            out.append(new String(b, 0, n));
+        }
+        return out.toString();
+    }
+
+    protected static InputStream preProcessInputStream(InputStream is)
+            throws Exception {
+        // basically read this sucker into a BufferedReader
+        // line by line, and replaceAll on \ with \\
+        // so \\\\ with \\\\\\\\
+        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+        String line = null;
+        StringBuffer buf = new StringBuffer();
+
+        while ((line = reader.readLine()) != null) {
+            // fix the line
+            line = line.replaceAll("\\\\", "\\\\\\\\");
+            buf.append(line + "\n");
+        }
+
+        if (reader != null) {
+            try {
+                reader.close();
+            } catch (Exception ignore) {
+            }
+
+            reader = null;
+        }
+
+        return new ByteArrayInputStream(buf.toString().getBytes());
+    }
+
+}

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecHelper.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecHelper.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecHelper.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecHelper.java Mon Mar  1 21:17:24 2010
@@ -1,7 +1,20 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.exec;
 

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecUtils.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecUtils.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecUtils.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/ExecUtils.java Mon Mar  1 21:17:24 2010
@@ -1,7 +1,20 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.exec;
 

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/StreamGobbler.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/StreamGobbler.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/StreamGobbler.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/exec/StreamGobbler.java Mon Mar  1 21:17:24 2010
@@ -1,7 +1,20 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.exec;
 

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/ObjectTimeEvent.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/ObjectTimeEvent.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/ObjectTimeEvent.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/ObjectTimeEvent.java Mon Mar  1 21:17:24 2010
@@ -1,48 +1,61 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.filter;
-
-/**
- * 
- * @author bfoster
- * @version $Revision$
- *
- * <p>A {@link TimeEvent} associated with a particular {@link Object}</p>.
- */
-public class ObjectTimeEvent<objType> extends TimeEvent {
-
-    private objType timeObj;
-
-    public ObjectTimeEvent(long startTime, long endTime, objType timeObj) {
-        super(startTime, endTime);
-        this.timeObj = timeObj;
-    }
-
-    public ObjectTimeEvent(long startTime, long endTime, double priority,
-            objType timeObj) {
-        super(startTime, endTime, priority);
-        this.timeObj = timeObj;
-    }
-
-    public objType getTimeObject() {
-        return this.timeObj;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof ObjectTimeEvent) {
-            ObjectTimeEvent<?> ote = (ObjectTimeEvent<?>) obj;
-            return super.equals(obj) && this.timeObj.equals(ote.timeObj);
-        } else
-            return false;
-    }
-    
-    @Override
-    public String toString() {
-        return super.toString() + " - " + timeObj;
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.filter;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>A {@link TimeEvent} associated with a particular {@link Object}</p>.
+ */
+public class ObjectTimeEvent<objType> extends TimeEvent {
+
+    private objType timeObj;
+
+    public ObjectTimeEvent(long startTime, long endTime, objType timeObj) {
+        super(startTime, endTime);
+        this.timeObj = timeObj;
+    }
+
+    public ObjectTimeEvent(long startTime, long endTime, double priority,
+            objType timeObj) {
+        super(startTime, endTime, priority);
+        this.timeObj = timeObj;
+    }
+
+    public objType getTimeObject() {
+        return this.timeObj;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof ObjectTimeEvent) {
+            ObjectTimeEvent<?> ote = (ObjectTimeEvent<?>) obj;
+            return super.equals(obj) && this.timeObj.equals(ote.timeObj);
+        } else
+            return false;
+    }
+    
+    @Override
+    public String toString() {
+        return super.toString() + " - " + timeObj;
+    }
+
+}

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEvent.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEvent.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEvent.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEvent.java Mon Mar  1 21:17:24 2010
@@ -1,89 +1,102 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.filter;
-
-//JDK imports
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * 
- * @author bfoster
- * @version $Revision$
- *
- * <p>
- * A basis for time-based queries results over a start/end datetime with
- * a duration
- * </p>.
- */
-public class TimeEvent implements Comparable<TimeEvent> {
-
-    protected long startTime, endTime, dur;
-
-    protected double priority;
-
-    public TimeEvent(long startTime, long endTime) {
-        this(startTime, endTime, 0);
-    }
-
-    public TimeEvent(long startTime, long endTime, double priority) {
-        this.startTime = startTime;
-        this.endTime = endTime;
-        this.dur = this.endTime - this.startTime;
-        this.priority = priority;
-    }
-
-    public void setPriority(double priority) {
-        this.priority = priority;
-    }
-
-    public double getPriority() {
-        return this.priority;
-    }
-
-    public long getStartTime() {
-        return this.startTime;
-    }
-
-    public long getEndTime() {
-        return this.endTime;
-    }
-
-    public long getDuration() {
-        return this.dur;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof TimeEvent) {
-            TimeEvent te = (TimeEvent) obj;
-            return te.startTime == this.startTime && te.endTime == this.endTime;
-        } else
-            return false;
-    }
-
-    @Override
-    public String toString() {
-        return "[" + this.startTime + "," + this.endTime + "] - "
-                + this.priority;
-    }
-    
-    public static boolean happenAtSameTime(TimeEvent te1, TimeEvent te2) {
-        return te1.getStartTime() == te2.getStartTime() && te1.getEndTime() == te2.getEndTime();
-    }
-
-    public int compareTo(TimeEvent te) {
-        return new Long(this.startTime).compareTo(te.startTime);
-    }
- 
-    public static List<? extends TimeEvent> getTimeOrderedEvents(List<? extends TimeEvent> events) {
-        TimeEvent[] eventsArray = events
-                .toArray(new TimeEvent[events.size()]);
-        Arrays.sort(eventsArray);
-        return Arrays.asList(eventsArray);
-    }
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.filter;
+
+//JDK imports
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A basis for time-based queries results over a start/end datetime with
+ * a duration
+ * </p>.
+ */
+public class TimeEvent implements Comparable<TimeEvent> {
+
+    protected long startTime, endTime, dur;
+
+    protected double priority;
+
+    public TimeEvent(long startTime, long endTime) {
+        this(startTime, endTime, 0);
+    }
+
+    public TimeEvent(long startTime, long endTime, double priority) {
+        this.startTime = startTime;
+        this.endTime = endTime;
+        this.dur = this.endTime - this.startTime;
+        this.priority = priority;
+    }
+
+    public void setPriority(double priority) {
+        this.priority = priority;
+    }
+
+    public double getPriority() {
+        return this.priority;
+    }
+
+    public long getStartTime() {
+        return this.startTime;
+    }
+
+    public long getEndTime() {
+        return this.endTime;
+    }
+
+    public long getDuration() {
+        return this.dur;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof TimeEvent) {
+            TimeEvent te = (TimeEvent) obj;
+            return te.startTime == this.startTime && te.endTime == this.endTime;
+        } else
+            return false;
+    }
+
+    @Override
+    public String toString() {
+        return "[" + this.startTime + "," + this.endTime + "] - "
+                + this.priority;
+    }
+    
+    public static boolean happenAtSameTime(TimeEvent te1, TimeEvent te2) {
+        return te1.getStartTime() == te2.getStartTime() && te1.getEndTime() == te2.getEndTime();
+    }
+
+    public int compareTo(TimeEvent te) {
+        return new Long(this.startTime).compareTo(te.startTime);
+    }
+ 
+    public static List<? extends TimeEvent> getTimeOrderedEvents(List<? extends TimeEvent> events) {
+        TimeEvent[] eventsArray = events
+                .toArray(new TimeEvent[events.size()]);
+        Arrays.sort(eventsArray);
+        return Arrays.asList(eventsArray);
+    }
+    
+}

Modified: incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEventWeightedHash.java
URL: http://svn.apache.org/viewvc/incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEventWeightedHash.java?rev=917722&r1=917721&r2=917722&view=diff
==============================================================================
--- incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEventWeightedHash.java (original)
+++ incubator/oodt/cas-commons/trunk/src/main/java/gov/nasa/jpl/oodt/cas/commons/filter/TimeEventWeightedHash.java Mon Mar  1 21:17:24 2010
@@ -1,396 +1,409 @@
-//Copyright (c) 2008, California Institute of Technology.
-//ALL RIGHTS RESERVED. U.S. Government sponsorship acknowledged.
-//
-//$Id$
-
-package gov.nasa.jpl.oodt.cas.commons.filter;
-
-//JDK imports
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
-* 
-* @author bfoster
-* @version $Revision$
-*
-* <p>
-* Builds a time sorted hash where the top value has the earliest time.  This hash
-* is a directional graph.  It builds all possible paths from top node to leaf
-* nodes.  At any time you can ask for the greatest weighted path in the hash -- that
-* is, the path from root node to a leaf node which fills the most time. Epsilon is 
-* TimeEvent objects allowed time overlap (it is of the same unit of measurement that 
-* is used in you TimeEvent objects added to this hash).
-* </p>.
-*/
-public class TimeEventWeightedHash {
-
-  private TimeEventNode root;
-  
-  protected long epsilon;
-  
-  private MyLinkedHashSet<TimeEventNode> leafNodes;
-      
-  private TimeEventWeightedHash() {
-      root = new TimeEventNode(new TimeEvent(-1, -1));
-      leafNodes = new MyLinkedHashSet<TimeEventNode>();
-      leafNodes.add(this.root);
-  }
-  
-  public static TimeEventWeightedHash buildHash(List<? extends TimeEvent> events) {
-	  return buildHash(events, 0);
-  }
-  
-  /**
-   * Returns the Greatest Weighted Path of TimeEvents
-   */
-  public static TimeEventWeightedHash buildHash(List<? extends TimeEvent> events, long epsilon) {
-	  TimeEventWeightedHash hash = new TimeEventWeightedHash();
-	  hash.epsilon = epsilon;
-      events = TimeEvent.getTimeOrderedEvents(events);
-      for (TimeEvent event : events)
-    	  hash.addEvent(event);
-      return hash;
-  }
-  
-  public List<? extends TimeEvent> getGreatestWeightedPathAsOrderedList() {
-      WeightedNode wn = this.getGreatestWeightedPath();
-      List<TimeEvent> gwpEvents = new LinkedList<TimeEvent>();
-      while(wn != null) {
-          gwpEvents.add(wn.getTimeEvent());
-          wn = wn.getChild();
-      }
-      
-      return gwpEvents;
-  }
- 
-  private void addEvent(TimeEvent newEvent) {
-      TimeEventNode newEventNode = new TimeEventNode(newEvent);
-      MyLinkedHashSet<TimeEventNode> parentNodes = this.findParents(newEvent);
-      MyLinkedHashSet<TimeEventNode> childrenNodes = this.findChildren(newEvent, parentNodes);
-      
-      if (childrenNodes.size() == 0)
-          leafNodes.add(newEventNode);
-      
-      newEventNode.addParents(parentNodes);
-      newEventNode.addChildren(childrenNodes);
-      
-  }
-  
-  private MyLinkedHashSet<TimeEventNode> findParents(TimeEvent newEvent) {
-      MyLinkedHashSet<TimeEventNode> parentNodes = new MyLinkedHashSet<TimeEventNode>();
-      MyLinkedHashSet<TimeEventNode> possibleParentNodes = new MyLinkedHashSet<TimeEventNode>();
-      MyLinkedHashSet<TimeEventNode> possibleParentNodesAlreadyChecked = new MyLinkedHashSet<TimeEventNode>();
-      
-      //iterate through possible parent nodes add possible parent child as
-      // possible parents if they do not conflict
-      TimeEventNode curPPN = this.root;
-      while (curPPN != null) {
-          boolean ppnListChanged = false;
-          for (TimeEventNode curChild : curPPN.getChildren()) {
-              //if curChild does not conficts with te, then it is a possible parent
-              if (happensBefore(curChild.getTimeEvent(), newEvent) 
-                      && !possibleParentNodesAlreadyChecked.contains(curChild)) {
-                  possibleParentNodes.add(curChild);
-                  ppnListChanged = true;
-              }
-          }
-          //if all children where not possible parents, then curPPN must be parent
-          if (!ppnListChanged)
-              parentNodes.add(curPPN);
-          
-          //get next curPPN
-          possibleParentNodes.remove(curPPN);
-          possibleParentNodesAlreadyChecked.add(curPPN);
-          while((curPPN = possibleParentNodes.get(0)) != null 
-                  && possibleParentNodesAlreadyChecked.contains(curPPN)) {
-              possibleParentNodes.remove(curPPN);
-          }
-      }
-      
-      return parentNodes;
-  }
-  
-  private MyLinkedHashSet<TimeEventNode> findChildren(TimeEvent newEvent, MyLinkedHashSet<TimeEventNode> parentNodes) {
-      MyLinkedHashSet<TimeEventNode> childrenNodes = new MyLinkedHashSet<TimeEventNode>();
-      MyLinkedHashSet<TimeEventNode> possibleChildrenNodes = new MyLinkedHashSet<TimeEventNode>();
-      for (TimeEventNode parent : parentNodes) {
-          possibleChildrenNodes.addAll(parent.getChildren());
-          TimeEventNode curPCN = possibleChildrenNodes.get(0);
-          while (curPCN != null) {
-              if (happensBefore(newEvent, curPCN.getTimeEvent())) {
-                  childrenNodes.add(curPCN);
-              }else {
-                  possibleChildrenNodes.addAll(curPCN.getChildren());
-              }
-              possibleChildrenNodes.remove(curPCN);
-              curPCN = possibleChildrenNodes.get(0);
-          }
-      }
-      return childrenNodes;
-  }
-  
-  private boolean happensBefore(TimeEvent t1, TimeEvent t2) {
-      long boundaryCheck = t2.getStartTime() - t1.getEndTime();
-      return (boundaryCheck + epsilon) > 0;
-  }
-  
-  private WeightedNode getGreatestWeightedPath() {
-      TimeEventNode max = this.leafNodes.get(0);
-      for (TimeEventNode ten : this.leafNodes) {
-         if (ten.getPathWeight() > max.getPathWeight() 
-                 || (ten.getPathWeight() == max.getPathWeight() 
-                         && ten.getPathPriorityWeight() > max.getPathPriorityWeight()))
-             max = ten;
-      }
-      WeightedNode root = new WeightedNode(max.getTimeEvent());
-      TimeEventNode curTEN = max.greatestWieghtedParent;
-      while (curTEN != null) {
-          WeightedNode temp = new WeightedNode(curTEN.getTimeEvent());
-          temp.setChild(root);
-          root = temp;
-          curTEN = curTEN.greatestWieghtedParent;
-      }
-      return root.getChild();
-  }
-  
-  private class MyLinkedHashSet<E> extends HashSet<E> {
-
-      private static final long serialVersionUID = -7319154087430025841L;
-      
-      private LinkedList<E> listSet;
-      
-      public MyLinkedHashSet() {
-          this.listSet = new LinkedList<E>();
-      }
-      
-      @Override
-      public boolean add(E ten) {
-          boolean wasAdded = false;
-          if (wasAdded = super.add(ten))
-              listSet.add(ten);
-          return wasAdded;
-      }
-      
-      @Override
-      public boolean addAll(Collection<? extends E> collection) {
-          boolean setChanged = false;
-          for (E ten : collection) {
-              if (this.add(ten))
-                  setChanged = true;
-          }
-          return setChanged;
-      }
-      
-      @Override
-      public boolean remove(Object ten) {
-          if (super.remove(ten)) {
-              this.listSet.remove(ten);
-              return true;
-          }else 
-              return false;
-      }
-      
-      @Override
-      public boolean removeAll(Collection<?> collection) {
-          boolean setChanged = false;
-          for (Object obj : collection) {
-              if (this.remove(obj))
-                  setChanged = true;
-          }
-          return setChanged;  
-      }
-      
-      public E get(int index) {
-          if (this.listSet.size() > index)
-              return this.listSet.get(index);
-          else 
-              return null;
-      }
-      
-      public List<E> getList() {
-          return this.listSet;
-      }
-      
-  }
-
-  private class TimeEventNode {
-
-      private TimeEvent te;
-      
-      private MyLinkedHashSet<TimeEventNode> children;
-
-      private MyLinkedHashSet<TimeEventNode> parents;
-      
-      private TimeEventNode greatestWieghtedParent;
-              
-      public TimeEventNode(TimeEvent te) {
-          this.te = te;
-          children = new MyLinkedHashSet<TimeEventNode>();
-          parents = new MyLinkedHashSet<TimeEventNode>();
-      }
-      
-      public long getPathWeight() {
-          if (this.greatestWieghtedParent != null)
-              return te.getDuration()
-                      + this.greatestWieghtedParent.getPathWeight();
-          else
-              return te.getDuration();
-      }
-
-      public double getPathPriorityWeight() {
-          if (this.greatestWieghtedParent != null)
-              return te.getPriority()
-                      + this.greatestWieghtedParent.getPathPriorityWeight();
-          else
-              return te.getPriority();
-      }
-
-      public TimeEvent getTimeEvent() {
-          return this.te;
-      }
-
-      public void setTimeEvent(TimeEvent te) {
-          this.te = te;
-      }
-      
-      public void addChild(TimeEventNode child) {            
-          //remove parent to grandchild links
-          for (TimeEventNode parent : this.parents) {
-              parent.children.remove(child);
-              child.parents.remove(parent);
-          }
-          
-          //link to child
-          this.children.add(child);
-          child.parents.add(this);
-          leafNodes.remove(this);
-          
-          //determine child's greatest weighted parent
-          child.greatestWieghtedParent = this;
-          for (TimeEventNode parent : child.parents) {
-              long gwpPaW = child.greatestWieghtedParent.getPathWeight();
-              long pPaW = parent.getPathWeight();
-              double gwpPiW = child.greatestWieghtedParent.getPathPriorityWeight();
-              double pPiW = parent.getPathPriorityWeight();
-              if (pPaW > gwpPaW || (pPaW == gwpPaW && pPiW > gwpPiW))                    
-                  child.greatestWieghtedParent = parent;
-          }
-      }
-      
-      public void addParent(TimeEventNode parent) {
-          parent.addChild(this);
-      }
-
-      public void addChildren(Collection<TimeEventNode> children) {
-          for (TimeEventNode child : children)
-              this.addChild(child);
-      }
-      
-      public void addParents(Collection<TimeEventNode> parents) {
-          for (TimeEventNode parent : parents)
-              this.addParent(parent);
-      }
-
-      public MyLinkedHashSet<TimeEventNode> getChildren() {
-          return this.children;
-      }
-      
-      public MyLinkedHashSet<TimeEventNode> getParents() {
-          return this.parents;
-      }
-
-      public boolean equals(Object obj) {
-          if (obj instanceof TimeEventNode) {
-              TimeEventNode ten = (TimeEventNode) obj;
-              return this.te.equals(ten.te);
-          } else
-              return false;
-      }
-
-      public String toString() {
-          return this.te.toString() + " -- " + this.getPathWeight();
-      }
-      
-  }
-
-  private class WeightedNode {
-
-      private long pathWeight;
-
-      private WeightedNode child;
-
-      private TimeEvent te;
-
-      private WeightedNode(TimeEvent te) {
-          this.te = te;
-          pathWeight = te.getDuration();
-      }
-
-      private void setChild(WeightedNode child) {
-          this.child = child;
-          if (child != null)
-              this.pathWeight = this.te.getDuration() + child.getPathWeight();
-      }
-
-      public TimeEvent getTimeEvent() {
-          return this.te;
-      }
-
-      public WeightedNode getChild() {
-          return this.child;
-      }
-
-      public long getPathWeight() {
-          return this.pathWeight;
-      }
-
-      public String toString() {
-          return te.toString() + "\n" 
-              + (child != null ? child.toString() : "");
-      }
-
-  }
-
-  public String toString() {
-      StringBuffer sb = new StringBuffer("");
-      LinkedList<TimeEventNode> printNodes = new LinkedList<TimeEventNode>();
-      printNodes.add(this.root);
-      sb.append(printNodes(printNodes, "-", 0));
-      return sb.toString();
-  }
-
-  private StringBuffer printNodes(List<TimeEventNode> list,
-          String spacer, long curPathWeight) {
-      StringBuffer output = new StringBuffer("");
-      for (TimeEventNode node : list) {
-          output.append(spacer);
-          output.append(node.te + " -- " + (curPathWeight + node.te.getDuration()) + "\n");
-          output.append(printNodes(node.getChildren().getList(), " " + spacer, curPathWeight + node.te.getDuration()));
-      }
-      return output;
-  }
-
-  public static void main(String[] args) {              
-      List<TimeEvent> events = new LinkedList<TimeEvent>();
-      events.add(new ObjectTimeEvent<String>(31, 32, 2, "Hello7"));
-      events.add(new ObjectTimeEvent<String>(20, 30, 1, "Hello8"));
-      events.add(new ObjectTimeEvent<String>(1, 8, 2, "Hello7"));
-      events.add(new ObjectTimeEvent<String>(8, 15, 1, "Hello8"));
-      events.add(new ObjectTimeEvent<String>(18, 20, 3, "Hello10"));
-      events.add(new ObjectTimeEvent<String>(10, 12, 1, "Hello1"));
-      events.add(new ObjectTimeEvent<String>(20, 30, 2, "Hello2"));
-      events.add(new ObjectTimeEvent<String>(1, 20, 1, "Hello3"));
-      events.add(new ObjectTimeEvent<String>(11, 13, 1, "Hello4"));
-      events.add(new ObjectTimeEvent<String>(15, 20, 1, "Hello5"));
-      events.add(new ObjectTimeEvent<String>(18, 20, 2, "Hello10"));
-      events.add(new ObjectTimeEvent<String>(1, 15, 1, "Hello6"));
-      events.add(new ObjectTimeEvent<String>(1, 18, 2, "Hello9"));
-      TimeEventWeightedHash timeEventHash = TimeEventWeightedHash.buildHash(events);
-      
-      System.out.println("Greatest Weighted Path: " + timeEventHash.getGreatestWeightedPathAsOrderedList());
-  }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 gov.nasa.jpl.oodt.cas.commons.filter;
+
+//JDK imports
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+* 
+* @author bfoster
+* @version $Revision$
+*
+* <p>
+* Builds a time sorted hash where the top value has the earliest time.  This hash
+* is a directional graph.  It builds all possible paths from top node to leaf
+* nodes.  At any time you can ask for the greatest weighted path in the hash -- that
+* is, the path from root node to a leaf node which fills the most time. Epsilon is 
+* TimeEvent objects allowed time overlap (it is of the same unit of measurement that 
+* is used in you TimeEvent objects added to this hash).
+* </p>.
+*/
+public class TimeEventWeightedHash {
+
+  private TimeEventNode root;
+  
+  protected long epsilon;
+  
+  private MyLinkedHashSet<TimeEventNode> leafNodes;
+      
+  private TimeEventWeightedHash() {
+      root = new TimeEventNode(new TimeEvent(-1, -1));
+      leafNodes = new MyLinkedHashSet<TimeEventNode>();
+      leafNodes.add(this.root);
+  }
+  
+  public static TimeEventWeightedHash buildHash(List<? extends TimeEvent> events) {
+	  return buildHash(events, 0);
+  }
+  
+  /**
+   * Returns the Greatest Weighted Path of TimeEvents
+   */
+  public static TimeEventWeightedHash buildHash(List<? extends TimeEvent> events, long epsilon) {
+	  TimeEventWeightedHash hash = new TimeEventWeightedHash();
+	  hash.epsilon = epsilon;
+      events = TimeEvent.getTimeOrderedEvents(events);
+      for (TimeEvent event : events)
+    	  hash.addEvent(event);
+      return hash;
+  }
+  
+  public List<? extends TimeEvent> getGreatestWeightedPathAsOrderedList() {
+      WeightedNode wn = this.getGreatestWeightedPath();
+      List<TimeEvent> gwpEvents = new LinkedList<TimeEvent>();
+      while(wn != null) {
+          gwpEvents.add(wn.getTimeEvent());
+          wn = wn.getChild();
+      }
+      
+      return gwpEvents;
+  }
+ 
+  private void addEvent(TimeEvent newEvent) {
+      TimeEventNode newEventNode = new TimeEventNode(newEvent);
+      MyLinkedHashSet<TimeEventNode> parentNodes = this.findParents(newEvent);
+      MyLinkedHashSet<TimeEventNode> childrenNodes = this.findChildren(newEvent, parentNodes);
+      
+      if (childrenNodes.size() == 0)
+          leafNodes.add(newEventNode);
+      
+      newEventNode.addParents(parentNodes);
+      newEventNode.addChildren(childrenNodes);
+      
+  }
+  
+  private MyLinkedHashSet<TimeEventNode> findParents(TimeEvent newEvent) {
+      MyLinkedHashSet<TimeEventNode> parentNodes = new MyLinkedHashSet<TimeEventNode>();
+      MyLinkedHashSet<TimeEventNode> possibleParentNodes = new MyLinkedHashSet<TimeEventNode>();
+      MyLinkedHashSet<TimeEventNode> possibleParentNodesAlreadyChecked = new MyLinkedHashSet<TimeEventNode>();
+      
+      //iterate through possible parent nodes add possible parent child as
+      // possible parents if they do not conflict
+      TimeEventNode curPPN = this.root;
+      while (curPPN != null) {
+          boolean ppnListChanged = false;
+          for (TimeEventNode curChild : curPPN.getChildren()) {
+              //if curChild does not conficts with te, then it is a possible parent
+              if (happensBefore(curChild.getTimeEvent(), newEvent) 
+                      && !possibleParentNodesAlreadyChecked.contains(curChild)) {
+                  possibleParentNodes.add(curChild);
+                  ppnListChanged = true;
+              }
+          }
+          //if all children where not possible parents, then curPPN must be parent
+          if (!ppnListChanged)
+              parentNodes.add(curPPN);
+          
+          //get next curPPN
+          possibleParentNodes.remove(curPPN);
+          possibleParentNodesAlreadyChecked.add(curPPN);
+          while((curPPN = possibleParentNodes.get(0)) != null 
+                  && possibleParentNodesAlreadyChecked.contains(curPPN)) {
+              possibleParentNodes.remove(curPPN);
+          }
+      }
+      
+      return parentNodes;
+  }
+  
+  private MyLinkedHashSet<TimeEventNode> findChildren(TimeEvent newEvent, MyLinkedHashSet<TimeEventNode> parentNodes) {
+      MyLinkedHashSet<TimeEventNode> childrenNodes = new MyLinkedHashSet<TimeEventNode>();
+      MyLinkedHashSet<TimeEventNode> possibleChildrenNodes = new MyLinkedHashSet<TimeEventNode>();
+      for (TimeEventNode parent : parentNodes) {
+          possibleChildrenNodes.addAll(parent.getChildren());
+          TimeEventNode curPCN = possibleChildrenNodes.get(0);
+          while (curPCN != null) {
+              if (happensBefore(newEvent, curPCN.getTimeEvent())) {
+                  childrenNodes.add(curPCN);
+              }else {
+                  possibleChildrenNodes.addAll(curPCN.getChildren());
+              }
+              possibleChildrenNodes.remove(curPCN);
+              curPCN = possibleChildrenNodes.get(0);
+          }
+      }
+      return childrenNodes;
+  }
+  
+  private boolean happensBefore(TimeEvent t1, TimeEvent t2) {
+      long boundaryCheck = t2.getStartTime() - t1.getEndTime();
+      return (boundaryCheck + epsilon) > 0;
+  }
+  
+  private WeightedNode getGreatestWeightedPath() {
+      TimeEventNode max = this.leafNodes.get(0);
+      for (TimeEventNode ten : this.leafNodes) {
+         if (ten.getPathWeight() > max.getPathWeight() 
+                 || (ten.getPathWeight() == max.getPathWeight() 
+                         && ten.getPathPriorityWeight() > max.getPathPriorityWeight()))
+             max = ten;
+      }
+      WeightedNode root = new WeightedNode(max.getTimeEvent());
+      TimeEventNode curTEN = max.greatestWieghtedParent;
+      while (curTEN != null) {
+          WeightedNode temp = new WeightedNode(curTEN.getTimeEvent());
+          temp.setChild(root);
+          root = temp;
+          curTEN = curTEN.greatestWieghtedParent;
+      }
+      return root.getChild();
+  }
+  
+  private class MyLinkedHashSet<E> extends HashSet<E> {
+
+      private static final long serialVersionUID = -7319154087430025841L;
+      
+      private LinkedList<E> listSet;
+      
+      public MyLinkedHashSet() {
+          this.listSet = new LinkedList<E>();
+      }
+      
+      @Override
+      public boolean add(E ten) {
+          boolean wasAdded = false;
+          if (wasAdded = super.add(ten))
+              listSet.add(ten);
+          return wasAdded;
+      }
+      
+      @Override
+      public boolean addAll(Collection<? extends E> collection) {
+          boolean setChanged = false;
+          for (E ten : collection) {
+              if (this.add(ten))
+                  setChanged = true;
+          }
+          return setChanged;
+      }
+      
+      @Override
+      public boolean remove(Object ten) {
+          if (super.remove(ten)) {
+              this.listSet.remove(ten);
+              return true;
+          }else 
+              return false;
+      }
+      
+      @Override
+      public boolean removeAll(Collection<?> collection) {
+          boolean setChanged = false;
+          for (Object obj : collection) {
+              if (this.remove(obj))
+                  setChanged = true;
+          }
+          return setChanged;  
+      }
+      
+      public E get(int index) {
+          if (this.listSet.size() > index)
+              return this.listSet.get(index);
+          else 
+              return null;
+      }
+      
+      public List<E> getList() {
+          return this.listSet;
+      }
+      
+  }
+
+  private class TimeEventNode {
+
+      private TimeEvent te;
+      
+      private MyLinkedHashSet<TimeEventNode> children;
+
+      private MyLinkedHashSet<TimeEventNode> parents;
+      
+      private TimeEventNode greatestWieghtedParent;
+              
+      public TimeEventNode(TimeEvent te) {
+          this.te = te;
+          children = new MyLinkedHashSet<TimeEventNode>();
+          parents = new MyLinkedHashSet<TimeEventNode>();
+      }
+      
+      public long getPathWeight() {
+          if (this.greatestWieghtedParent != null)
+              return te.getDuration()
+                      + this.greatestWieghtedParent.getPathWeight();
+          else
+              return te.getDuration();
+      }
+
+      public double getPathPriorityWeight() {
+          if (this.greatestWieghtedParent != null)
+              return te.getPriority()
+                      + this.greatestWieghtedParent.getPathPriorityWeight();
+          else
+              return te.getPriority();
+      }
+
+      public TimeEvent getTimeEvent() {
+          return this.te;
+      }
+
+      public void setTimeEvent(TimeEvent te) {
+          this.te = te;
+      }
+      
+      public void addChild(TimeEventNode child) {            
+          //remove parent to grandchild links
+          for (TimeEventNode parent : this.parents) {
+              parent.children.remove(child);
+              child.parents.remove(parent);
+          }
+          
+          //link to child
+          this.children.add(child);
+          child.parents.add(this);
+          leafNodes.remove(this);
+          
+          //determine child's greatest weighted parent
+          child.greatestWieghtedParent = this;
+          for (TimeEventNode parent : child.parents) {
+              long gwpPaW = child.greatestWieghtedParent.getPathWeight();
+              long pPaW = parent.getPathWeight();
+              double gwpPiW = child.greatestWieghtedParent.getPathPriorityWeight();
+              double pPiW = parent.getPathPriorityWeight();
+              if (pPaW > gwpPaW || (pPaW == gwpPaW && pPiW > gwpPiW))                    
+                  child.greatestWieghtedParent = parent;
+          }
+      }
+      
+      public void addParent(TimeEventNode parent) {
+          parent.addChild(this);
+      }
+
+      public void addChildren(Collection<TimeEventNode> children) {
+          for (TimeEventNode child : children)
+              this.addChild(child);
+      }
+      
+      public void addParents(Collection<TimeEventNode> parents) {
+          for (TimeEventNode parent : parents)
+              this.addParent(parent);
+      }
+
+      public MyLinkedHashSet<TimeEventNode> getChildren() {
+          return this.children;
+      }
+      
+      public MyLinkedHashSet<TimeEventNode> getParents() {
+          return this.parents;
+      }
+
+      public boolean equals(Object obj) {
+          if (obj instanceof TimeEventNode) {
+              TimeEventNode ten = (TimeEventNode) obj;
+              return this.te.equals(ten.te);
+          } else
+              return false;
+      }
+
+      public String toString() {
+          return this.te.toString() + " -- " + this.getPathWeight();
+      }
+      
+  }
+
+  private class WeightedNode {
+
+      private long pathWeight;
+
+      private WeightedNode child;
+
+      private TimeEvent te;
+
+      private WeightedNode(TimeEvent te) {
+          this.te = te;
+          pathWeight = te.getDuration();
+      }
+
+      private void setChild(WeightedNode child) {
+          this.child = child;
+          if (child != null)
+              this.pathWeight = this.te.getDuration() + child.getPathWeight();
+      }
+
+      public TimeEvent getTimeEvent() {
+          return this.te;
+      }
+
+      public WeightedNode getChild() {
+          return this.child;
+      }
+
+      public long getPathWeight() {
+          return this.pathWeight;
+      }
+
+      public String toString() {
+          return te.toString() + "\n" 
+              + (child != null ? child.toString() : "");
+      }
+
+  }
+
+  public String toString() {
+      StringBuffer sb = new StringBuffer("");
+      LinkedList<TimeEventNode> printNodes = new LinkedList<TimeEventNode>();
+      printNodes.add(this.root);
+      sb.append(printNodes(printNodes, "-", 0));
+      return sb.toString();
+  }
+
+  private StringBuffer printNodes(List<TimeEventNode> list,
+          String spacer, long curPathWeight) {
+      StringBuffer output = new StringBuffer("");
+      for (TimeEventNode node : list) {
+          output.append(spacer);
+          output.append(node.te + " -- " + (curPathWeight + node.te.getDuration()) + "\n");
+          output.append(printNodes(node.getChildren().getList(), " " + spacer, curPathWeight + node.te.getDuration()));
+      }
+      return output;
+  }
+
+  public static void main(String[] args) {              
+      List<TimeEvent> events = new LinkedList<TimeEvent>();
+      events.add(new ObjectTimeEvent<String>(31, 32, 2, "Hello7"));
+      events.add(new ObjectTimeEvent<String>(20, 30, 1, "Hello8"));
+      events.add(new ObjectTimeEvent<String>(1, 8, 2, "Hello7"));
+      events.add(new ObjectTimeEvent<String>(8, 15, 1, "Hello8"));
+      events.add(new ObjectTimeEvent<String>(18, 20, 3, "Hello10"));
+      events.add(new ObjectTimeEvent<String>(10, 12, 1, "Hello1"));
+      events.add(new ObjectTimeEvent<String>(20, 30, 2, "Hello2"));
+      events.add(new ObjectTimeEvent<String>(1, 20, 1, "Hello3"));
+      events.add(new ObjectTimeEvent<String>(11, 13, 1, "Hello4"));
+      events.add(new ObjectTimeEvent<String>(15, 20, 1, "Hello5"));
+      events.add(new ObjectTimeEvent<String>(18, 20, 2, "Hello10"));
+      events.add(new ObjectTimeEvent<String>(1, 15, 1, "Hello6"));
+      events.add(new ObjectTimeEvent<String>(1, 18, 2, "Hello9"));
+      TimeEventWeightedHash timeEventHash = TimeEventWeightedHash.buildHash(events);
+      
+      System.out.println("Greatest Weighted Path: " + timeEventHash.getGreatestWeightedPathAsOrderedList());
+  }
+
+}



Mime
View raw message