-
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) to obtains a ITmfDataProviderConfigurator. This interface has methods to get List<ITmfConfigurationSourceType> describing the parameters needed to create a derived data provider using method createDataProvider. "canDelete" indicates a the data provider can be deleted using the 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
326 additions
and
4 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
...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,115 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2024 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.config.TmfConfiguration; | ||
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 TmfConfiguration} | ||
* | ||
* @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
33 changes: 33 additions & 0 deletions
33
...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,33 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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; | ||
|
||
/** | ||
* @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 delete, 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
123 changes: 123 additions & 0 deletions
123
...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,123 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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; | ||
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; | ||
|
||
/** | ||
* A capabilities instance return all false. | ||
* | ||
* @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 IDataProviderDescriptor} | ||
* | ||
* @return a {@link IDataProviderDescriptor} instance | ||
*/ | ||
|
||
public IDataProviderCapabilities build() { | ||
return new DataProviderCapabilities(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.