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