formatting work

This commit is contained in:
Eugen Paraschiv
2018-03-04 17:53:14 +02:00
parent 5fd8e4293e
commit 8d633d6402
48 changed files with 101 additions and 248 deletions
@@ -9,8 +9,7 @@ public class AttrListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
servletContextEvent.getServletContext()
.setAttribute("servlet-context-attr", "test");
servletContextEvent.getServletContext().setAttribute("servlet-context-attr", "test");
System.out.println("context init");
}
@@ -16,8 +16,7 @@ public class EchoServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
Path path = File.createTempFile("echo", "tmp")
.toPath();
Path path = File.createTempFile("echo", "tmp").toPath();
Files.copy(request.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
Files.copy(path, response.getOutputStream());
Files.delete(path);
@@ -18,8 +18,7 @@ public class HelloFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletResponse.getOutputStream()
.print(filterConfig.getInitParameter("msg"));
servletResponse.getOutputStream().print(filterConfig.getInitParameter("msg"));
filterChain.doFilter(servletRequest, servletResponse);
}
@@ -21,9 +21,7 @@ public class HelloServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
response.getOutputStream()
.write(servletConfig.getInitParameter("msg")
.getBytes());
response.getOutputStream().write(servletConfig.getInitParameter("msg").getBytes());
} catch (IOException e) {
e.printStackTrace();
}
@@ -98,13 +98,8 @@ public class MySQLAutoconfiguration {
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionMessage.Builder message = ConditionMessage.forCondition("Hibernate");
return Arrays.stream(CLASS_NAMES)
.filter(className -> ClassUtils.isPresent(className, context.getClassLoader()))
.map(className -> ConditionOutcome.match(message.found("class")
.items(Style.NORMAL, className)))
.findAny()
.orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("class", "classes")
.items(Style.NORMAL, Arrays.asList(CLASS_NAMES))));
return Arrays.stream(CLASS_NAMES).filter(className -> ClassUtils.isPresent(className, context.getClassLoader())).map(className -> ConditionOutcome.match(message.found("class").items(Style.NORMAL, className))).findAny()
.orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("class", "classes").items(Style.NORMAL, Arrays.asList(CLASS_NAMES))));
}
}
@@ -28,9 +28,7 @@ public class ContactInfoValidator implements ConstraintValidator<ContactInfo, St
if (StringUtils.isEmptyOrWhitespace(expressionType)) {
LOG.error("Contact info type missing!");
} else {
pattern = expressionRepository.findOne(expressionType)
.map(ContactInfoExpression::getPattern)
.orElse("");
pattern = expressionRepository.findOne(expressionType).map(ContactInfoExpression::getPattern).orElse("");
}
}
@@ -18,10 +18,7 @@ public class PersistenceConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2)
.addScript("schema-expressions.sql")
.addScript("data-expressions.sql")
.build();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).addScript("schema-expressions.sql").addScript("data-expressions.sql").build();
return db;
}
}
@@ -12,15 +12,11 @@ public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnaly
}
private String getDescription(BeanNotOfRequiredTypeException ex) {
return String.format("The bean %s could not be injected as %s because it is of type %s", ex.getBeanName(), ex.getRequiredType()
.getName(),
ex.getActualType()
.getName());
return String.format("The bean %s could not be injected as %s because it is of type %s", ex.getBeanName(), ex.getRequiredType().getName(), ex.getActualType().getName());
}
private String getAction(BeanNotOfRequiredTypeException ex) {
return String.format("Consider creating a bean with name %s of type %s", ex.getBeanName(), ex.getRequiredType()
.getName());
return String.format("Consider creating a bean with name %s of type %s", ex.getBeanName(), ex.getRequiredType().getName());
}
}
@@ -11,8 +11,6 @@ public class AuthorDao {
}
public Optional<Author> getAuthor(String id) {
return authors.stream()
.filter(author -> id.equals(author.getId()))
.findFirst();
return authors.stream().filter(author -> id.equals(author.getId())).findFirst();
}
}
@@ -13,8 +13,7 @@ public class Mutation implements GraphQLMutationResolver {
public Post writePost(String title, String text, String category, String author) {
Post post = new Post();
post.setId(UUID.randomUUID()
.toString());
post.setId(UUID.randomUUID().toString());
post.setTitle(title);
post.setText(text);
post.setCategory(category);
@@ -11,16 +11,11 @@ public class PostDao {
}
public List<Post> getRecentPosts(int count, int offset) {
return posts.stream()
.skip(offset)
.limit(count)
.collect(Collectors.toList());
return posts.stream().skip(offset).limit(count).collect(Collectors.toList());
}
public List<Post> getAuthorPosts(String author) {
return posts.stream()
.filter(post -> author.equals(post.getAuthorId()))
.collect(Collectors.toList());
return posts.stream().filter(post -> author.equals(post.getAuthorId())).collect(Collectors.toList());
}
public void savePost(Post post) {
@@ -31,6 +31,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
registry.addInterceptor(localeChangeInterceptor());
}
}
@@ -15,18 +15,17 @@ public class QueryController {
private static int REQUEST_COUNTER = 0;
@GetMapping("/reqcount")
public int getReqCount(){
public int getReqCount() {
return REQUEST_COUNTER;
}
@GetMapping("/{code}")
public String getStockPrice(@PathVariable String code){
public String getStockPrice(@PathVariable String code) {
REQUEST_COUNTER++;
if("BTC".equalsIgnoreCase(code))
if ("BTC".equalsIgnoreCase(code))
return "10000";
else return "N/A";
else
return "N/A";
}
}
@@ -28,11 +28,7 @@ public class WebMvcConfigure extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/")
.setCachePeriod(3600)
.resourceChain(true)
.addResolver(new PathResourceResolver());
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
}
@Bean
@@ -13,7 +13,6 @@ public class AnnotationServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/annotationservlet.jsp")
.forward(request, response);
request.getRequestDispatcher("/annotationservlet.jsp").forward(request, response);
}
}
@@ -14,12 +14,10 @@ public class FeaturesAspect {
@Around(value = "@within(featureAssociation) || @annotation(featureAssociation)")
public Object checkAspect(ProceedingJoinPoint joinPoint, FeatureAssociation featureAssociation) throws Throwable {
if (featureAssociation.value()
.isActive()) {
if (featureAssociation.value().isActive()) {
return joinPoint.proceed();
} else {
LOG.info("Feature " + featureAssociation.value()
.name() + " is not enabled!");
LOG.info("Feature " + featureAssociation.value().name() + " is not enabled!");
return null;
}
}
@@ -17,8 +17,7 @@ public enum MyFeatures implements Feature {
EMPLOYEE_MANAGEMENT_FEATURE;
public boolean isActive() {
return FeatureContext.getFeatureManager()
.isActive(this);
return FeatureContext.getFeatureManager().isActive(this);
}
}
@@ -18,7 +18,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableJpaRepositories(basePackages = { "org.baeldung.boot.repository", "org.baeldung.boot.boottest","org.baeldung.repository" })
@EnableJpaRepositories(basePackages = { "org.baeldung.boot.repository", "org.baeldung.boot.boottest", "org.baeldung.repository" })
@PropertySource("classpath:persistence-generic-entity.properties")
@EnableTransactionManagement
public class H2JpaConfig {
@@ -39,31 +39,21 @@ public class GenericEntityController {
@RequestMapping("/entity/findby/{id}")
public GenericEntity findById(@PathVariable Long id) {
return entityList.stream()
.filter(entity -> entity.getId()
.equals(id))
.findFirst()
.get();
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
}
@GetMapping("/entity/findbydate/{date}")
public GenericEntity findByDate(@PathVariable("date") LocalDateTime date) {
return entityList.stream()
.findFirst()
.get();
return entityList.stream().findFirst().get();
}
@GetMapping("/entity/findbymode/{mode}")
public GenericEntity findByEnum(@PathVariable("mode") Modes mode) {
return entityList.stream()
.findFirst()
.get();
return entityList.stream().findFirst().get();
}
@GetMapping("/entity/findbyversion")
public ResponseEntity findByVersion(@Version String version) {
return version != null ? new ResponseEntity(entityList.stream()
.findFirst()
.get(), HttpStatus.OK) : new ResponseEntity(HttpStatus.NOT_FOUND);
return version != null ? new ResponseEntity(entityList.stream().findFirst().get(), HttpStatus.OK) : new ResponseEntity(HttpStatus.NOT_FOUND);
}
}
@@ -9,23 +9,20 @@ import java.util.Set;
public class GenericBigDecimalConverter implements GenericConverter {
@Override
public Set<ConvertiblePair> getConvertibleTypes () {
public Set<ConvertiblePair> getConvertibleTypes() {
ConvertiblePair[] pairs = new ConvertiblePair[] {
new ConvertiblePair(Number.class, BigDecimal.class),
new ConvertiblePair(String.class, BigDecimal.class)};
ConvertiblePair[] pairs = new ConvertiblePair[] { new ConvertiblePair(Number.class, BigDecimal.class), new ConvertiblePair(String.class, BigDecimal.class) };
return ImmutableSet.copyOf(pairs);
}
@Override
public Object convert (Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (sourceType.getType() == BigDecimal.class) {
return source;
}
if(sourceType.getType() == String.class) {
if (sourceType.getType() == String.class) {
String number = (String) source;
return new BigDecimal(number);
} else {
@@ -1,6 +1,5 @@
package org.baeldung.boot.converter;
import com.baeldung.toggle.Employee;
import org.springframework.core.convert.converter.Converter;
@@ -36,8 +36,7 @@ public class UserCombinedSerializer {
public static class UserJsonDeserializer extends JsonDeserializer<User> {
@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
TreeNode treeNode = jsonParser.getCodec()
.readTree(jsonParser);
TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
TextNode favoriteColor = (TextNode) treeNode.get("favoriteColor");
return new User(Color.web(favoriteColor.asText()));
}
@@ -15,8 +15,7 @@ import java.io.IOException;
public class UserJsonDeserializer extends JsonDeserializer<User> {
@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
TreeNode treeNode = jsonParser.getCodec()
.readTree(jsonParser);
TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
TextNode favoriteColor = (TextNode) treeNode.get("favoriteColor");
return new User(Color.web(favoriteColor.asText()));
}
@@ -14,8 +14,7 @@ public class MonitoringConfig {
@Bean
public JmxReporter jmxReporter() {
JmxReporter reporter = JmxReporter.forRegistry(registry)
.build();
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
reporter.start();
return reporter;
}
@@ -10,13 +10,9 @@ public class MyHealthCheck implements HealthIndicator {
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down()
.withDetail("Error Code", errorCode)
.withDetail("Description", "You custom MyHealthCheck endpoint is down")
.build();
return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build();
}
return Health.up()
.build();
return Health.up().build();
}
public int check() {
@@ -21,7 +21,7 @@ import java.util.concurrent.Executors;
@RestController
@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class)
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources","org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config"})
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config" })
public class SpringBootApplication {
private static ApplicationContext applicationContext;
@@ -16,8 +16,7 @@ public class LoginServiceImpl implements LoginService {
public boolean login(String userName, char[] password) {
boolean success;
if (userName.equals("admin") && "secret".toCharArray()
.equals(password)) {
if (userName.equals("admin") && "secret".toCharArray().equals(password)) {
counterService.increment("counter.login.success");
success = true;
} else {
@@ -14,14 +14,12 @@ public class FooRepositoryImpl implements FooRepository {
@Override
public void save(Foo foo) {
sessionFactory.getCurrentSession()
.saveOrUpdate(foo);
sessionFactory.getCurrentSession().saveOrUpdate(foo);
}
@Override
public Foo get(Integer id) {
return sessionFactory.getCurrentSession()
.get(Foo.class, id);
return sessionFactory.getCurrentSession().get(Foo.class, id);
}
}