mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Xomw: Add XomwSiteList and XomwGenericArrayObject
This commit is contained in:
parent
5967c75433
commit
a1d2e69211
@ -15,14 +15,15 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx;
|
||||
public interface Hash_adp extends gplx.core.lists.EnumerAble {
|
||||
int Count();
|
||||
boolean Has(Object key);
|
||||
Object Get_by(Object key);
|
||||
Object Get_by_or_fail(Object key);
|
||||
void Add(Object key, Object val);
|
||||
void Add_as_key_and_val(Object val);
|
||||
boolean Add_if_dupe_use_1st(Object key, Object val);
|
||||
void Add_if_dupe_use_nth(Object key, Object val);
|
||||
void Del(Object key);
|
||||
void Clear();
|
||||
int Count();
|
||||
boolean Has(Object key);
|
||||
Object Get_by(Object key);
|
||||
Object Get_by_or_fail(Object key);
|
||||
void Add(Object key, Object val);
|
||||
Hash_adp Add_and_more(Object key, Object val);
|
||||
void Add_as_key_and_val(Object val);
|
||||
boolean Add_if_dupe_use_1st(Object key, Object val);
|
||||
void Add_if_dupe_use_nth(Object key, Object val);
|
||||
void Del(Object key);
|
||||
void Clear();
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ class Hash_adp_noop implements Hash_adp {
|
||||
public Object Get_by(Object key) {return null;}
|
||||
public Object Get_by_or_fail(Object key) {throw Err_.new_missing_key(Object_.Xto_str_strict_or_null_mark(key));}
|
||||
public void Add(Object key, Object val) {}
|
||||
public Hash_adp Add_and_more(Object key, Object val) {return this;}
|
||||
public void Add_as_key_and_val(Object val) {}
|
||||
public void Add_if_dupe_use_nth(Object key, Object val) {}
|
||||
public boolean Add_if_dupe_use_1st(Object key, Object val) {return false;}
|
||||
|
@ -19,6 +19,7 @@ public abstract class Hash_adp_base implements Hash_adp {
|
||||
public Object Get_by(Object key) {return Fetch_base(key);}
|
||||
public Object Get_by_or_fail(Object key) {return Get_by_or_fail_base(key);}
|
||||
public void Add(Object key, Object val) {Add_base(key, val);}
|
||||
public Hash_adp Add_and_more(Object key, Object val) {Add_base(key, val); return this;}
|
||||
public void Add_as_key_and_val(Object val) {Add_base(val, val);}
|
||||
public void Add_if_dupe_use_nth(Object key, Object val) {
|
||||
Object existing = Fetch_base(key); if (existing != null) Del(key); // overwrite if exists
|
||||
|
@ -15,5 +15,5 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_conn_ {
|
||||
public static final Db_conn Noop = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.Null);
|
||||
public static final Db_conn Noop = new Db_conn(gplx.dbs.engines.noops.Noop_engine.Instance);
|
||||
}
|
||||
|
@ -17,4 +17,24 @@ package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
public class XophpArray {
|
||||
public static boolean popBoolOrN(List_adp list) {return Bool_.Cast(List_adp_.Pop_or(list, false));}
|
||||
public static byte[] popBryOrNull(List_adp list) {return (byte[])List_adp_.Pop_or(list, null);}
|
||||
public static String[] array_keys_str(Ordered_hash array) {
|
||||
int len = array.Len();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = (String)array.Get_at(i);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static boolean array_key_exists(int key, Ordered_hash array) {
|
||||
return array.Has(key);
|
||||
}
|
||||
public static boolean array_key_exists(String key, Ordered_hash array) {
|
||||
return array.Has(key);
|
||||
}
|
||||
public static boolean array_is_empty(Ordered_hash array) {
|
||||
return array.Len() == 0;
|
||||
}
|
||||
public static void unset(Ordered_hash array, Object key) {
|
||||
array.Del(key);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
|
||||
public class XophpInvalidArgumentException extends Err { public XophpInvalidArgumentException(String text) {super(false, "", text, text);}
|
||||
}
|
@ -38,6 +38,7 @@ public class XophpUtility {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean is_null(int v) {return v == NULL_INT;}
|
||||
public static final int NULL_INT = Int_.Max_value;
|
||||
public static final double NULL_DOUBLE = Double_.MinValue;
|
||||
public static final byte[] NULL_BRY = null;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
// bare-bones implementation of PHP ArrayObject
|
||||
// REF:http://php.net/manual/en/class.arrayobject.php
|
||||
public abstract class XomwArrayObject {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public boolean offsetExists(Object key) {
|
||||
return hash.Has(key);
|
||||
}
|
||||
public Object offsetGet(Object key) {
|
||||
return hash.Get_by(key);
|
||||
}
|
||||
public void offsetUnset(Object key) {
|
||||
hash.Del(key);
|
||||
}
|
||||
@gplx.Virtual public void offsetSet(int key, Object val) {
|
||||
hash.Add(key, val);
|
||||
}
|
||||
|
||||
public int count() {return hash.Len();}
|
||||
public Object Get_at(int i) {return hash.Get_at(i);}
|
||||
public void Add_or_update(Object val) {
|
||||
hash.Add(hash.Count(), val);
|
||||
}
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
/**
|
||||
* Extends ArrayObject and does two things:
|
||||
*
|
||||
* Allows for deriving cla+sses to easily intercept additions
|
||||
* and deletions for purposes such as additional indexing.
|
||||
*
|
||||
* Enforces the objects to be of a certain type, so this
|
||||
* can be replied upon, much like if this had true support
|
||||
* for generics, which sadly enough is not possible in PHP.
|
||||
*/
|
||||
public abstract class XomwGenericArrayObject extends XomwArrayObject { /**
|
||||
* Returns the name of an interface/class that the element should implement/extend.
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
abstract public Class<?> getObjectType();
|
||||
|
||||
/**
|
||||
* @see SiteList::getNewOffset()
|
||||
* @since 1.20
|
||||
* @var integer
|
||||
*/
|
||||
protected int indexOffset = 0;
|
||||
|
||||
/**
|
||||
* Finds a new offset for when appending an element.
|
||||
* The super class does this, so it would be better to integrate,
|
||||
* but there does not appear to be any way to do this...
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected int getNewOffset() {
|
||||
while (this.offsetExists(this.indexOffset)) {
|
||||
this.indexOffset++;
|
||||
}
|
||||
|
||||
return this.indexOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @see ArrayObject::__construct
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param null|array $input
|
||||
* @param int $flags
|
||||
* @param String $iterator_class
|
||||
*/
|
||||
public XomwGenericArrayObject() {
|
||||
// if (input != null) {
|
||||
// int len = Array_.Len(input);
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Object val = Array_.Get_at(input, i);
|
||||
// this.offsetSet(i, val);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayObject::append
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public void append(Object val) {
|
||||
this.setElement(XophpUtility.NULL_INT, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayObject::offsetSet()
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param mixed $index
|
||||
* @param mixed $value
|
||||
*/
|
||||
@Override public void offsetSet(int index, Object val) {
|
||||
this.setElement(index, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the provided value has the same type as the elements
|
||||
* that can be added to this ArrayObject.
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected boolean hasValidType(Object val) {
|
||||
Class<?> cls = this.getObjectType();
|
||||
return Type_adp_.Eq_typeSafe(val, cls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that actually sets the element and holds
|
||||
* all common code needed for set operations, including
|
||||
* type checking and offset resolving.
|
||||
*
|
||||
* If you want to do additional indexing or have code that
|
||||
* otherwise needs to be executed whenever an element is added,
|
||||
* you can overload @see preSetElement.
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param mixed $index
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected void setElement(int index, Object val) {
|
||||
if (!this.hasValidType(val)) {
|
||||
throw new XophpInvalidArgumentException(
|
||||
"Can only add " + Type_adp_.FullNameOf_type(this.getObjectType()) + " implementing objects to "
|
||||
+ Type_adp_.ClassOf_obj(this) + "."
|
||||
);
|
||||
}
|
||||
|
||||
if (XophpUtility.is_null(index)) {
|
||||
index = this.getNewOffset();
|
||||
}
|
||||
|
||||
if (this.preSetElement(index, val)) {
|
||||
super.offsetSet(index, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called before a new element is added to the ArrayObject.
|
||||
*
|
||||
* At this point the index is always set (ie not null) and the
|
||||
* value is always of the type returned by @see getObjectType.
|
||||
*
|
||||
* Should return a boolean. When false is returned the element
|
||||
* does not get added to the ArrayObject.
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param integer|String $index
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected boolean preSetElement(int index, Object val) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @see Serializable::serialize
|
||||
// *
|
||||
// * @since 1.20
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function serialize() {
|
||||
// return serialize(this.getSerializationData());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns an array holding all the data that should go into serialization calls.
|
||||
// * This is intended to allow overloading without having to reimplement the
|
||||
// * behavior of this super class.
|
||||
// *
|
||||
// * @since 1.20
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// protected function getSerializationData() {
|
||||
// return [
|
||||
// 'data' => this.getArrayCopy(),
|
||||
// 'index' => this.indexOffset,
|
||||
// ];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see Serializable::unserialize
|
||||
// *
|
||||
// * @since 1.20
|
||||
// *
|
||||
// * @param String $serialization
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function unserialize($serialization) {
|
||||
// $serializationData = unserialize($serialization);
|
||||
//
|
||||
// foreach ($serializationData['data'] as $offset => $value) {
|
||||
// // Just set the element, bypassing checks and offset resolving,
|
||||
// // as these elements have already gone through this.
|
||||
// parent::offsetSet($offset, $value);
|
||||
// }
|
||||
//
|
||||
// this.indexOffset = $serializationData['index'];
|
||||
//
|
||||
// return $serializationData;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns if the ArrayObject has no elements.
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@gplx.Virtual public boolean isEmpty() {
|
||||
return this.count() == 0;
|
||||
}
|
||||
}
|
@ -83,7 +83,7 @@ public class XomwSite {
|
||||
*
|
||||
* @var array[]
|
||||
*/
|
||||
private Hash_adp localIds;
|
||||
private Ordered_hash localIds;
|
||||
|
||||
/**
|
||||
* @since 1.21
|
||||
@ -492,12 +492,12 @@ public class XomwSite {
|
||||
*/
|
||||
public void addLocalId(String type, String identifier) {
|
||||
if (this.localIds == null) {
|
||||
this.localIds = Hash_adp_.New();
|
||||
this.localIds = Ordered_hash_.New();
|
||||
}
|
||||
|
||||
Hash_adp typeHash = (Hash_adp)this.localIds.Get_by(type);
|
||||
Ordered_hash typeHash = (Ordered_hash)this.localIds.Get_by(type);
|
||||
if (typeHash == null) {
|
||||
typeHash = Hash_adp_.New();
|
||||
typeHash = Ordered_hash_.New();
|
||||
this.localIds.Add(type, typeHash);
|
||||
}
|
||||
|
||||
@ -535,8 +535,8 @@ public class XomwSite {
|
||||
*
|
||||
* @return String[]
|
||||
*/
|
||||
public Hash_adp getInterwikiIds() {
|
||||
return (Hash_adp)this.localIds.Get_by(XomwSite.ID_INTERWIKI);
|
||||
public Ordered_hash getInterwikiIds() {
|
||||
return (Ordered_hash)this.localIds.Get_by(XomwSite.ID_INTERWIKI);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -547,8 +547,8 @@ public class XomwSite {
|
||||
*
|
||||
* @return String[]
|
||||
*/
|
||||
public Hash_adp getNavigationIds() {
|
||||
return (Hash_adp)this.localIds.Get_by(XomwSite.ID_EQUIVALENT);
|
||||
public Ordered_hash getNavigationIds() {
|
||||
return (Ordered_hash)this.localIds.Get_by(XomwSite.ID_EQUIVALENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -558,7 +558,7 @@ public class XomwSite {
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public Hash_adp getLocalIds() {
|
||||
public Ordered_hash getLocalIds() {
|
||||
return this.localIds;
|
||||
}
|
||||
|
||||
@ -635,20 +635,10 @@ public class XomwSite {
|
||||
* @return Site
|
||||
*/
|
||||
public static XomwSite newForType(String siteType) {
|
||||
// global $wgSiteTypes;
|
||||
|
||||
/*
|
||||
//$wgSiteTypes = [
|
||||
// 'mediawiki' => 'MediaWikiSite',
|
||||
//];
|
||||
Object o = XomwDefaultSettings.wgSiteTypes;
|
||||
if (o != null) {
|
||||
return new XomwMediaWikiSite()
|
||||
String type = (String)XomwDefaultSettings.wgSiteTypes.Get_by(siteType);
|
||||
if (String_.Eq(type, XomwDefaultSettings.wgSiteTypes__MediaWikiSite)) {
|
||||
return new XomwMediaWikiSite();
|
||||
}
|
||||
*/
|
||||
// if (array_key_exists($siteType, $wgSiteTypes)) {
|
||||
// return new $wgSiteTypes[$siteType]();
|
||||
// }
|
||||
|
||||
return new XomwSite(siteType);
|
||||
}
|
||||
|
@ -14,332 +14,340 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes.site; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.xowa.mediawiki.includes.libs.*;
|
||||
/**
|
||||
* Collection of Site objects.
|
||||
*/
|
||||
public class XomwSiteList {
|
||||
public int Len() {return 0;}
|
||||
public class XomwSiteList extends XomwGenericArrayObject { public int Len() {return 0;}
|
||||
public XomwSite GetAt(int idx) {return null;}
|
||||
// /**
|
||||
// * Internal site identifiers pointing to their sites offset value.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array Array of integer
|
||||
// */
|
||||
// protected $byInternalId = [];
|
||||
//
|
||||
// /**
|
||||
// * Global site identifiers pointing to their sites offset value.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @var array Array of String
|
||||
// */
|
||||
// protected $byGlobalId = [];
|
||||
//
|
||||
// /**
|
||||
// * Navigational site identifiers alias inter-language prefixes
|
||||
// * pointing to their sites offset value.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @var array Array of String
|
||||
// */
|
||||
// protected $byNavigationId = [];
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::getObjectType
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function getObjectType() {
|
||||
// return 'Site';
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::preSetElement
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int|String $index
|
||||
// * @param Site $site
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// protected function preSetElement( $index, $site ) {
|
||||
// if ( $this->hasSite( $site->getGlobalId() ) ) {
|
||||
// $this->removeSite( $site->getGlobalId() );
|
||||
// }
|
||||
//
|
||||
// $this->byGlobalId[$site->getGlobalId()] = $index;
|
||||
// $this->byInternalId[$site->getInternalId()] = $index;
|
||||
//
|
||||
// $ids = $site->getNavigationIds();
|
||||
// foreach ( $ids as $navId ) {
|
||||
// $this->byNavigationId[$navId] = $index;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see ArrayObject::offsetUnset()
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param mixed $index
|
||||
// */
|
||||
// public function offsetUnset( $index ) {
|
||||
// if ( $this->offsetExists( $index ) ) {
|
||||
// /**
|
||||
// * @var Site $site
|
||||
// */
|
||||
// $site = $this->offsetGet( $index );
|
||||
//
|
||||
// unset( $this->byGlobalId[$site->getGlobalId()] );
|
||||
// unset( $this->byInternalId[$site->getInternalId()] );
|
||||
//
|
||||
// $ids = $site->getNavigationIds();
|
||||
// foreach ( $ids as $navId ) {
|
||||
// unset( $this->byNavigationId[$navId] );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// parent::offsetUnset( $index );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns all the global site identifiers.
|
||||
// * Optionally only those belonging to the specified group.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getGlobalIdentifiers() {
|
||||
// return array_keys( $this->byGlobalId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains the site with the provided global site identifier.
|
||||
// *
|
||||
// * @param String $globalSiteId
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasSite( $globalSiteId ) {
|
||||
// return array_key_exists( $globalSiteId, $this->byGlobalId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Site with the provided global site identifier.
|
||||
// * The site needs to exist, so if not sure, call hasGlobalId first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $globalSiteId
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public function getSite( $globalSiteId ) {
|
||||
// return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the site with the specified global site identifier.
|
||||
// * The site needs to exist, so if not sure, call hasGlobalId first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $globalSiteId
|
||||
// */
|
||||
// public function removeSite( $globalSiteId ) {
|
||||
// $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains no sites.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isEmpty() {
|
||||
// return $this->byGlobalId === [];
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains the site with the provided site id.
|
||||
// *
|
||||
// * @param int $id
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasInternalId( $id ) {
|
||||
// return array_key_exists( $id, $this->byInternalId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Site with the provided site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int $id
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public function getSiteByInternalId( $id ) {
|
||||
// return $this->offsetGet( $this->byInternalId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the site with the specified site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param int $id
|
||||
// */
|
||||
// public function removeSiteByInternalId( $id ) {
|
||||
// $this->offsetUnset( $this->byInternalId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns if the list contains the site with the provided navigational site id.
|
||||
// *
|
||||
// * @param String $id
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function hasNavigationId( $id ) {
|
||||
// return array_key_exists( $id, $this->byNavigationId );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Site with the provided navigational site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @param String $id
|
||||
// *
|
||||
// * @return Site
|
||||
// */
|
||||
// public function getSiteByNavigationId( $id ) {
|
||||
// return $this->offsetGet( $this->byNavigationId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the site with the specified navigational site id.
|
||||
// * The site needs to exist, so if not sure, call has first.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @param String $id
|
||||
// */
|
||||
// public function removeSiteByNavigationId( $id ) {
|
||||
// $this->offsetUnset( $this->byNavigationId[$id] );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets a site in the list. If the site was not there,
|
||||
// * it will be added. If it was, it will be updated.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param Site $site
|
||||
// */
|
||||
// public function setSite( Site $site ) {
|
||||
// $this[] = $site;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the sites that are in the provided group.
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $groupName
|
||||
// *
|
||||
// * @return SiteList
|
||||
// */
|
||||
// public function getGroup( $groupName ) {
|
||||
// $group = new self();
|
||||
//
|
||||
// /**
|
||||
// * @var Site $site
|
||||
// */
|
||||
// foreach ( $this as $site ) {
|
||||
// if ( $site->getGroup() === $groupName ) {
|
||||
// $group[] = $site;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $group;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * A version ID that identifies the serialization structure used by getSerializationData()
|
||||
// * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @var String A String uniquely identifying the version of the serialization structure,
|
||||
// * not including any sub-structures.
|
||||
// */
|
||||
// static final SERIAL_VERSION_ID = '2014-03-17';
|
||||
//
|
||||
// /**
|
||||
// * Returns the version ID that identifies the serialization structure used by
|
||||
// * getSerializationData() and unserialize(), including the structure of any nested structures.
|
||||
// * This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @return String A String uniquely identifying the version of the serialization structure,
|
||||
// * including any sub-structures.
|
||||
// */
|
||||
// public static function getSerialVersionId() {
|
||||
// return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::getSerializationData
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// protected function getSerializationData() {
|
||||
// // NOTE: When changing the structure, either implement unserialize() to handle the
|
||||
// // old structure too, or update SERIAL_VERSION_ID to kill any caches.
|
||||
// return array_merge(
|
||||
// parent::getSerializationData(),
|
||||
// [
|
||||
// 'internalIds' => $this->byInternalId,
|
||||
// 'globalIds' => $this->byGlobalId,
|
||||
// 'navigationIds' => $this->byNavigationId
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::unserialize
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String $serialization
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function unserialize( $serialization ) {
|
||||
// $serializationData = parent::unserialize( $serialization );
|
||||
//
|
||||
// $this->byInternalId = $serializationData['internalIds'];
|
||||
// $this->byGlobalId = $serializationData['globalIds'];
|
||||
// $this->byNavigationId = $serializationData['navigationIds'];
|
||||
//
|
||||
// return $serializationData;
|
||||
// }
|
||||
public XomwSiteList() {super();
|
||||
}
|
||||
/**
|
||||
* Internal site identifiers pointing to their sites offset value.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @var array Array of integer
|
||||
*/
|
||||
private final Ordered_hash byInternalId = Ordered_hash_.New();
|
||||
|
||||
/**
|
||||
* Global site identifiers pointing to their sites offset value.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @var array Array of String
|
||||
*/
|
||||
private final Ordered_hash byGlobalId = Ordered_hash_.New();
|
||||
|
||||
/**
|
||||
* Navigational site identifiers alias inter-language prefixes
|
||||
* pointing to their sites offset value.
|
||||
*
|
||||
* @since 1.23
|
||||
*
|
||||
* @var array Array of String
|
||||
*/
|
||||
private final Ordered_hash byNavigationId = Ordered_hash_.New();
|
||||
|
||||
/**
|
||||
* @see GenericArrayObject::getObjectType
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@Override public Class<?> getObjectType() {
|
||||
return XomwSite.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenericArrayObject::preSetElement
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param int|String index
|
||||
* @param Site site
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean preSetElement(int index, XomwSite site) {
|
||||
if (this.hasSite(site.getGlobalId())) {
|
||||
this.removeSite(site.getGlobalId());
|
||||
}
|
||||
|
||||
this.byGlobalId.Add(site.getGlobalId(), index);
|
||||
this.byInternalId.Add(site.getInternalId(), index);
|
||||
|
||||
Ordered_hash ids = site.getNavigationIds();
|
||||
int len = ids.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int navId = Int_.cast(ids.Get_at(i));
|
||||
this.byNavigationId.Add(navId, index);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArrayObject::offsetUnset()
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param mixed index
|
||||
*/
|
||||
public void offsetUnset(int index) {
|
||||
if (this.offsetExists(index)) {
|
||||
/**
|
||||
* @var Site site
|
||||
*/
|
||||
XomwSite site = (XomwSite)this.offsetGet(index);
|
||||
|
||||
XophpArray.unset(this.byGlobalId, site.getGlobalId());
|
||||
XophpArray.unset(this.byInternalId, site.getInternalId());
|
||||
|
||||
Ordered_hash ids = site.getNavigationIds();
|
||||
int len = ids.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int navId = Int_.cast(ids.Get_at(i));
|
||||
XophpArray.unset(this.byNavigationId, navId);
|
||||
}
|
||||
}
|
||||
|
||||
super.offsetUnset(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the global site identifiers.
|
||||
* Optionally only those belonging to the specified group.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public String[] getGlobalIdentifiers() {
|
||||
return XophpArray.array_keys_str(this.byGlobalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the list contains the site with the provided global site identifier.
|
||||
*
|
||||
* @param String globalSiteId
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hasSite(String globalSiteId) {
|
||||
return XophpArray.array_key_exists(globalSiteId, this.byGlobalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Site with the provided global site identifier.
|
||||
* The site needs to exist, so if not sure, call hasGlobalId first.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param String globalSiteId
|
||||
*
|
||||
* @return Site
|
||||
*/
|
||||
public XomwSite getSite(String globalSiteId) {
|
||||
return (XomwSite)this.offsetGet(this.byGlobalId.Get_by(globalSiteId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the site with the specified global site identifier.
|
||||
* The site needs to exist, so if not sure, call hasGlobalId first.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param String globalSiteId
|
||||
*/
|
||||
public void removeSite(String globalSiteId) {
|
||||
this.offsetUnset(this.byGlobalId.Get_by(globalSiteId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the list contains no sites.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override public boolean isEmpty() {
|
||||
return XophpArray.array_is_empty(this.byGlobalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the list contains the site with the provided site id.
|
||||
*
|
||||
* @param int id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hasInternalId(int id) {
|
||||
return XophpArray.array_key_exists(id, this.byInternalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Site with the provided site id.
|
||||
* The site needs to exist, so if not sure, call has first.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param int id
|
||||
*
|
||||
* @return Site
|
||||
*/
|
||||
public XomwSite getSiteByInternalId(int id) {
|
||||
return (XomwSite)this.offsetGet(this.byInternalId.Get_by(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the site with the specified site id.
|
||||
* The site needs to exist, so if not sure, call has first.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param int id
|
||||
*/
|
||||
public void removeSiteByInternalId(int id) {
|
||||
this.offsetUnset(this.byInternalId.Get_by(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the list contains the site with the provided navigational site id.
|
||||
*
|
||||
* @param String id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hasNavigationId(String id) {
|
||||
return XophpArray.array_key_exists(id, this.byNavigationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Site with the provided navigational site id.
|
||||
* The site needs to exist, so if not sure, call has first.
|
||||
*
|
||||
* @since 1.23
|
||||
*
|
||||
* @param String id
|
||||
*
|
||||
* @return Site
|
||||
*/
|
||||
public XomwSite getSiteByNavigationId(String id) {
|
||||
return (XomwSite)this.offsetGet(this.byNavigationId.Get_by(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the site with the specified navigational site id.
|
||||
* The site needs to exist, so if not sure, call has first.
|
||||
*
|
||||
* @since 1.23
|
||||
*
|
||||
* @param String id
|
||||
*/
|
||||
public void removeSiteByNavigationId(String id) {
|
||||
this.offsetUnset(this.byNavigationId.Get_by(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a site in the list. If the site was not there,
|
||||
* it will be added. If it was, it will be updated.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param Site site
|
||||
*/
|
||||
public void setSite(XomwSite site) {
|
||||
this.Add_or_update(site);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sites that are in the provided group.
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @param String groupName
|
||||
*
|
||||
* @return SiteList
|
||||
*/
|
||||
public XomwSiteList getGroup(String groupName) {
|
||||
XomwSiteList group = new XomwSiteList();
|
||||
|
||||
/**
|
||||
* @var Site site
|
||||
*/
|
||||
int len = this.count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
XomwSite site = (XomwSite)this.Get_at(i);
|
||||
if (String_.Eq(site.getGroup(), groupName)) {
|
||||
group.Add_or_update(site);
|
||||
}
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * A version ID that identifies the serialization structure used by getSerializationData()
|
||||
// * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @var String A String uniquely identifying the version of the serialization structure,
|
||||
// * not including any sub-structures.
|
||||
// */
|
||||
// static final SERIAL_VERSION_ID = '2014-03-17';
|
||||
//
|
||||
// /**
|
||||
// * Returns the version ID that identifies the serialization structure used by
|
||||
// * getSerializationData() and unserialize(), including the structure of any nested structures.
|
||||
// * This is useful for constructing cache keys in cases where the cache relies
|
||||
// * on serialization for storing the SiteList.
|
||||
// *
|
||||
// * @return String A String uniquely identifying the version of the serialization structure,
|
||||
// * including any sub-structures.
|
||||
// */
|
||||
// public static function getSerialVersionId() {
|
||||
// return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::getSerializationData
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// protected function getSerializationData() {
|
||||
// // NOTE: When changing the structure, either implement unserialize() to handle the
|
||||
// // old structure too, or update SERIAL_VERSION_ID to kill any caches.
|
||||
// return array_merge(
|
||||
// super.getSerializationData(),
|
||||
// [
|
||||
// 'internalIds' => this.byInternalId,
|
||||
// 'globalIds' => this.byGlobalId,
|
||||
// 'navigationIds' => this.byNavigationId
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @see GenericArrayObject::unserialize
|
||||
// *
|
||||
// * @since 1.21
|
||||
// *
|
||||
// * @param String serialization
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function unserialize(serialization) {
|
||||
// serializationData = super.unserialize(serialization);
|
||||
//
|
||||
// this.byInternalId = serializationData['internalIds'];
|
||||
// this.byGlobalId = serializationData['globalIds'];
|
||||
// this.byNavigationId = serializationData['navigationIds'];
|
||||
//
|
||||
// return serializationData;
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user