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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Apr 19 09:59:46 BST 2016


Author: watt
Date: Tue Apr 19 09:59:46 2016
New Revision: 1936

Log:
Plain and Input formatters: check if bin is null

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

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/InputFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/InputFormatter.java	Tue Mar 29 11:11:39 2016	(r1935)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/InputFormatter.java	Tue Apr 19 09:59:46 2016	(r1936)
@@ -284,8 +284,12 @@
 			    }
 			}
                     } catch(Exception e){
-			if (ds.getXAxis(nx+1).getBin(i+1).getDescription() != null) {
-			    s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription());
+			if (ds.getXAxis(nx+1).getBin(i+1) != null) {
+			    if (ds.getXAxis(nx+1).getBin(i+1).getDescription() != null) {
+				s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription());
+			    } else {
+				s.append(" -");
+			    }
 			} else {
 			    s.append(" -");
                         }

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java	Tue Mar 29 11:11:39 2016	(r1935)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java	Tue Apr 19 09:59:46 2016	(r1936)
@@ -55,12 +55,12 @@
         if (d != null) {
             StringBuffer s = new StringBuffer();
             for (XAxis x : d.getXAxes()) {
-//                if (xid == null || x.getId().equals(xid)) {
-                 if (x.getId().equals(1)) {
-//                   for (YAxis y : d.getYAxes()) {
+		//                if (xid == null || x.getId().equals(xid)) {
+		if (x.getId().equals(1)) {
+		    //                   for (YAxis y : d.getYAxes()) {
                     if (d.getYAxes().size()>0) {
-                         YAxis y = d.getYAxis(1);
-                         if (yid == null || y.getId().equals(yid)) {
+			YAxis y = d.getYAxis(1);
+			if (yid == null || y.getId().equals(yid)) {
                             s.append(format(x, y));
                             s.append("\n");
                         }
@@ -109,7 +109,7 @@
                 }
                 Collections.sort(storelist);
                 nstore=storelist.size();
-                 for(int i=0; i<storelist.size(); i++){
+		for(int i=0; i<storelist.size(); i++){
                     store[ny-1][i]=storelist.get(i);
                 }
                 for (Property p : d.getYAxis(ny).getProperties()) {
@@ -207,12 +207,12 @@
                 s.append("x" + Integer.toString(ix+1) + "high\t");
             } 
             for ( YAxis yax : d.getYAxes()){
-               s.append("y\t");
-               if(yax.getPoints().size()>0) {
-                   for (int e = 0; e < yax.getPoints().first().getErrors().size(); ++e) {
+		s.append("y\t");
+		if(yax.getPoints().size()>0) {
+		    for (int e = 0; e < yax.getPoints().first().getErrors().size(); ++e) {
                         s.append("dy+\tdy-\t");
-                   }
-               }
+		    }
+		}
             }   
             s.append("\n");
 
@@ -222,30 +222,34 @@
                 Bin b = x.getBin(r);
                 Point p = y.getPoint(r);
                 if (b != null || p != null) {
-                    Double xlow = b.getLowValue();
-                    Double xhigh = b.getHighValue();
-                    Double xfocus = b.getFocus();
-                    String xdesc = b.getDescription();
+		    Double xlow = null, xhigh = null, xfocus = null;
+		    String xdesc = null;
+		    if (b != null) {
+			if (b.getLowValue() != null) { xlow = b.getLowValue(); }
+			if (b.getHighValue() != null) { xhigh = b.getHighValue(); }
+			if (b.getFocus() != null) { xfocus = b.getFocus(); }
+			if (b.getDescription() != null) { xdesc = b.getDescription(); }
+		    }
                     template = "$xdesc$\t$xfocus$\t$xlow$\t$xhigh$";
                     for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){
-                        template=template.concat("\t$val" + Integer.toString(ix) + "desc$");
-                        template=template.concat("\t$val" + Integer.toString(ix) + "$");
-                        template=template.concat("\t$val" + Integer.toString(ix) + "low$");
-                        template=template.concat("\t$val" + Integer.toString(ix) + "high$");
+			template=template.concat("\t$val" + Integer.toString(ix) + "desc$");
+			template=template.concat("\t$val" + Integer.toString(ix) + "$");
+			template=template.concat("\t$val" + Integer.toString(ix) + "low$");
+			template=template.concat("\t$val" + Integer.toString(ix) + "high$");
                     } 
-//                    template=template.concat("\t$yval$");
+		    //                    template=template.concat("\t$yval$");
                     row.setTemplate(template);
                     row.setAttribute("xdesc", xdesc);
                     row.setAttribute("xfocus", xfocus);
                     row.setAttribute("xlow", xlow);
                     row.setAttribute("xhigh", xhigh);
                     for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){
-                      if(x.getDataset().getXAxis(ix+1).getBin(r) != null){
-                        row.setAttribute("val" + Integer.toString(ix)+"desc",x.getDataset().getXAxis(ix+1).getBin(r).getDescription()); 
-                        row.setAttribute("val" + Integer.toString(ix),x.getDataset().getXAxis(ix+1).getBin(r).getFocus()); 
-                        row.setAttribute("val" + Integer.toString(ix)+"low",x.getDataset().getXAxis(ix+1).getBin(r).getLowValue());
-                        row.setAttribute("val" + Integer.toString(ix)+"high",x.getDataset().getXAxis(ix+1).getBin(r).getHighValue());
-                      }
+			if(x.getDataset().getXAxis(ix+1).getBin(r) != null){
+			    row.setAttribute("val" + Integer.toString(ix)+"desc",x.getDataset().getXAxis(ix+1).getBin(r).getDescription());
+			    row.setAttribute("val" + Integer.toString(ix),x.getDataset().getXAxis(ix+1).getBin(r).getFocus()); 
+			    row.setAttribute("val" + Integer.toString(ix)+"low",x.getDataset().getXAxis(ix+1).getBin(r).getLowValue());
+			    row.setAttribute("val" + Integer.toString(ix)+"high",x.getDataset().getXAxis(ix+1).getBin(r).getHighValue());
+			}
                     } 
                     s.append(row.toString());
                     for (int ny=1; ny<=d.getYAxes().size(); ny++ ) {
@@ -280,7 +284,7 @@
                         } catch (Exception  ex) { s.append("\t-"); }
                     }
                     s.append("\n");
-                  }
+		}
             }
             out = s.toString();
         }


More information about the HepData-svn mailing list