Gridarta Editor
MapFile.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapmodel;
21 
22 import java.io.File;
23 import java.io.Serializable;
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.annotations.Nullable;
26 
31 public class MapFile implements Serializable {
32 
36  private static final long serialVersionUID = 1L;
37 
41  @NotNull
42  private final File mapsDir;
43 
47  @NotNull
48  private final AbsoluteMapPath mapPath;
49 
54  public MapFile(@NotNull final File mapsDir) {
55  this.mapsDir = mapsDir;
56  mapPath = new AbsoluteMapPath();
57  }
58 
64  public MapFile(@NotNull final MapFile parent, @NotNull final String name) {
65  mapsDir = parent.mapsDir;
66  mapPath = new AbsoluteMapPath(parent.mapPath, name);
67  }
68 
74  public MapFile(@NotNull final MapFile parent, @NotNull final MapPath mapPath) {
75  mapsDir = parent.mapsDir;
76  this.mapPath = MapPathUtils.append(parent.mapPath, mapPath);
77  }
78 
83  @NotNull
84  public File getMapsDir() {
85  return mapsDir;
86  }
87 
92  @NotNull
94  return mapPath;
95  }
96 
101  @NotNull
102  public File getFile() {
103  return new File(mapsDir, mapPath.getPath());
104  }
105 
113  @NotNull
114  public MapPath getRelativeMapFileTo(@NotNull final MapFile mapFile) throws DifferentMapBaseException {
115  if (!mapsDir.equals(mapFile.mapsDir)) {
116  throw new DifferentMapBaseException(this, mapFile);
117  }
118  return mapFile.mapPath.getRelativeMapPathFrom(mapPath);
119  }
120 
121  @Override
122  public boolean equals(@Nullable final Object obj) {
123  if (obj == null || getClass() != obj.getClass()) {
124  return false;
125  }
126  final MapFile mapFile = (MapFile) obj;
127  return mapsDir.equals(mapFile.mapsDir) && mapPath.equals(mapFile.mapPath);
128  }
129 
130  @Override
131  public int hashCode() {
132  return mapsDir.hashCode() + mapPath.hashCode();
133  }
134 
135  @Override
136  public String toString() {
137  return mapPath.toString();
138  }
139 
140 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.getPath
String getPath()
Returns the map path information.
Definition: AbsoluteMapPath.java:80
net.sf.gridarta.model.mapmodel.AbsoluteMapPath
A MapPath that is absolute, that is, it starts with a "/".
Definition: AbsoluteMapPath.java:29
net.sf.gridarta.model.mapmodel.MapFile.getRelativeMapFileTo
MapPath getRelativeMapFileTo(@NotNull final MapFile mapFile)
Returns a map path of an another map file relative to this map file.
Definition: MapFile.java:114
net.sf.gridarta.model.mapmodel.DifferentMapBaseException
Thrown if two map files are within different map directories.
Definition: DifferentMapBaseException.java:28
net.sf.gridarta.model.mapmodel.MapFile.equals
boolean equals(@Nullable final Object obj)
Definition: MapFile.java:122
net.sf.gridarta.model.mapmodel.MapPathUtils
Utility class for MapPath related functions.
Definition: MapPathUtils.java:28
net.sf.gridarta.model.mapmodel.MapFile.MapFile
MapFile(@NotNull final File mapsDir)
Creates a new instance for the maps directory.
Definition: MapFile.java:54
net.sf.gridarta.model.mapmodel.MapFile.getMapPath
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.hashCode
int hashCode()
Definition: AbsoluteMapPath.java:112
net.sf.gridarta.model.mapmodel.MapPathUtils.append
static AbsoluteMapPath append(@NotNull final AbsoluteMapPath baseMapPath, @NotNull final MapPath mapPath)
Appends a map path to another map path.
Definition: MapPathUtils.java:85
net.sf.gridarta.model.mapmodel.MapFile.getMapsDir
File getMapsDir()
Returns the base directory this map file is part of.
Definition: MapFile.java:84
net.sf.gridarta.model.mapmodel.MapFile.getFile
File getFile()
Returns a File for this map file.
Definition: MapFile.java:102
net.sf.gridarta.model.mapmodel.MapFile.mapsDir
final File mapsDir
The maps directory this map file is part of.
Definition: MapFile.java:42
net.sf.gridarta.model.mapmodel.MapPath
Represents a maps directory local map path.
Definition: MapPath.java:31
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.toString
String toString()
Definition: AbsoluteMapPath.java:117
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.model.mapmodel.MapFile.MapFile
MapFile(@NotNull final MapFile parent, @NotNull final MapPath mapPath)
Creates a new instance.
Definition: MapFile.java:74
net.sf.gridarta.model.mapmodel.MapFile.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: MapFile.java:36
net.sf.gridarta.model.mapmodel.MapFile.toString
String toString()
Definition: MapFile.java:136
net.sf.gridarta.model.mapmodel.MapFile.hashCode
int hashCode()
Definition: MapFile.java:131
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.equals
boolean equals(@Nullable final Object obj)
Definition: AbsoluteMapPath.java:103
net.sf.gridarta.model.mapmodel.MapFile.MapFile
MapFile(@NotNull final MapFile parent, @NotNull final String name)
Creates a new instance for a child of a parent map file.
Definition: MapFile.java:64
net.sf.gridarta.model.mapmodel.MapFile.mapPath
final AbsoluteMapPath mapPath
The absolute map path within mapsDir.
Definition: MapFile.java:48