1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 319512: Extracted class MatchKey

This commit is contained in:
Andrew Gvozdev 2011-02-17 04:41:30 +00:00
parent 6be5fbc124
commit 666b5e3edb
4 changed files with 90 additions and 217 deletions

View file

@ -2322,71 +2322,12 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
return rBld == ManagedBuildManager.getRealBuilder(builder);
}
public boolean performMatchComparison(IBuilder builder){
if(builder == null)
return false;
if(builder == this)
return true;
// if(tool.isReal() && isReal())
// return false;
// if(!tool.getToolCommand().equals(getToolCommand()))
// return false;
if(!builder.getName().equals(getName()))
return false;
String thisVersion = ManagedBuildManager.getVersionFromIdAndVersion(getId());
String otherVersion = ManagedBuildManager.getVersionFromIdAndVersion(builder.getId());
if(thisVersion == null || thisVersion.length() == 0){
if(otherVersion != null && otherVersion.length() != 0)
return false;
} else {
if(!thisVersion.equals(otherVersion))
return false;
}
return true;
}
private class MatchKey {
Builder builder;
public MatchKey(Builder builder) {
this.builder = builder;
}
@Override
public boolean equals(Object obj) {
if(obj == this)
return true;
if(!(obj instanceof MatchKey))
return false;
MatchKey other = (MatchKey)obj;
return builder.performMatchComparison(other.builder);
}
@Override
public int hashCode() {
String name = getName();
if(name == null)
name = getId();
int code = name.hashCode();
String version = ManagedBuildManager.getVersionFromIdAndVersion(getId());
if(version != null)
code += version.hashCode();
return code;
}
}
public Object getMatchKey() {
if(isAbstract())
return null;
if(!isExtensionBuilder)
return null;
return new MatchKey(this);
return new MatchKey<Builder>(this);
}
public void setIdenticalList(List list) {

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
public class MatchKey<T extends BuildObject> {
private T buildObject;
public MatchKey(T builder) {
this.buildObject = builder;
}
@Override
public boolean equals(Object obj) {
if(obj == this)
return true;
if(!(obj instanceof MatchKey))
return false;
@SuppressWarnings("unchecked")
MatchKey<T> other = (MatchKey<T>)obj;
return performMatchComparison(other.buildObject);
}
@Override
public int hashCode() {
String name = buildObject.getName();
if(name == null)
name = buildObject.getId();
int code = name.hashCode();
String version = ManagedBuildManager.getVersionFromIdAndVersion(buildObject.getId());
if(version != null)
code += version.hashCode();
return code;
}
boolean performMatchComparison(T bo){
if(bo == null)
return false;
if(bo == buildObject)
return true;
// if(bo.isReal() && buildObject.isReal())
// return false;
// if(!bo.getToolCommand().equals(buildObject.getToolCommand()))
// return false;
if(!bo.getName().equals(buildObject.getName()))
return false;
String thisVersion = ManagedBuildManager.getVersionFromIdAndVersion(buildObject.getId());
String otherVersion = ManagedBuildManager.getVersionFromIdAndVersion(bo.getId());
if(thisVersion == null || thisVersion.length() == 0){
if(otherVersion != null && otherVersion.length() != 0)
return false;
} else {
if(!thisVersion.equals(otherVersion))
return false;
}
return true;
/* IOption options[] = buildObject.getOptions();
IOption otherOptions[] = bo.getOptions();
if(!ListComparator.match(options,
otherOptions,
new Comparator(){
public boolean equal(Object o1, Object o2){
return ((Option)o1).matches((Option)o2);
}
}))
return false;
return true;
*/
}
}

View file

@ -3590,48 +3590,6 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory, IMatch
return rT == ManagedBuildManager.getRealTool(tool);
}
boolean performMatchComparison(ITool tool){
if(tool == null)
return false;
if(tool == this)
return true;
// if(tool.isReal() && isReal())
// return false;
// if(!tool.getToolCommand().equals(getToolCommand()))
// return false;
if(!tool.getName().equals(getName()))
return false;
String thisVersion = ManagedBuildManager.getVersionFromIdAndVersion(getId());
String otherVersion = ManagedBuildManager.getVersionFromIdAndVersion(tool.getId());
if(thisVersion == null || thisVersion.length() == 0){
if(otherVersion != null && otherVersion.length() != 0)
return false;
} else {
if(!thisVersion.equals(otherVersion))
return false;
}
return true;
/* IOption options[] = getOptions();
IOption otherOptions[] = tool.getOptions();
if(!ListComparator.match(options,
otherOptions,
new Comparator(){
public boolean equal(Object o1, Object o2){
return ((Option)o1).matches((Option)o2);
}
}))
return false;
return true;
*/
}
/* public SupportedProperties getSupportedProperties(){
Map map = findSupportedProperties();
if(map != null)
@ -3658,43 +3616,12 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory, IMatch
return supportsManagedBuild.booleanValue();
}
private static class MatchKey {
Tool tool;
public MatchKey(Tool tch) {
tool = tch;
}
@Override
public boolean equals(Object obj) {
if(obj == this)
return true;
if(!(obj instanceof MatchKey))
return false;
MatchKey other = (MatchKey)obj;
return tool.performMatchComparison(other.tool);
}
@Override
public int hashCode() {
String name = tool.getName();
if(name == null)
name = tool.getId();
int code = name.hashCode();
String version = ManagedBuildManager.getVersionFromIdAndVersion(tool.getId());
if(version != null)
code += version.hashCode();
return code;
}
}
public Object getMatchKey() {
if(isAbstract())
return null;
if(!isExtensionTool)
return null;
return new MatchKey(this);
return new MatchKey<Tool>(this);
}
public void setIdenticalList(List list) {

View file

@ -2249,57 +2249,6 @@ public class ToolChain extends HoldsOptions implements IToolChain, IBuildPropert
return rTc == ManagedBuildManager.getRealToolChain(tc);
}
private boolean performMatchCompatison(IToolChain tCh){
if(tCh == null)
return false;
if(tCh == this)
return true;
// if(tCh.isReal() && isReal())
// return false;
String name = tCh.getName();
if(name == null){
if(getName() != null)
return false;
} else if(!name.equals(getName())){
return false;
}
String thisVersion = ManagedBuildManager.getVersionFromIdAndVersion(getId());
String otherVersion = ManagedBuildManager.getVersionFromIdAndVersion(tCh.getId());
if(thisVersion == null || thisVersion.length() == 0){
if(otherVersion != null && otherVersion.length() != 0)
return false;
} else {
if(!thisVersion.equals(otherVersion))
return false;
}
return true;
// if(true)
// return true;
//
// ITool tools[] = getTools();
// ITool otherTools[] = tCh.getTools();
//
// if(tools.length != otherTools.length)
// return false;
//
// if(!ListComparator.match(tools,
// otherTools,
// new Comparator(){
// public boolean equal(Object o1, Object o2){
// return ((Tool)o1).performMatchComparison((Tool)o2);
// }
// }))
// return false;
//
// return true;
}
public List getIdenticalList(){
return identicalList;//;(ArrayList)identicalToolChainsList.clone();
}
@ -2344,43 +2293,12 @@ public class ToolChain extends HoldsOptions implements IToolChain, IBuildPropert
return false;
}
private class MatchKey {
ToolChain toolChain;
public MatchKey(ToolChain tch) {
toolChain = tch;
}
@Override
public boolean equals(Object obj) {
if(obj == this)
return true;
if(!(obj instanceof MatchKey))
return false;
MatchKey other = (MatchKey)obj;
return toolChain.performMatchCompatison(other.toolChain);
}
@Override
public int hashCode() {
String name = getName();
if(name == null)
name = getId();
int code = name.hashCode();
String version = ManagedBuildManager.getVersionFromIdAndVersion(getId());
if(version != null)
code += version.hashCode();
return code;
}
}
public Object getMatchKey() {
if(isAbstract())
return null;
if(!isExtensionToolChain)
return null;
return new MatchKey(this);
return new MatchKey<ToolChain>(this);
}
public void setIdenticalList(List list) {