Java: List cleanup
authorjani <jani@asema.com>
Mon, 5 Aug 2019 15:14:03 +0000 (18:14 +0300)
committerjani <jani@asema.com>
Mon, 5 Aug 2019 15:14:03 +0000 (18:14 +0300)
Common/Java/SmartAPI/src/smartapi/rdf/ItemizedList.java
Common/Java/SmartAPI/src/smartapi/rdf/LinkedList.java
Common/Java/SmartAPI/src/smartapi/rdf/List.java
Common/Java/SmartAPI/src/smartapi/rdf/OrderedList.java
Common/Java/SmartAPI/src/smartapi/rdf/Variant.java

index 8e43e461145855bb43a7c3b6da4f201015fcbbb0..b6585c06262c87f4ff53f6710737e1bd19946ec6 100644 (file)
@@ -29,7 +29,7 @@ public class ItemizedList extends List {
                Resource resource = super.getSerialization(model);
                Resource first = model.createResource();
 
-               Property entriesProp = model.createProperty( PROPERTY.getUri(PROPERTY.ENTRIES) );       
+               Property entriesProp = model.createProperty( PROPERTY.getUri(PROPERTY.ENTRIES) );
                Property firstProp = model.createProperty( PROPERTY.getUri(PROPERTY.FIRST) );   
                Property valueProp = model.createProperty( PROPERTY.getUri(PROPERTY.RDF_VALUE) );
                first.addProperty(model.createProperty( PROPERTY.getUri(PROPERTY.SIZE) ), model.createTypedLiteral(this.getItems().size(), XSDDatatype.XSDinteger));
@@ -37,10 +37,10 @@ public class ItemizedList extends List {
                for( int i = 0; i < this.list.size(); i++ ) {
                        Object o = this.list.get(i);
                        if ( o instanceof Obj ) {
-                               arrayResource.addProperty(valueProp, ((Obj)o).serialize(model));                                
+                               arrayResource.addProperty(valueProp, ((Obj)o).serialize(model));
                        }
                        if ( o instanceof Variant ) {
-                               arrayResource.addProperty(valueProp, ((Variant)o).serialize(model));                            
+                               arrayResource.addProperty(valueProp, ((Variant)o).serialize(model));
                        }
                }
                first.addProperty(model.createProperty( PROPERTY.getUri(PROPERTY.ARRAY) ), arrayResource);
@@ -83,7 +83,7 @@ public class ItemizedList extends List {
                                Statement sizeStmt = first.getProperty(sizeProp);
                                if ( sizeStmt != null ) {
                                        try {
-                                               size = sizeStmt.getInt();                                                                                       
+                                               size = sizeStmt.getInt();
                                        } catch ( Exception e ) {
                                                System.err.println("Unable to interpret itemized list size property value as integer.");
                                                e.printStackTrace();
@@ -116,13 +116,11 @@ public class ItemizedList extends List {
                                System.err.println("Unable to parse smartapi:list property value.");
                                e.printStackTrace();
                        }
-                       return;                 
+                       return;
                }
                if ( propertyIndex != PROPERTY.REST ) {
                        // pass on to Object
                        super.parse(statement);
                }
-
        }
-
 }
index f4b875bc1893aec0964bc0bd7127be5da44a94f3..4160c1d1a33ec2ba03396ec57a937458fc6ca960 100644 (file)
@@ -32,7 +32,7 @@ public class LinkedList extends List {
                for ( int i = 0; i < this.getItems().size(); i++ ) {
                        Object o = this.getItems().get(i);
                        if ( o instanceof Obj ) {
-                               items[i] = ((Obj)o).serialize(model);                           
+                               items[i] = ((Obj)o).serialize(model);
                        }
                        if ( o instanceof Variant ) {
                                items[i] = ((Variant)o).serialize(model);
@@ -70,7 +70,7 @@ public class LinkedList extends List {
                        try {
                                Resource listEntry = statement.getResource();
                                Property firstProp = listEntry.getModel().createProperty(PROPERTY.getUri(PROPERTY.FIRST));
-                               Property restProp = listEntry.getModel().createProperty(PROPERTY.getUri(PROPERTY.REST));                                
+                               Property restProp = listEntry.getModel().createProperty(PROPERTY.getUri(PROPERTY.REST));
                                Statement currentItem = listEntry.getProperty(firstProp);
                                Resource rest = listEntry.getPropertyResourceValue(restProp);
                                // if there is at least the first item in the list
@@ -92,7 +92,7 @@ public class LinkedList extends List {
                                System.err.println("Unable to parse smartapi:list property value.");
                                e.printStackTrace();
                        }
-                       return;                 
+                       return;
                }
                // pass on to Object
                super.parse(statement);
index f64e489d434261eadd12ed8008378584ee17265c..aab47f58d344b3af462517f09541f74a3bc4a07a 100644 (file)
@@ -268,17 +268,17 @@ abstract public class List extends Obj {
                        // if baseObjectProperty is defined, add item as that property value to base object
                        if ( this.hasBaseObjectProperty() ) {
                                if ( item instanceof Variant ) {
-                                       baseObject.add(this.getBaseObjectProperty(), (Variant)item);                                                                    
+                                       baseObject.add(this.getBaseObjectProperty(), (Variant)item);
                                }
                                if ( item instanceof Obj ) {
-                                       baseObject.add(this.getBaseObjectProperty(), (Obj)item);                                                                        
+                                       baseObject.add(this.getBaseObjectProperty(), (Obj)item);
                                }
                                // clone object to put rdf:value to its standard place (when parsed)
-                               return baseObject.clone();                              
+                               return baseObject.clone();
                        } else {
                                // no baseObjectProperty defined and item is variant -> add as rdf:value of the base object
                                if ( item instanceof Variant ) {
-                                       baseObject.add(PROPERTY.RDF_VALUE, (Variant)item);                                      
+                                       baseObject.add(PROPERTY.RDF_VALUE, (Variant)item);
                                        // clone object to put rdf:value to its standard place (when parsed)
                                        return baseObject.clone();
                                }
@@ -292,7 +292,7 @@ abstract public class List extends Obj {
                                                baseObject.parse(statement);
                                        }
                                        return baseObject;
-                               }                               
+                               }
                        }
                        // we should not get here
                        System.err.println("Error while returning a list item. Item is not Obj or Variant!");
@@ -301,7 +301,7 @@ abstract public class List extends Obj {
                        if ( item instanceof Variant ) {
                                return ((Variant)item).getValue();
                        } else {
-                               return item;                            
+                               return item;
                        }
                }
        }
index 0117877446b4e2bd11af734c441d93fe206cd826..6e4f11e3ba4a03a878bde7c0ff318e6f3787cbdc 100644 (file)
@@ -32,8 +32,8 @@ public class OrderedList extends List {
                Resource resource = super.getSerialization(model);
                Resource first = model.createResource();
 
-               Property entriesProp = model.createProperty( PROPERTY.getUri(PROPERTY.ENTRIES) );       
-               Property entryProp = model.createProperty( PROPERTY.getUri(PROPERTY.ENTRY) );   
+               Property entriesProp = model.createProperty( PROPERTY.getUri(PROPERTY.ENTRIES) );
+               Property entryProp = model.createProperty( PROPERTY.getUri(PROPERTY.ENTRY) );
                Property indexProp = model.createProperty( PROPERTY.getUri(PROPERTY.INDEX) );
                Property valueProp = model.createProperty( PROPERTY.getUri(PROPERTY.RDF_VALUE) );
                first.addProperty(model.createProperty( PROPERTY.getUri(PROPERTY.SIZE) ), model.createTypedLiteral(this.getItems().size(), XSDDatatype.XSDinteger));
@@ -43,10 +43,10 @@ public class OrderedList extends List {
                        entryResource.addProperty(indexProp, model.createTypedLiteral(i, XSDDatatype.XSDinteger));
                        Object o = this.list.get(i);
                        if ( o instanceof Obj ) {
-                               entryResource.addProperty(valueProp, ((Obj)o).serialize(model));                                
+                               entryResource.addProperty(valueProp, ((Obj)o).serialize(model));
                        }
                        if ( o instanceof Variant ) {
-                               entryResource.addProperty(valueProp, ((Variant)o).serialize(model));                            
+                               entryResource.addProperty(valueProp, ((Variant)o).serialize(model));
                        }
                        arrayResource.addProperty(entryProp, entryResource);
                }
@@ -86,7 +86,7 @@ public class OrderedList extends List {
                                Resource first = statement.getResource();
                                Property sizeProp = first.getModel().createProperty( PROPERTY.getUri(PROPERTY.SIZE) );
                                Property arrayProp = first.getModel().createProperty( PROPERTY.getUri(PROPERTY.INDEXEDARRAY) );
-                               Property entryProp = first.getModel().createProperty( PROPERTY.getUri(PROPERTY.ENTRY) );        
+                               Property entryProp = first.getModel().createProperty( PROPERTY.getUri(PROPERTY.ENTRY) );
                                Property indexProp = first.getModel().createProperty( PROPERTY.getUri(PROPERTY.INDEX) );
                                Property valueProp = first.getModel().createProperty( PROPERTY.getUri(PROPERTY.RDF_VALUE) );
                                
@@ -94,7 +94,7 @@ public class OrderedList extends List {
                                Statement sizeStmt = first.getProperty(sizeProp);
                                if ( sizeStmt != null ) {
                                        try {
-                                               size = sizeStmt.getInt();                                                                                       
+                                               size = sizeStmt.getInt();
                                        } catch ( Exception e ) {
                                                System.err.println("Unable to interpret ordered list size property value as integer.");
                                                e.printStackTrace();
@@ -131,13 +131,12 @@ public class OrderedList extends List {
                                System.err.println("Unable to parse smartapi:list property value.");
                                e.printStackTrace();
                        }
-                       return;                 
+                       return;
                }
                if ( propertyIndex != PROPERTY.REST ) {
                        // pass on to Object
                        super.parse(statement);
                }
-
        }
 
 }
index 752d65835c7e0b2b738518ef040e880e7e9087b4..3b3f70dc29aa58cdfd2072ed81d2957dc0b5b10d 100644 (file)
@@ -486,7 +486,6 @@ public class Variant {
                default:        
                        return "";
                }
-
        }
        
        public boolean hasSameValue(Variant other)
@@ -612,13 +611,13 @@ public class Variant {
        {
                if (this.isObj()) {
                        try {
-                               return new URL(((Obj)this.getValue()).getIdentifierUri());                              
+                               return new URL(((Obj)this.getValue()).getIdentifierUri());
                        } catch ( Exception e ) {
                                e.printStackTrace();
                                return null;
                        }
                } else {
-                       return (URL)this.getValue();                    
+                       return (URL)this.getValue();
                }
        }
        
@@ -725,6 +724,5 @@ public class Variant {
                        // nothing to do
                        break;
                }
-
        }
 }
\ No newline at end of file