use of com.torodb.core.model.IndexedAttributes.IndexType in project torodb by torodb.
the class ToroIndexConverter method to.
@Override
public String to(NamedToroIndex userObject) {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
objectBuilder.add(NAME_KEY, userObject.getName());
if (userObject.isUnique()) {
objectBuilder.add(UNIQUE_KEY, true);
}
JsonArrayBuilder attsBuilder = Json.createArrayBuilder();
JsonArrayBuilder descBuilder = Json.createArrayBuilder();
int attPosition = 0;
boolean hasDescending = false;
for (Map.Entry<AttributeReference, IndexType> entry : userObject.getAttributes().entrySet()) {
attsBuilder.add(entry.getKey().toString());
if (IndexType.desc.equals(entry.getValue())) {
descBuilder.add(attPosition);
hasDescending = true;
}
attPosition++;
}
objectBuilder.add(ATTS_KEY, attsBuilder);
if (hasDescending) {
objectBuilder.add(DESCENDING, descBuilder);
}
StringWriter stringWriter = new StringWriter(200);
JsonWriter jsonWriter = Json.createWriter(stringWriter);
jsonWriter.writeObject(objectBuilder.build());
return stringWriter.toString();
}
Aggregations