Skip to content

Commit

Permalink
Merge pull request #6 from spdx/cleanup
Browse files Browse the repository at this point in the history
Code clean-up - fix IDE warnings
  • Loading branch information
goneall authored Dec 13, 2024
2 parents 845f67f + b6fd30f commit 859d91a
Show file tree
Hide file tree
Showing 38 changed files with 372 additions and 367 deletions.
51 changes: 27 additions & 24 deletions src/main/java/org/spdx/core/CoreModelObject.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2023 Source Auditor Inc.
*
* <p>
* SPDX-License-Identifier: Apache-2.0
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -40,18 +40,18 @@
/**
*
* Superclass for all SPDX model objects
*
* <p>
* Provides the primary interface to the storage class that access and stores the data for
* the model objects.
*
* <p>
* This class includes several helper methods to manage the storage and retrieval of properties.
*
* <p>
* Each model object is in itself stateless. All state is maintained in the Model Store.
*
* The concrete classes are expected to implements getters for the model class properties which translate
* <p>
* The concrete classes are expected to implement getters for the model class properties which translate
* into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property descriptor
* is passed as a parameter.
*
* <p>
* There are 2 methods of setting values:
* - call the setPropertyValue, clearValueCollection or addValueToCollection methods - this will call the modelStore and store the
* value immediately
Expand All @@ -60,18 +60,19 @@
* A convenience method <code>Write.applyUpdatesInOneTransaction</code> will perform all updates within
* a single transaction. This method may result in higher performance updates for some Model Store implementations.
* Note that none of the updates will be applied until the storage manager update method is invoked.
*
* <p>
* Property values are restricted to the following types:
* - String - Java Strings
* - Booolean - Java Boolean or primitive boolean types
* - CoreModelObject - A concrete subclass of this type
* - {@literal Collection<T>} - A Collection of type T where T is one of the supported non-collection types
*
* <p>
* This class also handles the conversion of a CoreModelObject to and from a TypeValue for storage in the ModelStore.
*
* @author Gary O'Neall
*
*/
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "LoggingSimilarMessage"})
public abstract class CoreModelObject {

static final Logger logger = LoggerFactory.getLogger(CoreModelObject.class);
Expand All @@ -85,10 +86,10 @@ public abstract class CoreModelObject {
protected String idPrefix; // Optional prefix to be used when generating new IDs

/**
* If non null, a reference made to a model object stored in a different modelStore and/or
* If non-null, a reference made to a model object stored in a different modelStore and/or
* document will be copied to this modelStore and documentUri
*/
protected IModelCopyManager copyManager = null;
protected IModelCopyManager copyManager;
/**
* if true, checks input values for setters to verify valid SPDX inputs
*/
Expand All @@ -99,7 +100,7 @@ public abstract class CoreModelObject {
/**
* Create a new Model Object using an Anonymous ID with the default store and default document URI
* @param specVersion - version of the SPDX spec the object complies with
* @throws InvalidSPDXAnalysisException
* @throws InvalidSPDXAnalysisException on any SPDX related exception
*/
protected CoreModelObject(String specVersion) throws InvalidSPDXAnalysisException {
this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous), specVersion);
Expand Down Expand Up @@ -327,7 +328,7 @@ public Optional<Object> getObjectPropertyValue(PropertyDescriptor propertyDescri
Optional<Object> retval = ModelObjectHelper.getObjectPropertyValue(modelStore, objectUri,
propertyDescriptor, copyManager, specVersion, type, idPrefix);
if (retval.isPresent() && retval.get() instanceof CoreModelObject && !strict) {
((CoreModelObject)retval.get()).setStrict(strict);
((CoreModelObject)retval.get()).setStrict(false);
}
return retval;
}
Expand Down Expand Up @@ -442,9 +443,9 @@ public Optional<Boolean> getBooleanPropertyValue(PropertyDescriptor propertyDesc
// try to convert
String sResult = ((String)result.get()).toLowerCase();
if ("true".equals(sResult)) {
return Optional.of(Boolean.valueOf(true));
return Optional.of(Boolean.TRUE);
} else if ("false".equals(sResult)) {
return Optional.of(Boolean.valueOf(false));
return Optional.of(Boolean.FALSE);
} else {
throw new SpdxInvalidTypeException(PROPERTY_MSG+propertyDescriptor+" is not of type Boolean");
}
Expand Down Expand Up @@ -569,7 +570,7 @@ public ModelSet<?> getObjectPropertyValueSet(PropertyDescriptor propertyDescript
* @return Collection of values associated with a property
*/
public ModelCollection<?> getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class<?> type) throws InvalidSPDXAnalysisException {
return new ModelCollection<>(this.modelStore, this.objectUri, propertyDescriptor,
return new ModelCollection<>(this.modelStore, this.objectUri, propertyDescriptor,
this.copyManager, type, specVersion, idPrefix);
}

Expand Down Expand Up @@ -716,8 +717,8 @@ private boolean propertyValuesEquivalent(PropertyDescriptor propertyDescriptor,

/**
* Compares 2 simple optional objects considering NONE and NOASSERTION values which are equivalent to their strings
* @param valueA
* @param valueB
* @param valueA value to compare
* @param valueB value to compare
* @return if the 2 values are equivalent
*/
private boolean optionalObjectsEquivalent(Optional<Object> valueA, Optional<Object> valueB) {
Expand Down Expand Up @@ -782,8 +783,9 @@ private boolean areEquivalent(List<?> firstList, List<?> secondList,
* @return true if the list contains an equal or equivalent item
* @throws InvalidSPDXAnalysisException on any SPDX related exception
*/
private boolean containsEqualOrEquivalentItem(List<?> list, Object itemToFind,
boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException {
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean containsEqualOrEquivalentItem(List<?> list, Object itemToFind,
boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException {
if (list.contains(itemToFind)) {
return true;
} else if (itemToFind instanceof IndividualUriValue && list.contains(new SimpleUriValue((IndividualUriValue) itemToFind))) {
Expand Down Expand Up @@ -839,7 +841,8 @@ public boolean equals(Object o) {
* @param modelStore model store to store the copy in
* @return a copy of this model object
*/
public CoreModelObject clone(IModelStore modelStore) {
@SuppressWarnings("unused")
public CoreModelObject clone(IModelStore modelStore) {
if (Objects.isNull(this.copyManager)) {
throw new IllegalStateException("A copy manager must be provided to clone");
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/spdx/core/DefaultModelStore.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2019 Source Auditor Inc.
*
* <p>
* SPDX-License-Identifier: Apache-2.0
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,7 +25,7 @@

/**
* Singleton class to hold a default model store used when no model store is provided
*
* <p>
* WARNING: The model store and copy manager are in memory and will continue to grow as they are utilized. There is NO garbage collection.
*
* @author Gary O'Neall
Expand Down Expand Up @@ -81,7 +81,7 @@ public static String getDefaultDocumentUri() throws DefaultStoreNotInitialized {
* @param newDefaultDocumentUri new SPDX 2.X document URI
* @param newDefaultCopyManager new default copy manager
*/
public static final void initialize(IModelStore newModelStore, String newDefaultDocumentUri,
public static void initialize(IModelStore newModelStore, String newDefaultDocumentUri,
IModelCopyManager newDefaultCopyManager) {
Objects.requireNonNull(newModelStore, "Model store can not be null");
Objects.requireNonNull(newDefaultDocumentUri, "Document URI can not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Gary O'Neall
*
*/
@SuppressWarnings("unused")
public class DefaultStoreNotInitialized extends InvalidSPDXAnalysisException {

private static final long serialVersionUID = 1L;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/spdx/core/DuplicateSpdxIdException.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2019 Source Auditor Inc.
*
* <p>
* SPDX-License-Identifier: Apache-2.0
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -22,6 +22,7 @@
*
* @author Gary O'Neall
*/
@SuppressWarnings("unused")
public class DuplicateSpdxIdException extends InvalidSPDXAnalysisException {

private static final long serialVersionUID = 1L;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/core/IExternalElementInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Information about an Element which is external to the collection or store
*
* <p>
* The information stored is version dependent and implemented in the models
*
* @author Gary O'Neall
Expand Down
68 changes: 34 additions & 34 deletions src/main/java/org/spdx/core/IModelCopyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

/**
* Implementation classes of this interface helps facilitate copying objects from one model to another.
*
* <p>
* In addition to the copy functions (methods), these objects keeps track of
* what was copied where so that the same object is not copied twice.
*
* <p>
* These objects can be passed into the constructor for ModelObjects to allow the objects to be copied.
*
* @author Gary O'Neall
Expand All @@ -30,38 +30,38 @@ public interface IModelCopyManager {
* @return Object URI for the copied object
* @throws InvalidSPDXAnalysisException on any SPDX related error
*/
public TypedValue copy(IModelStore toStore, IModelStore fromStore,
TypedValue copy(IModelStore toStore, IModelStore fromStore,
String sourceUri, String toSpecVersion, @Nullable String toNamespace) throws InvalidSPDXAnalysisException;

/**
* Copy an item from one Model Object Store to another
* @param toStore Model Store to copy to
* @param toObjectUri URI for the destination object
* @param fromStore Model Store containing the source item
* @param fromObjectUri Object URI for the source item
* @param toSpecVersion version of the spec the to value should comply with
* @param toNamespace optional namespace of the to property
* @throws InvalidSPDXAnalysisException on any SPDX related error
*/
public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri,
String toSpecVersion, @Nullable String toNamespace) throws InvalidSPDXAnalysisException;
/**
* @param fromStore Store copied from
* @param fromObjectUri Object URI in the from tsotre
* @param toStore store copied to
* @return the objectId which has already been copied, or null if it has not been copied
*/
public String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri,
IModelStore toStore);
/**
* Record a copied ID between model stores
* @param fromStore Store copied from
* @param fromObjectUri URI for the from Object
* @param toObjectUri URI for the to Object
* @return any copied to ID for the same stores, URI's, nameSpace and fromID
*/
public String putCopiedId(IModelStore fromStore, String fromObjectUri, IModelStore toStore,
String toObjectUri);
/**
* Copy an item from one Model Object Store to another
* @param toStore Model Store to copy to
* @param toObjectUri URI for the destination object
* @param fromStore Model Store containing the source item
* @param fromObjectUri Object URI for the source item
* @param toSpecVersion version of the spec the to value should comply with
* @param toNamespace optional namespace of the to property
* @throws InvalidSPDXAnalysisException on any SPDX related error
*/
void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri,
String toSpecVersion, @Nullable String toNamespace) throws InvalidSPDXAnalysisException;

/**
* @param fromStore Store copied from
* @param fromObjectUri Object URI in the from tsotre
* @param toStore store copied to
* @return the objectId which has already been copied, or null if it has not been copied
*/
String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri,
IModelStore toStore);

/**
* Record a copied ID between model stores
* @param fromStore Store copied from
* @param fromObjectUri URI for the from Object
* @param toObjectUri URI for the to Object
* @return any copied to ID for the same stores, URI's, nameSpace and fromID
*/
String putCopiedId(IModelStore fromStore, String fromObjectUri, IModelStore toStore,
String toObjectUri);
}
20 changes: 10 additions & 10 deletions src/main/java/org/spdx/core/ISpdxModelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public interface ISpdxModelInfo {
/**
* @return a map of URIs to Enums which represents individual vocabularies in the SPDX model
*/
public Map<String, Enum<?>> getUriToEnumMap();
Map<String, Enum<?>> getUriToEnumMap();

/**
* @return the spec versions this model supports
*/
public List<String> getSpecVersions();
List<String> getSpecVersions();

/**
* @param store store to use for the inflated object
Expand All @@ -35,15 +35,15 @@ public interface ISpdxModelInfo {
* @param specVersion version of the SPDX specification used by the external element
* @return model object of type type
*/
public CoreModelObject createExternalElement(IModelStore store, String uri,
@Nullable IModelCopyManager copyManager,Class<?> type, String specVersion) throws InvalidSPDXAnalysisException;
CoreModelObject createExternalElement(IModelStore store, String uri,
@Nullable IModelCopyManager copyManager, Class<?> type, String specVersion) throws InvalidSPDXAnalysisException;

/**
* @param uri URI for the individual
* @param type optional type hint - used for individuals where the type may be ambiguous
* @return a matching individual for a given URI or null if no individual exists
*/
public @Nullable Object uriToIndividual(String uri, Class<?> type);
@Nullable Object uriToIndividual(String uri, Class<?> type);

/**
* @param modelStore store to use for the inflated object
Expand All @@ -55,19 +55,19 @@ public CoreModelObject createExternalElement(IModelStore store, String uri,
* @param idPrefix optional prefix used for any new object URI's created in support of this model object
* @return fully inflated model object of type type
*/
public CoreModelObject createModelObject(IModelStore modelStore,
String objectUri, String type, IModelCopyManager copyManager,
String specVersion, boolean create, @Nullable String idPrefix) throws InvalidSPDXAnalysisException;
CoreModelObject createModelObject(IModelStore modelStore,
String objectUri, String type, IModelCopyManager copyManager,
String specVersion, boolean create, @Nullable String idPrefix) throws InvalidSPDXAnalysisException;

/**
* @return a map of string representation of types to classes which implement those types
*/
public Map<String, Class<?>> getTypeToClassMap();
Map<String, Class<?>> getTypeToClassMap();

/**
* @param clazz model class
* @return true if clazz can be represented as external to the store
*/
public boolean canBeExternal(Class<?> clazz);
boolean canBeExternal(Class<?> clazz);

}
Loading

0 comments on commit 859d91a

Please sign in to comment.