Skip to content

Commit

Permalink
Merge pull request eclipse-chemclipse#1963 from lorenzgerber/#1962_al…
Browse files Browse the repository at this point in the history
…low_duplicate_sample_names

fix eclipse-chemclipse#1962, prevent overwriting of identical sample names
  • Loading branch information
eselmeister authored Nov 19, 2024
2 parents fc235da + e30c9ea commit 30ef644
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 Lablicate GmbH.
* Copyright (c) 2018, 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -9,6 +9,7 @@
* Contributors:
* Jan Holy - initial API and implementation
* Philip Wenig - improvements
* Lorenz Gerber - allow duplicate sample names
*******************************************************************************/
package org.eclipse.chemclipse.model.statistics;

Expand Down Expand Up @@ -116,27 +117,4 @@ public int hashCode() {

return Objects.hash(sampleName);
}

@Override
public boolean equals(Object obj) {

if(this == obj) {
return true;
}
if(obj == null) {
return false;
}
if(getClass() != obj.getClass()) {
return false;
}
@SuppressWarnings("rawtypes")
AbstractSample other = (AbstractSample)obj;
return Objects.equals(sampleName, other.sampleName);
}

@Override
public String toString() {

return "AbstractSample [sampleName=" + sampleName + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class ScorePlot extends AbtractPlotPCA {

private final Map<String, IResultPCA> extractedResults = new HashMap<>();
private final Map<ISample, IResultPCA> extractedResults = new HashMap<>();

public ScorePlot(Composite parent, int style) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static List<IScatterSeriesData> basisVectorsToSeriesDescription(IResultsP
return scatterSeriesDataList;
}

public static List<IScatterSeriesData> sampleToSeries(IResultsPCA<? extends IResultPCA, ?> resultsPCA, List<ISample> highlighted, int pcX, int pcY, Map<String, IResultPCA> extractedPcaResults) {
public static List<IScatterSeriesData> sampleToSeries(IResultsPCA<? extends IResultPCA, ?> resultsPCA, List<ISample> highlighted, int pcX, int pcY, Map<ISample, IResultPCA> extractedPcaResults) {

IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
List<IScatterSeriesData> scatterSeriesDataList = new ArrayList<>();
Expand Down Expand Up @@ -145,7 +145,7 @@ public static List<IScatterSeriesData> sampleToSeries(IResultsPCA<? extends IRes
break;
}
//
extractedPcaResults.put(sampleName, pcaResult);
extractedPcaResults.put(pcaResult.getSample(), pcaResult);
if(!pcaResult.isDisplayed()) {
continue;
}
Expand All @@ -157,7 +157,8 @@ public static List<IScatterSeriesData> sampleToSeries(IResultsPCA<? extends IRes
x = i;
}
double y = eigenSpace[pcY - 1]; // e.g. 1 = PC2
ISeriesData seriesData = new SeriesData(new double[]{x}, new double[]{y}, sampleName);
String sampleInstanceId = pcaResult.getSample().getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(pcaResult.getSample()));
ISeriesData seriesData = new SeriesData(new double[]{x}, new double[]{y}, sampleInstanceId);
/*
* Set the color.
*/
Expand Down

0 comments on commit 30ef644

Please sign in to comment.