Remove classes
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package jscl.math;
|
||||
|
||||
import org.solovyev.common.Converter;
|
||||
|
||||
import jscl.math.function.Constant;
|
||||
import jscl.math.function.Fraction;
|
||||
import jscl.math.function.Inverse;
|
||||
@@ -16,38 +14,33 @@ import jscl.text.ParserUtils;
|
||||
import jscl.text.msg.Messages;
|
||||
import jscl.util.ArrayUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class Expression extends Generic {
|
||||
|
||||
protected static final Converter<Variable, Generic> FACTORIZE_CONVERTER = new Converter<Variable, Generic>() {
|
||||
protected static final com.google.common.base.Function<Variable, Generic> FACTORIZE_CONVERTER = new com.google.common.base.Function<Variable, Generic>() {
|
||||
@Nonnull
|
||||
public Generic convert(@Nonnull Variable variable) {
|
||||
public Generic apply(@Nonnull Variable variable) {
|
||||
return variable.factorize();
|
||||
}
|
||||
};
|
||||
protected static final Converter<Variable, Generic> ELEMENTARY_CONVERTER = new Converter<Variable, Generic>() {
|
||||
protected static final com.google.common.base.Function<Variable, Generic> ELEMENTARY_CONVERTER = new com.google.common.base.Function<Variable, Generic>() {
|
||||
@Nonnull
|
||||
public Generic convert(@Nonnull Variable variable) {
|
||||
public Generic apply(@Nonnull Variable variable) {
|
||||
return variable.elementary();
|
||||
}
|
||||
};
|
||||
protected static final Converter<Variable, Generic> EXPAND_CONVERTER = new Converter<Variable, Generic>() {
|
||||
protected static final com.google.common.base.Function<Variable, Generic> EXPAND_CONVERTER = new com.google.common.base.Function<Variable, Generic>() {
|
||||
@Nonnull
|
||||
public Generic convert(@Nonnull Variable variable) {
|
||||
public Generic apply(@Nonnull Variable variable) {
|
||||
return variable.expand();
|
||||
}
|
||||
};
|
||||
protected static final Converter<Variable, Generic> NUMERIC_CONVERTER = new Converter<Variable, Generic>() {
|
||||
protected static final com.google.common.base.Function<Variable, Generic> NUMERIC_CONVERTER = new com.google.common.base.Function<Variable, Generic>() {
|
||||
@Nonnull
|
||||
public Generic convert(@Nonnull Variable variable) {
|
||||
public Generic apply(@Nonnull Variable variable) {
|
||||
return variable.numeric();
|
||||
}
|
||||
};
|
||||
@@ -495,9 +488,9 @@ public class Expression extends Generic {
|
||||
}
|
||||
|
||||
public Generic substitute(@Nonnull final Variable variable, final Generic generic) {
|
||||
final Map<Variable, Generic> content = literalScm().content(new Converter<Variable, Generic>() {
|
||||
final Map<Variable, Generic> content = literalScm().content(new com.google.common.base.Function<Variable, Generic>() {
|
||||
@Nonnull
|
||||
public Generic convert(@Nonnull Variable v) {
|
||||
public Generic apply(@Nonnull Variable v) {
|
||||
return v.substitute(variable, generic);
|
||||
}
|
||||
});
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package jscl.math;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import jscl.math.function.Fraction;
|
||||
import jscl.math.function.Pow;
|
||||
import jscl.math.polynomial.Monomial;
|
||||
import jscl.mathml.MathML;
|
||||
import org.solovyev.common.Converter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -381,11 +381,11 @@ public class Literal implements Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
Map<Variable, Generic> content(@Nonnull Converter<Variable, Generic> c) {
|
||||
Map<Variable, Generic> content(@Nonnull Function<Variable, Generic> c) {
|
||||
final Map<Variable, Generic> result = new TreeMap<Variable, Generic>();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
result.put(variables[i], c.convert(variables[i]));
|
||||
result.put(variables[i], c.apply(variables[i]));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -5,7 +5,6 @@ import jscl.math.operator.Factorial;
|
||||
import jscl.math.operator.Operator;
|
||||
import jscl.mathml.MathML;
|
||||
import jscl.text.ParseException;
|
||||
import org.solovyev.common.Converter;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -19,31 +18,31 @@ public abstract class Variable implements Comparable, MathEntity {
|
||||
|
||||
@Nonnull
|
||||
public static final Comparator<Variable> comparator = VariableComparator.comparator;
|
||||
protected static final Converter<Generic, Generic> FACTORIZE_CONVERTER = new Converter<Generic, Generic>() {
|
||||
protected static final com.google.common.base.Function<Generic, Generic> FACTORIZE_CONVERTER = new com.google.common.base.Function<Generic, Generic>() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Generic convert(@Nonnull Generic generic) {
|
||||
public Generic apply(@Nonnull Generic generic) {
|
||||
return generic.factorize();
|
||||
}
|
||||
};
|
||||
protected static final Converter<Generic, Generic> ELEMENTARY_CONVERTER = new Converter<Generic, Generic>() {
|
||||
protected static final com.google.common.base.Function<Generic, Generic> ELEMENTARY_CONVERTER = new com.google.common.base.Function<Generic, Generic>() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Generic convert(@Nonnull Generic generic) {
|
||||
public Generic apply(@Nonnull Generic generic) {
|
||||
return generic.elementary();
|
||||
}
|
||||
};
|
||||
protected static final Converter<Generic, Generic> EXPAND_CONVERTER = new Converter<Generic, Generic>() {
|
||||
protected static final com.google.common.base.Function<Generic, Generic> EXPAND_CONVERTER = new com.google.common.base.Function<Generic, Generic>() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Generic convert(@Nonnull Generic generic) {
|
||||
public Generic apply(@Nonnull Generic generic) {
|
||||
return generic.expand();
|
||||
}
|
||||
};
|
||||
protected static final Converter<Generic, Generic> NUMERIC_CONVERTER = new Converter<Generic, Generic>() {
|
||||
protected static final com.google.common.base.Function<Generic, Generic> NUMERIC_CONVERTER = new com.google.common.base.Function<Generic, Generic>() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Generic convert(@Nonnull Generic generic) {
|
||||
public Generic apply(@Nonnull Generic generic) {
|
||||
return generic.numeric();
|
||||
}
|
||||
};
|
||||
|
@@ -4,10 +4,10 @@ import jscl.JsclMathEngine;
|
||||
import jscl.math.*;
|
||||
import jscl.mathml.MathML;
|
||||
import jscl.util.ArrayComparator;
|
||||
import org.solovyev.common.HashCodeBuilder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class Constant extends Variable {
|
||||
@@ -148,14 +148,7 @@ public class Constant extends Variable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final HashCodeBuilder result = HashCodeBuilder.newInstance();
|
||||
|
||||
result.append(Constant.class);
|
||||
result.append(name);
|
||||
result.append(subscripts);
|
||||
result.append(prime);
|
||||
|
||||
return result.toHashCode();
|
||||
return Objects.hash(Constant.class, name, subscripts, prime);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@@ -2,11 +2,6 @@ package jscl.math.function;
|
||||
|
||||
import org.solovyev.common.math.AbstractMathRegistry;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/7/11
|
||||
* Time: 11:59 AM
|
||||
*/
|
||||
public class ConstantsRegistry extends AbstractMathRegistry<IConstant> {
|
||||
|
||||
public static final String E = "e";
|
||||
|
@@ -4,7 +4,6 @@ import jscl.CustomFunctionCalculationException;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.math.*;
|
||||
import jscl.text.ParseException;
|
||||
import org.solovyev.common.JBuilder;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -211,7 +210,7 @@ public class CustomFunction extends Function implements IFunction {
|
||||
return new CustomFunction(name, parameterNames, content, description);
|
||||
}
|
||||
|
||||
public static class Builder implements JBuilder<CustomFunction> {
|
||||
public static class Builder {
|
||||
|
||||
private final boolean system;
|
||||
|
||||
@@ -320,7 +319,6 @@ public class CustomFunction extends Function implements IFunction {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public CustomFunction create() throws CustomFunctionCalculationException {
|
||||
final CustomFunction customFunction = new CustomFunction(name, parameterNames, prepareContent(content), description);
|
||||
customFunction.setSystem(system);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package jscl.math.function;
|
||||
|
||||
import org.solovyev.common.JBuilder;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -176,7 +175,7 @@ public class ExtendedConstant implements Comparable<ExtendedConstant>, IConstant
|
||||
return this.constant.compareTo(o.getConstant());
|
||||
}
|
||||
|
||||
public static final class Builder implements JBuilder<ExtendedConstant> {
|
||||
public static final class Builder {
|
||||
@Nonnull
|
||||
private Constant constant;
|
||||
|
||||
@@ -209,7 +208,6 @@ public class ExtendedConstant implements Comparable<ExtendedConstant>, IConstant
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ExtendedConstant create() {
|
||||
final ExtendedConstant result = new ExtendedConstant();
|
||||
|
||||
|
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Interface converts one object to another
|
||||
*
|
||||
* @param <FROM> type of object to be converted
|
||||
* @param <TO> type of result object (converted object)
|
||||
*/
|
||||
public interface Converter<FROM, TO> {
|
||||
|
||||
@Nonnull
|
||||
TO convert(@Nonnull FROM from);
|
||||
}
|
||||
|
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
import org.solovyev.common.equals.Equalizer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class EqualsResult<T> {
|
||||
|
||||
public static final Integer BOTH_NULLS_CONST = 0;
|
||||
|
||||
@Nullable
|
||||
private final Integer result;
|
||||
|
||||
@Nullable
|
||||
private final T o1;
|
||||
|
||||
@Nullable
|
||||
private final T o2;
|
||||
|
||||
@Nullable
|
||||
private final Equalizer<? super T> equalizer;
|
||||
|
||||
EqualsResult(@Nullable T o1, @Nullable T o2, @Nullable Equalizer<? super T> equalizer) {
|
||||
this.equalizer = equalizer;
|
||||
if (o1 == null && o2 == null) {
|
||||
result = EqualsResult.BOTH_NULLS_CONST;
|
||||
} else if (o1 == null) {
|
||||
result = -1;
|
||||
} else if (o2 == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
//both not nulls
|
||||
result = null;
|
||||
}
|
||||
this.o1 = o1;
|
||||
this.o2 = o2;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean areBothNotNulls() {
|
||||
return result == null;
|
||||
}
|
||||
|
||||
public boolean areBothNulls() {
|
||||
return result != null && result.equals(BOTH_NULLS_CONST);
|
||||
}
|
||||
|
||||
public boolean areEqual() {
|
||||
//noinspection ConstantConditions
|
||||
boolean areSame = o1 == o2;
|
||||
return areBothNulls() || areSame || (areBothNotNulls() && (equalizer == null ? o1.equals(o2) : equalizer.areEqual(o1, o2)));
|
||||
}
|
||||
}
|
@@ -1,550 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Assists in implementing {@link Object#hashCode()} methods.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* This class enables a good <code>hashCode</code> method to be built for any class. It follows the rules laid out in
|
||||
* the book <a href="http://java.sun.com/docs/books/effective/index.html">Effective Java</a> by Joshua Bloch. Writing a
|
||||
* good <code>hashCode</code> method is actually quite difficult. This class aims to simplify the process.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* All relevant fields from the object should be included in the <code>hashCode</code> method. Derived fields may be
|
||||
* excluded. In general, any field used in the <code>equals</code> method must be used in the <code>hashCode</code>
|
||||
* method.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* To use this class write code as follows:
|
||||
* </p>
|
||||
* <p/>
|
||||
* <pre>
|
||||
* public class Person {
|
||||
* String name;
|
||||
* int age;
|
||||
* boolean smoker;
|
||||
* ...
|
||||
*
|
||||
* public int hashCode() {
|
||||
* // you pick a hard-coded, randomly chosen, non-zero, odd number
|
||||
* // ideally different for each class
|
||||
* return new HashCodeBuilder(17, 37).
|
||||
* append(name).
|
||||
* append(age).
|
||||
* append(smoker).
|
||||
* toHashCode();
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* <p/>
|
||||
* <p>
|
||||
* If required, the superclass <code>hashCode()</code> can be added using {@link #appendSuper}.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
|
||||
* usually private, the method, <code>reflectionHashCode</code>, uses <code>AccessibleObject.setAccessible</code>
|
||||
* to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
|
||||
* are set up correctly. It is also slower than testing explicitly.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* A typical invocation for this method would look like:
|
||||
* </p>
|
||||
* <p/>
|
||||
* <pre>
|
||||
* public int hashCode() {
|
||||
* return HashCodeBuilder.reflectionHashCode(this);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Apache Software Foundation
|
||||
* @author Gary Gregory
|
||||
* @author Pete Gieser
|
||||
* @author Sergey Solovyev
|
||||
* @version $Id: HashCodeBuilder.java 907376 2010-02-07 03:43:02Z mbenson $
|
||||
* @since 1.0
|
||||
*/
|
||||
public class HashCodeBuilder {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constant to use in building the hashCode.
|
||||
*/
|
||||
private final int constant;
|
||||
|
||||
/**
|
||||
* Running total of the hashCode.
|
||||
*/
|
||||
private int total = 0;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Uses two hard coded choices for the constants needed to build a <code>hashCode</code>.
|
||||
* </p>
|
||||
*/
|
||||
private HashCodeBuilder() {
|
||||
constant = 37;
|
||||
total = 17;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
|
||||
* however this is not vital.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* Prime numbers are preferred, especially for the multiplier.
|
||||
* </p>
|
||||
*
|
||||
* @param initialNonZeroOddNumber a non-zero, odd number used as the initial value
|
||||
* @param multiplierNonZeroOddNumber a non-zero, odd number used as the multiplier
|
||||
* @throws IllegalArgumentException if the number is zero or even
|
||||
*/
|
||||
private HashCodeBuilder(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber) {
|
||||
if (initialNonZeroOddNumber == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires a non zero initial value");
|
||||
}
|
||||
if (initialNonZeroOddNumber % 2 == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires an odd initial value");
|
||||
}
|
||||
if (multiplierNonZeroOddNumber == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires a non zero multiplier");
|
||||
}
|
||||
if (multiplierNonZeroOddNumber % 2 == 0) {
|
||||
throw new IllegalArgumentException("HashCodeBuilder requires an odd multiplier");
|
||||
}
|
||||
constant = multiplierNonZeroOddNumber;
|
||||
total = initialNonZeroOddNumber;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static HashCodeBuilder newInstance() {
|
||||
return new HashCodeBuilder();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static HashCodeBuilder newInstance(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber) {
|
||||
return new HashCodeBuilder(initialNonZeroOddNumber, multiplierNonZeroOddNumber);
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* METHODS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>boolean</code>.
|
||||
* </p>
|
||||
* <p>
|
||||
* This adds <code>constant * 1</code> to the <code>hashCode</code> and not a <code>1231</code> or
|
||||
* <code>1237</code> as done in java.lang.Boolean. This is in accordance with the <quote>Effective Java</quote>
|
||||
* design.
|
||||
* </p>
|
||||
*
|
||||
* @param value the boolean to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(boolean value) {
|
||||
total = total * constant + (value ? 0 : 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>boolean</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(boolean[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (boolean element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>byte</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the byte to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(byte value) {
|
||||
total = total * constant + value;
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>byte</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(byte[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (byte element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>char</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the char to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(char value) {
|
||||
total = total * constant + value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>char</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(char[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (char element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>double</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the double to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(double value) {
|
||||
return append(Double.doubleToLongBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>double</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(double[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (double element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>float</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the float to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(float value) {
|
||||
total = total * constant + Float.floatToIntBits(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>float</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(float[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (float element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for an <code>int</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the int to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(int value) {
|
||||
total = total * constant + value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for an <code>int</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(int[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (int element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>long</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the long to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
// NOTE: This method uses >> and not >>> as Effective Java and
|
||||
// Long.hashCode do. Ideally we should switch to >>> at
|
||||
// some stage. There are backwards compat issues, so
|
||||
// that will have to wait for the time being. cf LANG-342.
|
||||
public HashCodeBuilder append(long value) {
|
||||
total = total * constant + ((int) (value ^ (value >> 32)));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>long</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(long[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (long element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for an <code>Object</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param object the Object to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(Object object) {
|
||||
if (object == null) {
|
||||
total = total * constant;
|
||||
|
||||
} else {
|
||||
if (object.getClass().isArray()) {
|
||||
// 'Switch' on type of array, to dispatch to the correct handler
|
||||
// This handles multi dimensional arrays
|
||||
if (object instanceof long[]) {
|
||||
append((long[]) object);
|
||||
} else if (object instanceof int[]) {
|
||||
append((int[]) object);
|
||||
} else if (object instanceof short[]) {
|
||||
append((short[]) object);
|
||||
} else if (object instanceof char[]) {
|
||||
append((char[]) object);
|
||||
} else if (object instanceof byte[]) {
|
||||
append((byte[]) object);
|
||||
} else if (object instanceof double[]) {
|
||||
append((double[]) object);
|
||||
} else if (object instanceof float[]) {
|
||||
append((float[]) object);
|
||||
} else if (object instanceof boolean[]) {
|
||||
append((boolean[]) object);
|
||||
} else {
|
||||
// Not an array of primitives
|
||||
append((Object[]) object);
|
||||
}
|
||||
} else {
|
||||
total = total * constant + object.hashCode();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for an <code>Object</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(Object[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (Object element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>short</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param value the short to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(short value) {
|
||||
total = total * constant + value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Append a <code>hashCode</code> for a <code>short</code> array.
|
||||
* </p>
|
||||
*
|
||||
* @param array the array to add to the <code>hashCode</code>
|
||||
* @return this
|
||||
*/
|
||||
public HashCodeBuilder append(short[] array) {
|
||||
if (array == null) {
|
||||
total = total * constant;
|
||||
} else {
|
||||
for (short element : array) {
|
||||
append(element);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Adds the result of super.hashCode() to this builder.
|
||||
* </p>
|
||||
*
|
||||
* @param superHashCode the result of calling <code>super.hashCode()</code>
|
||||
* @return this HashCodeBuilder, used to chain calls.
|
||||
* @since 2.0
|
||||
*/
|
||||
public HashCodeBuilder appendSuper(int superHashCode) {
|
||||
total = total * constant + superHashCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Return the computed <code>hashCode</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return <code>hashCode</code> based on the fields appended
|
||||
*/
|
||||
public int toHashCode() {
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* The computed <code>hashCode</code> from toHashCode() is returned due to the likelyhood
|
||||
* of bugs in mis-calling toHashCode() and the unlikelyness of it mattering what the hashCode for
|
||||
* HashCodeBuilder itself is.
|
||||
*
|
||||
* @return <code>hashCode</code> based on the fields appended
|
||||
* @since 2.5
|
||||
*/
|
||||
public int hashCode() {
|
||||
return toHashCode();
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface JBuilder<T> {
|
||||
|
||||
@Nonnull
|
||||
T create();
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Predicate, copy of Guava's {@link com.google.common.base.Predicate}
|
||||
*/
|
||||
public interface JPredicate<T> {
|
||||
|
||||
boolean apply(@Nullable T t);
|
||||
}
|
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 5/18/11
|
||||
* Time: 11:18 AM
|
||||
*/
|
||||
|
||||
import org.solovyev.common.equals.Equalizer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Objects {
|
||||
|
||||
protected Objects() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* EQUALS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public static EqualsResult getEqualsResult(@Nullable Object o1, @Nullable Object o2) {
|
||||
return new EqualsResult<Object>(o1, o2, null);
|
||||
}
|
||||
|
||||
public static <T> boolean areEqual(@Nullable T o1, @Nullable T o2) {
|
||||
return new EqualsResult<T>(o1, o2, null).areEqual();
|
||||
}
|
||||
|
||||
public static <T> boolean areEqual(@Nullable T o1, @Nullable T o2, @Nullable Equalizer<? super T> equalizer) {
|
||||
return new EqualsResult<T>(o1, o2, equalizer).areEqual();
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* COMPARE
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public static int compare(Object value1, Object value2) {
|
||||
Integer result = compareOnNullness(value1, value2);
|
||||
|
||||
if (result == null) {
|
||||
if (value1 instanceof Comparable && value2 instanceof Comparable) {
|
||||
//noinspection unchecked
|
||||
result = ((Comparable) value1).compareTo(value2);
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> int compare(@Nullable T l,
|
||||
@Nullable T r) {
|
||||
Integer result = compareOnNullness(l, r);
|
||||
|
||||
if (result == null) {
|
||||
assert l != null;
|
||||
result = l.compareTo(r);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int compare(List list1, List list2) {
|
||||
Integer result = compareOnNullness(list1, list2);
|
||||
|
||||
if (result == null) {
|
||||
result = list1.size() - list2.size();
|
||||
if (result == 0) {
|
||||
for (int i = 0; i < list1.size(); i++) {
|
||||
result = compare(list1.get(i), list2.get(i));
|
||||
if (result != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int compare(Number value1, Number value2) {
|
||||
Integer result = compareOnNullness(value1, value2);
|
||||
|
||||
if (result == null) {
|
||||
if (value1 instanceof Comparable && value2 instanceof Comparable) {
|
||||
//noinspection unchecked
|
||||
result = ((Comparable) value1).compareTo(value2);
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int compare(Date value1, Date value2) {
|
||||
Integer result = compareOnNullness(value1, value2);
|
||||
if (result == null) {
|
||||
if (value1.before(value2)) {
|
||||
result = -1;
|
||||
} else if (value1.after(value2)) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int compare(int value1, int value2) {
|
||||
if (value1 > value2) {
|
||||
return 1;
|
||||
} else if (value1 == value2) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static int compare(String value1, String value2, boolean ignoreCase) {
|
||||
Integer result = compareOnNullness(value1, value2);
|
||||
|
||||
if (result == null) {
|
||||
if (ignoreCase) {
|
||||
result = value1.toLowerCase().compareTo(value2.toLowerCase());
|
||||
} else {
|
||||
result = value1.compareTo(value2);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int compare(Boolean value1, Boolean value2) {
|
||||
Integer result = compareOnNullness(value1, value2);
|
||||
|
||||
if (result == null) {
|
||||
result = value1.compareTo(value2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method compares objects according their nullness property
|
||||
*
|
||||
* @param o1 first compared object
|
||||
* @param o2 second compared object
|
||||
* @return if both objects are nulls then 0 (they are equal), if first is null then -1, if second is null then 1, otherwise - null
|
||||
*/
|
||||
@Nullable
|
||||
public static Integer compareOnNullness(Object o1, Object o2) {
|
||||
Integer result;
|
||||
|
||||
if (o1 == null && o2 == null) {
|
||||
result = EqualsResult.BOTH_NULLS_CONST;
|
||||
} else if (o1 == null) {
|
||||
result = -1;
|
||||
} else if (o2 == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
//both not nulls
|
||||
result = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method compares objects according their nullness property
|
||||
*
|
||||
* @param o1 first compared object
|
||||
* @param o2 second compared object
|
||||
* @return if both objects are nulls then 0 (they are equal), if first is null then -1, if second is null then 1, otherwise - null
|
||||
*/
|
||||
public static EqualsResult compareOnNullnessWithResult(Object o1, Object o2) {
|
||||
return getEqualsResult(o1, o2);
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common.equals;
|
||||
|
||||
import org.solovyev.common.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
public class CollectionEqualizer<T> implements Equalizer<Collection<T>> {
|
||||
|
||||
@Nullable
|
||||
protected final Equalizer<T> nestedEqualizer;
|
||||
|
||||
public CollectionEqualizer(@Nullable Equalizer<T> nestedEqualizer) {
|
||||
this.nestedEqualizer = nestedEqualizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areEqual(@Nonnull Collection<T> first, @Nonnull Collection<T> second) {
|
||||
boolean result = false;
|
||||
|
||||
if (first.size() == second.size()) {
|
||||
result = true;
|
||||
|
||||
for (T el1 : first) {
|
||||
boolean found = false;
|
||||
|
||||
for (T el2 : second) {
|
||||
if (Objects.areEqual(el1, el2, nestedEqualizer)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.common.equals;
|
||||
|
||||
import org.solovyev.common.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ListEqualizer<T> implements Equalizer<List<T>> {
|
||||
|
||||
@Nonnull
|
||||
private static final Equalizer<List<Object>> instanceWithOrder = new ListEqualizer<>(true, null);
|
||||
|
||||
@Nonnull
|
||||
private static final Equalizer<List<Object>> instanceWithoutOrder = new ListEqualizer<>(false, null);
|
||||
|
||||
private final boolean checkOrder;
|
||||
|
||||
@Nullable
|
||||
protected final Equalizer<T> nestedEqualizer;
|
||||
|
||||
private ListEqualizer(boolean checkOrder, @Nullable Equalizer<T> nestedEqualizer) {
|
||||
this.checkOrder = checkOrder;
|
||||
this.nestedEqualizer = nestedEqualizer;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static <T> ListEqualizer<T> newWithNestedEqualizer(boolean checkOrder, @Nullable Equalizer<T> nestedEqualizer) {
|
||||
return new ListEqualizer<>(checkOrder, nestedEqualizer);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static <T> ListEqualizer<T> newWithNaturalEquals(boolean checkOrder) {
|
||||
if (checkOrder) {
|
||||
return (ListEqualizer<T>) instanceWithOrder;
|
||||
} else {
|
||||
return (ListEqualizer<T>) instanceWithoutOrder;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areEqual(@Nonnull List<T> first, @Nonnull List<T> second) {
|
||||
boolean result = false;
|
||||
|
||||
if (first.size() == second.size()) {
|
||||
if (checkOrder) {
|
||||
result = true;
|
||||
for (int i = 0; i < first.size(); i++) {
|
||||
final T el1 = first.get(i);
|
||||
final T el2 = second.get(i);
|
||||
|
||||
if (!Objects.areEqual(el1, el2, nestedEqualizer)) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
result = Objects.areEqual(first, second, new CollectionEqualizer<>(nestedEqualizer));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -22,7 +22,6 @@
|
||||
|
||||
package org.solovyev.common.math;
|
||||
|
||||
import org.solovyev.common.JBuilder;
|
||||
import org.solovyev.common.collections.SortedList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -117,34 +116,23 @@ public abstract class AbstractMathRegistry<T extends MathEntity> implements Math
|
||||
list.add(entity);
|
||||
}
|
||||
|
||||
public T add(@Nonnull JBuilder<? extends T> builder) {
|
||||
public T addOrUpdate(@Nonnull T entity) {
|
||||
synchronized (this) {
|
||||
final T entity = builder.create();
|
||||
|
||||
T varFromRegister;
|
||||
|
||||
if (entity.isIdDefined()) {
|
||||
varFromRegister = getById(entity.getId());
|
||||
} else {
|
||||
varFromRegister = get(entity.getName());
|
||||
}
|
||||
|
||||
if (varFromRegister == null) {
|
||||
varFromRegister = entity;
|
||||
|
||||
addEntity(entity, this.entities);
|
||||
this.entityNames.clear();
|
||||
final T existingEntity = entity.isIdDefined() ? getById(entity.getId()) : get(entity.getName());
|
||||
if (existingEntity == null) {
|
||||
addEntity(entity, entities);
|
||||
entityNames.clear();
|
||||
if (entity.isSystem()) {
|
||||
this.systemEntities.add(entity);
|
||||
systemEntities.add(entity);
|
||||
}
|
||||
return entity;
|
||||
} else {
|
||||
varFromRegister.copy(entity);
|
||||
existingEntity.copy(entity);
|
||||
this.entities.sort();
|
||||
this.entityNames.clear();
|
||||
this.systemEntities.sort();
|
||||
return existingEntity;
|
||||
}
|
||||
|
||||
return varFromRegister;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,8 +22,6 @@
|
||||
|
||||
package org.solovyev.common.math;
|
||||
|
||||
import org.solovyev.common.JBuilder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
@@ -36,7 +34,7 @@ public interface MathRegistry<T extends MathEntity> {
|
||||
@Nonnull
|
||||
List<T> getSystemEntities();
|
||||
|
||||
T add(@Nonnull JBuilder<? extends T> JBuilder);
|
||||
T addOrUpdate(@Nonnull T t);
|
||||
|
||||
void remove(@Nonnull T var);
|
||||
|
||||
|
@@ -22,9 +22,6 @@
|
||||
|
||||
package org.solovyev.common.msg;
|
||||
|
||||
import org.solovyev.common.HashCodeBuilder;
|
||||
import org.solovyev.common.Objects;
|
||||
import org.solovyev.common.equals.ListEqualizer;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -81,7 +78,7 @@ public abstract class AbstractMessage implements Message {
|
||||
|
||||
final AbstractMessage that = (AbstractMessage) o;
|
||||
|
||||
if (!Objects.areEqual(parameters, that.parameters, ListEqualizer.newWithNaturalEquals(true))) {
|
||||
if (!areEqual(parameters, that.parameters)) {
|
||||
return false;
|
||||
}
|
||||
if (!messageCode.equals(that.messageCode)) {
|
||||
@@ -94,15 +91,23 @@ public abstract class AbstractMessage implements Message {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean areEqual(@Nonnull List<Object> thisList, @Nonnull List<Object> thatList) {
|
||||
if (thisList.size() != thatList.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < thisList.size(); i++) {
|
||||
final Object thisItem = thisList.get(i);
|
||||
final Object thatItem = thatList.get(i);
|
||||
if (!thisItem.equals(thatItem)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final HashCodeBuilder hcb = HashCodeBuilder.newInstance();
|
||||
|
||||
hcb.append(messageCode);
|
||||
hcb.append(messageLevel);
|
||||
hcb.append(parameters);
|
||||
|
||||
return hcb.toHashCode();
|
||||
return com.google.common.base.Objects.hashCode(messageCode, messageLevel, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,12 +22,12 @@
|
||||
|
||||
package org.solovyev.common.search;
|
||||
|
||||
import org.solovyev.common.JPredicate;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StartsWithFinder implements JPredicate<String> {
|
||||
public class StartsWithFinder implements Predicate<String> {
|
||||
|
||||
private int i;
|
||||
|
||||
|
Reference in New Issue
Block a user