001 /////////////////////////////////////////////////////////////////////////////// 002 // Copyright (c) 2006, Frank S. Nestel, All Rights Reserved. 003 // 004 // This library is free software; you can redistribute it and/or 005 // modify it under the terms of the GNU Lesser General Public 006 // License as published by the Free Software Foundation; either 007 // version 2.1 of the License, or (at your option) any later version. 008 // 009 // This library is distributed in the hope that it will be useful, 010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 // GNU General Public License for more details. 013 // 014 // You should have received a copy of the GNU Lesser General Public 015 // License along with this program; if not, write to the Free Software 016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 017 /////////////////////////////////////////////////////////////////////////////// 018 019 package de.spieleck.app.turn.splitting; 020 021 import java.io.IOException; 022 023 import de.spieleck.app.turn.SplittingMode; 024 import de.spieleck.app.turn.LineSource; 025 026 /** 027 * Abstract base for programming SplittingMode's. 028 * <br /> 029 * Also contains the static {@link #transposeSplit} API to 030 * convert Splittings from one format to another. 031 * 032 * <p><a href="$URL: https://svn.sourceforge.net/svnroot/jtourney/src/de/spieleck/app/turn/splitting/BaseSplitter.java $">$URL: https://svn.sourceforge.net/svnroot/jtourney/src/de/spieleck/app/turn/splitting/BaseSplitter.java $</a></p> 033 * 034 * @author Frank S. Nestel 035 * @author $Author: nestefan $ 036 * @version $Revision: 2 $ $Date: 2006-03-20 14:33:27 +0100 (Mo, 20 Mrz 2006) $ $Author: nestefan $ 037 */ 038 public abstract class BaseSplitter 039 implements SplittingMode 040 { 041 public void init(LineSource ls) 042 throws IOException 043 { 044 } 045 046 public String toString() 047 { 048 return getClass().getSimpleName(); 049 } 050 051 /** 052 * "Transposes" a split from the counted to the seated format. 053 * 054 * That is [0,2,1] becomes [1,1,2]. 055 * That is [0,0,2,3] becomes [2,2,3,3,3]. 056 * That is [0,0,0,0,2,6] becomes [4,4,5,5,5,5,5,5]. 057 */ 058 public static int[] transposeSplit(int[] split) 059 { 060 int sum = 0; 061 for(int i = 0; i < split.length; i++) 062 sum += split[i]; 063 int[] res = new int[sum]; 064 int j = 0; 065 for(int i = 0; i < split.length; i++) 066 for(int k = 0; k < split[i]; k++) 067 res[j++] = i; 068 return res; 069 } 070 }