List of usage examples for java.util.function Predicate Predicate
Predicate
From source file:sample.jsp.SampleJspApplication.java
private Predicate<String> jspZipEntry() { return new Predicate<String>() { @Override/*w w w .j a v a 2 s . c o m*/ public boolean test(String zipEntry) { return jspEntryMatcher.matcher(zipEntry).matches(); } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with an IMO outside the given list. *//*from w w w. j a va2s . c o m*/ public Predicate<AisPacket> filterOnTargetImo(Integer[] imos) { final int[] list = ArrayUtils.toPrimitive(imos); Arrays.sort(list); return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final int imo = getImo(mmsi); // Extract IMO no. - if we know it return imo < 0 ? false : Arrays.binarySearch(list, imo) >= 0; } public String toString() { return "imo in " + skipBrackets(Arrays.toString(list)); } }; }
From source file:com.properned.application.SystemController.java
public void initialize() { logger.info("Initialize System controller"); localeButton.disableProperty().bind(multiLanguageProperties.isLoadedProperty().not()); saveButton.disableProperty().bind(multiLanguageProperties.isDirtyProperty().not() .or(multiLanguageProperties.isLoadedProperty().not())); Stage primaryStage = Properned.getInstance().getPrimaryStage(); primaryStage.titleProperty()/*from w ww .j a va2 s . co m*/ .bind(multiLanguageProperties.baseNameProperty() .concat(Bindings.when(multiLanguageProperties.isLoadedProperty()) .then(new SimpleStringProperty(" (") .concat(multiLanguageProperties.parentDirectoryPathProperty()).concat(")")) .otherwise("")) .concat(Bindings.when(multiLanguageProperties.isDirtyProperty()).then(" *").otherwise(""))); FilteredList<String> filteredList = new FilteredList<>(multiLanguageProperties.getListMessageKey(), new Predicate<String>() { @Override public boolean test(String t) { String filter = filterText.getText(); if (filter == null || filter.equals("")) { return true; } return t.contains(filter); } }); SortedList<String> sortedList = new SortedList<>(filteredList, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); messageKeyList.setItems(sortedList); filterText.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { // Filter the list filteredList.setPredicate(new Predicate<String>() { @Override public boolean test(String t) { String filter = filterText.getText(); if (filter == null || filter.equals("")) { return true; } return t.contains(filter); } }); // check the add button disabled status if (isKeyCanBeAdded(newValue)) { addButton.setDisable(false); } else { addButton.setDisable(true); } } }); ChangeListener<String> changeMessageListener = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { logger.info("Message key selection changed : " + newValue); valueList.setItems(FXCollections.observableArrayList()); valueList.setItems(FXCollections .observableArrayList(multiLanguageProperties.getMapPropertiesByLocale().keySet())); } }; messageKeyList.getSelectionModel().selectedItemProperty().addListener(changeMessageListener); messageKeyList.setCellFactory(c -> new MessageKeyListCell(multiLanguageProperties)); valueList.setCellFactory(c -> new ValueListCell(multiLanguageProperties, messageKeyList)); filterText.setOnKeyReleased(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.DOWN) { messageKeyList.requestFocus(); event.consume(); } else if (event.getCode() == KeyCode.ENTER) { addKey(); event.consume(); } } }); }
From source file:com.thoughtworks.go.server.service.plugins.builder.DefaultPluginInfoBuilder.java
public NewPluginInfo pluginInfoFor(String pluginId) { return builders.values().stream().map(new Function<NewPluginInfoBuilder, NewPluginInfo>() { @Override/*from w w w . j a va 2s . c o m*/ public NewPluginInfo apply(NewPluginInfoBuilder builder) { return builder.pluginInfoFor(pluginId); } }).filter(new Predicate<NewPluginInfo>() { @Override public boolean test(NewPluginInfo obj) { return Objects.nonNull(obj); } }).findFirst().orElse(null); }
From source file:org.forgerock.openig.migrate.action.InlineDeclarationsAction.java
private Predicate<? super ObjectModel> inlined() { return new Predicate<ObjectModel>() { @Override// w w w . ja v a2 s . c o m public boolean test(final ObjectModel objectModel) { return objectModel.isInlined(); } }; }
From source file:com.thoughtworks.go.server.service.RailsAssetsServiceTest.java
@Test public void shouldHaveAssetsAsTheSerializedNameForAssetsMapInRailsAssetsManifest_ThisIsRequiredSinceManifestFileGeneratedBySprocketsHasAMapOfAssetsWhichThisServiceNeedsAccessTo() { List<Field> fields = new ArrayList<>( Arrays.asList(RailsAssetsService.RailsAssetsManifest.class.getDeclaredFields())); List<Field> fieldsAnnotatedWithSerializedNameAsAssets = fields.stream().filter(new Predicate<Field>() { @Override/*from w w w . j a va2s . c o m*/ public boolean test(Field field) { if (field.isAnnotationPresent(SerializedName.class)) { SerializedName annotation = field.getAnnotation(SerializedName.class); if (annotation.value().equals("assets")) { return true; } return false; } return false; } }).collect(Collectors.toList()); assertThat("Expected a field annotated with SerializedName 'assets'", fieldsAnnotatedWithSerializedNameAsAssets.isEmpty(), is(false)); assertThat(fieldsAnnotatedWithSerializedNameAsAssets.size(), is(1)); assertThat(fieldsAnnotatedWithSerializedNameAsAssets.get(0).getType().getCanonicalName(), is(HashMap.class.getCanonicalName())); }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with an IMO no. different to 'imo'. * /*from w w w . jav a 2s . c o m*/ * @param operator * @param rhsShiptype * @return */ public Predicate<AisPacket> filterOnTargetShiptype(final CompareToOperator operator, Integer rhsShiptype) { final int shiptype = rhsShiptype; return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final int lhsShiptype = getShiptype(mmsi); // Extract shiptype - if we know it return lhsShiptype < 0 ? false : compare(lhsShiptype, shiptype, operator); } public String toString() { return "shiptype = " + shiptype; } }; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with an shiptype outside the given range. *//* w ww. j ava2s .c o m*/ public Predicate<AisPacket> filterOnTargetShiptype(final int min, final int max) { return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final int shiptype = getShiptype(mmsi); // Extract IMO no. - if we know it return shiptype < 0 ? false : inRange(min, max, shiptype); } public String toString() { return "imo in " + min + ".." + max; } }; }
From source file:com.microsoft.azure.utility.compute.VMImagesTests.java
@Test public void testVMImageListPublisher() throws Exception { VirtualMachineImageResourceList vmImages = computeManagementClient.getVirtualMachineImagesOperations() .listPublishers(parameters); Assert.assertTrue("image count", vmImages.getResources().size() > 0); Assert.assertTrue("list publishers contain param publishers", vmImages.getResources().stream().anyMatch(new Predicate<VirtualMachineImageResource>() { @Override/*ww w. j a v a 2 s. co m*/ public boolean test(VirtualMachineImageResource virtualMachineImageResource) { return virtualMachineImageResource.getName() .equalsIgnoreCase(parameters.getPublisherName()); } })); }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with a ship type outside the given list. *//* ww w . j a v a 2 s. c o m*/ public Predicate<AisPacket> filterOnTargetShiptype(Integer[] shiptypes) { final int[] list = ArrayUtils.toPrimitive(shiptypes); Arrays.sort(list); return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final int shiptype = getShiptype(mmsi); // Extract shiptype no. - if we know it return shiptype < 0 ? false : Arrays.binarySearch(list, shiptype) >= 0; } public String toString() { return "shiptype in " + skipBrackets(Arrays.toString(list)); } }; }