[jira] Created: (MATH-337) Equals methods rely on catching ClassCastException rather than using instanceof check

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (MATH-337) Equals methods rely on catching ClassCastException rather than using instanceof check

ASF GitHub Bot (Jira)
Equals methods rely on catching ClassCastException rather than using instanceof check
-------------------------------------------------------------------------------------

                 Key: MATH-337
                 URL: https://issues.apache.org/jira/browse/MATH-337
             Project: Commons Math
          Issue Type: Improvement
            Reporter: Sebb
            Priority: Minor


Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.

For example:
{code}
SimplexTableau.equals(Object){
  if (this == other) {
    return true;
  }
  if (other == null) {
    return false;
  }
  try {
      SimplexTableau rhs = (SimplexTableau) other;
      etc.
  } catch (ClassCastException ex) {
      return false;
  }
}
{code}

This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:

{code}
SimplexTableau.equals(Object){
  if (this == other) {
    return true;
  }
  if (!(other instanceof SimplexTableau)) {
    return false;
  }
  SimplexTableau rhs = (SimplexTableau) other;
  etc.
}
{code}

Note that the null check is no longer needed; it is replaced by the instanceof check.


--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (MATH-337) Equals methods rely on catching ClassCastException rather than using instanceof check

ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/MATH-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz updated MATH-337:
-----------------------------

    Fix Version/s: 2.1

> Equals methods rely on catching ClassCastException rather than using instanceof check
> -------------------------------------------------------------------------------------
>
>                 Key: MATH-337
>                 URL: https://issues.apache.org/jira/browse/MATH-337
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Sebb
>            Priority: Minor
>             Fix For: 2.1
>
>
> Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.
> For example:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (other == null) {
>     return false;
>   }
>   try {
>       SimplexTableau rhs = (SimplexTableau) other;
>       etc.
>   } catch (ClassCastException ex) {
>       return false;
>   }
> }
> {code}
> This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (!(other instanceof SimplexTableau)) {
>     return false;
>   }
>   SimplexTableau rhs = (SimplexTableau) other;
>   etc.
> }
> {code}
> Note that the null check is no longer needed; it is replaced by the instanceof check.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (MATH-337) Equals methods rely on catching ClassCastException rather than using instanceof check

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/MATH-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved MATH-337.
-----------------------

    Resolution: Fixed

URL: http://svn.apache.org/viewvc?rev=922713&view=rev
Log:
MATH-337 Equals methods rely on catching ClassCastException rather than using instanceof check

Modified:
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/complex/Complex.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/Vector3D.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearConstraint.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/BigReal.java
   commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/TransformerMap.java

> Equals methods rely on catching ClassCastException rather than using instanceof check
> -------------------------------------------------------------------------------------
>
>                 Key: MATH-337
>                 URL: https://issues.apache.org/jira/browse/MATH-337
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Sebb
>            Priority: Minor
>             Fix For: 2.1
>
>
> Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.
> For example:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (other == null) {
>     return false;
>   }
>   try {
>       SimplexTableau rhs = (SimplexTableau) other;
>       etc.
>   } catch (ClassCastException ex) {
>       return false;
>   }
> }
> {code}
> This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (!(other instanceof SimplexTableau)) {
>     return false;
>   }
>   SimplexTableau rhs = (SimplexTableau) other;
>   etc.
> }
> {code}
> Note that the null check is no longer needed; it is replaced by the instanceof check.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (MATH-337) Equals methods rely on catching ClassCastException rather than using instanceof check

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/MATH-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz updated MATH-337:
-----------------------------

    Affects Version/s: 2.0

> Equals methods rely on catching ClassCastException rather than using instanceof check
> -------------------------------------------------------------------------------------
>
>                 Key: MATH-337
>                 URL: https://issues.apache.org/jira/browse/MATH-337
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Sebb
>            Priority: Minor
>             Fix For: 2.1
>
>
> Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.
> For example:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (other == null) {
>     return false;
>   }
>   try {
>       SimplexTableau rhs = (SimplexTableau) other;
>       etc.
>   } catch (ClassCastException ex) {
>       return false;
>   }
> }
> {code}
> This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (!(other instanceof SimplexTableau)) {
>     return false;
>   }
>   SimplexTableau rhs = (SimplexTableau) other;
>   etc.
> }
> {code}
> Note that the null check is no longer needed; it is replaced by the instanceof check.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Closed: (MATH-337) Equals methods rely on catching ClassCastException rather than using instanceof check

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/MATH-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz closed MATH-337.
----------------------------


> Equals methods rely on catching ClassCastException rather than using instanceof check
> -------------------------------------------------------------------------------------
>
>                 Key: MATH-337
>                 URL: https://issues.apache.org/jira/browse/MATH-337
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Sebb
>            Priority: Minor
>             Fix For: 2.1
>
>
> Several of the equals methods rely on catching ClassCastException rather than using an instanceof check.
> For example:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (other == null) {
>     return false;
>   }
>   try {
>       SimplexTableau rhs = (SimplexTableau) other;
>       etc.
>   } catch (ClassCastException ex) {
>       return false;
>   }
> }
> {code}
> This is likely to be significantly slower if the cast fails. It would be cheaper to do the following:
> {code}
> SimplexTableau.equals(Object){
>   if (this == other) {
>     return true;
>   }
>   if (!(other instanceof SimplexTableau)) {
>     return false;
>   }
>   SimplexTableau rhs = (SimplexTableau) other;
>   etc.
> }
> {code}
> Note that the null check is no longer needed; it is replaced by the instanceof check.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.