Fix checkstyle violations in samples

This commit is contained in:
Phillip Webb
2018-05-25 15:57:29 -07:00
parent 4853477081
commit e69296d7d3
117 changed files with 453 additions and 482 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ public class DefaultEchoService implements EchoService {
private final String echoFormat;
public DefaultEchoService(String echoFormat) {
this.echoFormat = (echoFormat != null) ? echoFormat : "%s";
this.echoFormat = (echoFormat != null ? echoFormat : "%s");
}
@Override

View File

@@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -19,16 +18,16 @@ package samples.websocket.jetty.snake;
public class Location {
/**
* The X location.
*/
public int x;
/**
* The Y location.
*/
public int y;
public static final int GRID_SIZE = 10;
public static final int PLAYFIELD_HEIGHT = 480;
public static final int PLAYFIELD_WIDTH = 640;
public Location(int x, int y) {
this.x = x;
this.y = y;
@@ -37,13 +36,13 @@ public class Location {
public Location getAdjacentLocation(Direction direction) {
switch (direction) {
case NORTH:
return new Location(this.x, this.y - Location.GRID_SIZE);
return new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH:
return new Location(this.x, this.y + Location.GRID_SIZE);
return new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST:
return new Location(this.x + Location.GRID_SIZE, this.y);
return new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST:
return new Location(this.x - Location.GRID_SIZE, this.y);
return new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE:
// fall through
default:
@@ -59,16 +58,13 @@ public class Location {
if (o == null || getClass() != o.getClass()) {
return false;
}
Location location = (Location) o;
if (this.x != location.x) {
return false;
}
if (this.y != location.y) {
return false;
}
return true;
}

View File

@@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
/**
* Sets up the timer for the multi-player snake game WebSocket example.
*/
public class SnakeTimer {
public final class SnakeTimer {
private static final long TICK_DELAY = 100;
@@ -43,6 +42,9 @@ public class SnakeTimer {
private static Timer gameTimer = null;
private SnakeTimer() {
}
public static void addSnake(Snake snake) {
synchronized (MONITOR) {
if (snakes.isEmpty()) {

View File

@@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -20,16 +19,28 @@ package samples.websocket.jetty.snake;
import java.awt.Color;
import java.util.Random;
public class SnakeUtils {
public final class SnakeUtils {
/**
* The width of the playfield.
*/
public static final int PLAYFIELD_WIDTH = 640;
/**
* The height of the playfield.
*/
public static final int PLAYFIELD_HEIGHT = 480;
/**
* The grid size.
*/
public static final int GRID_SIZE = 10;
private static final Random random = new Random();
private SnakeUtils() {
}
public static String getRandomHexColor() {
float hue = random.nextFloat();
// sat between 0.1 and 0.3

View File

@@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -29,12 +28,6 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public class SnakeWebSocketHandler extends TextWebSocketHandler {
public static final int PLAYFIELD_WIDTH = 640;
public static final int PLAYFIELD_HEIGHT = 480;
public static final int GRID_SIZE = 10;
private static final AtomicInteger snakeIds = new AtomicInteger(0);
private static final Random random = new Random();
@@ -54,15 +47,15 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
}
public static Location getRandomLocation() {
int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH));
int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT));
int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH));
int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT));
return new Location(x, y);
}
private static int roundByGridSize(int value) {
value = value + (GRID_SIZE / 2);
value = value / GRID_SIZE;
value = value * GRID_SIZE;
value = value + (SnakeUtils.GRID_SIZE / 2);
value = value / SnakeUtils.GRID_SIZE;
value = value * SnakeUtils.GRID_SIZE;
return value;
}