Skip to content

Commit 7afc513

Browse files
committed
feat: simplicy stream api
Signed-off-by: Otavio Santana <[email protected]>
1 parent 0d785be commit 7afc513

File tree

24 files changed

+104
-106
lines changed

24 files changed

+104
-106
lines changed

jnosql-arangodb/src/test/java/org/eclipse/jnosql/databases/arangodb/communication/ArangoDBDocumentManagerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void shouldSaveSubDocument() {
133133
CommunicationEntity entitySaved = entityManager.insert(entity);
134134
Element id = entitySaved.find(KEY_NAME).get();
135135
SelectQuery query = select().from(COLLECTION_NAME).where(id.name()).eq(id.get()).build();
136-
CommunicationEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
136+
CommunicationEntity entityFound = entityManager.select(query).toList().get(0);
137137
Element subDocument = entityFound.find("phones").get();
138138
List<Element> documents = subDocument.get(new TypeReference<>() {
139139
});
@@ -147,7 +147,7 @@ void shouldSaveSubDocument2() {
147147
CommunicationEntity entitySaved = entityManager.insert(entity);
148148
Element id = entitySaved.find(KEY_NAME).get();
149149
SelectQuery query = select().from(COLLECTION_NAME).where(id.name()).eq(id.get()).build();
150-
CommunicationEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
150+
CommunicationEntity entityFound = entityManager.select(query).toList().get(0);
151151
Element subDocument = entityFound.find("phones").get();
152152
List<Element> documents = subDocument.get(new TypeReference<>() {
153153
});
@@ -226,7 +226,7 @@ void shouldReadFromDifferentBaseDocumentUsingInstance() {
226226
ArangoDB arangoDB = DefaultArangoDBDocumentManager.class.cast(entityManager).getArangoDB();
227227
arangoDB.db(DATABASE).collection(COLLECTION_NAME).insertDocument(new Human());
228228
SelectQuery select = select().from(COLLECTION_NAME).build();
229-
List<CommunicationEntity> entities = entityManager.select(select).collect(Collectors.toList());
229+
List<CommunicationEntity> entities = entityManager.select(select).toList();
230230
assertFalse(entities.isEmpty());
231231
}
232232

@@ -239,7 +239,7 @@ void shouldReadFromDifferentBaseDocumentUsingMap() {
239239
map.put("city", "Salvador");
240240
arangoDB.db(DATABASE).collection(COLLECTION_NAME).insertDocument(map);
241241
SelectQuery select = select().from(COLLECTION_NAME).build();
242-
List<CommunicationEntity> entities = entityManager.select(select).collect(Collectors.toList());
242+
List<CommunicationEntity> entities = entityManager.select(select).toList();
243243
assertFalse(entities.isEmpty());
244244
}
245245

@@ -248,7 +248,7 @@ void shouldExecuteAQLWithTypeParams() {
248248
entityManager.insert(getEntity());
249249
String aql = "FOR a IN person FILTER a.name == @name RETURN a.name";
250250
List<String> entities = entityManager.aql(aql,
251-
singletonMap("name", "Poliana"), String.class).collect(Collectors.toList());
251+
singletonMap("name", "Poliana"), String.class).toList();
252252

253253
assertFalse(entities.isEmpty());
254254
}
@@ -257,7 +257,7 @@ void shouldExecuteAQLWithTypeParams() {
257257
void shouldExecuteAQLWithType() {
258258
entityManager.insert(getEntity());
259259
String aql = "FOR a IN person RETURN a.name";
260-
List<String> entities = entityManager.aql(aql, String.class).collect(Collectors.toList());
260+
List<String> entities = entityManager.aql(aql, String.class).toList();
261261
assertFalse(entities.isEmpty());
262262
}
263263

jnosql-cassandra/src/main/java/org/eclipse/jnosql/databases/cassandra/communication/CassandraConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static UDT getUDT(ColumnDefinition definition, UdtValue udtValue) {
8686
String name = definition.getName().asInternal();
8787
final UserDefinedType type = udtValue.getType();
8888
List<Element> columns = new ArrayList<>();
89-
List<String> names = type.getFieldNames().stream().map(CqlIdentifier::asInternal).collect(toList());
89+
List<String> names = type.getFieldNames().stream().map(CqlIdentifier::asInternal).toList();
9090
for (CqlIdentifier fieldName : type.getFieldNames()) {
9191
final int index = names.indexOf(fieldName.asInternal());
9292
DataType fieldType = type.getFieldTypes().get(index);

jnosql-cassandra/src/main/java/org/eclipse/jnosql/databases/cassandra/communication/QueryUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static Insert insert(CommunicationEntity entity, String keyspace, CqlSession ses
6666

6767
Map<String, Term> values = new HashMap<>();
6868
InsertInto insert = QueryBuilder.insertInto(keyspace, entity.name());
69-
entity.elements().stream()
69+
entity.elements()
7070
.forEach(c -> {
7171
if (UDT.class.isInstance(c)) {
7272
insertUDT(UDT.class.cast(c), keyspace, entity.name(), session, values);
@@ -131,7 +131,7 @@ private static Object getUdtValue(UserDefinedType userType, Iterable elements, D
131131

132132
UdtValue udtValue = userType.newValue();
133133
final List<String> udtNames = userType.getFieldNames().stream().map(CqlIdentifier::asInternal)
134-
.collect(Collectors.toList());
134+
.toList();
135135
for (Object object : elements) {
136136
if (Element.class.isInstance(object)) {
137137
Element column = Element.class.cast(object);

jnosql-cassandra/src/test/java/org/eclipse/jnosql/databases/cassandra/communication/CassandraColumnManagerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void shouldInsertWithTtl() throws InterruptedException {
111111
sleep(2_000L);
112112

113113
List<CommunicationEntity> entities = entityManager.select(select().from(Constants.COLUMN_FAMILY).where("id").eq(10L).build())
114-
.collect(toList());
114+
.toList();
115115
assertTrue(entities.isEmpty());
116116
}
117117

@@ -122,7 +122,7 @@ void shouldInsertIterableWithTtl() throws InterruptedException {
122122
sleep(2_000L);
123123

124124
List<CommunicationEntity> entities = entityManager.select(select().from(Constants.COLUMN_FAMILY).build())
125-
.collect(toList());
125+
.toList();
126126
assertTrue(entities.isEmpty());
127127
}
128128

@@ -201,7 +201,7 @@ void shouldFindAll() {
201201
entityManager.insert(columnEntity);
202202

203203
var query = select().from(columnEntity.name()).build();
204-
List<CommunicationEntity> entities = entityManager.select(query).collect(toList());
204+
List<CommunicationEntity> entities = entityManager.select(query).toList();
205205
assertFalse(entities.isEmpty());
206206
}
207207

@@ -239,7 +239,7 @@ void shouldFindById() {
239239
entityManager.insert(getColumnFamily());
240240

241241
var query = select().from(Constants.COLUMN_FAMILY).where("id").eq(10L).build();
242-
List<CommunicationEntity> columnEntity = entityManager.select(query).collect(toList());
242+
List<CommunicationEntity> columnEntity = entityManager.select(query).toList();
243243
assertFalse(columnEntity.isEmpty());
244244
List<Element> columns = columnEntity.get(0).elements();
245245
assertThat(columns.stream().map(Element::name).collect(toList()))
@@ -254,7 +254,7 @@ void shouldFindByIdWithConsistenceLevel() {
254254

255255
entityManager.insert(getColumnFamily());
256256
var query = select().from(Constants.COLUMN_FAMILY).where("id").eq(10L).build();
257-
List<CommunicationEntity> columnEntity = entityManager.select(query, CONSISTENCY_LEVEL).collect(toList());
257+
List<CommunicationEntity> columnEntity = entityManager.select(query, CONSISTENCY_LEVEL).toList();
258258
assertFalse(columnEntity.isEmpty());
259259
List<Element> columns = columnEntity.get(0).elements();
260260
assertThat(columns.stream().map(Element::name).collect(toList())).contains("name", "version", "options", "id");
@@ -279,7 +279,7 @@ void shouldRunNativeQuery() {
279279
void shouldRunNativeQuery2() {
280280
entityManager.insert(getColumnFamily());
281281
String query = "select * from newKeySpace.newColumnFamily where id = :id;";
282-
List<CommunicationEntity> entities = entityManager.cql(query, singletonMap("id", 10L)).collect(toList());
282+
List<CommunicationEntity> entities = entityManager.cql(query, singletonMap("id", 10L)).toList();
283283
assertFalse(entities.isEmpty());
284284
List<Element> columns = entities.get(0).elements();
285285
assertThat(columns.stream().map(Element::name).collect(toList()))
@@ -293,7 +293,7 @@ void shouldPrepareStatement() {
293293
entityManager.insert(getColumnFamily());
294294
CassandraPreparedStatement preparedStatement = entityManager.nativeQueryPrepare("select * from newKeySpace.newColumnFamily where id=?");
295295
preparedStatement.bind(10L);
296-
List<CommunicationEntity> entities = preparedStatement.executeQuery().collect(toList());
296+
List<CommunicationEntity> entities = preparedStatement.executeQuery().toList();
297297
List<Element> columns = entities.get(0).elements();
298298
assertThat(columns.stream().map(Element::name).collect(toList()))
299299
.contains("name", "version", "options", "id");
@@ -339,7 +339,7 @@ void shouldLimitResult() {
339339
getEntities().forEach(entityManager::insert);
340340
var query = select().from(Constants.COLUMN_FAMILY).where("id").in(Arrays.asList(1L, 2L, 3L))
341341
.limit(2).build();
342-
List<CommunicationEntity> columnFamilyEntities = entityManager.select(query).collect(toList());
342+
List<CommunicationEntity> columnFamilyEntities = entityManager.select(query).toList();
343343
assertEquals(Integer.valueOf(2), Integer.valueOf(columnFamilyEntities.size()));
344344
}
345345

@@ -464,7 +464,7 @@ void shouldPagingState() {
464464

465465
assertFalse(cassandraQuery.getPagingState().isPresent());
466466

467-
List<CommunicationEntity> entities = entityManager.select(cassandraQuery).collect(toList());
467+
List<CommunicationEntity> entities = entityManager.select(cassandraQuery).toList();
468468
assertEquals(10, entities.size());
469469
assertTrue(cassandraQuery.getPagingState().isPresent());
470470
}

jnosql-couchbase/src/main/java/org/eclipse/jnosql/databases/couchbase/communication/EntityConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static JsonObject convert(CommunicationEntity entity) {
103103
requireNonNull(entity, "entity is required");
104104

105105
JsonObject jsonObject = JsonObject.create();
106-
entity.elements().stream()
106+
entity.elements()
107107
.forEach(toJsonObject(jsonObject));
108108
return jsonObject;
109109
}

jnosql-couchbase/src/main/java/org/eclipse/jnosql/databases/couchbase/communication/N1QLBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ private String identifierOf(String name) {
181181
}
182182

183183
private String select() {
184-
String documents = query.columns().stream()
185-
.collect(Collectors.joining(", "));
184+
String documents = String.join(", ", query.columns());
186185
if (documents.isBlank()) {
187186
return "*";
188187
}

jnosql-couchbase/src/test/java/org/eclipse/jnosql/databases/couchbase/communication/CouchbaseDocumentManagerTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void shouldRemoveEntityByName() throws InterruptedException {
129129
.where(name.name()).eq(name.get()).build();
130130
entityManager.delete(deleteQuery);
131131
Thread.sleep(1_000L);
132-
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
132+
assertTrue(entityManager.select(query).count() == 0);
133133
}
134134

135135
@Test
@@ -139,7 +139,7 @@ void shouldSaveSubDocument() {
139139
CommunicationEntity entitySaved = entityManager.insert(entity);
140140
Element id = entitySaved.find("_id").get();
141141
SelectQuery query = select().from(COLLECTION_PERSON_NAME).where(id.name()).eq(id.get()).build();
142-
CommunicationEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
142+
CommunicationEntity entityFound = entityManager.select(query).toList().get(0);
143143
Element subDocument = entityFound.find("phones").get();
144144
List<Element> documents = subDocument.get(new TypeReference<>() {
145145
});
@@ -154,7 +154,7 @@ void shouldSaveSubDocument2() throws InterruptedException {
154154
Thread.sleep(1_00L);
155155
Element id = entitySaved.find("_id").get();
156156
var query = select().from(COLLECTION_PERSON_NAME).where(id.name()).eq(id.get()).build();
157-
CommunicationEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
157+
CommunicationEntity entityFound = entityManager.select(query).toList().get(0);
158158
Element subDocument = entityFound.find("phones").get();
159159
List<Element> documents = subDocument.get(new TypeReference<>() {
160160
});
@@ -235,9 +235,8 @@ void shouldRunN1Ql() {
235235
CommunicationEntity entity = getEntity();
236236
entityManager.insert(entity);
237237
await().until(() ->
238-
!entityManager
239-
.n1qlQuery("select * from `jnosql`._default.person")
240-
.collect(Collectors.toList()).isEmpty()
238+
!(entityManager
239+
.n1qlQuery("select * from `jnosql`._default.person").count() == 0)
241240
);
242241
}
243242

@@ -249,9 +248,8 @@ void shouldRunN1QlParameters() {
249248
JsonObject params = JsonObject.create().put("name", entity.find("name", String.class).orElse(null));
250249

251250
await().until(() ->
252-
!entityManager
253-
.n1qlQuery("select * from `jnosql`._default.person where name = $name", params)
254-
.collect(Collectors.toList()).isEmpty()
251+
!(entityManager
252+
.n1qlQuery("select * from `jnosql`._default.person where name = $name", params).count() == 0)
255253
);
256254
}
257255

jnosql-couchbase/src/test/java/org/eclipse/jnosql/databases/couchbase/communication/DocumentQueryTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void shouldShouldDefineLimit() {
101101
.limit(2L)
102102
.build();
103103

104-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
104+
List<CommunicationEntity> entities = entityManager.select(query).toList();
105105
assertEquals(2, entities.size());
106106

107107
}
@@ -112,7 +112,7 @@ public void shouldShouldDefineStart() {
112112
.where("name").eq("name")
113113
.skip(1L)
114114
.build();
115-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
115+
List<CommunicationEntity> entities = entityManager.select(query).toList();
116116
assertEquals(2, entities.size());
117117

118118
}
@@ -129,7 +129,7 @@ public void shouldShouldDefineLimitAndStart() {
129129
.limit(2L)
130130
.build();
131131

132-
entities = entityManager.select(query).collect(Collectors.toList());
132+
entities = entityManager.select(query).toList();
133133
assertEquals(2, entities.size());
134134

135135
}
@@ -151,7 +151,7 @@ public void shouldFindDocumentByName() {
151151
.where("name")
152152
.eq("name")
153153
.build();
154-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
154+
List<CommunicationEntity> entities = entityManager.select(query).toList();
155155
assertFalse(entities.isEmpty());
156156
}
157157

@@ -162,7 +162,7 @@ public void shouldFindDocumentByNameSortAsc() {
162162
.orderBy("name").asc()
163163
.build();
164164

165-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
165+
List<CommunicationEntity> entities = entityManager.select(query).toList();
166166
List<String> result = entities.stream()
167167
.flatMap(e -> e.elements().stream())
168168
.filter(d -> "name".equals(d.name()))
@@ -180,7 +180,7 @@ public void shouldFindDocumentByNameSortDesc() {
180180
.orderBy("name").desc()
181181
.build();
182182

183-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
183+
List<CommunicationEntity> entities = entityManager.select(query).toList();
184184

185185
List<String> result = entities.stream().flatMap(e -> e.elements().stream())
186186
.filter(d -> "name".equals(d.name()))
@@ -198,7 +198,7 @@ public void shouldFindDocumentById() {
198198
.where("_id").eq("id")
199199
.build();
200200

201-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
201+
List<CommunicationEntity> entities = entityManager.select(query).toList();
202202
assertFalse(entities.isEmpty());
203203

204204
}

jnosql-couchdb/src/test/java/org/eclipse/jnosql/databases/couchdb/communication/DefaultCouchDBDocumentManagerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void shouldSelect() {
128128
@Test
129129
void shouldSelectEmptyResult() {
130130
var query = select().from(COLLECTION_NAME).where("no_field").eq("not_found").build();
131-
var entities = entityManager.select(query).collect(Collectors.toList());
131+
var entities = entityManager.select(query).toList();
132132
assertTrue(entities.isEmpty());
133133
}
134134

@@ -143,7 +143,7 @@ void shouldRemoveEntityByName() {
143143
var deleteQuery = delete().from(COLLECTION_NAME)
144144
.where(name.name()).eq(name.get()).build();
145145
entityManager.delete(deleteQuery);
146-
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
146+
assertTrue(entityManager.select(query).count() == 0);
147147
}
148148

149149
@Test
@@ -192,7 +192,7 @@ void shouldExecuteInStringQueryAtCouchbase() {
192192
}
193193
CouchDBDocumentQuery query = CouchDBDocumentQuery.of(select().from(COLLECTION_NAME)
194194
.where("name").in(Arrays.asList("Poliana", "Poliana")).build());
195-
List<CommunicationEntity> entities = entityManager.select(query).collect(Collectors.toList());
195+
List<CommunicationEntity> entities = entityManager.select(query).toList();
196196
assertEquals(4, entities.size());
197197
}
198198

@@ -226,7 +226,7 @@ void shouldSaveSubDocument() {
226226
.where("_id").eq(id.get())
227227
.build();
228228

229-
var entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
229+
var entityFound = entityManager.select(query).toList().get(0);
230230
var subDocument = entityFound.find("phones").get();
231231
List<Element> documents = subDocument.get(new TypeReference<>() {
232232
});
@@ -244,7 +244,7 @@ void shouldSaveSubDocument2() {
244244
var query = select().from(COLLECTION_NAME)
245245
.where(id.name()).eq(id.get())
246246
.build();
247-
var entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
247+
var entityFound = entityManager.select(query).toList().get(0);
248248
var subDocument = entityFound.find("phones").get();
249249
List<Element> documents = subDocument.get(new TypeReference<>() {
250250
});

jnosql-elasticsearch/src/main/java/org/eclipse/jnosql/databases/elasticsearch/communication/ElasticsearchDocumentConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ElasticsearchClient buildElasticsearchClient(Settings settings) {
9696
.forEach(httpHosts::add);
9797

9898
RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[0]));
99-
builder.setDefaultHeaders(headers.stream().toArray(Header[]::new));
99+
builder.setDefaultHeaders(headers.toArray(Header[]::new));
100100

101101
final Optional<String> username = settings
102102
.getSupplier(asList(Configurations.USER,

0 commit comments

Comments
 (0)