2009-06-25 07:16:22 -07:00
|
|
|
|
/*
|
|
|
|
|
* VsqEventList.cs
|
|
|
|
|
* Copyright (c) 2008-2009 kbinani
|
|
|
|
|
*
|
|
|
|
|
* This file is part of Boare.Lib.Vsq.
|
|
|
|
|
*
|
|
|
|
|
* Boare.Lib.Vsq is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the BSD License.
|
|
|
|
|
*
|
|
|
|
|
* Boare.Lib.Vsq 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.
|
|
|
|
|
*/
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
package org.kbinani.vsq;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
#else
|
|
|
|
|
using System;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using bocoree;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
using bocoree.java.util;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
namespace Boare.Lib.Vsq {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
using Integer = System.Int32;
|
|
|
|
|
#endif
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 固有ID付きのVsqEventのリストを取り扱う
|
|
|
|
|
/// </summary>
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
public class VsqEventList implements Serializable {
|
|
|
|
|
#else
|
2009-06-25 07:16:22 -07:00
|
|
|
|
[Serializable]
|
|
|
|
|
public class VsqEventList {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public Vector<VsqEvent> Events;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
private Vector<Integer> m_ids;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// コンストラクタ
|
|
|
|
|
/// </summary>
|
|
|
|
|
public VsqEventList() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Events = new Vector<VsqEvent>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
m_ids = new Vector<Integer>();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-30 08:02:59 -07:00
|
|
|
|
public VsqEvent findFromID( int internal_id ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = Events.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
VsqEvent item = (VsqEvent)itr.next();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( item.InternalID == internal_id ) {
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setForID( int internal_id, VsqEvent value ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
int c = Events.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < c; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( Events.get( i ).InternalID == internal_id ) {
|
|
|
|
|
Events.set( i, value );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public void sort() {
|
|
|
|
|
lock ( this ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( Events );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
updateIDList();
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public void clear() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Events.clear();
|
|
|
|
|
m_ids.clear();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Iterator iterator() {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return Events.iterator();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void add( VsqEvent item ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
add( item, getNextId( 0 ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void add( VsqEvent item, int internal_id ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
item.InternalID = internal_id;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Events.add( item );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
m_ids.add( internal_id );
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Collections.sort( Events );
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = Events.size();
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_ids.set( i, Events.get( i ).InternalID );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeAt( int index ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Events.removeElementAt( index );
|
|
|
|
|
m_ids.removeElementAt( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getNextId( int next ) {
|
2009-07-29 10:03:20 -07:00
|
|
|
|
updateIDList();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int index = -1;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
Vector<Integer> current = new Vector<Integer>( m_ids );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int nfound = 0;
|
|
|
|
|
while ( true ) {
|
|
|
|
|
index++;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( !current.contains( index ) ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
nfound++;
|
|
|
|
|
if ( nfound == next + 1 ) {
|
|
|
|
|
return index;
|
|
|
|
|
} else {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
current.add( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCount() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return Events.size();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VsqEvent getElement( int index ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return Events.get( index );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setElement( int index, VsqEvent value ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
value.InternalID = Events.get( index ).InternalID;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
Events.set( index, value );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateIDList() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
if ( m_ids.size() != Events.size() ) {
|
|
|
|
|
m_ids.clear();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = Events.size();
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_ids.add( Events.get( i ).InternalID );
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-07-30 08:02:59 -07:00
|
|
|
|
} else {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
int count = Events.size();
|
|
|
|
|
for ( int i = 0; i < count; i++ ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_ids.set( i, Events.get( i ).InternalID );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
2009-07-29 10:03:20 -07:00
|
|
|
|
}
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
2009-06-25 07:16:22 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|