@@ -83,21 +83,51 @@ public static DgraphProto.NQuad newNQuadEdgeWithFacets(
83
83
* @param value
84
84
* @return
85
85
*/
86
- public static DgraphProto .Facet newFacet (String key , Object value ) {
87
- DgraphProto .Facet .ValType valType = DgraphProto .Facet .ValType .STRING ;
88
- if (null != valType ) {
89
- if (value instanceof Integer ) {
90
- valType = DgraphProto .Facet .ValType .INT ;
91
- } else if (value instanceof Float ) {
92
- valType = DgraphProto .Facet .ValType .FLOAT ;
93
- } else if (value instanceof Boolean ) {
94
- valType = DgraphProto .Facet .ValType .BOOL ;
95
- }
96
- }
86
+ public static DgraphProto .Facet newFacet (String key , Integer value ) {
97
87
return DgraphProto .Facet .newBuilder ()
98
88
.setKey (key )
99
- .setValType (valType )
100
- .setValue (ByteString .copyFromUtf8 ((null == value ) ? "" : value .toString ()))
89
+ .setValType (DgraphProto . Facet . ValType . INT )
90
+ .setValue (ByteString .copyFromUtf8 ((null == value ) ? "0 " : value .toString ()))
101
91
.build ();
102
92
}
93
+
94
+ /**
95
+ * @param key
96
+ * @param value
97
+ * @return
98
+ */
99
+ public static DgraphProto .Facet newFacet (String key , Float value ) {
100
+ return DgraphProto .Facet .newBuilder ()
101
+ .setKey (key )
102
+ .setValType (DgraphProto .Facet .ValType .FLOAT )
103
+ .setValue (ByteString .copyFromUtf8 ((null == value ) ? "0.0" : value .toString ()))
104
+ .build ();
105
+
106
+ }
107
+ /**
108
+ * @param key
109
+ * @param value
110
+ * @return
111
+ */
112
+ public static DgraphProto .Facet newFacet (String key , String value ) {
113
+ return DgraphProto .Facet .newBuilder ()
114
+ .setKey (key )
115
+ .setValType (DgraphProto .Facet .ValType .STRING )
116
+ .setValue (ByteString .copyFromUtf8 ((null == value ) ? "" : value .toString ()))
117
+ .build ();
118
+
119
+ }
120
+ /**
121
+ * @param key
122
+ * @param value
123
+ * @return
124
+ */
125
+ public static DgraphProto .Facet newFacet (String key , Boolean value ) {
126
+ return DgraphProto .Facet .newBuilder ()
127
+ .setKey (key )
128
+ .setValType (DgraphProto .Facet .ValType .BOOL )
129
+ .setValue (ByteString .copyFromUtf8 ((null == value ) ? "FALSE" : value .toString ()))
130
+ .build ();
131
+
132
+ }
103
133
}
0 commit comments