Skip to content

Commit a8a010f

Browse files
committed
style: code formatting
1 parent 92ebb9d commit a8a010f

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/main/java/com/flowingcode/vaadin/addons/chipfield/ChipField.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.chipfield;
2121

22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.HashMap;
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.Optional;
28+
import java.util.concurrent.atomic.AtomicInteger;
29+
import java.util.stream.Stream;
30+
2231
import com.vaadin.flow.component.AbstractField;
2332
import com.vaadin.flow.component.AttachEvent;
2433
import com.vaadin.flow.component.ComponentEvent;
@@ -38,18 +47,10 @@
3847
import com.vaadin.flow.data.provider.Query;
3948
import com.vaadin.flow.function.SerializableFunction;
4049
import com.vaadin.flow.shared.Registration;
50+
4151
import elemental.json.JsonArray;
4252
import elemental.json.JsonObject;
4353
import elemental.json.impl.JreJsonFactory;
44-
import java.util.ArrayList;
45-
import java.util.Arrays;
46-
import java.util.HashMap;
47-
import java.util.List;
48-
import java.util.Map;
49-
import java.util.Optional;
50-
import java.util.concurrent.atomic.AtomicInteger;
51-
import java.util.stream.Collectors;
52-
import java.util.stream.Stream;
5354

5455
@SuppressWarnings("serial")
5556
@Tag("paper-chip-input-autocomplete")
@@ -93,15 +94,15 @@ private void configure() {
9394
JsonObject eventData = e.getEventData();
9495
String chipLabel = eventData.get(CHIP_LABEL).asString();
9596
Stream<T> streamItems = availableItems.fetch(new Query<>());
96-
Optional<T> newItem = streamItems.filter(item -> itemLabelGenerator.apply(item).equals(chipLabel))
97-
.findFirst();
97+
Optional<T> newItem = streamItems.filter(item -> itemLabelGenerator.apply(item).equals(chipLabel)).findFirst();
9898
if (newItem.isPresent()) {
9999
selectedItems.put(chipLabel, newItem.get());
100-
this.setValue(new ArrayList<>(selectedItems.values()));
100+
setValue(new ArrayList<>(selectedItems.values()));
101101
} else {
102102
if (isAllowAdditionalItems()) {
103-
if (newItemHandler == null)
103+
if (newItemHandler == null) {
104104
throw new IllegalStateException("You need to setup a NewItemHandler");
105+
}
105106
T item = this.newItemHandler.apply(chipLabel);
106107
selectedItems.put(chipLabel, item);
107108
setValue(new ArrayList<>(selectedItems.values()));
@@ -131,7 +132,7 @@ private void configureItems() {
131132
object.put("value", itemLabelGenerator.apply(item));
132133
array.set(index.getAndIncrement(), object);
133134
});
134-
this.getElement().setPropertyJson("source", array);
135+
getElement().setPropertyJson("source", array);
135136
}
136137

137138
@Override
@@ -228,7 +229,7 @@ public String getAllowedPattern() {
228229
}
229230

230231
public void setAllowAdditionalItems(boolean allowAdditionalItems) {
231-
this.getElement().setProperty("additionalItems", allowAdditionalItems);
232+
getElement().setProperty("additionalItems", allowAdditionalItems);
232233
}
233234

234235
public boolean isAllowAdditionalItems() {
@@ -245,8 +246,7 @@ public static class ChipRemovedEvent<T> extends ComponentEvent<ChipField<T>> {
245246

246247
private final String chipLabel;
247248

248-
public ChipRemovedEvent(ChipField<T> source, boolean fromClient,
249-
@EventData(CHIP_LABEL) String chipLabel) {
249+
public ChipRemovedEvent(ChipField<T> source, boolean fromClient, @EventData(CHIP_LABEL) String chipLabel) {
250250
super(source, fromClient);
251251
this.chipLabel = chipLabel;
252252
}
@@ -261,8 +261,7 @@ public static class ChipCreatedEvent<T> extends ComponentEvent<ChipField<T>> {
261261

262262
private final String chipLabel;
263263

264-
public ChipCreatedEvent(ChipField<T> source, boolean fromClient,
265-
@EventData(CHIP_LABEL) String chipLabel) {
264+
public ChipCreatedEvent(ChipField<T> source, boolean fromClient, @EventData(CHIP_LABEL) String chipLabel) {
266265
super(source, fromClient);
267266
this.chipLabel = chipLabel;
268267
}
@@ -302,21 +301,21 @@ public void setDataProvider(DataProvider<T, ?> dataProvider) {
302301

303302
public void addSelectedItem(T newItem) {
304303
if (availableItems.fetch(new Query<>()).noneMatch(item -> item.equals(newItem)) && !isAllowAdditionalItems()) {
305-
throw new UnsupportedOperationException("Cannot select item '" + newItem
306-
+ "', because is not present in DataProvider, and adding new items is not permitted.");
304+
throw new UnsupportedOperationException(
305+
"Cannot select item '" + newItem + "', because is not present in DataProvider, and adding new items is not permitted.");
307306
} else {
308-
this.getValue().add(newItem);
307+
getValue().add(newItem);
309308
this.selectedItems.put(itemLabelGenerator.apply(newItem), newItem);
310309
this.appendClientChipWithoutEvent(itemLabelGenerator.apply(newItem));
311-
this.fireEvent(new ChipCreatedEvent<>(this, false, itemLabelGenerator.apply(newItem)));
310+
fireEvent(new ChipCreatedEvent<>(this, false, itemLabelGenerator.apply(newItem)));
312311
}
313312
}
314313

315314
public void removeSelectedItem(T itemToRemove) {
316-
this.getValue().remove(itemToRemove);
315+
getValue().remove(itemToRemove);
317316
this.selectedItems.remove(itemLabelGenerator.apply(itemToRemove), itemToRemove);
318317
this.removeClientChipWithoutEvent(itemLabelGenerator.apply(itemToRemove));
319-
this.fireEvent(new ChipRemovedEvent<>(this, false, itemLabelGenerator.apply(itemToRemove)));
318+
fireEvent(new ChipRemovedEvent<>(this, false, itemLabelGenerator.apply(itemToRemove)));
320319
}
321320

322321
@DomEvent("chip-clicked")

0 commit comments

Comments
 (0)