[HepData-svn] r1904 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Nov 9 16:56:03 GMT 2015


Author: whalley
Date: Mon Nov  9 16:56:03 2015
New Revision: 1904

Log:
mods to sort qualifiers alphabetically for consistency plus remove errors tag when there are no numerical errors

Modified:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java	Mon Nov  9 12:13:26 2015	(r1903)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java	Mon Nov  9 16:56:03 2015	(r1904)
@@ -445,41 +445,45 @@
 		if(!unit.equals("")){ s.append(", units: '"+unit+"'"); }
 		s.append("}\n");
 		boolean first=true;
+                List <String> storelist = new ArrayList();
 		for (Property prop : yax.getProperties()){
+                    StringBuffer stemp = new StringBuffer();
 		    if(first) { s.append(s4+"qualifiers:\n"); }
 		    first=false;
 
-		    s.append(s4+sp+"{name: '"+prop.getName().replaceAll("'","''")+"'");
+		    stemp.append(s4+sp+"{name: '"+prop.getName().replaceAll("'","''").replaceFirst("\\.","zzzz")+"'");
 
 		    if(prop.getFocus()!=null || prop.getLowValue()!=null || prop.getHighValue()!=null){
-			s.append(", value: '");
+			stemp.append(", value: '");
 		    }
 		    if (prop.getFocus() != null){
-			s.append(prop.getFocus());
+			stemp.append(prop.getFocus());
 		    }
                 
 		    if (prop.getLowValue() != null && prop.getHighValue() != null &&
 			prop.getLowValue().equals(prop.getHighValue())) {
-			s.append(prop.getLowValue());
+			stemp.append(prop.getLowValue());
 		    } else {
-			if(prop.getFocus() != null) { s.append(" ("); }
-			s.append(prop.getLowValue());
-			s.append("-");
-			s.append(prop.getHighValue());
-			if(prop.getFocus() != null) { s.append(")"); }
+			if(prop.getFocus() != null) { stemp.append(" ("); }
+			stemp.append(prop.getLowValue());
+			stemp.append("-");
+			stemp.append(prop.getHighValue());
+			if(prop.getFocus() != null) { stemp.append(")"); }
 		    }
 		    if(prop.getFocus()!=null || prop.getLowValue()!=null || prop.getHighValue()!=null){
-			s.append("'");
+			stemp.append("'");
 		    }
                     
 		    if (prop.getUnit().toString().equals("") || !prop.getUnit().isDimensionless()) {
-			s.append(", units: '");
-			s.append(prop.getUnit().toString()+"'");
+			stemp.append(", units: '");
+			stemp.append(prop.getUnit().toString()+"'");
 		    }
                   
-		    s.append("}\n");
-		}
+		    stemp.append("}\n");
+                    storelist.add(stemp.toString());
+                }
 		for (String comment : yax.getComments()){
+                    StringBuffer stemp = new StringBuffer();
 		    if(first) { s.append(s4+"qualifiers:\n"); }
 		    first=false;
 		    unit="";
@@ -498,8 +502,8 @@
 			unit=type.substring(type.indexOf(" in ")+4).trim();
 			type=type.substring(0,type.indexOf(" in ")).trim();
 		    }
-		    s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'");
-		    s.append(", value: '"+ value.replaceAll("'","''")+"'"); 
+		    stemp.append(s4+sp+"{name: '"+type.replaceAll("'","''").replaceFirst("\\.","zzzz")+"'");
+		    stemp.append(", value: '"+ value.replaceAll("'","''")+"'"); 
 		    //                if(type.equals("SYS") && value.indexOf("//")>-1){
 		    //                    String comments[] = value.replaceAll("////","//").split("//");
 		    //                    for( int i=0; i<comments.length; i++) { 
@@ -513,10 +517,15 @@
 		    //                    s.append(", value: '"+ value.replaceAll("'","''")+"'"); 
 		    //                } 
 		    if(!unit.equals("")){
-			s.append(", units: '"+ unit+"'");
+			stemp.append(", units: '"+ unit+"'");
 		    }
-		    s.append("}\n");
+		    stemp.append("}\n");
+                    storelist.add(stemp.toString());
 		}
+                Collections.sort(storelist);
+                for (int i=0; i<storelist.size(); i++){
+                    s.append(storelist.get(i).replaceFirst("zzzz",""));
+                }         
 
 		for(Uncertainty error : ds.getErrors()){
 		    if(error.getPlus()==0.0){
@@ -558,23 +567,27 @@
 			    s.append("'");
 			}
 			s.append("\n");
-			if (point.getErrors().size() > 0
-			    || yax.getErrors().size() > 0
-			    || ds.getErrors().size() > 0) {
-			    s.append(s4+s4+"errors:\n");
-			}
+                        boolean firstError=true;
+//			if (point.getErrors().size() > 0
+//			    || yax.getErrors().size() > 0
+//			    || ds.getErrors().size() > 0) {
+//			    s.append(s4+s4+"errors:\n");
+//			}
 			if(point.getErrors().size()>0){
 			    for(Uncertainty error : point.getErrors()){
+                                if(firstError) { s.append(s4+s4+"errors:\n"); firstError=false; }
 				s.append(_formatError(error,"point"));
 			    }
 			}
 			if(yax.getErrors().size()>0){
 			    for(Uncertainty error : yax.getErrors()){
+                                if(firstError && error.getPlus()!=0.0) { s.append(s4+s4+"errors:\n"); firstError=false; }
 				if(error.getPlus()!=0.0) s.append(_formatError(error,"axis"));
 			    }
 			}
 			if(ds.getErrors().size()>0){
 			    for(Uncertainty error : ds.getErrors()){
+                                if(firstError && error.getPlus()!=0.0) { s.append(s4+s4+"errors:\n"); firstError=false; }
 				if(error.getPlus()!=0.0) s.append(_formatError(error,"dataset"));
 			    }
 			}


More information about the HepData-svn mailing list