Author: adrianc
Date: Sat Feb 27 16:48:32 2010 New Revision: 916987 URL: http://svn.apache.org/viewvc?rev=916987&view=rev Log: Created a new Java package - org.ofbiz/base/lang - which is intended to be used as a home for basic Java types. Moved some basic Java type classes into the new package. Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java (with props) ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java (with props) ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java (with props) Removed: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Appender.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Range.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMap.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMapCollection.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ComparableRangeTests.java ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java?rev=916987&view=auto ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java (added) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java Sat Feb 27 16:48:32 2010 @@ -0,0 +1,23 @@ +/* + * 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 org.ofbiz.base.lang; + +public interface Appender<T> { + T appendTo(T target); +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Appender.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java?rev=916987&view=auto ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java (added) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java Sat Feb 27 16:48:32 2010 @@ -0,0 +1,111 @@ +/******************************************************************************* + * 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 org.ofbiz.base.lang; + +/** An immutable range of values. */ +public class ComparableRange<T extends Comparable<T>> implements Range<T> { + + protected final T start; + protected final T end; + protected final boolean isPoint; + + public ComparableRange(T start, T end) { + if (start.getClass() != end.getClass()) { + throw new IllegalArgumentException("start Class and end Class must be the same"); + } + if (end.compareTo(start) >= 0) { + this.start = start; + this.end = end; + } else { + this.start = end; + this.end = start; + } + this.isPoint = start.equals(end); + } + + @Override + public boolean after(Range<T> range) { + return this.start.compareTo(range.end()) > 0; + } + + @Override + public boolean after(T value) { + return this.start.compareTo(value) > 0; + } + + @Override + public boolean before(Range<T> range) { + return this.end.compareTo(range.start()) < 0; + } + + @Override + public boolean before(T value) { + return this.end.compareTo(value) < 0; + } + + @Override + public T end() { + return this.end; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + try { + ComparableRange that = (ComparableRange) obj; + return this.start.equals(that.start) && this.end.equals(that.end); + } catch (ClassCastException e) {} + return false; + } + + @Override + public boolean includes(Range<T> range) { + return this.includes(range.start()) && this.includes(range.end()); + } + + @Override + public boolean includes(T value) { + if (this.isPoint) { + return value.equals(this.start); + } + return (value.compareTo(this.start) >= 0 && value.compareTo(this.end) <= 0); + } + + @Override + public boolean isPoint() { + return this.isPoint; + } + + @Override + public boolean overlaps(Range<T> range) { + return range.includes(this.start) || range.includes(this.end) || this.includes(range); + } + + @Override + public T start() { + return this.start; + } + + @Override + public String toString() { + return this.start + " - " + this.end; + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ComparableRange.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java?rev=916987&view=auto ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java (added) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java Sat Feb 27 16:48:32 2010 @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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 org.ofbiz.base.lang; + +/** A range of values. */ +public interface Range<T> { + /** Returns <code>true</code> if the lowest value in this range + * occurs after the greatest value in <code>range</code>. + * @param range The range to test + * @return <code>true</code> if the lowest value in this range + * occurs after the greatest value in <code>range</code> + */ + boolean after(Range<T> range); + + /** Returns <code>true</code> if this range occurs after <code>value</code>. + * @param value The value to test + * @return <code>true</code> if this range occurs after <code>value</code> + */ + boolean after(T value); + + /** Returns <code>true</code> if the greatest value in this range + * occurs before the lowest value in <code>range</code>. + * @param range The range to test + * @return <code>true</code> if the greatest value in this range + * occurs before the lowest value in <code>range</code> + */ + boolean before(Range<T> range); + + /** Returns <code>true</code> if this range occurs before <code>value</code>. + * @param value The value to test + * @return <code>true</code> if this range occurs before <code>value</code> + */ + boolean before(T value); + + /** Returns the ending value of this range. + * @return Ending value + */ + T end(); + + /** Returns <code>true</code> if this range includes <code>range</code>. + * @param range The range to test + * @return <code>true</code> if this range includes <code>range</code> + */ + boolean includes(Range<T> range); + + /** Returns <code>true</code> if <code>date</code> occurs within this range. + * @param value The value to test + * @return <code>true</code> if <code>value</code> occurs within this range + */ + boolean includes(T value); + + /** Returns <code>true</code> if the starting and ending values are equal. + * @return <code>true</code> if the starting and ending values are equal + */ + boolean isPoint(); + + /** Returns <code>true</code> if this range overlaps <code>range</code>. + * @param range The range to test + * @return <code>true</code> if this range overlaps <code>range</code> + */ + boolean overlaps(Range<T> range); + + /** Returns the starting value of this range. + * @return Starting value + */ + T start(); + +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/Range.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java Sat Feb 27 16:48:32 2010 @@ -22,6 +22,8 @@ import java.sql.Timestamp; import java.util.Date; +import org.ofbiz.base.lang.ComparableRange; + /** An immutable range of dates. This class is here for backward compatibility - * new code should use <code>ComparableRange<Date></code> instead. */ Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java Sat Feb 27 16:48:32 2010 @@ -39,6 +39,7 @@ import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Hex; +import org.ofbiz.base.lang.Appender; import org.owasp.esapi.Encoder; import org.owasp.esapi.ValidationErrorList; import org.owasp.esapi.Validator; Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMap.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMap.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMap.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMap.java Sat Feb 27 16:48:32 2010 @@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; -import org.ofbiz.base.util.Appender; +import org.ofbiz.base.lang.Appender; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilObject; Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMapCollection.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMapCollection.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMapCollection.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/collections/GenericMapCollection.java Sat Feb 27 16:48:32 2010 @@ -25,8 +25,6 @@ import javolution.util.FastList; -import org.ofbiz.base.util.Appender; - public abstract class GenericMapCollection<K, V, M extends Map<K, V>, I> implements Collection<I> { protected final M source; Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ComparableRangeTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ComparableRangeTests.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ComparableRangeTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ComparableRangeTests.java Sat Feb 27 16:48:32 2010 @@ -19,7 +19,7 @@ package org.ofbiz.base.util.test; import org.ofbiz.base.test.GenericTestCaseBase; -import org.ofbiz.base.util.ComparableRange; +import org.ofbiz.base.lang.ComparableRange; public class ComparableRangeTests extends GenericTestCaseBase { Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java (original) +++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Atom.java Sat Feb 27 16:48:32 2010 @@ -18,7 +18,7 @@ */ package org.ofbiz.sql; -import org.ofbiz.base.util.Appender; +import org.ofbiz.base.lang.Appender; public abstract class Atom implements Appender<StringBuilder> { public String toString() { Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java?rev=916987&r1=916986&r2=916987&view=diff ============================================================================== --- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java (original) +++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java Sat Feb 27 16:48:32 2010 @@ -18,7 +18,7 @@ */ package org.ofbiz.sql; -import org.ofbiz.base.util.Appender; +import org.ofbiz.base.lang.Appender; public interface InsertSource extends Appender<StringBuilder> { } |
Free forum by Nabble | Edit this page |