Skip to content

Commit

Permalink
[CLEANUP] missing hashCode for overridden equals in engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tgf committed May 24, 2017
1 parent 198ce17 commit 64cbfe0
Show file tree
Hide file tree
Showing 24 changed files with 224 additions and 145 deletions.
69 changes: 69 additions & 0 deletions engine/src/org/pentaho/di/base/AbstractMeta.java
Expand Up @@ -83,6 +83,7 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public abstract class AbstractMeta implements ChangedFlagInterface, UndoInterface, HasDatabasesInterface, VariableSpace,
Expand Down Expand Up @@ -1910,7 +1911,75 @@ protected List<SharedObjectInterface> getAllSharedObjects() {
* @throws MetaStoreException
* in case there is an error.
*/
@Deprecated
public void saveMetaStoreObjects( Repository repository, IMetaStore metaStore ) throws MetaStoreException {

}

protected int compare( AbstractMeta meta1, AbstractMeta meta2 ) {
// If we don't have a filename, it comes from a repository
if ( Utils.isEmpty( meta1.getFilename() ) ) {

if ( !Utils.isEmpty( meta2.getFilename() ) ) {
return -1;
}

// First compare names...
if ( Utils.isEmpty( meta1.getName() ) && !Utils.isEmpty( meta2.getName() ) ) {
return -1;
}
if ( !Utils.isEmpty( meta1.getName() ) && Utils.isEmpty( meta2.getName() ) ) {
return 1;
}
int cmpName = meta1.getName().compareTo( meta2.getName() );
if ( cmpName != 0 ) {
return cmpName;
}

// Same name, compare Repository directory...
int cmpDirectory = meta1.getRepositoryDirectory().getPath().compareTo( meta2.getRepositoryDirectory().getPath() );
if ( cmpDirectory != 0 ) {
return cmpDirectory;
}

// Same name, same directory, compare versions
if ( meta1.getObjectRevision() != null && meta2.getObjectRevision() == null ) {
return 1;
}
if ( meta1.getObjectRevision() == null && meta2.getObjectRevision() != null ) {
return -1;
}
if ( meta1.getObjectRevision() == null && meta2.getObjectRevision() == null ) {
return 0;
}
return meta1.getObjectRevision().getName().compareTo( meta2.getObjectRevision().getName() );

} else {
if ( Utils.isEmpty( meta2.getFilename() ) ) {
return 1;
}

// First compare names
//
if ( Utils.isEmpty( meta1.getName() ) && !Utils.isEmpty( meta2.getName() ) ) {
return -1;
}
if ( !Utils.isEmpty( meta1.getName() ) && Utils.isEmpty( meta2.getName() ) ) {
return 1;
}
int cmpName = meta1.getName().compareTo( meta2.getName() );
if ( cmpName != 0 ) {
return cmpName;
}

// Same name, compare filenames...
return meta1.getFilename().compareTo( meta2.getFilename() );
}
}

@Override
public int hashCode() {
boolean inRepo = Utils.isEmpty( getFilename() );
return Objects.hash( name, inRepo, inRepo ? filename : getRepositoryDirectory().getPath() );
}
}
60 changes: 1 addition & 59 deletions engine/src/org/pentaho/di/job/JobMeta.java
Expand Up @@ -336,65 +336,7 @@ public JobEntryCopy getDummy() {
*
*/
public int compare( JobMeta j1, JobMeta j2 ) {
// If we don't have a filename, the jobs comes from a repository
//
if ( Utils.isEmpty( j1.getFilename() ) ) {

if ( !Utils.isEmpty( j2.getFilename() ) ) {
return -1;
}

// First compare names...
if ( Utils.isEmpty( j1.getName() ) && !Utils.isEmpty( j2.getName() ) ) {
return -1;
}
if ( !Utils.isEmpty( j1.getName() ) && Utils.isEmpty( j2.getName() ) ) {
return 1;
}
int cmpName = j1.getName().compareTo( j2.getName() );
if ( cmpName != 0 ) {
return cmpName;
}

// Same name, compare Repository directory...
int cmpDirectory = j1.getRepositoryDirectory().getPath().compareTo( j2.getRepositoryDirectory().getPath() );
if ( cmpDirectory != 0 ) {
return cmpDirectory;
}

// Same name, same directory, compare versions
if ( j1.getObjectRevision() != null && j2.getObjectRevision() == null ) {
return 1;
}
if ( j1.getObjectRevision() == null && j2.getObjectRevision() != null ) {
return -1;
}
if ( j1.getObjectRevision() == null && j2.getObjectRevision() == null ) {
return 0;
}
return j1.getObjectRevision().getName().compareTo( j2.getObjectRevision().getName() );

} else {
if ( Utils.isEmpty( j2.getFilename() ) ) {
return 1;
}

// First compare names
//
if ( Utils.isEmpty( j1.getName() ) && !Utils.isEmpty( j2.getName() ) ) {
return -1;
}
if ( !Utils.isEmpty( j1.getName() ) && Utils.isEmpty( j2.getName() ) ) {
return 1;
}
int cmpName = j1.getName().compareTo( j2.getName() );
if ( cmpName != 0 ) {
return cmpName;
}

// Same name, compare filenames...
return j1.getFilename().compareTo( j2.getFilename() );
}
return super.compare( j1, j2 );
}

/**
Expand Down
7 changes: 6 additions & 1 deletion engine/src/org/pentaho/di/job/entry/JobEntryBase.java
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -168,6 +168,11 @@ public boolean equals( Object obj ) {
return name.equalsIgnoreCase( ( (JobEntryBase) obj ).getName() );
}

@Override
public int hashCode() {
return name.toLowerCase().hashCode();
}

/**
* Clears all variable values
*/
Expand Down
5 changes: 5 additions & 0 deletions engine/src/org/pentaho/di/trans/TransHopMeta.java
Expand Up @@ -23,6 +23,7 @@
package org.pentaho.di.trans;

import java.util.List;
import java.util.Objects;

import org.pentaho.di.base.BaseHopMeta;
import org.pentaho.di.core.Const;
Expand Down Expand Up @@ -113,6 +114,10 @@ public boolean equals( Object obj ) {
return this.from.equals( other.getFromStep() ) && this.to.equals( other.getToStep() );
}

public int hashCode() {
return Objects.hash( to, from );
}

/**
* Compare 2 hops.
*/
Expand Down
66 changes: 2 additions & 64 deletions engine/src/org/pentaho/di/trans/TransMeta.java
Expand Up @@ -497,69 +497,7 @@ public TransMeta( String filename, String name, String[] arguments ) {
*/
@Override
public int compare( TransMeta t1, TransMeta t2 ) {
// If we don't have a filename, the transformation comes from a repository
//
if ( Utils.isEmpty( t1.getFilename() ) ) {

if ( !Utils.isEmpty( t2.getFilename() ) ) {
return -1;
}

// First compare names...
//
if ( Utils.isEmpty( t1.getName() ) && !Utils.isEmpty( t2.getName() ) ) {
return -1;
}
if ( !Utils.isEmpty( t1.getName() ) && Utils.isEmpty( t2.getName() ) ) {
return 1;
}
int cmpName = t1.getName().compareTo( t2.getName() );
if ( cmpName != 0 ) {
return cmpName;
}

// Same name, compare Repository directory...
//
int cmpDirectory = t1.getRepositoryDirectory().getPath().compareTo( t2.getRepositoryDirectory().getPath() );
if ( cmpDirectory != 0 ) {
return cmpDirectory;
}

// Same name, same directory, compare versions
//
if ( t1.getObjectRevision() != null && t2.getObjectRevision() == null ) {
return 1;
}
if ( t1.getObjectRevision() == null && t2.getObjectRevision() != null ) {
return -1;
}
if ( t1.getObjectRevision() == null && t2.getObjectRevision() == null ) {
return 0;
}
return t1.getObjectRevision().getName().compareTo( t2.getObjectRevision().getName() );

} else {
if ( Utils.isEmpty( t2.getFilename() ) ) {
return 1;
}

// First compare names
//
if ( Utils.isEmpty( t1.getName() ) && !Utils.isEmpty( t2.getName() ) ) {
return -1;
}
if ( !Utils.isEmpty( t1.getName() ) && Utils.isEmpty( t2.getName() ) ) {
return 1;
}
int cmpName = t1.getName().compareTo( t2.getName() );
if ( cmpName != 0 ) {
return cmpName;
}

// Same name, compare filenames...
//
return t1.getFilename().compareTo( t2.getFilename() );
}
return super.compare( t1, t2 );
}

/**
Expand Down Expand Up @@ -1769,7 +1707,7 @@ public RowMetaInterface getStepFields( StepMeta[] stepMeta ) throws KettleStepEx
for ( int i = 0; i < stepMeta.length; i++ ) {
RowMetaInterface flds = getStepFields( stepMeta[i] );
if ( flds != null ) {
fields.mergeRowMeta( flds );
fields.mergeRowMeta( flds, stepMeta[i].getName() );
}
}
return fields;
Expand Down
7 changes: 6 additions & 1 deletion engine/src/org/pentaho/di/trans/step/RemoteStep.java
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -244,6 +244,11 @@ public boolean equals( Object obj ) {
return toString().equalsIgnoreCase( obj.toString() );
}

@Override
public int hashCode() {
return toString().hashCode();
}

public int compareTo( RemoteStep remoteStep ) {
return toString().compareTo( remoteStep.toString() );
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -105,6 +105,11 @@ public boolean equals( Object obj ) {
return partitionSchemaName.equalsIgnoreCase( meta.partitionSchemaName );
}

@Override
public int hashCode() {
return partitionSchemaName == null ? 0 : partitionSchemaName.toLowerCase().hashCode();
}

@Override
public String toString() {

Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -79,6 +79,11 @@ public boolean equals( Object obj ) {
return false;
}

@Override
public int hashCode() {
return description.hashCode();
}

public String getStepname() {
if ( stepMeta == null ) {
return null;
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -22,6 +22,7 @@

package org.pentaho.di.trans.steps.calculator;

import java.util.Arrays;
import java.util.List;

import org.pentaho.di.core.CheckResult;
Expand Down Expand Up @@ -105,6 +106,11 @@ public boolean equals( Object obj ) {
return false;
}

@Override
public int hashCode() {
return Arrays.hashCode( calculation );
}

@Override
public Object clone() {
CalculatorMeta retval = (CalculatorMeta) super.clone();
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -454,6 +454,11 @@ public boolean equals( Object obj ) {
return false;
}

@Override
public int hashCode() {
return getXML().hashCode();
}

@Override
public Object clone() {
try {
Expand Down

0 comments on commit 64cbfe0

Please sign in to comment.