001package ball.game.scrabble;
002/*-
003 * ##########################################################################
004 * Game Applications and Utilities
005 * $Id: Tile.java 5285 2020-02-05 04:23:21Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-game/trunk/src/main/java/ball/game/scrabble/Tile.java $
007 * %%
008 * Copyright (C) 2010 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import java.beans.ConstructorProperties;
024import java.util.Collection;
025
026import static java.util.stream.Collectors.joining;
027
028/**
029 * Scrabble {@link Tile}.
030 *
031 * {@bean.info}
032 *
033 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
034 * @version $Revision: 5285 $
035 */
036public class Tile {
037
038    /**
039     * {@link #BLANK} = {@value #BLANK}
040     */
041    public static final char BLANK = '_';
042
043    private final char letter;
044    private final int points;
045
046    /**
047     * Sole constructor.
048     *
049     * @param   letter          The {@link Tile} letter value.
050     * @param   points          The {@link Tile} points value.
051     */
052    @ConstructorProperties({ "letter", "points" })
053    public Tile(char letter, int points) {
054        this.letter = letter;
055        this.points = points;
056    }
057
058    public char getLetter() { return letter; }
059    public int getPoints() { return points; }
060    public boolean isBlank() { return (getLetter() == BLANK); }
061
062    @Override
063    public String toString() { return String.valueOf(letter); }
064
065    /**
066     * Static method to return the {@link String} represented by the
067     * {@link Collection} of {@link Tile}s.
068     *
069     * @param   collection      The {@link Collection} of {@link Tile}s.
070     *
071     * @return  The {@link String} representation.
072     */
073    public static String toString(Collection<Tile> collection) {
074        return collection.stream().map(t -> t.toString()).collect(joining());
075    }
076}