-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tmf: add capabilities data structure to IDataProviderDescriptor
With this a data provider factory instance can advertise special capabilities that can be applied for the given data provider. This commit adds code for that and implements the "canCreate" and "canDelete" capability. "canCreate" indicates that this instance can create a derived data provider. Use the IDataProviderFactory method getAdapter(ITmfDataProviderConfigurator.class) to obtains an instance of ITmfDataProviderConfigurator. This interface has methods to get List<ITmfConfigurationSourceType> describing the parameters needed to create a derived data provider using method ITmfDataProviderConfigurator#createDataProvider. "canDelete" indicates a the data provider can be deleted using method ITmfDataProviderConfigurator#deleteDataProviderDescriptor. [Added] capabilities data structure to IDataProviderDescriptor Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
- Loading branch information
Showing
6 changed files
with
338 additions
and
5 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
...tests/src/org/eclipse/tracecompass/tmf/core/tests/model/DataProviderCapabilitiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2025 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
package org.eclipse.tracecompass.tmf.core.tests.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderCapabilities; | ||
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities; | ||
import org.junit.Test; | ||
|
||
/** | ||
* JUnit Test class to test {@link DataProviderCapabilities} | ||
* | ||
* @author Bernd Hufmann | ||
*/ | ||
public class DataProviderCapabilitiesTest { | ||
|
||
private static final String EXPECTED_TO_STRING = "DataProviderCapabilities[canCreate=true, canDelete=true]"; | ||
|
||
// ------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------ | ||
/** | ||
* Test builder, constructor and getter/setters. | ||
*/ | ||
@Test | ||
public void testBuilder() { | ||
DataProviderCapabilities.Builder builder = new DataProviderCapabilities.Builder() | ||
.setCanCreate(true) | ||
.setCanDelete(true); | ||
IDataProviderCapabilities capabilities = builder.build(); | ||
assertTrue(capabilities.canCreate()); | ||
assertTrue(capabilities.canDelete()); | ||
} | ||
|
||
/** | ||
* Test {@Link DataProviderCapabilities#equals()} | ||
*/ | ||
@Test | ||
public void testEquality() { | ||
DataProviderCapabilities.Builder builder = new DataProviderCapabilities.Builder() | ||
.setCanCreate(true) | ||
.setCanDelete(true); | ||
IDataProviderCapabilities baseCapabilities = builder.build(); | ||
|
||
// Make sure it is equal to itself | ||
IDataProviderCapabilities testCapabilities = builder.build(); | ||
assertEquals(baseCapabilities, testCapabilities); | ||
assertEquals(testCapabilities, baseCapabilities); | ||
|
||
// Change each of the variable and make sure result is not equal | ||
builder.setCanCreate(false); | ||
testCapabilities = builder.build(); | ||
assertNotEquals(baseCapabilities, testCapabilities); | ||
assertNotEquals(testCapabilities, baseCapabilities); | ||
|
||
builder.setCanCreate(true); | ||
builder.setCanDelete(false); | ||
testCapabilities = builder.build(); | ||
assertNotEquals(baseCapabilities, testCapabilities); | ||
assertNotEquals(testCapabilities, baseCapabilities); | ||
|
||
builder.setCanCreate(false); | ||
builder.setCanDelete(false); | ||
testCapabilities = builder.build(); | ||
assertNotEquals(baseCapabilities, testCapabilities); | ||
assertNotEquals(testCapabilities, baseCapabilities); | ||
|
||
// Different objects with same content | ||
assertFalse(testCapabilities == DataProviderCapabilities.NULL_INSTANCE); | ||
|
||
// Equal by content | ||
assertEquals(DataProviderCapabilities.NULL_INSTANCE, testCapabilities); | ||
} | ||
|
||
/** | ||
* Test {@Link TmfConfiguration#toString()} | ||
**/ | ||
@Test | ||
public void testToString() { | ||
DataProviderCapabilities.Builder builder = new DataProviderCapabilities.Builder() | ||
.setCanCreate(true) | ||
.setCanDelete(true); | ||
assertEquals(EXPECTED_TO_STRING, builder.build().toString()); | ||
} | ||
|
||
/** | ||
* Test {@Link TmfConfiguration#hashCode()} | ||
*/ | ||
@Test | ||
public void testHashCode() { | ||
DataProviderCapabilities.Builder builder = new DataProviderCapabilities.Builder() | ||
.setCanCreate(true) | ||
.setCanDelete(true); | ||
|
||
IDataProviderCapabilities capabilities1 = builder.build(); | ||
IDataProviderCapabilities capabilities2 = DataProviderCapabilities.NULL_INSTANCE; | ||
|
||
assertEquals(capabilities1.hashCode(), capabilities1.hashCode()); | ||
assertEquals(capabilities2.hashCode(), capabilities2.hashCode()); | ||
assertNotEquals(capabilities1.hashCode(), capabilities2.hashCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...mf.core/src/org/eclipse/tracecompass/tmf/core/dataprovider/IDataProviderCapabilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.tracecompass.tmf.core.dataprovider; | ||
|
||
import org.eclipse.tracecompass.tmf.core.config.ITmfDataProviderConfigurator; | ||
|
||
/** | ||
* Interface to implement to indicate capabilities of a data provider, such as | ||
* "canCreate" and "canDelete" capability. | ||
* | ||
* "canCreate" indicates that a given data provider can create a derived data | ||
* provider. "canDelete" indicates that a the data provider can be deleted. | ||
* | ||
* Call method {@link IDataProviderFactory#getAdapter(Class)} with class | ||
* {@link ITmfDataProviderConfigurator} to obtain an instance of | ||
* {@link ITmfDataProviderConfigurator}, which implements the "canCreate" and | ||
* "canDelete" capabilities. | ||
* | ||
* @since 9.5 | ||
* @author Bernd Hufmann | ||
*/ | ||
public interface IDataProviderCapabilities { | ||
/** | ||
* Whether the data provider can create derived data providers. | ||
* | ||
* @return {@code true} if this data provider can create a derived data | ||
* provider, else {@code false} | ||
*/ | ||
boolean canCreate(); | ||
|
||
/** | ||
* Whether the data provider can be deleted. | ||
* | ||
* @return {@code true} if this data provider can be deleted, else | ||
* {@code false} | ||
*/ | ||
boolean canDelete(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...ompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/model/DataProviderCapabilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.tracecompass.tmf.core.model; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderCapabilities; | ||
|
||
/** | ||
* An instance of data provider capabilities, indicating what capabilities a | ||
* data provider has. | ||
* | ||
* @since 9.5 | ||
* @author Bernd Hufmann | ||
*/ | ||
public class DataProviderCapabilities implements IDataProviderCapabilities { | ||
|
||
/** The NullCapabilities instance */ | ||
public static final IDataProviderCapabilities NULL_INSTANCE = new DataProviderCapabilities.Builder().build(); | ||
|
||
private final boolean canCreate; | ||
private final boolean canDelete; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param builder | ||
* a builder instance | ||
*/ | ||
public DataProviderCapabilities(Builder builder) { | ||
canCreate = builder.canCreate; | ||
canDelete = builder.canDelete; | ||
} | ||
|
||
@Override | ||
public boolean canCreate() { | ||
return canCreate; | ||
} | ||
|
||
@Override | ||
public boolean canDelete() { | ||
return canDelete; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("nls") | ||
public String toString() { | ||
return new StringBuilder(getClass().getSimpleName()) | ||
.append("[") | ||
.append("canCreate=").append(canCreate()) | ||
.append(", canDelete=").append(canDelete()) | ||
.append("]").toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(canCreate, canDelete); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (!(obj instanceof DataProviderCapabilities)) { | ||
return false; | ||
} | ||
DataProviderCapabilities other = (DataProviderCapabilities) obj; | ||
return canCreate == other.canCreate && canDelete == other.canDelete; | ||
} | ||
|
||
/** | ||
* Builder class to build a IDataProviderCapabilities instance | ||
*/ | ||
public static class Builder { | ||
private boolean canCreate = false; | ||
private boolean canDelete = false; | ||
|
||
/** | ||
* Sets canCreate flag | ||
* | ||
* @param canCreate | ||
* true if data provider can create a derived data provider | ||
* @return the builder instance. | ||
*/ | ||
public Builder setCanCreate(boolean canCreate) { | ||
this.canCreate = canCreate; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets canDelete flag | ||
* | ||
* @param canDelete | ||
* true if data provider can create a derived data provider | ||
* @return the builder instance. | ||
*/ | ||
public Builder setCanDelete(boolean canDelete) { | ||
this.canDelete = canDelete; | ||
return this; | ||
} | ||
|
||
/** | ||
* The method to construct an instance of | ||
* {@link IDataProviderCapabilities} | ||
* | ||
* @return a {@link IDataProviderCapabilities} instance | ||
*/ | ||
public IDataProviderCapabilities build() { | ||
return new DataProviderCapabilities(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.