mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-16 23:55:23 +01:00
Added support for RegionIndexFactories.
This commit is contained in:
parent
2a504ffbde
commit
cc9bbec1c9
@ -0,0 +1,31 @@
|
||||
// $Id$
|
||||
/*
|
||||
* This file is a part of WorldGuard.
|
||||
* Copyright (c) sk89q <http://www.sk89q.com>
|
||||
* Copyright (c) the WorldGuard team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.region.indices;
|
||||
|
||||
/**
|
||||
* Creates new {@link FlatIndex} instances.
|
||||
*/
|
||||
public class FlatIndexFactory implements RegionIndexFactory {
|
||||
|
||||
@Override
|
||||
public RegionIndex newIndex() {
|
||||
return new FlatIndex();
|
||||
}
|
||||
|
||||
}
|
@ -35,11 +35,22 @@
|
||||
*/
|
||||
public class PriorityRTreeIndex extends AbstractRegionIndex {
|
||||
|
||||
private static final int BRANCH_FACTOR = 30;
|
||||
private int branchFactor;
|
||||
private Map<String, ProtectedRegion> regions;
|
||||
private MBRConverter<ProtectedRegion> converter;
|
||||
private PRTree<ProtectedRegion> tree;
|
||||
|
||||
private Map<String, ProtectedRegion> regions = new TreeMap<String, ProtectedRegion>();
|
||||
private MBRConverter<ProtectedRegion> converter = new ProtectedRegionMBRConverter();
|
||||
private PRTree<ProtectedRegion> tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||
/**
|
||||
* Construct a new priority R-tree index with a given branch factor.
|
||||
*
|
||||
* @param branchFactor branch factor
|
||||
*/
|
||||
public PriorityRTreeIndex(int branchFactor) {
|
||||
this.branchFactor = branchFactor;
|
||||
regions = new TreeMap<String, ProtectedRegion>();
|
||||
converter = new ProtectedRegionMBRConverter();
|
||||
tree = new PRTree<ProtectedRegion>(converter, branchFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(ProtectedRegion... region) {
|
||||
@ -47,7 +58,7 @@ public synchronized void add(ProtectedRegion... region) {
|
||||
for (ProtectedRegion r : region) {
|
||||
regions.put(normalizeId(r.getId()), r);
|
||||
}
|
||||
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||
tree = new PRTree<ProtectedRegion>(converter, branchFactor);
|
||||
tree.load(regions.values());
|
||||
}
|
||||
|
||||
@ -57,7 +68,7 @@ public synchronized void remove(String... id) {
|
||||
for (String i : id) {
|
||||
regions.remove(normalizeId(i));
|
||||
}
|
||||
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
|
||||
tree = new PRTree<ProtectedRegion>(converter, branchFactor);
|
||||
tree.load(regions.values());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
// $Id$
|
||||
/*
|
||||
* This file is a part of WorldGuard.
|
||||
* Copyright (c) sk89q <http://www.sk89q.com>
|
||||
* Copyright (c) the WorldGuard team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.region.indices;
|
||||
|
||||
/**
|
||||
* Creates new {@link PriorityRTreeIndex} instances.
|
||||
*/
|
||||
public class PriorityRTreeIndexFactory implements RegionIndexFactory {
|
||||
|
||||
private int branchFactor = 30;
|
||||
|
||||
/**
|
||||
* Construct a new {@link PriorityRTreeIndex} factory with a branch factor of 30.
|
||||
*/
|
||||
public PriorityRTreeIndexFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link PriorityRTreeIndex} factory with a given branch factor.
|
||||
*
|
||||
* @param branchFactor branch factor
|
||||
*/
|
||||
public PriorityRTreeIndexFactory(int branchFactor) {
|
||||
this.branchFactor = branchFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionIndex newIndex() {
|
||||
return new PriorityRTreeIndex(branchFactor);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
// $Id$
|
||||
/*
|
||||
* This file is a part of WorldGuard.
|
||||
* Copyright (c) sk89q <http://www.sk89q.com>
|
||||
* Copyright (c) the WorldGuard team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.region.indices;
|
||||
|
||||
/**
|
||||
* Creates new {@link RegionIndex} instances.
|
||||
*/
|
||||
public interface RegionIndexFactory {
|
||||
|
||||
/**
|
||||
* Create a new index.
|
||||
*
|
||||
* @return a new index
|
||||
*/
|
||||
RegionIndex newIndex();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user