Crossfire JXClient, Trunk  R20561
StartingMapBuilder.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.server.crossfire;
23 
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
36 public class StartingMapBuilder {
37 
42  @Nullable
43  private byte[] archName;
44 
49  @Nullable
50  private String name;
51 
56  @Nullable
57  private String description;
58 
62  @NotNull
63  private final Collection<StartingMap> startingMaps = new ArrayList<>();
64 
70  public void setArchName(@NotNull final byte[] archName) {
72  this.archName = archName.clone();
73  name = null;
74  description = null;
75  }
76 
82  public void setName(@NotNull final String name) {
83  if (archName == null) {
84  System.err.println("missing archetype name for name '"+name+"' in startingmap block");
85  return;
86  }
87  if (this.name != null) {
88  System.err.println("duplicate name '"+name+"' in startingmap block; previous name was '"+this.name+"'");
89  return;
90  }
91  this.name = name;
92  }
93 
99  public void setDescription(@NotNull final String description) {
100  if (archName == null) {
101  System.err.println("missing archetype name for description '"+description+"' in startingmap block");
102  return;
103  }
104  if (this.description != null) {
105  System.err.println("duplicate description '"+description+"' in startingmap block; previous description was '"+this.description+"'");
106  return;
107  }
108  this.description = description;
109  }
110 
115  @NotNull
116  public Collection<StartingMap> finish() {
117  addStartingMap();
118  return Collections.unmodifiableCollection(startingMaps);
119  }
120 
125  private void addStartingMap() {
126  if (archName == null) {
127  return;
128  }
129 
130  startingMaps.add(new StartingMap(archName, name == null ? "" : name, description == null ? "" : description));
131  archName = null;
132  name = null;
133  description = null;
134  }
135 
136 }
Builder for StartingMap instances while parsing a "replyinfo startingmap" response packet...
One possible starting map for character creation.
void addStartingMap()
Adds a new StartingMap entry to startingMaps for the current entry.
void setArchName(@NotNull final byte[] archName)
Starts a new starting map entry.
void setName(@NotNull final String name)
Sets the name of the current entry.
final Collection< StartingMap > startingMaps
The StartingMap entries parsed so far.
void setDescription(@NotNull final String description)
Sets the description of the current entry.
byte [] archName
The archetype name of the current entry.