mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
PL-10332 Use Java 8 Optional instead of Guava
This commit is contained in:
parent
f2bf0e5712
commit
73e50f41a9
@ -17,7 +17,6 @@
|
||||
|
||||
package com.haulmont.cuba.desktop.settings;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.haulmont.cuba.core.global.ClientType;
|
||||
import com.haulmont.cuba.desktop.App;
|
||||
import com.haulmont.cuba.desktop.ApplicationSession;
|
||||
@ -29,11 +28,11 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* User settings provider for desktop application. Caches settings in desktop app per user session.
|
||||
*
|
||||
*/
|
||||
@Component(SettingsClient.NAME)
|
||||
public class DesktopSettingsClient implements SettingsClient {
|
||||
@ -46,24 +45,24 @@ public class DesktopSettingsClient implements SettingsClient {
|
||||
Map<String, Optional<String>> settings = getCache();
|
||||
Optional<String> cached = settings.get(name);
|
||||
if (cached != null) {
|
||||
return cached.orNull();
|
||||
return cached.orElse(null);
|
||||
}
|
||||
|
||||
String setting = userSettingService.loadSetting(ClientType.DESKTOP, name);
|
||||
settings.put(name, Optional.fromNullable(setting));
|
||||
settings.put(name, Optional.ofNullable(setting));
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSetting(String name, @Nullable String value) {
|
||||
getCache().put(name, Optional.fromNullable(value));
|
||||
getCache().put(name, Optional.ofNullable(value));
|
||||
userSettingService.saveSetting(ClientType.DESKTOP, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSettings(String name) {
|
||||
getCache().put(name, Optional.absent());
|
||||
getCache().put(name, Optional.empty());
|
||||
userSettingService.deleteSettings(ClientType.DESKTOP, name);
|
||||
}
|
||||
|
||||
|
@ -17,18 +17,18 @@
|
||||
|
||||
package com.haulmont.cuba.gui.app.security.ds;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl;
|
||||
import com.haulmont.cuba.security.entity.Permission;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class RestorablePermissionDatasource extends CollectionDatasourceImpl<Permission, UUID> {
|
||||
|
||||
public Permission findRemovedEntity(Predicate<Permission> predicate) {
|
||||
for (Object item : itemsToDelete) {
|
||||
Permission permission = (Permission) item;
|
||||
if (predicate.apply(permission))
|
||||
if (predicate.test(permission))
|
||||
return permission;
|
||||
}
|
||||
return null;
|
||||
|
@ -17,16 +17,16 @@
|
||||
|
||||
package com.haulmont.cuba.web.settings;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.haulmont.cuba.core.global.ClientType;
|
||||
import com.haulmont.cuba.gui.settings.SettingsClient;
|
||||
import com.haulmont.cuba.security.app.UserSettingService;
|
||||
import com.vaadin.server.VaadinSession;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@ -44,24 +44,24 @@ public class WebSettingsClient implements SettingsClient {
|
||||
//noinspection Guava
|
||||
Optional<String> cached = settings.get(name);
|
||||
if (cached != null) {
|
||||
return cached.orNull();
|
||||
return cached.orElse(null);
|
||||
}
|
||||
|
||||
String setting = userSettingService.loadSetting(ClientType.WEB, name);
|
||||
settings.put(name, Optional.fromNullable(setting));
|
||||
settings.put(name, Optional.ofNullable(setting));
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSetting(String name, @Nullable String value) {
|
||||
getCache().put(name, Optional.fromNullable(value));
|
||||
getCache().put(name, Optional.ofNullable(value));
|
||||
userSettingService.saveSetting(ClientType.WEB, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSettings(String name) {
|
||||
getCache().put(name, Optional.absent());
|
||||
getCache().put(name, Optional.empty());
|
||||
userSettingService.deleteSettings(ClientType.WEB, name);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user