DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_catalog / commons / src / main / java / org / onap / sdc / dcae / catalog / commons / Neo.java
1 package org.onap.sdc.dcae.catalog.commons;
2
3 import java.util.Iterator;
4
5 import com.google.common.base.Predicate;
6 import com.google.common.collect.Iterators;
7
8 import org.json.JSONObject;
9
10
11 public class Neo {
12
13   /*
14    */
15   public static String literalMap(JSONObject theProps,
16                                   String theNameAlias,
17                                   String theValueAlias,
18                                   String theAssignmentOp,
19                                                                                                                                         String theRelationOp,
20                                   Predicate theFieldFilter) {
21     if(theProps.length() == 0)
22       return "";
23     StringBuilder sb = new StringBuilder("");
24     for (Iterator i = Iterators.filter(theProps.keys(),
25                                        theFieldFilter);
26          i.hasNext();) {
27       String propName = (String)i.next();
28
29       if (theNameAlias != null) {
30         sb.append(theNameAlias)
31           .append('.');
32       }
33       sb.append('`')
34         .append(propName)
35         .append('`')
36         .append(theAssignmentOp)
37         .append(" {")
38         .append(theValueAlias)
39         .append("}.")
40         .append('`')
41         .append(propName)
42         .append('`')
43         .append(theRelationOp);
44     }
45     return sb.substring(0, sb.length() - theRelationOp.length());
46   }
47
48   public static String literalMap(JSONObject theProps,
49                                   String theAlias) {
50     return literalMap(theProps, null, theAlias, ":", ",", f -> true);
51   }
52
53 }
54