2006-11-22 17:38:46 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.ibm.wala.util.intset;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object that creates mutable sparse int sets.
|
|
|
|
*/
|
2010-10-15 14:31:13 +00:00
|
|
|
public class MutableSparseIntSetFactory implements MutableIntSetFactory<MutableSparseIntSet> {
|
2006-11-22 17:38:46 +00:00
|
|
|
|
2007-01-15 18:31:55 +00:00
|
|
|
/**
|
2007-05-15 03:15:05 +00:00
|
|
|
* @throws IllegalArgumentException if set is null
|
2007-01-15 18:31:55 +00:00
|
|
|
*/
|
2010-10-15 14:31:13 +00:00
|
|
|
public MutableSparseIntSet make(int[] set) {
|
2007-05-15 03:15:05 +00:00
|
|
|
if (set == null) {
|
|
|
|
throw new IllegalArgumentException("set is null");
|
|
|
|
}
|
2007-01-15 18:31:55 +00:00
|
|
|
if (set.length == 0) {
|
2007-10-29 13:18:26 +00:00
|
|
|
return MutableSparseIntSet.makeEmpty();
|
2007-01-15 18:31:55 +00:00
|
|
|
} else {
|
|
|
|
// XXX not very efficient.
|
|
|
|
TreeSet<Integer> T = new TreeSet<Integer>();
|
|
|
|
for (int i = 0; i < set.length; i++) {
|
|
|
|
T.add(new Integer(set[i]));
|
|
|
|
}
|
|
|
|
int[] copy = new int[T.size()];
|
|
|
|
int i = 0;
|
|
|
|
for (Iterator<Integer> it = T.iterator(); it.hasNext();) {
|
|
|
|
Integer I = it.next();
|
|
|
|
copy[i++] = I.intValue();
|
|
|
|
}
|
|
|
|
MutableSparseIntSet result = new MutableSparseIntSet(copy);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2006-11-22 17:38:46 +00:00
|
|
|
|
2007-01-15 18:31:55 +00:00
|
|
|
/**
|
|
|
|
* @param string
|
|
|
|
*/
|
2010-10-15 14:31:13 +00:00
|
|
|
public MutableSparseIntSet parse(String string) throws NumberFormatException {
|
2007-01-15 18:31:55 +00:00
|
|
|
int[] backingStore = SparseIntSet.parseIntArray(string);
|
|
|
|
return new MutableSparseIntSet(backingStore);
|
|
|
|
}
|
2006-11-22 17:38:46 +00:00
|
|
|
|
2007-01-15 18:31:55 +00:00
|
|
|
/*
|
2006-11-22 17:38:46 +00:00
|
|
|
* @see com.ibm.wala.util.intset.MutableIntSetFactory#make(com.ibm.wala.util.intset.IntSet)
|
|
|
|
*/
|
2010-10-15 14:31:13 +00:00
|
|
|
public MutableSparseIntSet makeCopy(IntSet x) throws IllegalArgumentException {
|
2007-08-22 16:33:45 +00:00
|
|
|
if (x == null) {
|
|
|
|
throw new IllegalArgumentException("x == null");
|
|
|
|
}
|
|
|
|
return MutableSparseIntSet.make(x);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
2007-01-15 18:31:55 +00:00
|
|
|
/*
|
2006-11-22 17:38:46 +00:00
|
|
|
* @see com.ibm.wala.util.intset.MutableIntSetFactory#make()
|
|
|
|
*/
|
2010-10-15 14:31:13 +00:00
|
|
|
public MutableSparseIntSet make() {
|
2007-10-29 13:18:26 +00:00
|
|
|
return MutableSparseIntSet.makeEmpty();
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|