diff --git a/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java b/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java index bbe67279e..ebaec03e6 100644 --- a/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java +++ b/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/AbstractSchemaMigrator.java @@ -267,14 +267,14 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { } } - protected void createTable( + protected boolean createTable( Table table, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { - applySqlStrings( + return applySqlStrings( false, dialect.getTableExporter().getSqlCreateStrings( table, metadata ), formatter, @@ -283,7 +283,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { ); } - protected void migrateTable( + protected boolean migrateTable( Table table, TableInformation tableInformation, Dialect dialect, @@ -294,7 +294,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { final Database database = metadata.getDatabase(); //noinspection unchecked - applySqlStrings( + return applySqlStrings( false, table.sqlAlterStrings( dialect, @@ -551,17 +551,19 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { exportIdentifiers.add( exportIdentifier ); } - protected static void applySqlStrings( + protected static boolean applySqlStrings( boolean quiet, String[] sqlStrings, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { + boolean success = true; if ( sqlStrings != null ) { for ( String sqlString : sqlStrings ) { - applySqlString( quiet, sqlString, formatter, options, targets ); + success &= applySqlString( quiet, sqlString, formatter, options, targets ); } } + return success; } protected void createSchemaAndCatalog( @@ -604,7 +606,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { } } - private static void applySqlString( + private static boolean applySqlString( boolean quiet, String sqlString, Formatter formatter, @@ -619,24 +621,27 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator { if ( !quiet ) { options.getExceptionHandler().handleException( e ); } - // otherwise ignore the exception + return false; } } } + return true; } - private static void applySqlStrings( + private static boolean applySqlStrings( boolean quiet, Iterator sqlStrings, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { + boolean success = true; if ( sqlStrings != null ) { while ( sqlStrings.hasNext() ) { final String sqlString = sqlStrings.next(); - applySqlString( quiet, sqlString, formatter, options, targets ); + success &= applySqlString( quiet, sqlString, formatter, options, targets ); } } + return success; } private String getDefaultCatalogName(Database database, Dialect dialect) { diff --git a/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java b/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java index 7d397a377..01f023369 100644 --- a/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java +++ b/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/GroupedSchemaMigratorImpl.java @@ -63,28 +63,31 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator { targets ); final NameSpaceTablesInformation tables = existingDatabase.getTablesInformation( namespace ); + boolean tableValid = true; for ( Table table : namespace.getTables() ) { if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { checkExportIdentifier( table, exportIdentifiers ); final TableInformation tableInformation = tables.getTableInformation( table ); if ( tableInformation == null ) { - createTable( table, dialect, metadata, formatter, options, targets ); + tableValid &= createTable( table, dialect, metadata, formatter, options, targets ); } else if ( tableInformation != null && tableInformation.isPhysicalTable() ) { tablesInformation.addTableInformation( tableInformation ); - migrateTable( table, tableInformation, dialect, metadata, formatter, options, targets ); + tableValid &= migrateTable( table, tableInformation, dialect, metadata, formatter, options, targets ); } } } - for ( Table table : namespace.getTables() ) { - if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { - final TableInformation tableInformation = tablesInformation.getTableInformation( table ); - if ( tableInformation == null || ( tableInformation != null && tableInformation.isPhysicalTable() ) ) { - applyIndexes( table, tableInformation, dialect, metadata, formatter, options, targets ); - applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, targets ); - if (tableInformation != null) { - applyPrimaryKey(table, tableInformation, dialect, metadata, formatter, options, targets); + if (tableValid) { + for (Table table : namespace.getTables()) { + if (schemaFilter.includeTable(table) && table.isPhysicalTable()) { + final TableInformation tableInformation = tablesInformation.getTableInformation(table); + if (tableInformation == null || (tableInformation != null && tableInformation.isPhysicalTable())) { + applyIndexes(table, tableInformation, dialect, metadata, formatter, options, targets); + applyUniqueKeys(table, tableInformation, dialect, metadata, formatter, options, targets); + if (tableInformation != null) { + applyPrimaryKey(table, tableInformation, dialect, metadata, formatter, options, targets); + } } } } diff --git a/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java b/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java index 154b20f63..b1a279895 100644 --- a/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java +++ b/fine-hibernate/src/main/java/com/fr/third/org/hibernate/tool/schema/internal/IndividuallySchemaMigratorImpl.java @@ -63,28 +63,31 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator { namespace, targets ); + boolean tableValid = true; for ( Table table : namespace.getTables() ) { if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { checkExportIdentifier( table, exportIdentifiers ); final TableInformation tableInformation = existingDatabase.getTableInformation( table.getQualifiedTableName() ); if ( tableInformation == null ) { - createTable( table, dialect, metadata, formatter, options, targets ); + tableValid &= createTable( table, dialect, metadata, formatter, options, targets ); } else if ( tableInformation != null && tableInformation.isPhysicalTable() ) { tablesInformation.addTableInformation( tableInformation ); - migrateTable( table, tableInformation, dialect, metadata, formatter, options, targets ); + tableValid &= migrateTable( table, tableInformation, dialect, metadata, formatter, options, targets ); } } } - for ( Table table : namespace.getTables() ) { - if ( schemaFilter.includeTable( table ) && table.isPhysicalTable() ) { - final TableInformation tableInformation = tablesInformation.getTableInformation( table ); - if ( tableInformation == null || ( tableInformation != null && tableInformation.isPhysicalTable() ) ) { - applyIndexes( table, tableInformation, dialect, metadata, formatter, options, targets ); - applyUniqueKeys( table, tableInformation, dialect, metadata, formatter, options, targets ); - if (tableInformation != null) { - applyPrimaryKey(table, tableInformation, dialect, metadata, formatter, options, targets); + if (tableValid) { + for (Table table : namespace.getTables()) { + if (schemaFilter.includeTable(table) && table.isPhysicalTable()) { + final TableInformation tableInformation = tablesInformation.getTableInformation(table); + if (tableInformation == null || (tableInformation != null && tableInformation.isPhysicalTable())) { + applyIndexes(table, tableInformation, dialect, metadata, formatter, options, targets); + applyUniqueKeys(table, tableInformation, dialect, metadata, formatter, options, targets); + if (tableInformation != null) { + applyPrimaryKey(table, tableInformation, dialect, metadata, formatter, options, targets); + } } } } diff --git a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Connection.java b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Connection.java index fef773ccc..36a0b3198 100644 --- a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Connection.java +++ b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Connection.java @@ -276,6 +276,11 @@ public class Connection implements Closeable { return (List) readProtocolWithCheckingBroken(); } + @SuppressWarnings("unchecked") + public List getUnflushedObjectMultiBulkReply() { + return (List) readProtocolWithCheckingBroken(); + } + public List getObjectMultiBulkReply() { return getRawObjectMultiBulkReply(); } diff --git a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java index ef2973500..dd23d2f69 100644 --- a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java +++ b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/JedisPubSub.java @@ -128,7 +128,7 @@ public abstract class JedisPubSub { private void process(Client client) { do { - List reply = client.getRawObjectMultiBulkReply(); + List reply = client.getUnflushedObjectMultiBulkReply(); final Object firstObj = reply.get(0); if (!(firstObj instanceof byte[])) { throw new JedisException("Unknown message type: " + firstObj); diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ArrayContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ArrayContainer.java deleted file mode 100644 index bdf19e669..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ArrayContainer.java +++ /dev/null @@ -1,1240 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableArrayContainer; -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableContainer; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.ShortBuffer; -import java.util.Arrays; -import java.util.Iterator; - - -/** - * Simple container made of an array of 16-bit integers - */ -public final class ArrayContainer extends Container implements Cloneable { - static final int DEFAULT_MAX_SIZE = 4096;// containers with DEFAULT_MAX_SZE or less integers - private static final int DEFAULT_INIT_SIZE = 4; - private static final int ARRAY_LAZY_LOWERBOUND = 1024; - // should be ArrayContainers - private static final long serialVersionUID = 1L; - protected int cardinality = 0; - short[] content; - - /** - * Create an array container with default capacity - */ - public ArrayContainer() { - this(DEFAULT_INIT_SIZE); - } - - - /** - * Create an array container with specified capacity - * - * @param capacity The capacity of the container - */ - public ArrayContainer(final int capacity) { - content = new short[capacity]; - } - - /** - * Create an array container with a run of ones from firstOfRun to lastOfRun, inclusive. Caller is - * responsible for making sure the range is small enough that ArrayContainer is appropriate. - * - * @param firstOfRun first index - * @param lastOfRun last index (range is exclusive) - */ - public ArrayContainer(final int firstOfRun, final int lastOfRun) { - final int valuesInRange = lastOfRun - firstOfRun; - this.content = new short[valuesInRange]; - for (int i = 0; i < valuesInRange; ++i) { - content[i] = (short) (firstOfRun + i); - } - cardinality = valuesInRange; - } - - /** - * Create a new container, no copy is made - * - * @param newCard desired cardinality - * @param newContent actual values (length should equal or exceed cardinality) - */ - public ArrayContainer(int newCard, short[] newContent) { - this.cardinality = newCard; - this.content = Arrays.copyOf(newContent, newCard); - } - - /** - * Creates a new non-mappeable container from a mappeable one. This copies the data. - * - * @param bc the original container - */ - public ArrayContainer(MappeableArrayContainer bc) { - this.cardinality = bc.getCardinality(); - this.content = bc.toShortArray(); - } - - protected ArrayContainer(short[] newContent) { - this.cardinality = newContent.length; - this.content = newContent; - } - - protected static int serializedSizeInBytes(int cardinality) { - return cardinality * 2 + 2; - } - - @Override - public Container add(int begin, int end) { - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - // TODO: may need to convert to a RunContainer - int indexstart = Util.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = Util.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = end - begin; - int newcardinality = indexstart + (cardinality - indexend) + rangelength; - if (newcardinality > DEFAULT_MAX_SIZE) { - BitmapContainer a = this.toBitmapContainer(); - return a.iadd(begin, end); - } - ArrayContainer answer = new ArrayContainer(newcardinality, content); - System.arraycopy(content, indexend, answer.content, indexstart + rangelength, - cardinality - indexend); - for (int k = 0; k < rangelength; ++k) { - answer.content[k + indexstart] = (short) (begin + k); - } - answer.cardinality = newcardinality; - return answer; - } - - - /** - * running time is in O(n) time if insert is not in order. - */ - @Override - public Container add(final short x) { - int loc = Util.unsignedBinarySearch(content, 0, cardinality, x); - if (loc < 0) { - // Transform the ArrayContainer to a BitmapContainer - // when cardinality = DEFAULT_MAX_SIZE - if (cardinality >= DEFAULT_MAX_SIZE) { - BitmapContainer a = this.toBitmapContainer(); - a.add(x); - return a; - } - if (cardinality >= this.content.length) { - increaseCapacity(); - } - // insertion : shift the elements > x by one position to - // the right - // and put x in it's appropriate place - System.arraycopy(content, -loc - 1, content, -loc, cardinality + loc + 1); - content[-loc - 1] = x; - ++cardinality; - } - return this; - } - - private int advance(ShortIterator it) { - if (it.hasNext()) { - return Util.toIntUnsigned(it.next()); - } else { - return -1; - } - } - - @Override - public ArrayContainer and(final ArrayContainer value2) { - ArrayContainer value1 = this; - final int desiredCapacity = Math.min(value1.getCardinality(), value2.getCardinality()); - ArrayContainer answer = new ArrayContainer(desiredCapacity); - answer.cardinality = Util.unsignedIntersect2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content); - return answer; - } - - @Override - public Container and(BitmapContainer x) { - return x.and(this); - } - - @Override - // see andNot for an approach that might be better. - public Container and(RunContainer x) { - return x.and(this); - } - - @Override - public int andCardinality(final ArrayContainer value2) { - return Util.unsignedLocalIntersect2by2Cardinality(content, cardinality, value2.content, - value2.getCardinality()); - } - - @Override - public int andCardinality(BitmapContainer x) { - return x.andCardinality(this); - } - - @Override - // see andNot for an approach that might be better. - public int andCardinality(RunContainer x) { - return x.andCardinality(this); - } - - @Override - public ArrayContainer andNot(final ArrayContainer value2) { - ArrayContainer value1 = this; - final int desiredCapacity = value1.getCardinality(); - ArrayContainer answer = new ArrayContainer(desiredCapacity); - answer.cardinality = Util.unsignedDifference(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content); - return answer; - } - - @Override - public ArrayContainer andNot(BitmapContainer value2) { - final ArrayContainer answer = new ArrayContainer(content.length); - int pos = 0; - for (int k = 0; k < cardinality; ++k) { - short val = this.content[k]; - if (!value2.contains(val)) { - answer.content[pos++] = val; - } - } - answer.cardinality = pos; - return answer; - } - - @Override - public Container andNot(RunContainer x) { - int writeLocation = 0; - int runStart, runEnd; // the current or upcoming run. - int whichRun; - short[] buffer = new short[cardinality]; - if (x.nbrruns == 0) { - return clone(); - } else { - runStart = Util.toIntUnsigned(x.getValue(0)); - runEnd = runStart + Util.toIntUnsigned(x.getLength(0)); - whichRun = 0; - } - - short val; - for (int i = 0; i < cardinality; ++i) { - val = content[i]; - int valInt = Util.toIntUnsigned(val); - if (valInt < runStart) { - buffer[writeLocation++] = val; - } else if (valInt <= runEnd) { - ; // don't want item - } else { - // greater than this run, need to do an advanceUntil on runs - // done sequentially for now (no galloping attempts). - do { - if (whichRun + 1 < x.nbrruns) { - whichRun++; - runStart = Util.toIntUnsigned(x.getValue(whichRun)); - runEnd = runStart + Util.toIntUnsigned(x.getLength(whichRun)); - } else { - runStart = runEnd = (1 << 16) + 1; // infinity.... - } - } while (valInt > runEnd); - --i; // need to re-process this val - } - } - return new ArrayContainer(writeLocation, buffer); - } - - @Override - public void clear() { - cardinality = 0; - } - - @Override - public ArrayContainer clone() { - return new ArrayContainer(this.cardinality, this.content); - } - - @Override - public boolean contains(final short x) { - return Util.unsignedBinarySearch(content, 0, cardinality, x) >= 0; - } - - @Override - public void deserialize(DataInput in) throws IOException { - this.cardinality = 0xFFFF & Short.reverseBytes(in.readShort()); - if (this.content.length < this.cardinality) { - this.content = new short[this.cardinality]; - } - for (int k = 0; k < this.cardinality; ++k) { - this.content[k] = Short.reverseBytes(in.readShort()); - ; - } - } - - // in order - private void emit(short val) { - if (cardinality == content.length) { - increaseCapacity(true); - } - content[cardinality++] = val; - } - - - @Override - public boolean equals(Object o) { - if (o instanceof ArrayContainer) { - ArrayContainer srb = (ArrayContainer) o; - if (srb.cardinality != this.cardinality) { - return false; - } - for (int i = 0; i < this.cardinality; ++i) { - if (this.content[i] != srb.content[i]) { - return false; - } - } - return true; - } else if (o instanceof RunContainer) { - return o.equals(this); - } - return false; - } - - @Override - public void fillLeastSignificant16bits(int[] x, int i, int mask) { - for (int k = 0; k < this.cardinality; ++k) { - x[k + i] = Util.toIntUnsigned(this.content[k]) | mask; - } - - } - - @Override - public Container flip(short x) { - int loc = Util.unsignedBinarySearch(content, 0, cardinality, x); - if (loc < 0) { - // Transform the ArrayContainer to a BitmapContainer - // when cardinality = DEFAULT_MAX_SIZE - if (cardinality >= DEFAULT_MAX_SIZE) { - BitmapContainer a = this.toBitmapContainer(); - a.add(x); - return a; - } - if (cardinality >= this.content.length) { - increaseCapacity(); - } - // insertion : shift the elements > x by one position to - // the right - // and put x in it's appropriate place - System.arraycopy(content, -loc - 1, content, -loc, cardinality + loc + 1); - content[-loc - 1] = x; - ++cardinality; - } else { - System.arraycopy(content, loc + 1, content, loc, cardinality - loc - 1); - --cardinality; - } - return this; - } - - @Override - protected int getArraySizeInBytes() { - return cardinality * 2; - } - - @Override - public int getCardinality() { - return cardinality; - } - - @Override - public ShortIterator getReverseShortIterator() { - return new ReverseArrayContainerShortIterator(this); - } - - @Override - public PeekableShortIterator getShortIterator() { - return new ArrayContainerShortIterator(this); - } - - - @Override - public int getSizeInBytes() { - return this.cardinality * 2 + 4; - } - - @Override - public int hashCode() { - int hash = 0; - for (int k = 0; k < cardinality; ++k) { - hash += 31 * hash + content[k]; - } - return hash; - } - - @Override - public Container iadd(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = Util.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = Util.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = end - begin; - int newcardinality = indexstart + (cardinality - indexend) + rangelength; - if (newcardinality > DEFAULT_MAX_SIZE) { - BitmapContainer a = this.toBitmapContainer(); - return a.iadd(begin, end); - } - if (newcardinality >= this.content.length) { - increaseCapacity(newcardinality); - } - System.arraycopy(content, indexend, content, indexstart + rangelength, cardinality - indexend); - for (int k = 0; k < rangelength; ++k) { - content[k + indexstart] = (short) (begin + k); - } - cardinality = newcardinality; - return this; - } - - - @Override - public ArrayContainer iand(final ArrayContainer value2) { - ArrayContainer value1 = this; - value1.cardinality = Util.unsignedIntersect2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), value1.content); - return this; - } - - @Override - public Container iand(BitmapContainer value2) { - int pos = 0; - for (int k = 0; k < cardinality; ++k) { - short v = this.content[k]; - if (value2.contains(v)) { - this.content[pos++] = v; - } - } - cardinality = pos; - return this; - } - - @Override - public Container iand(RunContainer x) { - // possible performance issue, not taking advantage of possible inplace - return x.and(this); - } - - - @Override - public ArrayContainer iandNot(final ArrayContainer value2) { - this.cardinality = Util.unsignedDifference(this.content, this.getCardinality(), value2.content, - value2.getCardinality(), this.content); - return this; - } - - @Override - public ArrayContainer iandNot(BitmapContainer value2) { - int pos = 0; - for (int k = 0; k < cardinality; ++k) { - short v = this.content[k]; - if (!value2.contains(v)) { - this.content[pos++] = v; - } - } - this.cardinality = pos; - return this; - } - - @Override - public Container iandNot(RunContainer x) { - // possible performance issue, not taking advantage of possible inplace - // could adapt algo above - return andNot(x); - } - - private void increaseCapacity() { - increaseCapacity(false); - } - - - // temporarily allow an illegally large size, as long as the operation creating - // the illegal container does not return it. - private void increaseCapacity(boolean allowIllegalSize) { - int newCapacity = (this.content.length == 0) ? DEFAULT_INIT_SIZE - : this.content.length < 64 ? this.content.length * 2 - : this.content.length < 1067 ? this.content.length * 3 / 2 - : this.content.length * 5 / 4; - // never allocate more than we will ever need - if (newCapacity > ArrayContainer.DEFAULT_MAX_SIZE && !allowIllegalSize) { - newCapacity = ArrayContainer.DEFAULT_MAX_SIZE; - } - // if we are within 1/16th of the max, go to max - if (newCapacity > ArrayContainer.DEFAULT_MAX_SIZE - ArrayContainer.DEFAULT_MAX_SIZE / 16 - && !allowIllegalSize) { - newCapacity = ArrayContainer.DEFAULT_MAX_SIZE; - } - this.content = Arrays.copyOf(this.content, newCapacity); - } - - private void increaseCapacity(int min) { - int newCapacity = (this.content.length == 0) ? DEFAULT_INIT_SIZE - : this.content.length < 64 ? this.content.length * 2 - : this.content.length < 1024 ? this.content.length * 3 / 2 - : this.content.length * 5 / 4; - if (newCapacity < min) { - newCapacity = min; - } - // never allocate more than we will ever need - if (newCapacity > ArrayContainer.DEFAULT_MAX_SIZE) { - newCapacity = ArrayContainer.DEFAULT_MAX_SIZE; - } - // if we are within 1/16th of the max, go to max - if (newCapacity > ArrayContainer.DEFAULT_MAX_SIZE - ArrayContainer.DEFAULT_MAX_SIZE / 16) { - newCapacity = ArrayContainer.DEFAULT_MAX_SIZE; - } - this.content = Arrays.copyOf(this.content, newCapacity); - } - - @Override - public Container inot(final int firstOfRange, final int lastOfRange) { - // TODO: may need to convert to a RunContainer - // determine the span of array indices to be affected - int startIndex = Util.unsignedBinarySearch(content, 0, cardinality, (short) firstOfRange); - if (startIndex < 0) { - startIndex = -startIndex - 1; - } - int lastIndex = Util.unsignedBinarySearch(content, 0, cardinality, (short) (lastOfRange - 1)); - if (lastIndex < 0) { - lastIndex = -lastIndex - 1 - 1; - } - final int currentValuesInRange = lastIndex - startIndex + 1; - final int spanToBeFlipped = lastOfRange - firstOfRange; - final int newValuesInRange = spanToBeFlipped - currentValuesInRange; - final short[] buffer = new short[newValuesInRange]; - final int cardinalityChange = newValuesInRange - currentValuesInRange; - final int newCardinality = cardinality + cardinalityChange; - - if (cardinalityChange > 0) { // expansion, right shifting needed - if (newCardinality > content.length) { - // so big we need a bitmap? - if (newCardinality > DEFAULT_MAX_SIZE) { - return toBitmapContainer().inot(firstOfRange, lastOfRange); - } - content = Arrays.copyOf(content, newCardinality); - } - // slide right the contents after the range - System.arraycopy(content, lastIndex + 1, content, lastIndex + 1 + cardinalityChange, - cardinality - 1 - lastIndex); - negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange); - } else { // no expansion needed - negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange); - if (cardinalityChange < 0) { - // contraction, left sliding. - // Leave array oversize - System.arraycopy(content, startIndex + newValuesInRange - cardinalityChange, content, - startIndex + newValuesInRange, newCardinality - (startIndex + newValuesInRange)); - } - } - cardinality = newCardinality; - return this; - } - - @Override - public boolean intersects(ArrayContainer value2) { - ArrayContainer value1 = this; - return Util.unsignedIntersects(value1.content, value1.getCardinality(), value2.content, - value2.getCardinality()); - } - - - @Override - public boolean intersects(BitmapContainer x) { - return x.intersects(this); - } - - @Override - public boolean intersects(RunContainer x) { - return x.intersects(this); - } - - - @Override - public Container ior(final ArrayContainer value2) { - return this.or(value2); - } - - @Override - public Container ior(BitmapContainer x) { - return x.or(this); - } - - @Override - public Container ior(RunContainer x) { - // possible performance issue, not taking advantage of possible inplace - return x.or(this); - } - - @Override - public Container iremove(int begin, int end) { - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = Util.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = Util.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = indexend - indexstart; - System.arraycopy(content, indexstart + rangelength, content, indexstart, - cardinality - indexstart - rangelength); - cardinality -= rangelength; - return this; - } - - @Override - public Iterator iterator() { - return new Iterator() { - short pos = 0; - - @Override - public boolean hasNext() { - return pos < ArrayContainer.this.cardinality; - } - - @Override - public Short next() { - return ArrayContainer.this.content[pos++]; - } - - @Override - public void remove() { - ArrayContainer.this.remove((short) (pos - 1)); - pos--; - } - }; - } - - @Override - public Container ixor(final ArrayContainer value2) { - return this.xor(value2); - } - - @Override - public Container ixor(BitmapContainer x) { - return x.xor(this); - } - - - @Override - public Container ixor(RunContainer x) { - // possible performance issue, not taking advantage of possible inplace - return x.xor(this); - } - - - @Override - public Container limit(int maxcardinality) { - if (maxcardinality < this.getCardinality()) { - return new ArrayContainer(maxcardinality, this.content); - } else { - return clone(); - } - } - - protected void loadData(final BitmapContainer bitmapContainer) { - this.cardinality = bitmapContainer.cardinality; - bitmapContainer.fillArray(content); - } - - // for use in inot range known to be nonempty - private void negateRange(final short[] buffer, final int startIndex, final int lastIndex, - final int startRange, final int lastRange) { - // compute the negation into buffer - - int outPos = 0; - int inPos = startIndex; // value here always >= valInRange, - // until it is exhausted - // n.b., we can start initially exhausted. - - int valInRange = startRange; - for (; valInRange < lastRange && inPos <= lastIndex; ++valInRange) { - if ((short) valInRange != content[inPos]) { - buffer[outPos++] = (short) valInRange; - } else { - ++inPos; - } - } - - // if there are extra items (greater than the biggest - // pre-existing one in range), buffer them - for (; valInRange < lastRange; ++valInRange) { - buffer[outPos++] = (short) valInRange; - } - - if (outPos != buffer.length) { - throw new RuntimeException( - "negateRange: outPos " + outPos + " whereas buffer.length=" + buffer.length); - } - // copy back from buffer...caller must ensure there is room - int i = startIndex; - for (short item : buffer) { - content[i++] = item; - } - } - - // shares lots of code with inot; candidate for refactoring - @Override - public Container not(final int firstOfRange, final int lastOfRange) { - // TODO: may need to convert to a RunContainer - if (firstOfRange >= lastOfRange) { - return clone(); // empty range - } - - // determine the span of array indices to be affected - int startIndex = Util.unsignedBinarySearch(content, 0, cardinality, (short) firstOfRange); - if (startIndex < 0) { - startIndex = -startIndex - 1; - } - int lastIndex = Util.unsignedBinarySearch(content, 0, cardinality, (short) (lastOfRange - 1)); - if (lastIndex < 0) { - lastIndex = -lastIndex - 2; - } - final int currentValuesInRange = lastIndex - startIndex + 1; - final int spanToBeFlipped = lastOfRange - firstOfRange; - final int newValuesInRange = spanToBeFlipped - currentValuesInRange; - final int cardinalityChange = newValuesInRange - currentValuesInRange; - final int newCardinality = cardinality + cardinalityChange; - - if (newCardinality > DEFAULT_MAX_SIZE) { - return toBitmapContainer().not(firstOfRange, lastOfRange); - } - - ArrayContainer answer = new ArrayContainer(newCardinality); - - // copy stuff before the active area - System.arraycopy(content, 0, answer.content, 0, startIndex); - - int outPos = startIndex; - int inPos = startIndex; // item at inPos always >= valInRange - - int valInRange = firstOfRange; - for (; valInRange < lastOfRange && inPos <= lastIndex; ++valInRange) { - if ((short) valInRange != content[inPos]) { - answer.content[outPos++] = (short) valInRange; - } else { - ++inPos; - } - } - - for (; valInRange < lastOfRange; ++valInRange) { - answer.content[outPos++] = (short) valInRange; - } - - // content after the active range - for (int i = lastIndex + 1; i < cardinality; ++i) { - answer.content[outPos++] = content[i]; - } - answer.cardinality = newCardinality; - return answer; - } - - @Override - int numberOfRuns() { - if (cardinality == 0) { - return 0; // should never happen - } - int numRuns = 1; - int oldv = Util.toIntUnsigned(content[0]); - for (int i = 1; i < cardinality; i++) { - int newv = Util.toIntUnsigned(content[i]); - if (oldv + 1 != newv) { - ++numRuns; - } - oldv = newv; - } - return numRuns; - } - - @Override - public Container or(final ArrayContainer value2) { - final ArrayContainer value1 = this; - int totalCardinality = value1.getCardinality() + value2.getCardinality(); - if (totalCardinality > DEFAULT_MAX_SIZE) {// it could be a bitmap! - BitmapContainer bc = new BitmapContainer(); - for (int k = 0; k < value2.cardinality; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - bc.bitmap[i] |= (1L << v); - } - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - bc.bitmap[i] |= (1L << v); - } - bc.cardinality = 0; - for (long k : bc.bitmap) { - bc.cardinality += Long.bitCount(k); - } - if (bc.cardinality <= DEFAULT_MAX_SIZE) { - return bc.toArrayContainer(); - } - return bc; - } - final int desiredCapacity = totalCardinality; // Math.min(BitmapContainer.MAX_CAPACITY, - // totalCardinality); - ArrayContainer answer = new ArrayContainer(desiredCapacity); - answer.cardinality = Util.unsignedUnion2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content); - return answer; - } - - @Override - public Container or(BitmapContainer x) { - return x.or(this); - } - - @Override - public Container or(RunContainer x) { - return x.or(this); - } - - protected Container or(ShortIterator it) { - return or(it, false); - } - - /** - * it must return items in (unsigned) sorted order. Possible candidate for Container interface? - **/ - private Container or(ShortIterator it, final boolean exclusive) { - ArrayContainer ac = new ArrayContainer(); - int myItPos = 0; - ac.cardinality = 0; - // do a merge. int -1 denotes end of input. - int myHead = (myItPos == cardinality) ? -1 : Util.toIntUnsigned(content[myItPos++]); - int hisHead = advance(it); - - while (myHead != -1 && hisHead != -1) { - if (myHead < hisHead) { - ac.emit((short) myHead); - myHead = (myItPos == cardinality) ? -1 : Util.toIntUnsigned(content[myItPos++]); - } else if (myHead > hisHead) { - ac.emit((short) hisHead); - hisHead = advance(it); - } else { - if (!exclusive) { - ac.emit((short) hisHead); - } - hisHead = advance(it); - myHead = (myItPos == cardinality) ? -1 : Util.toIntUnsigned(content[myItPos++]); - } - } - - while (myHead != -1) { - ac.emit((short) myHead); - myHead = (myItPos == cardinality) ? -1 : Util.toIntUnsigned(content[myItPos++]); - } - - while (hisHead != -1) { - ac.emit((short) hisHead); - hisHead = advance(it); - } - - if (ac.cardinality > DEFAULT_MAX_SIZE) { - return ac.toBitmapContainer(); - } else { - return ac; - } - } - - @Override - public int rank(short lowbits) { - int answer = Util.unsignedBinarySearch(content, 0, cardinality, lowbits); - if (answer >= 0) { - return answer + 1; - } else { - return -answer - 1; - } - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - deserialize(in); - } - - @Override - public Container remove(int begin, int end) { - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = Util.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = Util.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = indexend - indexstart; - ArrayContainer answer = clone(); - System.arraycopy(content, indexstart + rangelength, answer.content, indexstart, - cardinality - indexstart - rangelength); - answer.cardinality = cardinality - rangelength; - return answer; - } - - @Override - public Container remove(final short x) { - final int loc = Util.unsignedBinarySearch(content, 0, cardinality, x); - if (loc >= 0) { - // insertion - System.arraycopy(content, loc + 1, content, loc, cardinality - loc - 1); - --cardinality; - } - return this; - } - - @Override - public Container repairAfterLazy() { - return this; - } - - @Override - public Container runOptimize() { - // TODO: consider borrowing the BitmapContainer idea of early - // abandonment - // with ArrayContainers, when the number of runs in the arrayContainer - // passes some threshold based on the cardinality. - int numRuns = numberOfRuns(); - int sizeAsRunContainer = RunContainer.serializedSizeInBytes(numRuns); - if (getArraySizeInBytes() > sizeAsRunContainer) { - return new RunContainer(this, numRuns); // this could be maybe - // faster if initial - // container is a bitmap - } else { - return this; - } - } - - @Override - public short select(int j) { - return this.content[j]; - } - - @Override - public void serialize(DataOutput out) throws IOException { - out.writeShort(Short.reverseBytes((short) this.cardinality)); - // little endian - for (int k = 0; k < this.cardinality; ++k) { - out.writeShort(Short.reverseBytes(this.content[k])); - } - } - - @Override - public int serializedSizeInBytes() { - return serializedSizeInBytes(cardinality); - } - - /** - * Copies the data in a bitmap container. - * - * @return the bitmap container - */ - public BitmapContainer toBitmapContainer() { - BitmapContainer bc = new BitmapContainer(); - bc.loadData(this); - return bc; - } - - @Override - public MappeableContainer toMappeableContainer() { - return new MappeableArrayContainer(this); - } - - /** - * Return the content of this container as a ShortBuffer. This creates a copy and might be - * relatively slow. - * - * @return the ShortBuffer - */ - public ShortBuffer toShortBuffer() { - ShortBuffer sb = ShortBuffer.allocate(this.cardinality); - sb.put(this.content, 0, this.cardinality); - return sb; - } - - @Override - public String toString() { - if (this.cardinality == 0) { - return "{}"; - } - StringBuilder sb = new StringBuilder(); - sb.append("{"); - for (int i = 0; i < this.cardinality - 1; i++) { - sb.append(this.content[i]); - sb.append(","); - } - sb.append(this.content[this.cardinality - 1]); - sb.append("}"); - return sb.toString(); - } - - @Override - public void trim() { - if (this.content.length == this.cardinality) { - return; - } - this.content = Arrays.copyOf(this.content, this.cardinality); - } - - @Override - protected void writeArray(DataOutput out) throws IOException { - // little endian - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content[k]; - out.write(v & 0xFF); - out.write((v >>> 8) & 0xFF); - } - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - serialize(out); - } - - @Override - public Container xor(final ArrayContainer value2) { - final ArrayContainer value1 = this; - final int totalCardinality = value1.getCardinality() + value2.getCardinality(); - if (totalCardinality > DEFAULT_MAX_SIZE) {// it could be a bitmap! - BitmapContainer bc = new BitmapContainer(); - for (int k = 0; k < value2.cardinality; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - bc.bitmap[i] ^= (1L << v); - } - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - bc.bitmap[i] ^= (1L << v); - } - bc.cardinality = 0; - for (long k : bc.bitmap) { - bc.cardinality += Long.bitCount(k); - } - if (bc.cardinality <= DEFAULT_MAX_SIZE) { - return bc.toArrayContainer(); - } - return bc; - } - final int desiredCapacity = totalCardinality; - ArrayContainer answer = new ArrayContainer(desiredCapacity); - answer.cardinality = Util.unsignedExclusiveUnion2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content); - return answer; - } - - @Override - public Container xor(BitmapContainer x) { - return x.xor(this); - } - - @Override - public Container xor(RunContainer x) { - return x.xor(this); - } - - - protected Container xor(ShortIterator it) { - return or(it, true); - } - - @Override - public void forEach(short msb, IntConsumer ic) { - int high = ((int) msb) << 16; - for (int k = 0; k < cardinality; ++k) { - ic.accept((content[k] & 0xFFFF) | high); - } - } - - protected Container lazyor(ArrayContainer value2) { - final ArrayContainer value1 = this; - int totalCardinality = value1.getCardinality() + value2.getCardinality(); - if (totalCardinality > ARRAY_LAZY_LOWERBOUND) {// it could be a bitmap! - BitmapContainer bc = new BitmapContainer(); - for (int k = 0; k < value2.cardinality; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - bc.bitmap[i] |= (1L << v); - } - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - bc.bitmap[i] |= (1L << v); - } - bc.cardinality = -1; - return bc; - } - final int desiredCapacity = totalCardinality; // Math.min(BitmapContainer.MAX_CAPACITY, - // totalCardinality); - ArrayContainer answer = new ArrayContainer(desiredCapacity); - answer.cardinality = Util.unsignedUnion2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content); - return answer; - - } - - -} - - -final class ArrayContainerShortIterator implements PeekableShortIterator { - int pos; - ArrayContainer parent; - - ArrayContainerShortIterator() { - } - - ArrayContainerShortIterator(ArrayContainer p) { - wrap(p); - } - - @Override - public void advanceIfNeeded(short minval) { - pos = Util.advanceUntil(parent.content, pos - 1, parent.cardinality, minval); - } - - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < parent.cardinality; - } - - @Override - public short next() { - return parent.content[pos++]; - } - - @Override - public int nextAsInt() { - return Util.toIntUnsigned(parent.content[pos++]); - } - - @Override - public short peekNext() { - return parent.content[pos]; - } - - - @Override - public void remove() { - parent.remove((short) (pos - 1)); - pos--; - } - - void wrap(ArrayContainer p) { - parent = p; - pos = 0; - } - -}; - - -final class ReverseArrayContainerShortIterator implements ShortIterator { - int pos; - ArrayContainer parent; - - ReverseArrayContainerShortIterator() { - } - - ReverseArrayContainerShortIterator(ArrayContainer p) { - wrap(p); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - @Override - public short next() { - return parent.content[pos--]; - } - - @Override - public int nextAsInt() { - return Util.toIntUnsigned(parent.content[pos--]); - } - - - @Override - public void remove() { - parent.remove((short) (pos + 1)); - pos++; - } - - void wrap(ArrayContainer p) { - parent = p; - pos = parent.cardinality - 1; - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitSetUtil.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitSetUtil.java deleted file mode 100644 index c213e2a6a..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitSetUtil.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.fr.third.bitmap.roaringbitmap; - - -import java.util.Arrays; -import java.util.BitSet; - - -/*** - * - * This class provides convenience functions to manipulate BitSet and RoaringBitmap objects. - * - */ -public class BitSetUtil { - // todo: add a method to convert a RoaringBitmap to a BitSet using BitSet.valueOf - - // a block consists has a maximum of 1024 words, each representing 64 bits, - // thus representing at maximum 65536 bits - static final private int BLOCK_LENGTH = BitmapContainer.MAX_CAPACITY / Long.SIZE; // - // 64-bit - // word - - private static ArrayContainer arrayContainerOf(final int from, final int to, - final int cardinality, final long[] words) { - // precondition: cardinality is max 4096 - final short[] content = new short[cardinality]; - int index = 0; - - for (int i = from, socket = 0; i < to; ++i, socket += Long.SIZE) { - long word = words[i]; - while (word != 0) { - long t = word & -word; - content[index++] = (short) (socket + Long.bitCount(t - 1)); - word ^= t; - } - } - return new ArrayContainer(content); - } - - /** - * Generate a RoaringBitmap out of a long[], each long using little-endian representation of its - * bits - * - * @param words array of longs (will not be modified) - * @return roaring bitmap - * @see BitSet#toLongArray() for an equivalent - */ - public static RoaringBitmap bitmapOf(final long[] words) { - // split long[] into blocks. - // each block becomes a single container, if any bit is set - final RoaringBitmap ans = new RoaringBitmap(); - int containerIndex = 0; - for (int from = 0; from < words.length; from += BLOCK_LENGTH) { - final int to = Math.min(from + BLOCK_LENGTH, words.length); - final int blockCardinality = cardinality(from, to, words); - if (blockCardinality > 0) { - ans.highLowContainer.insertNewKeyValueAt(containerIndex++, Util.highbits(from * Long.SIZE), - BitSetUtil.containerOf(from, to, blockCardinality, words)); - } - } - return ans; - } - - private static int cardinality(final int from, final int to, final long[] words) { - int sum = 0; - for (int i = from; i < to; i++) { - sum += Long.bitCount(words[i]); - } - return sum; - } - - - private static Container containerOf(final int from, final int to, final int blockCardinality, - final long[] words) { - // find the best container available - if (blockCardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - // containers with DEFAULT_MAX_SIZE or less integers should be - // ArrayContainers - return arrayContainerOf(from, to, blockCardinality, words); - } else { - // otherwise use bitmap container - return new BitmapContainer(Arrays.copyOfRange(words, from, from + BLOCK_LENGTH), - blockCardinality); - } - } - - - /** - * Compares a RoaringBitmap and a BitSet. They are equal if and only if they contain the same set - * of integers. - * - * @param bitset first object to be compared - * @param bitmap second object to be compared - * @return whether they are equals - */ - public static boolean equals(final BitSet bitset, final RoaringBitmap bitmap) { - if (bitset.cardinality() != bitmap.getCardinality()) { - return false; - } - final IntIterator it = bitmap.getIntIterator(); - while (it.hasNext()) { - int val = it.next(); - if (!bitset.get(val)) { - return false; - } - } - return true; - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitmapContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitmapContainer.java deleted file mode 100644 index 5d33fe299..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitmapContainer.java +++ /dev/null @@ -1,1392 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableBitmapContainer; -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableContainer; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.LongBuffer; -import java.util.Arrays; -import java.util.Iterator; - - -/** - * Simple bitset-like container. - */ -public final class BitmapContainer extends Container implements Cloneable { - /** - * optimization flag: whether the cardinality of the bitmaps is maintained through branchless - * operations - */ - public static final boolean USE_BRANCHLESS = true; - protected static final int MAX_CAPACITY = 1 << 16; - private static final long serialVersionUID = 2L; - // 64 words can have max 32 runs per word, max 2k runs - // bail out early when the number of runs is excessive, without - // an exact count (just a decent lower bound) - private static final int BLOCKSIZE = 128; - // nruns value for which RunContainer.serializedSizeInBytes == - // BitmapContainer.getArraySizeInBytes() - private final int MAXRUNS = (getArraySizeInBytes() - 2) / 4; - long[] bitmap; - int cardinality; - - /** - * Create a bitmap container with all bits set to false - */ - public BitmapContainer() { - this.cardinality = 0; - this.bitmap = new long[MAX_CAPACITY / 64]; - } - - /** - * Create a bitmap container with a run of ones from firstOfRun to lastOfRun. Caller must ensure - * that the range isn't so small that an ArrayContainer should have been created instead - * - * @param firstOfRun first index - * @param lastOfRun last index (range is exclusive) - */ - public BitmapContainer(final int firstOfRun, final int lastOfRun) { - this.cardinality = lastOfRun - firstOfRun; - this.bitmap = new long[MAX_CAPACITY / 64]; - Util.setBitmapRange(bitmap, firstOfRun, lastOfRun); - } - - private BitmapContainer(int newCardinality, long[] newBitmap) { - this.cardinality = newCardinality; - this.bitmap = Arrays.copyOf(newBitmap, newBitmap.length); - } - - - /** - * Create a new container, no copy is made. - * - * @param newBitmap content - * @param newCardinality desired cardinality. - */ - public BitmapContainer(long[] newBitmap, int newCardinality) { - this.cardinality = newCardinality; - this.bitmap = newBitmap; - } - - - /** - * Creates a new non-mappeable container from a mappeable one. This copies the data. - * - * @param bc the original container - */ - public BitmapContainer(MappeableBitmapContainer bc) { - this.cardinality = bc.getCardinality(); - this.bitmap = bc.toLongArray(); - } - - /** - * Return a bitmap iterator over this array - * - * @param bitmap array to be iterated over - * @return an iterator - */ - public static ShortIterator getReverseShortIterator(long[] bitmap) { - return new ReverseBitmapContainerShortIterator(bitmap); - } - - /** - * Return a bitmap iterator over this array - * - * @param bitmap array to be iterated over - * @return an iterator - */ - public static PeekableShortIterator getShortIterator(long[] bitmap) { - return new BitmapContainerShortIterator(bitmap); - } - - // the parameter is for overloading and symmetry with ArrayContainer - protected static int serializedSizeInBytes(int unusedCardinality) { - return MAX_CAPACITY / 8; - } - - @Override - public Container add(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - BitmapContainer answer = clone(); - Util.setBitmapRange(answer.bitmap, begin, end); - answer.computeCardinality(); - return answer; - } - - - @Override - public Container add(final short i) { - final int x = Util.toIntUnsigned(i); - final long previous = bitmap[x / 64]; - long newval = previous | (1L << x); - bitmap[x / 64] = newval; - if (USE_BRANCHLESS) { - cardinality += (previous ^ newval) >>> x; - } else if (previous != newval) { - ++cardinality; - } - return this; - } - - @Override - public ArrayContainer and(final ArrayContainer value2) { - final ArrayContainer answer = new ArrayContainer(value2.content.length); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content[k]; - if (this.contains(v)) { - answer.content[answer.cardinality++] = v; - } - } - return answer; - } - - @Override - public Container and(final BitmapContainer value2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] & value2.bitmap[k]); - } - if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { - final BitmapContainer answer = new BitmapContainer(); - for (int k = 0; k < answer.bitmap.length; ++k) { - answer.bitmap[k] = this.bitmap[k] & value2.bitmap[k]; - } - answer.cardinality = newCardinality; - return answer; - } - ArrayContainer ac = new ArrayContainer(newCardinality); - Util.fillArrayAND(ac.content, this.bitmap, value2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public Container and(RunContainer x) { - return x.and(this); - } - - @Override - public int andCardinality(final ArrayContainer value2) { - int answer = 0; - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content[k]; - if (this.contains(v)) { - answer++; - } - } - return answer; - } - - @Override - public int andCardinality(final BitmapContainer value2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] & value2.bitmap[k]); - } - return newCardinality; - } - - @Override - public int andCardinality(RunContainer x) { - return x.andCardinality(this); - } - - @Override - public Container andNot(final ArrayContainer value2) { - final BitmapContainer answer = clone(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - long w = answer.bitmap[i]; - long aft = w & (~(1L << v)); - answer.bitmap[i] = aft; - answer.cardinality -= (w ^ aft) >>> v; - } - if (answer.cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - return answer.toArrayContainer(); - } - return answer; - } - - @Override - public Container andNot(final BitmapContainer value2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] & (~value2.bitmap[k])); - } - if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { - final BitmapContainer answer = new BitmapContainer(); - for (int k = 0; k < answer.bitmap.length; ++k) { - answer.bitmap[k] = this.bitmap[k] & (~value2.bitmap[k]); - } - answer.cardinality = newCardinality; - return answer; - } - ArrayContainer ac = new ArrayContainer(newCardinality); - Util.fillArrayANDNOT(ac.content, this.bitmap, value2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public Container andNot(RunContainer x) { - // could be rewritten as return andNot(x.toBitmapOrArrayContainer()); - BitmapContainer answer = this.clone(); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(x.getValue(rlepos)); - int end = start + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.resetBitmapRange(answer.bitmap, start, end); - } - answer.computeCardinality(); - if (answer.getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public void clear() { - if (cardinality != 0) { - cardinality = 0; - Arrays.fill(bitmap, 0); - } - } - - @Override - public BitmapContainer clone() { - return new BitmapContainer(this.cardinality, this.bitmap); - } - - /** - * Recomputes the cardinality of the bitmap. - */ - protected void computeCardinality() { - this.cardinality = 0; - for (int k = 0; k < this.bitmap.length; k++) { - this.cardinality += Long.bitCount(this.bitmap[k]); - } - } - - @Override - public boolean contains(final short i) { - final int x = Util.toIntUnsigned(i); - return (bitmap[x / 64] & (1L << x)) != 0; - } - - @Override - public void deserialize(DataInput in) throws IOException { - // little endian - this.cardinality = 0; - for (int k = 0; k < bitmap.length; ++k) { - long w = Long.reverseBytes(in.readLong()); - bitmap[k] = w; - this.cardinality += Long.bitCount(w); - } - } - - @Override - public boolean equals(Object o) { - if (o instanceof BitmapContainer) { - BitmapContainer srb = (BitmapContainer) o; - if (srb.cardinality != this.cardinality) { - return false; - } - return Arrays.equals(this.bitmap, srb.bitmap); - } else if (o instanceof RunContainer) { - return o.equals(this); - } - return false; - } - - - /** - * Fill the array with set bits - * - * @param array container (should be sufficiently large) - */ - protected void fillArray(final short[] array) { - int pos = 0; - int base = 0; - for (int k = 0; k < bitmap.length; ++k) { - long bitset = bitmap[k]; - while (bitset != 0) { - long t = bitset & -bitset; - array[pos++] = (short) (base + Long.bitCount(t - 1)); - bitset ^= t; - } - base += 64; - } - } - - @Override - public void fillLeastSignificant16bits(int[] x, int i, int mask) { - int pos = i; - int base = mask; - for (int k = 0; k < bitmap.length; ++k) { - long bitset = bitmap[k]; - while (bitset != 0) { - long t = bitset & -bitset; - x[pos++] = base + Long.bitCount(t - 1); - bitset ^= t; - } - base += 64; - } - } - - - @Override - public Container flip(short i) { - final int x = Util.toIntUnsigned(i); - int index = x / 64; - long bef = bitmap[index]; - long mask = 1L << x; - if (cardinality == ArrayContainer.DEFAULT_MAX_SIZE + 1) {// this is - // the - // uncommon - // path - if ((bef & mask) != 0) { - --cardinality; - bitmap[index] &= ~mask; - return this.toArrayContainer(); - } - } - // TODO: check whether a branchy version could be faster - cardinality += 1 - 2 * ((bef & mask) >>> x); - bitmap[index] ^= mask; - return this; - } - - @Override - protected int getArraySizeInBytes() { - return MAX_CAPACITY / 8; - } - - @Override - public int getCardinality() { - return cardinality; - } - - @Override - public ShortIterator getReverseShortIterator() { - return new ReverseBitmapContainerShortIterator(this.bitmap); - } - - @Override - public PeekableShortIterator getShortIterator() { - return new BitmapContainerShortIterator(this.bitmap); - } - - @Override - public int getSizeInBytes() { - return this.bitmap.length * 8; - } - - @Override - public int hashCode() { - return Arrays.hashCode(this.bitmap); - } - - @Override - public Container iadd(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - Util.setBitmapRange(bitmap, begin, end); - computeCardinality(); - return this; - } - - @Override - public Container iand(final ArrayContainer b2) { - return b2.and(this);// no inplace possible - } - - @Override - public Container iand(final BitmapContainer b2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] & b2.bitmap[k]); - } - if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < this.bitmap.length; ++k) { - this.bitmap[k] = this.bitmap[k] & b2.bitmap[k]; - } - this.cardinality = newCardinality; - return this; - } - ArrayContainer ac = new ArrayContainer(newCardinality); - Util.fillArrayAND(ac.content, this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public Container iand(RunContainer x) { - // could probably be replaced with return iand(x.toBitmapOrArrayContainer()); - final int card = x.getCardinality(); - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - // no point in doing it in-place - ArrayContainer answer = new ArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(x.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(x.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (this.contains((short) runValue)) {// it looks like contains() should be cheap enough - // if accessed sequentially - answer.content[answer.cardinality++] = (short) runValue; - } - } - } - return answer; - } - int start = 0; - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int end = Util.toIntUnsigned(x.getValue(rlepos)); - Util.resetBitmapRange(this.bitmap, start, end); - start = end + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - } - Util.resetBitmapRange(this.bitmap, start, Util.maxLowBitAsInteger() + 1); - computeCardinality(); - if (getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - } - - @Override - public Container iandNot(final ArrayContainer b2) { - for (int k = 0; k < b2.cardinality; ++k) { - this.remove(b2.content[k]); - } - if (cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - return this.toArrayContainer(); - } - return this; - } - - @Override - public Container iandNot(final BitmapContainer b2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] & (~b2.bitmap[k])); - } - if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < this.bitmap.length; ++k) { - this.bitmap[k] = this.bitmap[k] & (~b2.bitmap[k]); - } - this.cardinality = newCardinality; - return this; - } - ArrayContainer ac = new ArrayContainer(newCardinality); - Util.fillArrayANDNOT(ac.content, this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public Container iandNot(RunContainer x) { - // could probably be replaced with return iandNot(x.toBitmapOrArrayContainer()); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(x.getValue(rlepos)); - int end = start + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.resetBitmapRange(this.bitmap, start, end); - } - computeCardinality(); - if (getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - } - - protected Container ilazyor(ArrayContainer value2) { - this.cardinality = -1;// invalid - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - this.bitmap[i] |= (1L << v); - } - return this; - } - - protected Container ilazyor(BitmapContainer x) { - this.cardinality = -1;// invalid - for (int k = 0; k < this.bitmap.length; k++) { - this.bitmap[k] |= x.bitmap[k]; - } - return this; - } - - protected Container ilazyor(RunContainer x) { - // could be implemented as return ilazyor(x.toTemporaryBitmap()); - cardinality = -1; // invalid - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(x.getValue(rlepos)); - int end = start + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.setBitmapRange(this.bitmap, start, end); - } - return this; - } - - @Override - public Container inot(final int firstOfRange, final int lastOfRange) { - if (lastOfRange - firstOfRange == MAX_CAPACITY) { - Util.flipBitmapRange(bitmap, firstOfRange, lastOfRange); - cardinality = MAX_CAPACITY - cardinality; - } else if (lastOfRange - firstOfRange > MAX_CAPACITY / 2) { - Util.flipBitmapRange(bitmap, firstOfRange, lastOfRange); - computeCardinality(); - } else { - cardinality += Util.flipBitmapRangeAndCardinalityChange(bitmap, firstOfRange, lastOfRange); - } - if (cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - return toArrayContainer(); - } - return this; - } - - @Override - public boolean intersects(ArrayContainer value2) { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - if (this.contains(value2.content[k])) { - return true; - } - } - return false; - } - - @Override - public boolean intersects(BitmapContainer value2) { - for (int k = 0; k < this.bitmap.length; ++k) { - if ((this.bitmap[k] & value2.bitmap[k]) != 0) { - return true; - } - } - return false; - } - - @Override - public boolean intersects(RunContainer x) { - return x.intersects(this); - } - - @Override - public BitmapContainer ior(final ArrayContainer value2) { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - final int i = Util.toIntUnsigned(value2.content[k]) >>> 6; - - long bef = this.bitmap[i]; - long aft = bef | (1L << value2.content[k]); - this.bitmap[i] = aft; - if (USE_BRANCHLESS) { - cardinality += (bef - aft) >>> 63; - } else { - if (bef != aft) { - cardinality++; - } - } - } - return this; - } - - @Override - public Container ior(final BitmapContainer b2) { - this.cardinality = 0; - for (int k = 0; k < this.bitmap.length; k++) { - long w = this.bitmap[k] | b2.bitmap[k]; - this.bitmap[k] = w; - this.cardinality += Long.bitCount(w); - } - return this; - } - - @Override - public Container ior(RunContainer x) { - // could probably be replaced with return ior(x.toBitmapOrArrayContainer()); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(x.getValue(rlepos)); - int end = start + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.setBitmapRange(this.bitmap, start, end); - } - computeCardinality(); - return this; - } - - @Override - public Container iremove(int begin, int end) { - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - Util.resetBitmapRange(bitmap, begin, end); - computeCardinality(); - if (getCardinality() <= ArrayContainer.DEFAULT_MAX_SIZE) { - return toArrayContainer(); - } - return this; - } - - @Override - public Iterator iterator() { - return new Iterator() { - final ShortIterator si = BitmapContainer.this.getShortIterator(); - - @Override - public boolean hasNext() { - return si.hasNext(); - } - - @Override - public Short next() { - return si.next(); - } - - @Override - public void remove() { - // TODO: implement - throw new RuntimeException("unsupported operation: remove"); - } - }; - } - - @Override - public Container ixor(final ArrayContainer value2) { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short vc = value2.content[k]; - long mask = 1L << vc; - final int index = Util.toIntUnsigned(vc) >>> 6; - long ba = this.bitmap[index]; - // TODO: check whether a branchy version could be faster - this.cardinality += 1 - 2 * ((ba & mask) >>> vc); - this.bitmap[index] = ba ^ mask; - } - if (this.cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - return this.toArrayContainer(); - } - return this; - } - - - @Override - public Container ixor(BitmapContainer b2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] ^ b2.bitmap[k]); - } - if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < this.bitmap.length; ++k) { - this.bitmap[k] = this.bitmap[k] ^ b2.bitmap[k]; - } - this.cardinality = newCardinality; - return this; - } - ArrayContainer ac = new ArrayContainer(newCardinality); - Util.fillArrayXOR(ac.content, this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public Container ixor(RunContainer x) { - // could probably be replaced with return ixor(x.toBitmapOrArrayContainer()); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(x.getValue(rlepos)); - int end = start + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.flipBitmapRange(this.bitmap, start, end); - } - computeCardinality(); - if (this.getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - } - - protected Container lazyor(ArrayContainer value2) { - BitmapContainer answer = this.clone(); - answer.cardinality = -1;// invalid - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - answer.bitmap[i] |= (1L << v); - } - return answer; - } - - protected Container lazyor(BitmapContainer x) { - BitmapContainer answer = new BitmapContainer(); - answer.cardinality = -1;// invalid - for (int k = 0; k < this.bitmap.length; k++) { - answer.bitmap[k] = this.bitmap[k] | x.bitmap[k]; - } - return answer; - } - - - protected Container lazyor(RunContainer x) { - BitmapContainer bc = clone(); - bc.cardinality = -1; // invalid - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(x.getValue(rlepos)); - int end = start + Util.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.setBitmapRange(bc.bitmap, start, end); - } - return bc; - } - - @Override - public Container limit(int maxcardinality) { - if (maxcardinality >= this.cardinality) { - return clone(); - } - if (maxcardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - ArrayContainer ac = new ArrayContainer(maxcardinality); - int pos = 0; - for (int k = 0; (ac.cardinality < maxcardinality) && (k < bitmap.length); ++k) { - long bitset = bitmap[k]; - while ((ac.cardinality < maxcardinality) && (bitset != 0)) { - long t = bitset & -bitset; - ac.content[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - ac.cardinality++; - bitset ^= t; - } - } - return ac; - } - BitmapContainer bc = new BitmapContainer(maxcardinality, this.bitmap); - int s = Util.toIntUnsigned(select(maxcardinality)); - int usedwords = (s + 63) / 64; - int todelete = this.bitmap.length - usedwords; - for (int k = 0; k < todelete; ++k) { - bc.bitmap[bc.bitmap.length - 1 - k] = 0; - } - int lastword = s % 64; - if (lastword != 0) { - bc.bitmap[s / 64] &= (0xFFFFFFFFFFFFFFFFL >>> (64 - lastword)); - } - return bc; - } - - protected void loadData(final ArrayContainer arrayContainer) { - this.cardinality = arrayContainer.cardinality; - for (int k = 0; k < arrayContainer.cardinality; ++k) { - final short x = arrayContainer.content[k]; - bitmap[Util.toIntUnsigned(x) / 64] |= (1L << x); - } - } - - /** - * Find the index of the next set bit greater or equal to i, returns -1 if none found. - * - * @param i starting index - * @return index of the next set bit - */ - public int nextSetBit(final int i) { - int x = i >> 6; // i / 64 with sign extension - long w = bitmap[x]; - w >>>= i; - if (w != 0) { - return i + Long.numberOfTrailingZeros(w); - } - for (++x; x < bitmap.length; ++x) { - if (bitmap[x] != 0) { - return x * 64 + Long.numberOfTrailingZeros(bitmap[x]); - } - } - return -1; - } - - /** - * Find the index of the next unset bit greater or equal to i, returns -1 if none found. - * - * @param i starting index - * @return index of the next unset bit - */ - public short nextUnsetBit(final int i) { - int x = i / 64; - long w = ~bitmap[x]; - w >>>= i; - if (w != 0) { - return (short) (i + Long.numberOfTrailingZeros(w)); - } - ++x; - for (; x < bitmap.length; ++x) { - if (bitmap[x] != ~0L) { - return (short) (x * 64 + Long.numberOfTrailingZeros(~bitmap[x])); - } - } - return -1; - } - - - @Override - public Container not(final int firstOfRange, final int lastOfRange) { - BitmapContainer answer = clone(); - return answer.inot(firstOfRange, lastOfRange); - } - - @Override - int numberOfRuns() { - int numRuns = 0; - long nextWord = bitmap[0]; - - for (int i = 0; i < bitmap.length - 1; i++) { - long word = nextWord; - nextWord = bitmap[i + 1]; - numRuns += Long.bitCount((~word) & (word << 1)) + ((word >>> 63) & ~nextWord); - } - - long word = nextWord; - numRuns += Long.bitCount((~word) & (word << 1)); - if ((word & 0x8000000000000000L) != 0) { - numRuns++; - } - - return numRuns; - } - - /** - * Computes the number of runs - * - * @return the number of runs - */ - public int numberOfRunsAdjustment() { - int ans = 0; - long nextWord = bitmap[0]; - for (int i = 0; i < bitmap.length - 1; i++) { - final long word = nextWord; - - nextWord = bitmap[i + 1]; - ans += ((word >>> 63) & ~nextWord); - } - final long word = nextWord; - - if ((word & 0x8000000000000000L) != 0) { - ans++; - } - return ans; - } - - /** - * Counts how many runs there is in the bitmap, up to a maximum - * - * @param mustNotExceed maximum of runs beyond which counting is pointless - * @return estimated number of courses - */ - public int numberOfRunsLowerBound(int mustNotExceed) { - int numRuns = 0; - - for (int blockOffset = 0; blockOffset < bitmap.length; blockOffset += BLOCKSIZE) { - - for (int i = blockOffset; i < blockOffset + BLOCKSIZE; i++) { - long word = bitmap[i]; - numRuns += Long.bitCount((~word) & (word << 1)); - } - if (numRuns > mustNotExceed) { - return numRuns; - } - } - return numRuns; - } - - @Override - public BitmapContainer or(final ArrayContainer value2) { - final BitmapContainer answer = clone(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content[k]; - final int i = Util.toIntUnsigned(v) >>> 6; - long w = answer.bitmap[i]; - long aft = w | (1L << v); - answer.bitmap[i] = aft; - if (USE_BRANCHLESS) { - answer.cardinality += (w - aft) >>> 63; - } else { - if (w != aft) { - answer.cardinality++; - } - } - } - return answer; - } - - @Override - public Container or(final BitmapContainer value2) { - BitmapContainer value1 = this.clone(); - return value1.ior(value2); - } - - @Override - public Container or(RunContainer x) { - return x.or(this); - } - - /** - * Find the index of the previous set bit less than or equal to i, returns -1 if none found. - * - * @param i starting index - * @return index of the previous set bit - */ - public int prevSetBit(final int i) { - int x = i >> 6; // i / 64 with sign extension - long w = bitmap[x]; - w <<= 64 - i - 1; - if (w != 0) { - return i - Long.numberOfLeadingZeros(w); - } - for (--x; x >= 0; --x) { - if (bitmap[x] != 0) { - return x * 64 + 63 - Long.numberOfLeadingZeros(bitmap[x]); - } - } - return -1; - } - - @Override - public int rank(short lowbits) { - int x = Util.toIntUnsigned(lowbits); - int leftover = (x + 1) & 63; - int answer = 0; - for (int k = 0; k < (x + 1) / 64; ++k) { - answer += Long.bitCount(bitmap[k]); - } - if (leftover != 0) { - answer += Long.bitCount(bitmap[(x + 1) / 64] << (64 - leftover)); - } - return answer; - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - deserialize(in); - } - - - @Override - public Container remove(int begin, int end) { - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - BitmapContainer answer = clone(); - Util.resetBitmapRange(answer.bitmap, begin, end); - answer.computeCardinality(); - if (answer.getCardinality() <= ArrayContainer.DEFAULT_MAX_SIZE) { - return answer.toArrayContainer(); - } - return answer; - } - - @Override - public Container remove(final short i) { - final int x = Util.toIntUnsigned(i); - int index = x / 64; - long bef = bitmap[index]; - long mask = 1L << x; - if (cardinality == ArrayContainer.DEFAULT_MAX_SIZE + 1) {// this is - // the - // uncommon - // path - if ((bef & mask) != 0) { - --cardinality; - bitmap[x / 64] = bef & (~mask); - return this.toArrayContainer(); - } - } - long aft = bef & (~mask); - cardinality -= (aft - bef) >>> 63; - bitmap[index] = aft; - return this; - } - - @Override - public Container repairAfterLazy() { - if (getCardinality() < 0) { - computeCardinality(); - if (getCardinality() <= ArrayContainer.DEFAULT_MAX_SIZE) { - return this.toArrayContainer(); - } - } - return this; - } - - @Override - public Container runOptimize() { - int numRuns = numberOfRunsLowerBound(MAXRUNS); // decent choice - - int sizeAsRunContainerLowerBound = RunContainer.serializedSizeInBytes(numRuns); - - if (sizeAsRunContainerLowerBound >= getArraySizeInBytes()) { - return this; - } - // else numRuns is a relatively tight bound that needs to be exact - // in some cases (or if we need to make the runContainer the right - // size) - numRuns += numberOfRunsAdjustment(); - int sizeAsRunContainer = RunContainer.serializedSizeInBytes(numRuns); - - if (getArraySizeInBytes() > sizeAsRunContainer) { - return new RunContainer(this, numRuns); - } else { - return this; - } - } - - @Override - public short select(int j) { - int leftover = j; - for (int k = 0; k < bitmap.length; ++k) { - int w = Long.bitCount(bitmap[k]); - if (w > leftover) { - return (short) (k * 64 + Util.select(bitmap[k], leftover)); - } - leftover -= w; - } - throw new IllegalArgumentException("Insufficient cardinality."); - } - - @Override - public void serialize(DataOutput out) throws IOException { - // little endian - for (long w : bitmap) { - out.writeLong(Long.reverseBytes(w)); - } - } - - @Override - public int serializedSizeInBytes() { - return serializedSizeInBytes(0); - } - - /** - * Copies the data to an array container - * - * @return the array container - */ - public ArrayContainer toArrayContainer() { - ArrayContainer ac = new ArrayContainer(cardinality); - ac.loadData(this); - if (ac.getCardinality() != cardinality) { - throw new RuntimeException("Internal error."); - } - return ac; - } - - /** - * Return the content of this container as a LongBuffer. This creates a copy and might be - * relatively slow. - * - * @return the LongBuffer - */ - public LongBuffer toLongBuffer() { - LongBuffer lb = LongBuffer.allocate(bitmap.length); - lb.put(bitmap); - return lb; - } - - @Override - public MappeableContainer toMappeableContainer() { - return new MappeableBitmapContainer(this); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - final ShortIterator i = this.getShortIterator(); - sb.append("{"); - while (i.hasNext()) { - sb.append(i.next()); - if (i.hasNext()) { - sb.append(","); - } - } - sb.append("}"); - return sb.toString(); - } - - @Override - public void trim() { - } - - @Override - protected void writeArray(DataOutput out) throws IOException { - serialize(out); - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - serialize(out); - } - - @Override - public Container xor(final ArrayContainer value2) { - final BitmapContainer answer = clone(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short vc = value2.content[k]; - final int index = Util.toIntUnsigned(vc) >>> 6; - final long mask = 1L << vc; - final long val = answer.bitmap[index]; - // TODO: check whether a branchy version could be faster - answer.cardinality += 1 - 2 * ((val & mask) >>> vc); - answer.bitmap[index] = val ^ mask; - } - if (answer.cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) { - return answer.toArrayContainer(); - } - return answer; - } - - @Override - public Container xor(BitmapContainer value2) { - int newCardinality = 0; - for (int k = 0; k < this.bitmap.length; ++k) { - newCardinality += Long.bitCount(this.bitmap[k] ^ value2.bitmap[k]); - } - if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { - final BitmapContainer answer = new BitmapContainer(); - for (int k = 0; k < answer.bitmap.length; ++k) { - answer.bitmap[k] = this.bitmap[k] ^ value2.bitmap[k]; - } - answer.cardinality = newCardinality; - return answer; - } - ArrayContainer ac = new ArrayContainer(newCardinality); - Util.fillArrayXOR(ac.content, this.bitmap, value2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public Container xor(RunContainer x) { - return x.xor(this); - } - - @Override - public void forEach(short msb, IntConsumer ic) { - int high = ((int) msb) << 16; - for (int x = 0; x < bitmap.length; ++x) { - long w = bitmap[x]; - while (w != 0) { - long t = w & -w; - ic.accept((x * 64 + Long.bitCount(t - 1)) | high); - w ^= t; - } - } - } - - @Override - public BitmapContainer toBitmapContainer() { - return this; - } - -} - - -final class BitmapContainerShortIterator implements PeekableShortIterator { - - long w; - int x; - - long[] bitmap; - - BitmapContainerShortIterator() { - } - - BitmapContainerShortIterator(long[] p) { - wrap(p); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return x < bitmap.length; - } - - @Override - public short next() { - long t = w & -w; - short answer = (short) (x * 64 + Long.bitCount(t - 1)); - w ^= t; - while (w == 0) { - ++x; - if (x == bitmap.length) { - break; - } - w = bitmap[x]; - } - return answer; - } - - - @Override - public int nextAsInt() { - long t = w & -w; - int answer = (x << 6) + Long.bitCount(t - 1); - w ^= t; - while (w == 0) { - ++x; - if (x == bitmap.length) { - break; - } - w = bitmap[x]; - } - return answer; - } - - @Override - public void remove() { - // TODO: implement - throw new RuntimeException("unsupported operation: remove"); - } - - - public void wrap(long[] b) { - bitmap = b; - for (x = 0; x < bitmap.length; ++x) { - if ((w = bitmap[x]) != 0) { - break; - } - } - } - - @Override - public void advanceIfNeeded(short minval) { - if (Util.toIntUnsigned(minval) >= (x + 1) * 64) { - x = Util.toIntUnsigned(minval) / 64; - w = bitmap[x]; - while (w == 0) { - ++x; - if (x == bitmap.length) { - return; - } - w = bitmap[x]; - } - } - while (hasNext() && (Util.toIntUnsigned(peekNext()) < Util.toIntUnsigned(minval))) { - next(); // could be optimized - } - } - - @Override - public short peekNext() { - long t = w & -w; - return (short) (x * 64 + Long.bitCount(t - 1)); - } -} - - -final class ReverseBitmapContainerShortIterator implements ShortIterator { - - long w; - int x; - - long[] bitmap; - - ReverseBitmapContainerShortIterator() { - } - - ReverseBitmapContainerShortIterator(long[] b) { - wrap(b); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } - } - - @Override - public boolean hasNext() { - return x >= 0; - } - - @Override - public short next() { - long t = w & -w; - short answer = (short) ((x + 1) * 64 - 1 - Long.bitCount(t - 1)); - w ^= t; - while (w == 0) { - --x; - if (x < 0) { - break; - } - w = Long.reverse(bitmap[x]); - } - return answer; - } - - @Override - public int nextAsInt() { - long t = w & -w; - int answer = (x + 1) * 64 - 1 - Long.bitCount(t - 1); - w ^= t; - while (w == 0) { - --x; - if (x < 0) { - break; - } - w = Long.reverse(bitmap[x]); - } - return answer; - } - - @Override - public void remove() { - // TODO: implement - throw new RuntimeException("unsupported operation: remove"); - } - - void wrap(long[] b) { - bitmap = b; - for (x = bitmap.length - 1; x >= 0; --x) { - if ((w = Long.reverse(bitmap[x])) != 0) { - break; - } - } - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitmapDataProvider.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitmapDataProvider.java deleted file mode 100644 index f38969b52..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/BitmapDataProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * Representing a general bitmap interface. - */ -public interface BitmapDataProvider extends ImmutableBitmapDataProvider { - /** - * set the value to "true", whether it already appears or not. - * - * @param x integer value - */ - public void add(int x); - - /** - * If present remove the specified integers (effectively, sets its bit value to false) - * - * @param x integer value representing the index in a bitmap - */ - public void remove(int x); - - /** - * Return the jth value stored in this bitmap. - * - * @param j index of the value - * @return the value - */ - @Override - public int select(int j); - - /** - * Recover allocated but unused memory. - */ - public void trim(); -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/Container.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/Container.java deleted file mode 100644 index 0a119bf84..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/Container.java +++ /dev/null @@ -1,808 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableContainer; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.Externalizable; -import java.io.IOException; - -/** - * Base container class. - */ -public abstract class Container implements Iterable, Cloneable, Externalizable { - - /** - * Name of the various possible containers - */ - public static String ContainerNames[] = {"bitmap", "array", "run"}; - - /** - * Create a container initialized with a range of consecutive values - * - * @param start first index - * @param last last index (range is exclusive) - * @return a new container initialized with the specified values - */ - public static Container rangeOfOnes(final int start, final int last) { - final int sizeAsArrayContainer = ArrayContainer.serializedSizeInBytes(last - start); - final int sizeAsRunContainer = RunContainer.serializedSizeInBytes(1); - Container answer = - sizeAsRunContainer < sizeAsArrayContainer ? new RunContainer() : new ArrayContainer(); - answer = answer.iadd(start, last); - return answer; - } - - /** - * Return a new container with all shorts in [begin,end) added using an unsigned interpretation. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract Container add(int begin, int end); - - /** - * Add a short to the container. May generate a new container. - * - * @param x short to be added - * @return the new container - */ - public abstract Container add(short x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container and(ArrayContainer x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container and(BitmapContainer x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public Container and(Container x) { - if (x instanceof ArrayContainer) { - return and((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return and((BitmapContainer) x); - } - return and((RunContainer) x); - } - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container and(RunContainer x); - - protected abstract int andCardinality(ArrayContainer x); - - protected abstract int andCardinality(BitmapContainer x); - - protected abstract int andCardinality(RunContainer x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public int andCardinality(Container x) { - if (this.getCardinality() == 0) { - return 0; - } else if (x.getCardinality() == 0) { - return 0; - } else { - if (x instanceof ArrayContainer) { - return andCardinality((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return andCardinality((BitmapContainer) x); - } - return andCardinality((RunContainer) x); - } - } - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container andNot(ArrayContainer x); - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container andNot(BitmapContainer x); - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public Container andNot(Container x) { - if (x instanceof ArrayContainer) { - return andNot((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return andNot((BitmapContainer) x); - } - return andNot((RunContainer) x); - } - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container andNot(RunContainer x); - - /** - * Empties the container - */ - public abstract void clear(); - - @Override - public abstract Container clone(); - - /** - * Checks whether the contain contains the provided value - * - * @param x value to check - * @return whether the value is in the container - */ - public abstract boolean contains(short x); - - /** - * Deserialize (recover) the container. - * - * @param in the DataInput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public abstract void deserialize(DataInput in) throws IOException; - - /** - * Fill the least significant 16 bits of the integer array, starting at index i, with the short - * values from this container. The caller is responsible to allocate enough room. The most - * significant 16 bits of each integer are given by the most significant bits of the provided - * mask. - * - * @param x provided array - * @param i starting index - * @param mask indicates most significant bits - */ - public abstract void fillLeastSignificant16bits(int[] x, int i, int mask); - - /** - * Add a short to the container if it is not present, otherwise remove it. May generate a new - * container. - * - * @param x short to be added - * @return the new container - */ - public abstract Container flip(short x); - - /** - * Size of the underlying array - * - * @return size in bytes - */ - protected abstract int getArraySizeInBytes(); - - /** - * Computes the distinct number of short values in the container. Can be expected to run in - * constant time. - * - * @return the cardinality - */ - public abstract int getCardinality(); - - /** - * Get the name of this container. - * - * @return name of the container - */ - public String getContainerName() { - if (this instanceof BitmapContainer) { - return ContainerNames[0]; - } else if (this instanceof ArrayContainer) { - return ContainerNames[1]; - } else { - return ContainerNames[2]; - } - } - - /** - * Iterate through the values of this container and pass them - * along to the IntConsumer, using msb as the 16 most significant bits. - * - * @param msb 16 most significant bits - * @param ic consumer - */ - public abstract void forEach(short msb, IntConsumer ic); - - /** - * Iterator to visit the short values in the container in descending order. - * - * @return iterator - */ - public abstract ShortIterator getReverseShortIterator(); - - /** - * Iterator to visit the short values in the container in ascending order. - * - * @return iterator - */ - public abstract PeekableShortIterator getShortIterator(); - - /** - * Computes an estimate of the memory usage of this container. The estimate is not meant to be - * exact. - * - * @return estimated memory usage in bytes - */ - public abstract int getSizeInBytes(); - - /** - * Add all shorts in [begin,end) using an unsigned interpretation. May generate a new container. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract Container iadd(int begin, int end); - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container iand(ArrayContainer x); - - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container iand(BitmapContainer x); - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public Container iand(Container x) { - if (x instanceof ArrayContainer) { - return iand((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return iand((BitmapContainer) x); - } - return iand((RunContainer) x); - } - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container iand(RunContainer x); - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container iandNot(ArrayContainer x); - - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container iandNot(BitmapContainer x); - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public Container iandNot(Container x) { - if (x instanceof ArrayContainer) { - return iandNot((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return iandNot((BitmapContainer) x); - } - return iandNot((RunContainer) x); - } - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container iandNot(RunContainer x); - - - /** - * Computes the in-place bitwise NOT of this container (complement). Only those bits within the - * range are affected. The current container is generally modified. May generate a new container. - * - * @param rangeStart beginning of range (inclusive); 0 is beginning of this container. - * @param rangeEnd ending of range (exclusive) - * @return (partially) complemented container - */ - public abstract Container inot(int rangeStart, int rangeEnd); - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public abstract boolean intersects(ArrayContainer x); - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public abstract boolean intersects(BitmapContainer x); - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public boolean intersects(Container x) { - if (x instanceof ArrayContainer) { - return intersects((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return intersects((BitmapContainer) x); - } - return intersects((RunContainer) x); - } - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public abstract boolean intersects(RunContainer x); - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container ior(ArrayContainer x); - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container ior(BitmapContainer x); - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public Container ior(Container x) { - if (x instanceof ArrayContainer) { - return ior((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ior((BitmapContainer) x); - } - return ior((RunContainer) x); - } - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container ior(RunContainer x); - - /** - * Remove shorts in [begin,end) using an unsigned interpretation. May generate a new container. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract Container iremove(int begin, int end); - - /** - * Computes the in-place bitwise XOR of this container with another (symmetric difference). The - * current container is generally modified, whereas the provided container (x) is unaffected. May - * generate a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container ixor(ArrayContainer x); - - /** - * Computes the in-place bitwise XOR of this container with another (symmetric difference). The - * current container is generally modified, whereas the provided container (x) is unaffected. May - * generate a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container ixor(BitmapContainer x); - - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public Container ixor(Container x) { - if (x instanceof ArrayContainer) { - return ixor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ixor((BitmapContainer) x); - } - return ixor((RunContainer) x); - } - - /** - * Computes the in-place bitwise XOR of this container with another (symmetric difference). The - * current container is generally modified, whereas the provided container (x) is unaffected. May - * generate a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract Container ixor(RunContainer x); - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. The resulting container may not track its cardinality correctly. The resulting - * container may not track its cardinality correctly. This can be fixed as follows: - * if(c.getCardinality()<0) ((BitmapContainer)c).computeCardinality(); - * - * @param x other container - * @return aggregated container - */ - public Container lazyIOR(Container x) { - if (this instanceof ArrayContainer) { - if (x instanceof ArrayContainer) { - return ((ArrayContainer) this).lazyor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ior((BitmapContainer) x); - } - return ((RunContainer) x).lazyor((ArrayContainer) this); - } else if (this instanceof RunContainer) { - if (x instanceof ArrayContainer) { - return ((RunContainer) this).ilazyor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ior((BitmapContainer) x); - } - return ior((RunContainer) x); - } else { - if (x instanceof ArrayContainer) { - return ((BitmapContainer) this).ilazyor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ((BitmapContainer) this).ilazyor((BitmapContainer) x); - } - return ((BitmapContainer) this).ilazyor((RunContainer) x); - } - } - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. The resulting container may not track its cardinality - * correctly. This can be fixed as follows: if(c.getCardinality()<0) - * ((BitmapContainer)c).computeCardinality(); - * - * @param x other container - * @return aggregated container - */ - public Container lazyOR(Container x) { - if (this instanceof ArrayContainer) { - if (x instanceof ArrayContainer) { - return ((ArrayContainer) this).lazyor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ((BitmapContainer) x).lazyor((ArrayContainer) this); - } - return ((RunContainer) x).lazyor((ArrayContainer) this); - } else if (this instanceof RunContainer) { - if (x instanceof ArrayContainer) { - return ((RunContainer) this).lazyor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ((BitmapContainer) x).lazyor((RunContainer) this); - } - return or((RunContainer) x); - } else { - if (x instanceof ArrayContainer) { - return ((BitmapContainer) this).lazyor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return ((BitmapContainer) this).lazyor((BitmapContainer) x); - } - return ((BitmapContainer) this).lazyor((RunContainer) x); - } - } - - /** - * Create a new Container containing at most maxcardinality integers. - * - * @param maxcardinality maximal cardinality - * @return a new bitmap with cardinality no more than maxcardinality - */ - public abstract Container limit(int maxcardinality); - - /** - * Computes the bitwise NOT of this container (complement). Only those bits within the range are - * affected. The current container is left unaffected. - * - * @param rangeStart beginning of range (inclusive); 0 is beginning of this container. - * @param rangeEnd ending of range (exclusive) - * @return (partially) complemented container - */ - public abstract Container not(int rangeStart, int rangeEnd); - - abstract int numberOfRuns(); // exact - - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container or(ArrayContainer x); - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container or(BitmapContainer x); - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public Container or(Container x) { - if (x instanceof ArrayContainer) { - return or((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return or((BitmapContainer) x); - } - return or((RunContainer) x); - } - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container or(RunContainer x); - - - /** - * Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be - * GetCardinality()). - * - * @param lowbits upper limit - * @return the rank - */ - public abstract int rank(short lowbits); - - /** - * Return a new container with all shorts in [begin,end) remove using an unsigned interpretation. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract Container remove(int begin, int end); - - /** - * Remove the short from this container. May create a new container. - * - * @param x to be removed - * @return New container - */ - public abstract Container remove(short x); - - /** - * The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it. - * - * @return a new valid container - */ - public abstract Container repairAfterLazy(); - - /** - * Convert to RunContainers, when the result is smaller. Overridden by RunContainer to possibility - * switch from RunContainer to a smaller alternative. Overridden by BitmapContainer with a more - * efficient approach. - * - * @return the new container - */ - public abstract Container runOptimize(); - - /** - * Return the jth value - * - * @param j index of the value - * @return the value - */ - public abstract short select(int j); - - /** - * Serialize the container. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public abstract void serialize(DataOutput out) throws IOException; - - /** - * Report the number of bytes required to serialize this container. - * - * @return the size in bytes - */ - public abstract int serializedSizeInBytes(); - - /** - * Convert to a mappeable container. - * - * @return the mappeable container - */ - public abstract MappeableContainer toMappeableContainer(); - - - /** - * If possible, recover wasted memory. - */ - public abstract void trim(); - - /** - * Write just the underlying array. - * - * @param out output stream - * @throws IOException in case of failure - */ - protected abstract void writeArray(DataOutput out) throws IOException; - - - /** - * Computes the bitwise XOR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container xor(ArrayContainer x); - - /** - * Computes the bitwise XOR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container xor(BitmapContainer x); - - - /** - * Computes the bitwise OR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other parameter - * @return aggregated container - */ - public Container xor(Container x) { - if (x instanceof ArrayContainer) { - return xor((ArrayContainer) x); - } else if (x instanceof BitmapContainer) { - return xor((BitmapContainer) x); - } - return xor((RunContainer) x); - } - - /** - * Computes the bitwise XOR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract Container xor(RunContainer x); - - /** - * Convert the current container to a BitmapContainer, if a conversion is needed. - * If the container is already a bitmap, the container is returned unchanged. - * - * @return a bitmap container - */ - public abstract BitmapContainer toBitmapContainer(); -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ContainerPointer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ContainerPointer.java deleted file mode 100644 index 59bbe841f..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ContainerPointer.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * This interface allows you to iterate over the containers in a roaring bitmap. - */ -public interface ContainerPointer extends Comparable, Cloneable { - /** - * Move to the next container - */ - void advance(); - - - /** - * Create a copy - * - * @return return a clone of this pointer - */ - ContainerPointer clone(); - - /** - * Return the cardinality of the current container - * - * @return the cardinality - */ - int getCardinality(); - - /** - * This method can be used to check whether there is current a valid container as it returns null - * when there is not. - * - * @return null or the current container - */ - Container getContainer(); - - /** - * Check whether the current container is a bitmap container. - * - * @return whether it is a bitmap container - */ - boolean isBitmapContainer(); - - /** - * Check whether the current container is a run container. - * - * @return whether it is a run container - */ - boolean isRunContainer(); - - /** - * The key is a 16-bit integer that indicates the position of the container in the roaring bitmap. - * To be interpreted as an unsigned integer. - * - * @return the key - */ - short key(); -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/FastAggregation.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/FastAggregation.java deleted file mode 100644 index 5a301db3c..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/FastAggregation.java +++ /dev/null @@ -1,532 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.PriorityQueue; - - -/** - * Fast algorithms to aggregate many bitmaps. - * - * @author Daniel Lemire - */ -public final class FastAggregation { - - - /** - * Private constructor to prevent instantiation of utility class - */ - private FastAggregation() { - } - - /** - * Compute the AND aggregate. - *

- * In practice, calls {#link naive_and} - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap and(Iterator bitmaps) { - return naive_and(bitmaps); - } - - /** - * Compute the AND aggregate. - *

- * In practice, calls {#link naive_and} - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap and(RoaringBitmap... bitmaps) { - return naive_and(bitmaps); - } - - /** - * Calls naive_or. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - @Deprecated - public static RoaringBitmap horizontal_or(Iterator bitmaps) { - return naive_or(bitmaps); - } - - /** - * Minimizes memory usage while computing the or aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #or(RoaringBitmap...) - */ - public static RoaringBitmap horizontal_or(List bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - if (bitmaps.isEmpty()) { - return answer; - } - PriorityQueue pq = new PriorityQueue(bitmaps.size()); - for (int k = 0; k < bitmaps.size(); ++k) { - ContainerPointer x = bitmaps.get(k).highLowContainer.getContainerPointer(); - if (x.getContainer() != null) { - pq.add(x); - } - } - - while (!pq.isEmpty()) { - ContainerPointer x1 = pq.poll(); - if (pq.isEmpty() || (pq.peek().key() != x1.key())) { - answer.highLowContainer.append(x1.key(), x1.getContainer().clone()); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - continue; - } - ContainerPointer x2 = pq.poll(); - Container newc = x1.getContainer().lazyOR(x2.getContainer()); - while (!pq.isEmpty() && (pq.peek().key() == x1.key())) { - - ContainerPointer x = pq.poll(); - newc = newc.lazyIOR(x.getContainer()); - x.advance(); - if (x.getContainer() != null) { - pq.add(x); - } else if (pq.isEmpty()) { - break; - } - } - newc = newc.repairAfterLazy(); - answer.highLowContainer.append(x1.key(), newc); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - x2.advance(); - if (x2.getContainer() != null) { - pq.add(x2); - } - } - return answer; - } - - /** - * Minimizes memory usage while computing the or aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #or(RoaringBitmap...) - */ - public static RoaringBitmap horizontal_or(RoaringBitmap... bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - if (bitmaps.length == 0) { - return answer; - } - PriorityQueue pq = new PriorityQueue(bitmaps.length); - for (int k = 0; k < bitmaps.length; ++k) { - ContainerPointer x = bitmaps[k].highLowContainer.getContainerPointer(); - if (x.getContainer() != null) { - pq.add(x); - } - } - - while (!pq.isEmpty()) { - ContainerPointer x1 = pq.poll(); - if (pq.isEmpty() || (pq.peek().key() != x1.key())) { - answer.highLowContainer.append(x1.key(), x1.getContainer().clone()); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - continue; - } - ContainerPointer x2 = pq.poll(); - Container newc = x1.getContainer().lazyOR(x2.getContainer()); - while (!pq.isEmpty() && (pq.peek().key() == x1.key())) { - - ContainerPointer x = pq.poll(); - newc = newc.lazyIOR(x.getContainer()); - x.advance(); - if (x.getContainer() != null) { - pq.add(x); - } else if (pq.isEmpty()) { - break; - } - } - newc = newc.repairAfterLazy(); - answer.highLowContainer.append(x1.key(), newc); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - x2.advance(); - if (x2.getContainer() != null) { - pq.add(x2); - } - } - return answer; - } - - /** - * Minimizes memory usage while computing the xor aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #xor(RoaringBitmap...) - */ - public static RoaringBitmap horizontal_xor(RoaringBitmap... bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - if (bitmaps.length == 0) { - return answer; - } - PriorityQueue pq = new PriorityQueue(bitmaps.length); - for (int k = 0; k < bitmaps.length; ++k) { - ContainerPointer x = bitmaps[k].highLowContainer.getContainerPointer(); - if (x.getContainer() != null) { - pq.add(x); - } - } - - while (!pq.isEmpty()) { - ContainerPointer x1 = pq.poll(); - if (pq.isEmpty() || (pq.peek().key() != x1.key())) { - answer.highLowContainer.append(x1.key(), x1.getContainer().clone()); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - continue; - } - ContainerPointer x2 = pq.poll(); - Container newc = x1.getContainer().xor(x2.getContainer()); - while (!pq.isEmpty() && (pq.peek().key() == x1.key())) { - ContainerPointer x = pq.poll(); - newc = newc.ixor(x.getContainer()); - x.advance(); - if (x.getContainer() != null) { - pq.add(x); - } else if (pq.isEmpty()) { - break; - } - } - answer.highLowContainer.append(x1.key(), newc); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - x2.advance(); - if (x2.getContainer() != null) { - pq.add(x2); - } - } - return answer; - } - - /** - * Compute overall AND between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap naive_and(Iterator bitmaps) { - if (!bitmaps.hasNext()) { - return new RoaringBitmap(); - } - RoaringBitmap answer = bitmaps.next().clone(); - while (bitmaps.hasNext()) { - answer.and(bitmaps.next()); - } - return answer; - } - - /** - * Compute overall AND between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap naive_and(RoaringBitmap... bitmaps) { - if (bitmaps.length == 0) { - return new RoaringBitmap(); - } - RoaringBitmap answer = bitmaps[0].clone(); - for (int k = 1; k < bitmaps.length; ++k) { - answer.and(bitmaps[k]); - } - return answer; - } - - /** - * Compute overall OR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap naive_or(Iterator bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - while (bitmaps.hasNext()) { - answer.naivelazyor(bitmaps.next()); - } - answer.repairAfterLazy(); - return answer; - } - - /** - * Compute overall OR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap naive_or(RoaringBitmap... bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - for (int k = 0; k < bitmaps.length; ++k) { - answer.naivelazyor(bitmaps[k]); - } - answer.repairAfterLazy(); - return answer; - } - - /** - * Compute overall XOR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap naive_xor(Iterator bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - while (bitmaps.hasNext()) { - answer.xor(bitmaps.next()); - } - return answer; - } - - /** - * Compute overall XOR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap naive_xor(RoaringBitmap... bitmaps) { - RoaringBitmap answer = new RoaringBitmap(); - for (int k = 0; k < bitmaps.length; ++k) { - answer.xor(bitmaps[k]); - } - return answer; - } - - /** - * Compute overall OR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap or(Iterator bitmaps) { - return naive_or(bitmaps); - } - - /** - * Compute overall OR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap or(RoaringBitmap... bitmaps) { - return naive_or(bitmaps); - } - - /** - * Uses a priority queue to compute the or aggregate. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #horizontal_or(RoaringBitmap...) - */ - public static RoaringBitmap priorityqueue_or(Iterator bitmaps) { - if (!bitmaps.hasNext()) { - return new RoaringBitmap(); - } - // we buffer the call to getSizeInBytes(), hence the code complexity - ArrayList buffer = new ArrayList(); - while (bitmaps.hasNext()) { - buffer.add(bitmaps.next()); - } - final long[] sizes = new long[buffer.size()]; - final boolean[] istmp = new boolean[buffer.size()]; - for (int k = 0; k < sizes.length; ++k) { - sizes[k] = buffer.get(k).getLongSizeInBytes(); - } - PriorityQueue pq = new PriorityQueue(128, new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return (int) (sizes[a] - sizes[b]); - } - }); - for (int k = 0; k < sizes.length; ++k) { - pq.add(k); - } - while (pq.size() > 1) { - Integer x1 = pq.poll(); - Integer x2 = pq.poll(); - if (istmp[x2] && istmp[x1]) { - buffer.set(x1, RoaringBitmap.lazyorfromlazyinputs(buffer.get(x1), buffer.get(x2))); - sizes[x1] = buffer.get(x1).getLongSizeInBytes(); - istmp[x1] = true; - pq.add(x1); - } else if (istmp[x2]) { - buffer.get(x2).lazyor(buffer.get(x1)); - sizes[x2] = buffer.get(x2).getLongSizeInBytes(); - pq.add(x2); - } else if (istmp[x1]) { - buffer.get(x1).lazyor(buffer.get(x2)); - sizes[x1] = buffer.get(x1).getLongSizeInBytes(); - pq.add(x1); - } else { - buffer.set(x1, RoaringBitmap.lazyor(buffer.get(x1), buffer.get(x2))); - sizes[x1] = buffer.get(x1).getLongSizeInBytes(); - istmp[x1] = true; - pq.add(x1); - } - } - RoaringBitmap answer = buffer.get(pq.poll()); - answer.repairAfterLazy(); - return answer; - } - - /** - * Uses a priority queue to compute the or aggregate. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #horizontal_or(RoaringBitmap...) - */ - public static RoaringBitmap priorityqueue_or(RoaringBitmap... bitmaps) { - if (bitmaps.length == 0) { - return new RoaringBitmap(); - } - // we buffer the call to getSizeInBytes(), hence the code complexity - final RoaringBitmap[] buffer = Arrays.copyOf(bitmaps, bitmaps.length); - final long[] sizes = new long[buffer.length]; - final boolean[] istmp = new boolean[buffer.length]; - for (int k = 0; k < sizes.length; ++k) { - sizes[k] = buffer[k].getLongSizeInBytes(); - } - PriorityQueue pq = new PriorityQueue(128, new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return (int) (sizes[a] - sizes[b]); - } - }); - for (int k = 0; k < sizes.length; ++k) { - pq.add(k); - } - while (pq.size() > 1) { - Integer x1 = pq.poll(); - Integer x2 = pq.poll(); - if (istmp[x2] && istmp[x1]) { - buffer[x1] = RoaringBitmap.lazyorfromlazyinputs(buffer[x1], buffer[x2]); - sizes[x1] = buffer[x1].getLongSizeInBytes(); - istmp[x1] = true; - pq.add(x1); - } else if (istmp[x2]) { - buffer[x2].lazyor(buffer[x1]); - sizes[x2] = buffer[x2].getLongSizeInBytes(); - pq.add(x2); - } else if (istmp[x1]) { - buffer[x1].lazyor(buffer[x2]); - sizes[x1] = buffer[x1].getLongSizeInBytes(); - pq.add(x1); - } else { - buffer[x1] = RoaringBitmap.lazyor(buffer[x1], buffer[x2]); - sizes[x1] = buffer[x1].getLongSizeInBytes(); - istmp[x1] = true; - pq.add(x1); - } - } - RoaringBitmap answer = buffer[pq.poll()]; - answer.repairAfterLazy(); - return answer; - } - - /** - * Uses a priority queue to compute the xor aggregate. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #horizontal_xor(RoaringBitmap...) - */ - public static RoaringBitmap priorityqueue_xor(RoaringBitmap... bitmaps) { - // TODO: This code could be faster, see priorityqueue_or - if (bitmaps.length == 0) { - return new RoaringBitmap(); - } - - PriorityQueue pq = - new PriorityQueue(bitmaps.length, new Comparator() { - @Override - public int compare(RoaringBitmap a, RoaringBitmap b) { - return (int) (a.getLongSizeInBytes() - b.getLongSizeInBytes()); - } - }); - Collections.addAll(pq, bitmaps); - while (pq.size() > 1) { - RoaringBitmap x1 = pq.poll(); - RoaringBitmap x2 = pq.poll(); - pq.add(RoaringBitmap.xor(x1, x2)); - } - return pq.poll(); - } - - /** - * Compute overall XOR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap xor(Iterator bitmaps) { - return naive_xor(bitmaps); - } - - /** - * Compute overall XOR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap xor(RoaringBitmap... bitmaps) { - return naive_xor(bitmaps); - } - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ImmutableBitmapDataProvider.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ImmutableBitmapDataProvider.java deleted file mode 100644 index f1cdd5d4f..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ImmutableBitmapDataProvider.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -import java.io.DataOutput; -import java.io.IOException; - -/** - * Interface representing an immutable bitmap. - */ -public interface ImmutableBitmapDataProvider { - /** - * Checks whether the value in included, which is equivalent to checking if the corresponding bit - * is set (get in BitSet class). - * - * @param x integer value - * @return whether the integer value is included. - */ - public boolean contains(int x); - - /** - * Returns the number of distinct integers added to the bitmap (e.g., number of bits set). - * Internally, this is computed as a 64-bit number. - * - * @return the cardinality - */ - public int getCardinality(); - - /** - * Returns the number of distinct integers added to the bitmap (e.g., number of bits set). - * This returns a full 64-bit result. - * - * @return the cardinality - */ - public long getLongCardinality(); - - /** - * Visit all values in the bitmap and pass them to the consumer. - *

- * * Usage: - *

-     * {@code
-     *  bitmap.forEach(new IntConsumer() {
-     *
-     *    {@literal @}Override
-     *    public void accept(int value) {
-     *      // do something here
-     *
-     *    }});
-     *   }
-     * }
-     * 
- * - * @param ic the consumer - */ - public void forEach(IntConsumer ic); - - /** - * For better performance, consider the Use the {@link #forEach forEach} method. - * - * @return a custom iterator over set bits, the bits are traversed in ascending sorted order - */ - public PeekableIntIterator getIntIterator(); - - /** - * @return a custom iterator over set bits, the bits are traversed in descending sorted order - */ - public IntIterator getReverseIntIterator(); - - /** - * Estimate of the memory usage of this data structure. - *

- * Internally, this is computed as a 64-bit counter. - * - * @return estimated memory usage. - */ - public int getSizeInBytes(); - - /** - * Estimate of the memory usage of this data structure. Provides - * full 64-bit number. - * - * @return estimated memory usage. - */ - public long getLongSizeInBytes(); - - /** - * Checks whether the bitmap is empty. - * - * @return true if this bitmap contains no set bit - */ - public boolean isEmpty(); - - /** - * Create a new bitmap of the same class, containing at most maxcardinality integers. - * - * @param x maximal cardinality - * @return a new bitmap with cardinality no more than maxcardinality - */ - public ImmutableBitmapDataProvider limit(int x); - - /** - * Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be - * GetCardinality()). - *

- * The value is internally computed as a 64-bit number. - * - * @param x upper limit - * @return the rank - */ - public int rank(int x); - - /** - * Same as "rank" but produces a full 64-bit value. - * - * @param x upper limit - * @return the rank - */ - public long rankLong(int x); - - /** - * Return the jth value stored in this bitmap. - * - * @param j index of the value - * @return the value - */ - public int select(int j); - - /** - * Serialize this bitmap. - *

- * The current bitmap is not modified. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void serialize(DataOutput out) throws IOException; - - /** - * Report the number of bytes required to serialize this bitmap. This is the number of bytes - * written out when using the serialize method. When using the writeExternal method, the count - * will be higher due to the overhead of Java serialization. - * - * @return the size in bytes - */ - public int serializedSizeInBytes(); - - /** - * Return the set values as an array. The integer values are in sorted order. - * - * @return array representing the set values. - */ - public int[] toArray(); - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntConsumer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntConsumer.java deleted file mode 100644 index 47ff1e27d..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntConsumer.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.fr.third.bitmap.roaringbitmap; - -/** - * An IntConsumer receives the int values contained in a data structure. - * Each value is visited once. - *

- * Usage: - *

- *

- * {@code
- *  bitmap.forEach(new IntConsumer() {
- *
- *    @Override
- *    public void accept(int value) {
- *      // do something here
- *
- *    }});
- *   }
- * }
- * 
- */ -public interface IntConsumer { - /** - * Receives the integer - * - * @param value the integer value - */ - void accept(int value); -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntIterator.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntIterator.java deleted file mode 100644 index ef86f6611..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntIterator.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * A simple iterator over integer values - */ -public interface IntIterator extends Cloneable { - /** - * Creates a copy of the iterator. - * - * @return a clone of the current iterator - */ - IntIterator clone(); - - /** - * @return whether there is another value - */ - boolean hasNext(); - - /** - * @return next integer value - */ - int next(); - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntIteratorFlyweight.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntIteratorFlyweight.java deleted file mode 100644 index 36a91b168..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/IntIteratorFlyweight.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * Fast iterator minimizing the stress on the garbage collector. You can create one reusable - * instance of this class and then {@link #wrap(RoaringBitmap)} - *

- * For better performance, consider the {@link RoaringBitmap#forEach} method. - * - * @author Borislav Ivanov - **/ -public class IntIteratorFlyweight implements PeekableIntIterator { - - private int hs; - - private PeekableShortIterator iter; - - private ArrayContainerShortIterator arrIter = new ArrayContainerShortIterator(); - - private BitmapContainerShortIterator bitmapIter = new BitmapContainerShortIterator(); - - private RunContainerShortIterator runIter = new RunContainerShortIterator(); - - private int pos; - - private RoaringBitmap roaringBitmap = null; - - /** - * Creates an instance that is not ready for iteration. You must first call - * {@link #wrap(RoaringBitmap)}. - */ - public IntIteratorFlyweight() { - - } - - /** - * Creates an instance that is ready for iteration. - * - * @param r bitmap to be iterated over - */ - public IntIteratorFlyweight(RoaringBitmap r) { - wrap(r); - } - - @Override - public PeekableIntIterator clone() { - try { - IntIteratorFlyweight x = (IntIteratorFlyweight) super.clone(); - x.iter = this.iter.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < this.roaringBitmap.highLowContainer.size(); - } - - @Override - public int next() { - int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - ++pos; - nextContainer(); - } - return x; - } - - private void nextContainer() { - if (pos < this.roaringBitmap.highLowContainer.size()) { - - Container container = this.roaringBitmap.highLowContainer.getContainerAtIndex(pos); - - if (container instanceof BitmapContainer) { - bitmapIter.wrap(((BitmapContainer) container).bitmap); - iter = bitmapIter; - } else if (container instanceof ArrayContainer) { - arrIter.wrap((ArrayContainer) container); - iter = arrIter; - } else { - runIter.wrap((RunContainer) container); - iter = runIter; - } - hs = Util.toIntUnsigned(this.roaringBitmap.highLowContainer.getKeyAtIndex(pos)) << 16; - } - } - - /** - * Prepares a bitmap for iteration - * - * @param r bitmap to be iterated over - */ - public void wrap(RoaringBitmap r) { - this.hs = 0; - this.pos = 0; - this.roaringBitmap = r; - this.nextContainer(); - } - - @Override - public void advanceIfNeeded(final int minval) { - while (hasNext() && ((hs >>> 16) < (minval >>> 16))) { - ++pos; - nextContainer(); - } - if (hasNext() && ((hs >>> 16) == (minval >>> 16))) { - iter.advanceIfNeeded(Util.lowbits(minval)); - if (!iter.hasNext()) { - ++pos; - nextContainer(); - } - } - } - - @Override - public int peekNext() { - return Util.toIntUnsigned(iter.peekNext()) | hs; - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/PeekableIntIterator.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/PeekableIntIterator.java deleted file mode 100644 index 906f23b73..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/PeekableIntIterator.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.fr.third.bitmap.roaringbitmap; - - -/** - * Simple extension to the IntIterator interface. - * It allows you to "skip" values using the advanceIfNeeded - * method, and to look at the value without advancing (peekNext). - */ -public interface PeekableIntIterator extends IntIterator { - /** - * If needed, advance as long as the next value is smaller than minval - * - * @param minval threshold - */ - public void advanceIfNeeded(int minval); - - /** - * Look at the next value without advancing - * - * @return next value - */ - public int peekNext(); - - /** - * Creates a copy of the iterator. - * - * @return a clone of the current iterator - */ - @Override - PeekableIntIterator clone(); -} - - diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/PeekableShortIterator.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/PeekableShortIterator.java deleted file mode 100644 index 278f0e20a..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/PeekableShortIterator.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ -package com.fr.third.bitmap.roaringbitmap; - - -/** - * Simple extension to the ShortIterator interface - */ -public interface PeekableShortIterator extends ShortIterator { - /** - * If needed, advance as long as the next value is smaller than minval (as an unsigned - * short) - * - * @param minval threshold - */ - public void advanceIfNeeded(short minval); - - /** - * Look at the next value without advancing - * - * @return next value - */ - public short peekNext(); - - /** - * Creates a copy of the iterator. - * - * @return a clone of the current iterator - */ - @Override - PeekableShortIterator clone(); -} - diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ReverseIntIteratorFlyweight.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ReverseIntIteratorFlyweight.java deleted file mode 100644 index 0475cc78d..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ReverseIntIteratorFlyweight.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * Fast iterator minimizing the stress on the garbage collector. You can create one reusable - * instance of this class and then {@link #wrap(RoaringBitmap)} - *

- * This iterator enumerates the stored values in reverse (starting from the end). - * - * @author Borislav Ivanov - **/ -public class ReverseIntIteratorFlyweight implements IntIterator { - - private int hs; - - private ShortIterator iter; - - private ReverseArrayContainerShortIterator arrIter = new ReverseArrayContainerShortIterator(); - - private ReverseBitmapContainerShortIterator bitmapIter = - new ReverseBitmapContainerShortIterator(); - - private ReverseRunContainerShortIterator runIter = new ReverseRunContainerShortIterator(); - - private short pos; - - private RoaringBitmap roaringBitmap = null; - - - /** - * Creates an instance that is not ready for iteration. You must first call - * {@link #wrap(RoaringBitmap)}. - */ - public ReverseIntIteratorFlyweight() { - - } - - /** - * Creates an instance that is ready for iteration. - * - * @param r bitmap to be iterated over - */ - public ReverseIntIteratorFlyweight(RoaringBitmap r) { - wrap(r); - } - - @Override - public IntIterator clone() { - try { - ReverseIntIteratorFlyweight x = (ReverseIntIteratorFlyweight) super.clone(); - x.iter = this.iter.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - - @Override - public int next() { - final int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - --pos; - nextContainer(); - } - return x; - } - - private void nextContainer() { - - - if (pos >= 0) { - - Container container = this.roaringBitmap.highLowContainer.getContainerAtIndex(pos); - if (container instanceof BitmapContainer) { - bitmapIter.wrap(((BitmapContainer) container).bitmap); - iter = bitmapIter; - } else if (container instanceof ArrayContainer) { - arrIter.wrap((ArrayContainer) container); - iter = arrIter; - } else { - runIter.wrap((RunContainer) container); - iter = runIter; - } - hs = Util.toIntUnsigned(this.roaringBitmap.highLowContainer.getKeyAtIndex(pos)) << 16; - } - } - - /** - * Prepares a bitmap for iteration - * - * @param r bitmap to be iterated over - */ - public void wrap(RoaringBitmap r) { - this.roaringBitmap = r; - this.hs = 0; - this.pos = (short) (this.roaringBitmap.highLowContainer.size() - 1); - this.nextContainer(); - } - -} - diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringArray.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringArray.java deleted file mode 100644 index eebb99d77..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringArray.java +++ /dev/null @@ -1,582 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -/** - * Specialized array to store the containers used by a RoaringBitmap. This is not meant to be used - * by end users. - */ -public final class RoaringArray implements Cloneable, Externalizable { - protected static final short SERIAL_COOKIE_NO_RUNCONTAINER = 12346; - protected static final short SERIAL_COOKIE = 12347; - protected static final int NO_OFFSET_THRESHOLD = 4; - static final int INITIAL_CAPACITY = 4; - // bumped serialVersionUID with runcontainers, so default serialization - // will not work... - private static final long serialVersionUID = 8L; - short[] keys = null; - - Container[] values = null; - - int size = 0; - - protected RoaringArray() { - this.keys = new short[INITIAL_CAPACITY]; - this.values = new Container[INITIAL_CAPACITY]; - } - - /** - * Find the smallest integer index larger than pos such that array[index].key>=x. If none can - * be found, return size. Based on code by O. Kaser. - * - * @param x minimal value - * @param pos index to exceed - * @return the smallest index greater than pos such that array[index].key is at least as large as - * min, or size if it is not possible. - */ - protected int advanceUntil(short x, int pos) { - int lower = pos + 1; - - // special handling for a possibly common sequential case - if (lower >= size || Util.toIntUnsigned(keys[lower]) >= Util.toIntUnsigned(x)) { - return lower; - } - - int spansize = 1; // could set larger - // bootstrap an upper limit - - while (lower + spansize < size - && Util.toIntUnsigned(keys[lower + spansize]) < Util.toIntUnsigned(x)) { - spansize *= 2; // hoping for compiler will reduce to shift - } - int upper = (lower + spansize < size) ? lower + spansize : size - 1; - - // maybe we are lucky (could be common case when the seek ahead - // expected to be small and sequential will otherwise make us look bad) - if (keys[upper] == x) { - return upper; - } - - if (Util.toIntUnsigned(keys[upper]) < Util.toIntUnsigned(x)) {// means array has no item key >= - // x - return size; - } - - // we know that the next-smallest span was too small - lower += (spansize / 2); - - // else begin binary search - // invariant: array[lower]x - while (lower + 1 != upper) { - int mid = (lower + upper) / 2; - if (keys[mid] == x) { - return mid; - } else if (Util.toIntUnsigned(keys[mid]) < Util.toIntUnsigned(x)) { - lower = mid; - } else { - upper = mid; - } - } - return upper; - } - - protected void append(short key, Container value) { - extendArray(1); - this.keys[this.size] = key; - this.values[this.size] = value; - this.size++; - } - - /** - * Append copies of the values AFTER a specified key (may or may not be present) to end. - * - * @param sa other array - * @param beforeStart given key is the largest key that we won't copy - */ - protected void appendCopiesAfter(RoaringArray sa, short beforeStart) { - int startLocation = sa.getIndex(beforeStart); - if (startLocation >= 0) { - startLocation++; - } else { - startLocation = -startLocation - 1; - } - extendArray(sa.size - startLocation); - - for (int i = startLocation; i < sa.size; ++i) { - this.keys[this.size] = sa.keys[i]; - this.values[this.size] = sa.values[i].clone(); - this.size++; - } - } - - /** - * Append copies of the values from another array, from the start - * - * @param sourceArray The array to copy from - * @param stoppingKey any equal or larger key in other array will terminate copying - */ - protected void appendCopiesUntil(RoaringArray sourceArray, short stoppingKey) { - int stopKey = Util.toIntUnsigned(stoppingKey); - for (int i = 0; i < sourceArray.size; ++i) { - if (Util.toIntUnsigned(sourceArray.keys[i]) >= stopKey) { - break; - } - extendArray(1); - this.keys[this.size] = sourceArray.keys[i]; - this.values[this.size] = sourceArray.values[i].clone(); - this.size++; - } - } - - /** - * Append copy of the one value from another array - * - * @param sa other array - * @param index index in the other array - */ - protected void appendCopy(RoaringArray sa, int index) { - extendArray(1); - this.keys[this.size] = sa.keys[index]; - this.values[this.size] = sa.values[index].clone(); - this.size++; - } - - /** - * Append copies of the values from another array - * - * @param sa other array - * @param startingIndex starting index in the other array - * @param end endingIndex (exclusive) in the other array - */ - protected void appendCopy(RoaringArray sa, int startingIndex, int end) { - extendArray(end - startingIndex); - for (int i = startingIndex; i < end; ++i) { - this.keys[this.size] = sa.keys[i]; - this.values[this.size] = sa.values[i].clone(); - this.size++; - } - } - - - /** - * Append the values from another array, no copy is made (use with care) - * - * @param sa other array - * @param startingIndex starting index in the other array - * @param end endingIndex (exclusive) in the other array - */ - protected void append(RoaringArray sa, int startingIndex, int end) { - extendArray(end - startingIndex); - for (int i = startingIndex; i < end; ++i) { - this.keys[this.size] = sa.keys[i]; - this.values[this.size] = sa.values[i]; - this.size++; - } - } - - - private int binarySearch(int begin, int end, short key) { - return Util.unsignedBinarySearch(keys, begin, end, key); - } - - protected void clear() { - this.keys = null; - this.values = null; - this.size = 0; - } - - @Override - public RoaringArray clone() throws CloneNotSupportedException { - RoaringArray sa; - sa = (RoaringArray) super.clone(); - sa.keys = Arrays.copyOf(this.keys, this.size); - sa.values = Arrays.copyOf(this.values, this.size); - for (int k = 0; k < this.size; ++k) { - sa.values[k] = sa.values[k].clone(); - } - sa.size = this.size; - return sa; - } - - protected void copyRange(int begin, int end, int newBegin) { - // assuming begin <= end and newBegin < begin - final int range = end - begin; - System.arraycopy(this.keys, begin, this.keys, newBegin, range); - System.arraycopy(this.values, begin, this.values, newBegin, range); - } - - /** - * Deserialize. - * - * @param in the DataInput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void deserialize(DataInput in) throws IOException { - this.clear(); - // little endian - final int cookie = Integer.reverseBytes(in.readInt()); - if ((cookie & 0xFFFF) != SERIAL_COOKIE && cookie != SERIAL_COOKIE_NO_RUNCONTAINER) { - throw new IOException("I failed to find one of the right cookies."); - } - this.size = ((cookie & 0xFFFF) == SERIAL_COOKIE) ? (cookie >>> 16) + 1 - : Integer.reverseBytes(in.readInt()); - - if ((this.keys == null) || (this.keys.length < this.size)) { - this.keys = new short[this.size]; - this.values = new Container[this.size]; - } - - - byte[] bitmapOfRunContainers = null; - boolean hasrun = (cookie & 0xFFFF) == SERIAL_COOKIE; - if (hasrun) { - bitmapOfRunContainers = new byte[(size + 7) / 8]; - in.readFully(bitmapOfRunContainers); - } - - final short keys[] = new short[this.size]; - final int cardinalities[] = new int[this.size]; - final boolean isBitmap[] = new boolean[this.size]; - for (int k = 0; k < this.size; ++k) { - keys[k] = Short.reverseBytes(in.readShort()); - cardinalities[k] = 1 + (0xFFFF & Short.reverseBytes(in.readShort())); - - isBitmap[k] = cardinalities[k] > ArrayContainer.DEFAULT_MAX_SIZE; - if (bitmapOfRunContainers != null && (bitmapOfRunContainers[k / 8] & (1 << (k % 8))) != 0) { - isBitmap[k] = false; - } - } - if ((!hasrun) || (this.size >= NO_OFFSET_THRESHOLD)) { - // skipping the offsets - in.skipBytes(this.size * 4); - } - // Reading the containers - for (int k = 0; k < this.size; ++k) { - Container val; - if (isBitmap[k]) { - final long[] bitmapArray = new long[BitmapContainer.MAX_CAPACITY / 64]; - // little endian - for (int l = 0; l < bitmapArray.length; ++l) { - bitmapArray[l] = Long.reverseBytes(in.readLong()); - } - val = new BitmapContainer(bitmapArray, cardinalities[k]); - } else if (bitmapOfRunContainers != null - && ((bitmapOfRunContainers[k / 8] & (1 << (k % 8))) != 0)) { - // cf RunContainer.writeArray() - int nbrruns = Util.toIntUnsigned(Short.reverseBytes(in.readShort())); - final short lengthsAndValues[] = new short[2 * nbrruns]; - - for (int j = 0; j < 2 * nbrruns; ++j) { - lengthsAndValues[j] = Short.reverseBytes(in.readShort()); - } - val = new RunContainer(lengthsAndValues, nbrruns); - } else { - final short[] shortArray = new short[cardinalities[k]]; - for (int l = 0; l < shortArray.length; ++l) { - shortArray[l] = Short.reverseBytes(in.readShort()); - } - val = new ArrayContainer(shortArray); - } - this.keys[k] = keys[k]; - this.values[k] = val; - } - } - - @Override - public boolean equals(Object o) { - if (o instanceof RoaringArray) { - RoaringArray srb = (RoaringArray) o; - if (srb.size != this.size) { - return false; - } - for (int i = 0; i < srb.size; ++i) { - if (this.keys[i] != srb.keys[i] || !this.values[i].equals(srb.values[i])) { - return false; - } - } - return true; - } - return false; - } - - // make sure there is capacity for at least k more elements - protected void extendArray(int k) { - // size + 1 could overflow - if (this.size + k >= this.keys.length) { - int newCapacity; - if (this.keys.length < 1024) { - newCapacity = 2 * (this.size + k); - } else { - newCapacity = 5 * (this.size + k) / 4; - } - this.keys = Arrays.copyOf(this.keys, newCapacity); - this.values = Arrays.copyOf(this.values, newCapacity); - } - } - - // involves a binary search - protected Container getContainer(short x) { - int i = this.binarySearch(0, size, x); - if (i < 0) { - return null; - } - return this.values[i]; - } - - protected Container getContainerAtIndex(int i) { - return this.values[i]; - } - - /** - * Create a ContainerPointer for this RoaringArray - * - * @return a ContainerPointer - */ - public ContainerPointer getContainerPointer() { - return getContainerPointer(0); - } - - /** - * Create a ContainerPointer for this RoaringArray - * - * @param startIndex starting index in the container list - * @return a ContainerPointer - */ - public ContainerPointer getContainerPointer(final int startIndex) { - return new ContainerPointer() { - int k = startIndex; - - @Override - public void advance() { - ++k; - - } - - @Override - public ContainerPointer clone() { - try { - return (ContainerPointer) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public int compareTo(ContainerPointer o) { - if (key() != o.key()) { - return Util.toIntUnsigned(key()) - Util.toIntUnsigned(o.key()); - } - return o.getCardinality() - getCardinality(); - } - - @Override - public int getCardinality() { - return getContainer().getCardinality(); - } - - @Override - public Container getContainer() { - if (k >= RoaringArray.this.size) { - return null; - } - return RoaringArray.this.values[k]; - } - - - @Override - public boolean isBitmapContainer() { - return getContainer() instanceof BitmapContainer; - } - - @Override - public boolean isRunContainer() { - return getContainer() instanceof RunContainer; - } - - - @Override - public short key() { - return RoaringArray.this.keys[k]; - - } - }; - } - - // involves a binary search - protected int getIndex(short x) { - // before the binary search, we optimize for frequent cases - if ((size == 0) || (keys[size - 1] == x)) { - return size - 1; - } - // no luck we have to go through the list - return this.binarySearch(0, size, x); - } - - protected short getKeyAtIndex(int i) { - return this.keys[i]; - } - - @Override - public int hashCode() { - int hashvalue = 0; - for (int k = 0; k < this.size; ++k) { - hashvalue = 31 * hashvalue + keys[k] * 0xF0F0F0 + values[k].hashCode(); - } - return hashvalue; - } - - boolean hasRunContainer() { - for (int k = 0; k < size; ++k) { - Container ck = values[k]; - if (ck instanceof RunContainer) { - return true; - } - } - return false; - } - - protected int headerSize() { - if (hasRunContainer()) { - if (size < NO_OFFSET_THRESHOLD) {// for small bitmaps, we omit the offsets - return 4 + (size + 7) / 8 + 4 * size; - } - return 4 + (size + 7) / 8 + 8 * size;// - 4 because we pack the size with the cookie - } else { - return 4 + 4 + 8 * size; - } - } - - - // insert a new key, it is assumed that it does not exist - protected void insertNewKeyValueAt(int i, short key, Container value) { - extendArray(1); - System.arraycopy(keys, i, keys, i + 1, size - i); - keys[i] = key; - System.arraycopy(values, i, values, i + 1, size - i); - values[i] = value; - size++; - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - deserialize(in); - } - - protected void removeAtIndex(int i) { - System.arraycopy(keys, i + 1, keys, i, size - i - 1); - keys[size - 1] = 0; - System.arraycopy(values, i + 1, values, i, size - i - 1); - values[size - 1] = null; - size--; - } - - protected void removeIndexRange(int begin, int end) { - if (end <= begin) { - return; - } - final int range = end - begin; - System.arraycopy(keys, end, keys, begin, size - end); - System.arraycopy(values, end, values, begin, size - end); - for (int i = 1; i <= range; ++i) { - keys[size - i] = 0; - values[size - i] = null; - } - size -= range; - } - - protected void replaceKeyAndContainerAtIndex(int i, short key, Container c) { - this.keys[i] = key; - this.values[i] = c; - } - - protected void resize(int newLength) { - Arrays.fill(this.keys, newLength, this.size, (short) 0); - Arrays.fill(this.values, newLength, this.size, null); - this.size = newLength; - } - - - /** - * Serialize. - *

- * The current bitmap is not modified. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void serialize(DataOutput out) throws IOException { - int startOffset = 0; - boolean hasrun = hasRunContainer(); - if (hasrun) { - out.writeInt(Integer.reverseBytes(SERIAL_COOKIE | ((size - 1) << 16))); - byte[] bitmapOfRunContainers = new byte[(size + 7) / 8]; - for (int i = 0; i < size; ++i) { - if (this.values[i] instanceof RunContainer) { - bitmapOfRunContainers[i / 8] |= (1 << (i % 8)); - } - } - out.write(bitmapOfRunContainers); - if (this.size < NO_OFFSET_THRESHOLD) { - startOffset = 4 + 4 * this.size + bitmapOfRunContainers.length; - } else { - startOffset = 4 + 8 * this.size + bitmapOfRunContainers.length; - } - } else { // backwards compatibility - out.writeInt(Integer.reverseBytes(SERIAL_COOKIE_NO_RUNCONTAINER)); - out.writeInt(Integer.reverseBytes(size)); - startOffset = 4 + 4 + 4 * this.size + 4 * this.size; - } - for (int k = 0; k < size; ++k) { - out.writeShort(Short.reverseBytes(this.keys[k])); - out.writeShort(Short.reverseBytes((short) (this.values[k].getCardinality() - 1))); - } - if ((!hasrun) || (this.size >= NO_OFFSET_THRESHOLD)) { - // writing the containers offsets - for (int k = 0; k < this.size; k++) { - out.writeInt(Integer.reverseBytes(startOffset)); - startOffset = startOffset + this.values[k].getArraySizeInBytes(); - } - } - for (int k = 0; k < size; ++k) { - values[k].writeArray(out); - } - } - - /** - * Report the number of bytes required for serialization. - * - * @return the size in bytes - */ - public int serializedSizeInBytes() { - int count = headerSize(); - for (int k = 0; k < size; ++k) { - count += values[k].getArraySizeInBytes(); - } - return count; - } - - protected void setContainerAtIndex(int i, Container c) { - this.values[i] = c; - } - - protected int size() { - return this.size; - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - serialize(out); - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringBitmap.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringBitmap.java index e300cb8b8..146848602 100644 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringBitmap.java +++ b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RoaringBitmap.java @@ -1,2205 +1,194 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - package com.fr.third.bitmap.roaringbitmap; -import com.fr.third.bitmap.roaringbitmap.buffer.ImmutableRoaringBitmap; -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableContainerPointer; -import com.fr.third.bitmap.roaringbitmap.buffer.MutableRoaringBitmap; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serializable; import java.util.Iterator; - /** - * RoaringBitmap, a compressed alternative to the BitSet. - *

- *

- * {@code
- *      import com.fr.swift.bitmap.roaringbitmap.*;
+ * Created by loy on 2021/7/13.
  *
- *      //...
- *
- *      RoaringBitmap rr = RoaringBitmap.bitmapOf(1,2,3,1000);
- *      RoaringBitmap rr2 = new RoaringBitmap();
- *      for(int k = 4000; k<4255;++k) rr2.add(k);
- *      RoaringBitmap rror = RoaringBitmap.or(rr, rr2);
- *
- *      //...
- *      DataOutputStream wheretoserialize = ...
- *      rr.runOptimize(); // can help compression
- *      rr.serialize(wheretoserialize);
- * }
- * 
- *

- * Integers are added in unsigned sorted order. That is, they are treated as unsigned integers (see - * Java 8's Integer.toUnsignedLong function). - *

- * Bitmaps are limited to a maximum of Integer.MAX_VALUE entries. Trying to create larger bitmaps - * could result in undefined behaviors. + *

兼容新引擎æ’件中用到的这个类,åŽç»­ä¼šåˆ é™¤ */ +@Deprecated +public class RoaringBitmap { + private byte[] value; + private int length; + private int cap; -public class RoaringBitmap implements Cloneable, Serializable, Iterable, Externalizable, - ImmutableBitmapDataProvider { - - private static final long serialVersionUID = 6L; - RoaringArray highLowContainer = null; - - /** - * Create an empty bitmap - */ public RoaringBitmap() { - highLowContainer = new RoaringArray(); - } - - /** - * Create a RoaringBitmap from a MutableRoaringBitmap or ImmutableRoaringBitmap. The source is not - * modified. - * - * @param rb the original bitmap - */ - public RoaringBitmap(ImmutableRoaringBitmap rb) { - highLowContainer = new RoaringArray(); - MappeableContainerPointer cp = rb.getContainerPointer(); - while (cp.getContainer() != null) { - highLowContainer.append(cp.key(), cp.getContainer().toContainer()); - cp.advance(); - } - } - - private static void rangeSanityCheck(final long rangeStart, final long rangeEnd) { - if (rangeStart < 0 || rangeStart > (1L << 32) - 1) { - throw new IllegalArgumentException("rangeStart=" + rangeStart - + " should be in [0, 0xffffffff]"); - } - if (rangeEnd > (1L << 32) || rangeEnd < 0) { - throw new IllegalArgumentException("rangeEnd=" + rangeEnd - + " should be in [0, 0xffffffff + 1]"); - } - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) added. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - */ - public static RoaringBitmap add(RoaringBitmap rb, final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return rb.clone(); // empty range - } - - - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - - RoaringBitmap answer = new RoaringBitmap(); - answer.highLowContainer.appendCopiesUntil(rb.highLowContainer, (short) hbStart); - - if (hbStart == hbLast) { - final int i = rb.highLowContainer.getIndex((short) hbStart); - final Container c = - i >= 0 ? rb.highLowContainer.getContainerAtIndex(i).add(lbStart, lbLast + 1) - : Container.rangeOfOnes(lbStart, lbLast + 1); - answer.highLowContainer.append((short) hbStart, c); - answer.highLowContainer.appendCopiesAfter(rb.highLowContainer, (short) hbLast); - return answer; - } - int ifirst = rb.highLowContainer.getIndex((short) hbStart); - int ilast = rb.highLowContainer.getIndex((short) hbLast); - - { - final Container c = ifirst >= 0 - ? rb.highLowContainer.getContainerAtIndex(ifirst).add(lbStart, - Util.maxLowBitAsInteger() + 1) - : Container.rangeOfOnes(lbStart, Util.maxLowBitAsInteger() + 1); - answer.highLowContainer.append((short) hbStart, c); - } - for (int hb = hbStart + 1; hb < hbLast; ++hb) { - Container c = Container.rangeOfOnes(0, Util.maxLowBitAsInteger() + 1); - answer.highLowContainer.append((short) hb, c); - } - { - final Container c = - ilast >= 0 ? rb.highLowContainer.getContainerAtIndex(ilast).add(0, lbLast + 1) - : Container.rangeOfOnes(0, lbLast + 1); - answer.highLowContainer.append((short) hbLast, c); - } - answer.highLowContainer.appendCopiesAfter(rb.highLowContainer, (short) hbLast); - return answer; - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) added. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static RoaringBitmap add(RoaringBitmap rb, final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return add(rb, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return add(rb, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * Bitwise AND (intersection) operation. The provided bitmaps are *not* modified. This operation - * is thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - * @see FastAggregation#and(RoaringBitmap...) - */ - public static RoaringBitmap and(final RoaringBitmap x1, final RoaringBitmap x2) { - final RoaringBitmap answer = new RoaringBitmap(); - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - int pos1 = 0, pos2 = 0; - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final Container c = c1.and(c2); - if (c.getCardinality() > 0) { - answer.highLowContainer.append(s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return answer; - } - - /** - * Cardinality of Bitwise AND (intersection) operation. The provided bitmaps are *not* modified. - * This operation is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return as if you did and(x2,x2).getCardinality() - * @see FastAggregation#and(RoaringBitmap...) - */ - public static int andCardinality(final RoaringBitmap x1, final RoaringBitmap x2) { - int answer = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - int pos1 = 0, pos2 = 0; - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - // TODO: could be made faster if we did not have to materialize container - answer += c1.andCardinality(c2); - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return answer; - } - - /** - * Bitwise ANDNOT (difference) operation. The provided bitmaps are *not* modified. This operation - * is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - */ - public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2) { - final RoaringBitmap answer = new RoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final Container c = c1.andNot(c2); - if (c.getCardinality() > 0) { - answer.highLowContainer.append(s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, nextPos1); - pos1 = nextPos1; - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - if (pos2 == length2) { - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); - } - return answer; - } - - /** - * Generate a bitmap with the specified values set to true. The provided integers values don't - * have to be in sorted order, but it may be preferable to sort them from a performance point of - * view. - * - * @param dat set values - * @return a new bitmap - */ - public static RoaringBitmap bitmapOf(final int... dat) { - final RoaringBitmap ans = new RoaringBitmap(); - ans.add(dat); - return ans; - } - - /** - * Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The - * given bitmap is unchanged. - * - * @param bm bitmap being negated - * @param rangeStart inclusive beginning of range, in [0, 0xffffffff] - * @param rangeEnd exclusive ending of range, in [0, 0xffffffff + 1] - * @return a new Bitmap - */ - public static RoaringBitmap flip(RoaringBitmap bm, final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return bm.clone(); - } - RoaringBitmap answer = new RoaringBitmap(); - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - - // copy the containers before the active area - answer.highLowContainer.appendCopiesUntil(bm.highLowContainer, (short) hbStart); - - for (int hb = hbStart; hb <= hbLast; ++hb) { - final int containerStart = (hb == hbStart) ? lbStart : 0; - final int containerLast = (hb == hbLast) ? lbLast : Util.maxLowBitAsInteger(); - - final int i = bm.highLowContainer.getIndex((short) hb); - final int j = answer.highLowContainer.getIndex((short) hb); - assert j < 0; - - if (i >= 0) { - Container c = - bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); - if (c.getCardinality() > 0) { - answer.highLowContainer.insertNewKeyValueAt(-j - 1, (short) hb, c); - } - - } else { // *think* the range of ones must never be - // empty. - answer.highLowContainer.insertNewKeyValueAt(-j - 1, (short) hb, - Container.rangeOfOnes(containerStart, containerLast + 1)); - } - } - // copy the containers after the active area. - answer.highLowContainer.appendCopiesAfter(bm.highLowContainer, (short) hbLast); - return answer; - } - - /** - * Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The - * given bitmap is unchanged. - * - * @param rb bitmap being negated - * @param rangeStart inclusive beginning of range, in [0, 0xffffffff] - * @param rangeEnd exclusive ending of range, in [0, 0xffffffff + 1] - * @return a new Bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static RoaringBitmap flip(RoaringBitmap rb, final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return flip(rb, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return flip(rb, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - - /** - * Checks whether the two bitmaps intersect. This can be much faster than calling "and" and - * checking the cardinality of the result. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return true if they intersect - */ - public static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2) { - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - int pos1 = 0, pos2 = 0; - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - if (c1.intersects(c2)) { - return true; - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return false; - } - - - // important: inputs should not have been computed lazily - protected static RoaringBitmap lazyor(final RoaringBitmap x1, final RoaringBitmap x2) { - final RoaringBitmap answer = new RoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - answer.highLowContainer.append(s1, x1.highLowContainer.getContainerAtIndex(pos1) - .lazyOR(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1); - pos1++; - if (pos1 == length1) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - answer.highLowContainer.appendCopy(x2.highLowContainer, pos2); - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - answer.highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); - } else if (pos2 == length2) { - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); - } - return answer; - } - - // important: inputs should not be reused - protected static RoaringBitmap lazyorfromlazyinputs(final RoaringBitmap x1, - final RoaringBitmap x2) { - final RoaringBitmap answer = new RoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); - Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - if ((c2 instanceof BitmapContainer) && (!(c1 instanceof BitmapContainer))) { - Container tmp = c1; - c1 = c2; - c2 = tmp; - } - answer.highLowContainer.append(s1, c1.lazyIOR(c2)); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - Container c1 = x1.highLowContainer.getContainerAtIndex(pos1); - answer.highLowContainer.append(s1, c1); - pos1++; - if (pos1 == length1) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - answer.highLowContainer.append(s2, c2); - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - answer.highLowContainer.append(x2.highLowContainer, pos2, length2); - } else if (pos2 == length2) { - answer.highLowContainer.append(x1.highLowContainer, pos1, length1); - } - return answer; + this(8192); } - - /** - * Compute overall OR between bitmaps. - *

- * (Effectively calls {@link FastAggregation#or}) - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap or(Iterator bitmaps) { - return FastAggregation.or(bitmaps); + public RoaringBitmap(int cap) { + this.cap = cap; + this.value = new byte[(cap + 7) / 8]; } - /** - * Compute overall OR between bitmaps. - *

- * (Effectively calls {@link FastAggregation#or}) - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static RoaringBitmap or(RoaringBitmap... bitmaps) { - return FastAggregation.or(bitmaps); - } - - /** - * Bitwise OR (union) operation. The provided bitmaps are *not* modified. This operation is - * thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - * @see FastAggregation#or(RoaringBitmap...) - * @see FastAggregation#horizontal_or(RoaringBitmap...) - */ - public static RoaringBitmap or(final RoaringBitmap x1, final RoaringBitmap x2) { - final RoaringBitmap answer = new RoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - answer.highLowContainer.append(s1, x1.highLowContainer.getContainerAtIndex(pos1) - .or(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1); - pos1++; - if (pos1 == length1) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - answer.highLowContainer.appendCopy(x2.highLowContainer, pos2); - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } + public void add(int n) { + checkIndex(n); + ensureCap(n); + int idx0 = n / 8; + int idx1 = n % 8; + if ((value[idx0] & (1 << idx1)) == 0) { + length++; + value[idx0] |= (1 << idx1); } - if (pos1 == length1) { - answer.highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); - } else if (pos2 == length2) { - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); - } - return answer; - } - - /** - * Cardinality of the bitwise OR (union) operation. The provided bitmaps are *not* modified. This - * operation is thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return cardinality of the union - * @see FastAggregation#or(RoaringBitmap...) - * @see FastAggregation#horizontal_or(RoaringBitmap...) - */ - public static int orCardinality(final RoaringBitmap x1, final RoaringBitmap x2) { - // we use the fact that the cardinality of the bitmaps is known so that - // the union is just the total cardinality minus the intersection - return x1.getCardinality() + x2.getCardinality() - andCardinality(x1, x2); } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - */ - public static RoaringBitmap remove(RoaringBitmap rb, final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return rb.clone(); // empty range - } - - - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - RoaringBitmap answer = new RoaringBitmap(); - answer.highLowContainer.appendCopiesUntil(rb.highLowContainer, (short) hbStart); - - if (hbStart == hbLast) { - final int i = rb.highLowContainer.getIndex((short) hbStart); - if (i >= 0) { - final Container c = rb.highLowContainer.getContainerAtIndex(i).remove(lbStart, lbLast + 1); - if (c.getCardinality() > 0) { - answer.highLowContainer.append((short) hbStart, c); - } - } - answer.highLowContainer.appendCopiesAfter(rb.highLowContainer, (short) hbLast); - return answer; - } - int ifirst = rb.highLowContainer.getIndex((short) hbStart); - int ilast = rb.highLowContainer.getIndex((short) hbLast); - if ((ifirst >= 0) && (lbStart != 0)) { - final Container c = rb.highLowContainer.getContainerAtIndex(ifirst).remove(lbStart, - Util.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - answer.highLowContainer.append((short) hbStart, c); - } - } - if ((ilast >= 0) && (lbLast != Util.maxLowBitAsInteger())) { - final Container c = rb.highLowContainer.getContainerAtIndex(ilast).remove(0, lbLast + 1); - if (c.getCardinality() > 0) { - answer.highLowContainer.append((short) hbLast, c); - } - } - answer.highLowContainer.appendCopiesAfter(rb.highLowContainer, (short) hbLast); - return answer; - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static RoaringBitmap remove(RoaringBitmap rb, final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return remove(rb, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return remove(rb, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - - /** - * Bitwise XOR (symmetric difference) operation. The provided bitmaps are *not* modified. This - * operation is thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - * @see FastAggregation#xor(RoaringBitmap...) - * @see FastAggregation#horizontal_xor(RoaringBitmap...) - */ - public static RoaringBitmap xor(final RoaringBitmap x1, final RoaringBitmap x2) { - final RoaringBitmap answer = new RoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - final Container c = x1.highLowContainer.getContainerAtIndex(pos1) - .xor(x2.highLowContainer.getContainerAtIndex(pos2)); - if (c.getCardinality() > 0) { - answer.highLowContainer.append(s1, c); - } - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1); - pos1++; - if (pos1 == length1) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - answer.highLowContainer.appendCopy(x2.highLowContainer, pos2); - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - answer.highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); - } else if (pos2 == length2) { - answer.highLowContainer.appendCopy(x1.highLowContainer, pos1, length1); - } - - return answer; - } - - /** - * Computes AND between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - */ - public static RoaringBitmap and(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - - Iterator bitmapsIterator; - bitmapsIterator = selectRangeWithoutCopy(bitmaps, rangeStart, rangeEnd); - return FastAggregation.and(bitmapsIterator); - } - - /** - * Computes AND between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - * @deprecated use the version where longs specify the range. Negative range end are illegal. - */ - @Deprecated - public static RoaringBitmap and(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final int rangeStart, final int rangeEnd) { - return and(bitmaps, (long) rangeStart, (long) rangeEnd); - } - - /** - * Bitwise ANDNOT (difference) operation for the given range, rangeStart (inclusive) and rangeEnd - * (exclusive). The provided bitmaps are *not* modified. This operation is thread-safe as long as - * the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @param rangeStart starting point of the range (inclusive) - * @param rangeEnd end point of the range (exclusive) - * @return result of the operation - */ - public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2, - long rangeStart, long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - - RoaringBitmap rb1 = selectRangeWithoutCopy(x1, rangeStart, rangeEnd); - RoaringBitmap rb2 = selectRangeWithoutCopy(x2, rangeStart, rangeEnd); - return andNot(rb1, rb2); - } - - /** - * Bitwise ANDNOT (difference) operation for the given range, rangeStart (inclusive) and rangeEnd - * (exclusive). The provided bitmaps are *not* modified. This operation is thread-safe as long as - * the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @param rangeStart starting point of the range (inclusive) - * @param rangeEnd end point of the range (exclusive) - * @return result of the operation - * @deprecated use the version where longs specify the range. Negative values for range - * endpoints are not allowed. - */ - @Deprecated - public static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2, - final int rangeStart, final int rangeEnd) { - return andNot(x1, x2, (long) rangeStart, (long) rangeEnd); - } - - /** - * Computes OR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - */ - public static RoaringBitmap or(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - - Iterator bitmapsIterator; - bitmapsIterator = selectRangeWithoutCopy(bitmaps, rangeStart, rangeEnd); - return or(bitmapsIterator); - } - - /** - * Computes OR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - * @deprecated use the version where longs specify the range. - * Negative range points are forbidden. - */ - @Deprecated - public static RoaringBitmap or(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final int rangeStart, final int rangeEnd) { - return or(bitmaps, (long) rangeStart, (long) rangeEnd); - } - - /** - * Assume that one wants to store "cardinality" integers in [0, universe_size), this function - * returns an upper bound on the serialized size in bytes. - * - * @param cardinality maximal cardinality - * @param universe_size maximal value - * @return upper bound on the serialized size in bytes of the bitmap - */ - public static long maximumSerializedSize(long cardinality, long universe_size) { - long contnbr = (universe_size + 65535) / 65536; - if (contnbr > cardinality) { - contnbr = cardinality; - // we can't have more containers than we have values - } - final long headermax = Math.max(8, 4 + (contnbr + 7) / 8) + 8 * contnbr; - final long valsarray = 2 * cardinality; - final long valsbitmap = contnbr * 8192; - final long valsbest = Math.min(valsarray, valsbitmap); - return valsbest + headermax; - } - - /** - * Return new iterator with only values from rangeStart (inclusive) to rangeEnd (exclusive) - * - * @param bitmaps bitmaps iterator - * @param rangeStart inclusive - * @param rangeEnd exclusive - * @return new iterator of bitmaps - */ - private static Iterator selectRangeWithoutCopy(final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - Iterator bitmapsIterator; - bitmapsIterator = new Iterator() { - @Override - public boolean hasNext() { - return bitmaps.hasNext(); - } - - @Override - public RoaringBitmap next() { - RoaringBitmap next = (RoaringBitmap) bitmaps.next(); - return selectRangeWithoutCopy(next, rangeStart, rangeEnd); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Remove not supported"); - } - }; - return bitmapsIterator; - } - - /* - * In testing, original int-range code failed an assertion with some negative ranges - * so presumably nobody relies on negative ranges. rangeEnd=0 also failed. - */ - - /** - * Extracts the values in the specified range, rangeStart (inclusive) and rangeEnd (exclusive) - * while avoiding copies as much as possible. - * - * @param rb input bitmap - * @param rangeStart inclusive - * @param rangeEnd exclusive - * @return new bitmap - */ - - // had formerly failed if rangeEnd==0 - private static RoaringBitmap selectRangeWithoutCopy(RoaringBitmap rb, final long rangeStart, - final long rangeEnd) { - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - RoaringBitmap answer = new RoaringBitmap(); - - assert (rangeStart >= 0 && rangeEnd >= 0); - - if (rangeEnd <= rangeStart) { - return answer; - } - - if (hbStart == hbLast) { - final int i = rb.highLowContainer.getIndex((short) hbStart); - if (i >= 0) { - final Container c = rb.highLowContainer.getContainerAtIndex(i).remove(0, lbStart) - .iremove(lbLast + 1, Util.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - answer.highLowContainer.append((short) hbStart, c); - } - } - return answer; - } - int ifirst = rb.highLowContainer.getIndex((short) hbStart); - int ilast = rb.highLowContainer.getIndex((short) hbLast); - if (ifirst >= 0) { - final Container c = rb.highLowContainer.getContainerAtIndex(ifirst).remove(0, lbStart); - if (c.getCardinality() > 0) { - answer.highLowContainer.append((short) hbStart, c); - } - } - - // revised to loop on ints - for (int hb = hbStart + 1; hb <= hbLast - 1; ++hb) { - final int i = rb.highLowContainer.getIndex((short) hb); - final int j = answer.highLowContainer.getIndex((short) hb); - assert j < 0; - - if (i >= 0) { - final Container c = rb.highLowContainer.getContainerAtIndex(i); - answer.highLowContainer.insertNewKeyValueAt(-j - 1, (short) hb, c); - } - } - - if (ilast >= 0) { - final Container c = rb.highLowContainer.getContainerAtIndex(ilast).remove(lbLast + 1, - Util.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - answer.highLowContainer.append((short) hbLast, c); - } - } - return answer; - } - - /** - * Computes XOR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - */ - public static RoaringBitmap xor(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - Iterator bitmapsIterator; - bitmapsIterator = selectRangeWithoutCopy(bitmaps, rangeStart, rangeEnd); - return FastAggregation.xor(bitmapsIterator); - } - - /** - * Computes XOR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bi - * @deprecated use the version where longs specify the range. - * Negative values not allowed for rangeStart and rangeEnd - */ - @Deprecated - public static RoaringBitmap xor(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final int rangeStart, final int rangeEnd) { - return xor(bitmaps, (long) rangeStart, (long) rangeEnd); - } - - /** - * Set all the specified values to true. This can be expected to be slightly - * faster than calling "add" repeatedly. The provided integers values don't - * have to be in sorted order, but it may be preferable to sort them from a performance point of - * view. - * - * @param dat set values - */ - public void add(final int... dat) { - Container currentcont = null; - short currenthb = 0; - int currentcontainerindex = 0; - int j = 0; - if (j < dat.length) { - int val = dat[j]; - currenthb = Util.highbits(val); - currentcontainerindex = highLowContainer.getIndex(currenthb); - if (currentcontainerindex >= 0) { - currentcont = highLowContainer.getContainerAtIndex(currentcontainerindex); - Container newcont = currentcont.add(Util.lowbits(val)); - if (newcont != currentcont) { - highLowContainer.setContainerAtIndex(currentcontainerindex, newcont); - currentcont = newcont; - } - } else { - currentcontainerindex = -currentcontainerindex - 1; - final ArrayContainer newac = new ArrayContainer(); - currentcont = newac.add(Util.lowbits(val)); - highLowContainer.insertNewKeyValueAt(currentcontainerindex, currenthb, currentcont); - } - j++; - } - for (; j < dat.length; ++j) { - int val = dat[j]; - short newhb = Util.highbits(val); - if (currenthb == newhb) {// easy case - // this could be quite frequent - Container newcont = currentcont.add(Util.lowbits(val)); - if (newcont != currentcont) { - highLowContainer.setContainerAtIndex(currentcontainerindex, newcont); - currentcont = newcont; - } - } else { - currenthb = newhb; - currentcontainerindex = highLowContainer.getIndex(currenthb); - if (currentcontainerindex >= 0) { - currentcont = highLowContainer.getContainerAtIndex(currentcontainerindex); - Container newcont = currentcont.add(Util.lowbits(val)); - if (newcont != currentcont) { - highLowContainer.setContainerAtIndex(currentcontainerindex, newcont); - currentcont = newcont; - } - } else { - currentcontainerindex = -currentcontainerindex - 1; - final ArrayContainer newac = new ArrayContainer(); - currentcont = newac.add(Util.lowbits(val)); - highLowContainer.insertNewKeyValueAt(currentcontainerindex, currenthb, currentcont); - } - } - } - } - - /** - * Add the value to the container (set the value to "true"), whether it already appears or not. - * - * @param x integer value - */ - public void add(final int x) { - final short hb = Util.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i >= 0) { - highLowContainer.setContainerAtIndex(i, - highLowContainer.getContainerAtIndex(i).add(Util.lowbits(x))); - } else { - final ArrayContainer newac = new ArrayContainer(); - highLowContainer.insertNewKeyValueAt(-i - 1, hb, newac.add(Util.lowbits(x))); - } - } - - /** - * Add to the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - */ - public void add(final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return; // empty range - } - - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - for (int hb = hbStart; hb <= hbLast; ++hb) { - - // first container may contain partial range - final int containerStart = (hb == hbStart) ? lbStart : 0; - // last container may contain partial range - final int containerLast = (hb == hbLast) ? lbLast : Util.maxLowBitAsInteger(); - final int i = highLowContainer.getIndex((short) hb); - - if (i >= 0) { - final Container c = - highLowContainer.getContainerAtIndex(i).iadd(containerStart, containerLast + 1); - highLowContainer.setContainerAtIndex(i, c); - } else { - highLowContainer.insertNewKeyValueAt(-i - 1, (short) hb, - Container.rangeOfOnes(containerStart, containerLast + 1)); - } - } - } - - /** - * Add to the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @deprecated use the version where longs specify the range - */ - @Deprecated - public void add(final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - add((long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - add(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * In-place bitwise AND (intersection) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void and(final RoaringBitmap x2) { - int pos1 = 0, pos2 = 0, intersectionSize = 0; - final int length1 = highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final Container c1 = highLowContainer.getContainerAtIndex(pos1); - final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final Container c = c1.iand(c2); - if (c.getCardinality() > 0) { - highLowContainer.replaceKeyAndContainerAtIndex(intersectionSize++, s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - highLowContainer.resize(intersectionSize); - } - - /** - * In-place bitwise ANDNOT (difference) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void andNot(final RoaringBitmap x2) { - int pos1 = 0, pos2 = 0, intersectionSize = 0; - final int length1 = highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final Container c1 = highLowContainer.getContainerAtIndex(pos1); - final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final Container c = c1.iandNot(c2); - if (c.getCardinality() > 0) { - highLowContainer.replaceKeyAndContainerAtIndex(intersectionSize++, s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - if (pos1 != intersectionSize) { - final Container c1 = highLowContainer.getContainerAtIndex(pos1); - highLowContainer.replaceKeyAndContainerAtIndex(intersectionSize, s1, c1); - } - ++intersectionSize; - ++pos1; - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } + public void remove(int n) { + checkIndex(n); + if (n >= value.length * 8) { + return; } - if (pos1 < length1) { - highLowContainer.copyRange(pos1, length1, intersectionSize); - intersectionSize += length1 - pos1; + int idx0 = n / 8; + int idx1 = n % 8; + if ((value[idx0] & (1 << idx1)) != 0) { + length--; + value[idx0] &= ~(1 << idx1); } - highLowContainer.resize(intersectionSize); } - /** - * Add the value to the container (set the value to "true"), whether it already appears or not. - * - * @param x integer value - * @return true if the added int wasn't already contained in the bitmap. False otherwise. - */ - public boolean checkedAdd(final int x) { - final short hb = Util.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i >= 0) { - Container c = highLowContainer.getContainerAtIndex(i); - int oldCard = c.getCardinality(); - // we need to keep the newContainer if a switch between containers type - // occur, in order to get the new cardinality - Container newCont = c.add(Util.lowbits(x)); - highLowContainer.setContainerAtIndex(i, newCont); - if (newCont.getCardinality() > oldCard) { - return true; - } - } else { - final ArrayContainer newac = new ArrayContainer(); - highLowContainer.insertNewKeyValueAt(-i - 1, hb, newac.add(Util.lowbits(x))); - return true; - } - return false; - } - - /** - * If present remove the specified integer (effectively, sets its bit value to false) - * - * @param x integer value representing the index in a bitmap - * @return true if the unset bit was already in the bitmap - */ - public boolean checkedRemove(final int x) { - final short hb = Util.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i < 0) { - return false; - } - Container C = highLowContainer.getContainerAtIndex(i); - int oldcard = C.getCardinality(); - C.remove(Util.lowbits(x)); - int newcard = C.getCardinality(); - if (newcard == oldcard) { + public boolean contains(int n) { + checkIndex(n); + if (n >= value.length * 8) { return false; } - if (newcard > 0) { - highLowContainer.setContainerAtIndex(i, C); - } else { - highLowContainer.removeAtIndex(i); - } - return true; - } - - /** - * reset to an empty bitmap; result occupies as much space a newly created bitmap. - */ - public void clear() { - highLowContainer = new RoaringArray(); // lose references + int idx0 = n / 8; + int idx1 = n % 8; + return (value[idx0] & (1 << idx1)) != 0; } - @Override - public RoaringBitmap clone() { - try { - final RoaringBitmap x = (RoaringBitmap) super.clone(); - x.highLowContainer = highLowContainer.clone(); - return x; - } catch (final CloneNotSupportedException e) { - throw new RuntimeException("shouldn't happen with clone", e); + public void flip(long rangeStart, long rangeEnd) { + int sIdx0 = (int) ((rangeStart + 7) / 8); + int sIdx1 = (int) (rangeStart % 8); + int eIdx0 = (int) (rangeEnd / 8); + int eIdx1 = (int) (rangeEnd % 8); + int lenDiff = 0; + if (sIdx1 > 0) { + byte b = value[sIdx0 - 1]; + byte b2 = (byte) (~(b & 0xff) >> sIdx1 << sIdx1 + ((b & 0xff) << (32 - sIdx1) >> (32 - sIdx1))); + value[sIdx0 - 1] = b2; + lenDiff += countInByte(b2) - countInByte(b); } - } - - /** - * Checks whether the value in included, which is equivalent to checking if the corresponding bit - * is set (get in BitSet class). - * - * @param x integer value - * @return whether the integer value is included. - */ - @Override - public boolean contains(final int x) { - final short hb = Util.highbits(x); - final Container c = highLowContainer.getContainer(hb); - return c != null && c.contains(Util.lowbits(x)); - } - - /** - * Deserialize (retrieve) this bitmap. - *

- * The current bitmap is overwritten. - * - * @param in the DataInput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void deserialize(DataInput in) throws IOException { - this.highLowContainer.deserialize(in); - } - - @Override - public boolean equals(Object o) { - if (o instanceof RoaringBitmap) { - final RoaringBitmap srb = (RoaringBitmap) o; - return srb.highLowContainer.equals(this.highLowContainer); - } - return false; - } - - /** - * Add the value if it is not already present, otherwise remove it. - * - * @param x integer value - */ - public void flip(final int x) { - final short hb = Util.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i >= 0) { - Container c = highLowContainer.getContainerAtIndex(i).flip(Util.lowbits(x)); - if (c.getCardinality() > 0) { - highLowContainer.setContainerAtIndex(i, c); - } else { - highLowContainer.removeAtIndex(i); - } - } else { - final ArrayContainer newac = new ArrayContainer(); - highLowContainer.insertNewKeyValueAt(-i - 1, hb, newac.add(Util.lowbits(x))); - } - } - - /** - * Modifies the current bitmap by complementing the bits in the given range, from rangeStart - * (inclusive) rangeEnd (exclusive). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - */ - public void flip(final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return; // empty range - } - - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - - // TODO:this can be accelerated considerably - for (int hb = hbStart; hb <= hbLast; ++hb) { - // first container may contain partial range - final int containerStart = (hb == hbStart) ? lbStart : 0; - // last container may contain partial range - final int containerLast = (hb == hbLast) ? lbLast : Util.maxLowBitAsInteger(); - final int i = highLowContainer.getIndex((short) hb); - - if (i >= 0) { - final Container c = - highLowContainer.getContainerAtIndex(i).inot(containerStart, containerLast + 1); - if (c.getCardinality() > 0) { - highLowContainer.setContainerAtIndex(i, c); - } else { - highLowContainer.removeAtIndex(i); - } - } else { - highLowContainer.insertNewKeyValueAt(-i - 1, (short) hb, - Container.rangeOfOnes(containerStart, containerLast + 1)); - } - } - } - - /** - * Modifies the current bitmap by complementing the bits in the given range, from rangeStart - * (inclusive) rangeEnd (exclusive). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @deprecated use the version where longs specify the range - */ - @Deprecated - public void flip(final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - flip((long) rangeStart, (long) rangeEnd); - } else { - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - flip(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); + for (int i = sIdx0; i < eIdx0; i++) { + value[i] = (byte) ~(value[i]); + lenDiff += countInByte(value[i]) * 2 - 8; } - } - - /** - * Returns the number of distinct integers added to the bitmap (e.g., number of bits set). - * - * @return the cardinality - */ - @Override - public long getLongCardinality() { - long size = 0; - for (int i = 0; i < this.highLowContainer.size(); i++) { - size += this.highLowContainer.getContainerAtIndex(i).getCardinality(); + if (eIdx1 > 0) { + byte b = value[eIdx0]; + byte b2 = (byte) (((b & 0xff) >> eIdx1 << eIdx1) + ~(b & 0xff) << (32 - eIdx1) >> (32 - eIdx1)); + value[eIdx0] = b2; + lenDiff += countInByte(b2) - countInByte(b); } - return size; + length += lenDiff; } - @Override public int getCardinality() { - return (int) getLongCardinality(); + return length; } @Override - public void forEach(IntConsumer ic) { - for (int i = 0; i < this.highLowContainer.size(); i++) { - this.highLowContainer.getContainerAtIndex(i).forEach(this.highLowContainer.keys[i], ic); - } - } - - /** - * Return a low-level container pointer that can be used to access the underlying data structure. - * - * @return container pointer - */ - public ContainerPointer getContainerPointer() { - return this.highLowContainer.getContainerPointer(); - } - - /** - * For better performance, consider the Use the {@link #forEach forEach} method. - * - * @return a custom iterator over set bits, the bits are traversed in ascending sorted order - */ - @Override - public PeekableIntIterator getIntIterator() { - return new RoaringIntIterator(); - } - - /** - * @return a custom iterator over set bits, the bits are traversed in descending sorted order - */ - @Override - public IntIterator getReverseIntIterator() { - return new RoaringReverseIntIterator(); + public RoaringBitmap clone() { + RoaringBitmap bm = new RoaringBitmap(cap); + bm.length = length; + bm.value = new byte[value.length]; + System.arraycopy(value, 0, bm.value, 0, value.length); + return bm; } - /** - * Estimate of the memory usage of this data structure. This can be expected to be within 1% of - * the true memory usage. - * - * @return estimated memory usage. - */ - @Override - public long getLongSizeInBytes() { - long size = 8; - for (int i = 0; i < this.highLowContainer.size(); i++) { - final Container c = this.highLowContainer.getContainerAtIndex(i); - size += 2 + c.getSizeInBytes(); + public static RoaringBitmap and(RoaringBitmap bm1, RoaringBitmap bm2) { + int len = Integer.min(bm1.value.length, bm2.value.length); + RoaringBitmap bm = new RoaringBitmap(Integer.max(bm1.cap, bm2.cap)); + bm.value = new byte[len]; + for (int i = 0; i < len; i++) { + byte b = (byte) (bm1.value[i] & bm2.value[i]); + if (b == 0) { + continue; + } + bm.value[i] = b; + bm.length += countInByte(b); } - return size; - } - - @Override - public int getSizeInBytes() { - return (int) getLongSizeInBytes(); - } - - @Override - public int hashCode() { - return highLowContainer.hashCode(); + return bm; } - /** - * Check whether this bitmap has had its runs compressed. - * - * @return whether this bitmap has run compression - */ - public boolean hasRunCompression() { - for (int i = 0; i < this.highLowContainer.size(); i++) { - Container c = this.highLowContainer.getContainerAtIndex(i); - if (c instanceof RunContainer) { - return true; + public static int andCardinality(RoaringBitmap bm1, RoaringBitmap bm2) { + int len = Integer.min(bm1.value.length, bm2.value.length); + int count = 0; + for (int i = 0; i < len; i++) { + byte b = (byte) (bm1.value[i] & bm2.value[i]); + if (b == 0) { + continue; } + count += countInByte(b); } - return false; + return count; } - /** - * Checks whether the bitmap is empty. - * - * @return true if this bitmap contains no set bit - */ - @Override - public boolean isEmpty() { - return highLowContainer.size() == 0; - } - - /** - * iterate over the positions of the true values. - * - * @return the iterator - */ - @Override public Iterator iterator() { return new Iterator() { - private int hs = 0; - - private ShortIterator iter; - - private int pos = 0; - - private int x; - + private int idx0 = 0; + private int idx1 = 0; @Override public boolean hasNext() { - return pos < RoaringBitmap.this.highLowContainer.size(); - } - - private Iterator init() { - if (pos < RoaringBitmap.this.highLowContainer.size()) { - iter = RoaringBitmap.this.highLowContainer.getContainerAtIndex(pos).getShortIterator(); - hs = RoaringBitmap.this.highLowContainer.getKeyAtIndex(pos) << 16; + while (idx0 < value.length) { + if (value[idx0] != 0) { + byte b = value[idx0]; + while (idx1 < 8) { + if ((b & (1 << idx1)) != 0) { + return true; + } + idx1++; + } + } + idx0++; + idx1 = 0; } - return this; + return false; } @Override public Integer next() { - x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - ++pos; - init(); - } - return x; - } - - @Override - public void remove() { - if ((x & hs) == hs) {// still in same container - iter.remove(); - } else { - RoaringBitmap.this.remove(x); - } - } - - }.init(); - } - - // don't forget to call repairAfterLazy() afterward - // important: x2 should not have been computed lazily - protected void lazyor(final RoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - this.highLowContainer.setContainerAtIndex(pos1, highLowContainer.getContainerAtIndex(pos1) - .lazyIOR(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - highLowContainer.insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); - } - } - - // don't forget to call repairAfterLazy() afterward - // important: x2 should not have been computed lazily - // this method is like lazyor except that it will convert - // the current container to a bitset - public void naivelazyor(RoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - Container c1 = highLowContainer.getContainerAtIndex(pos1); - c1 = c1.toBitmapContainer(); - this.highLowContainer.setContainerAtIndex(pos1, - c1.lazyIOR(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - highLowContainer.insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); - } - } - - /** - * Create a new Roaring bitmap containing at most maxcardinality integers. - * - * @param maxcardinality maximal cardinality - * @return a new bitmap with cardinality no more than maxcardinality - */ - @Override - public RoaringBitmap limit(int maxcardinality) { - RoaringBitmap answer = new RoaringBitmap(); - int currentcardinality = 0; - for (int i = 0; (currentcardinality < maxcardinality) - && (i < this.highLowContainer.size()); i++) { - Container c = this.highLowContainer.getContainerAtIndex(i); - if (c.getCardinality() + currentcardinality <= maxcardinality) { - answer.highLowContainer.appendCopy(this.highLowContainer, i); - currentcardinality += c.getCardinality(); - } else { - int leftover = maxcardinality - currentcardinality; - Container limited = c.limit(leftover); - answer.highLowContainer.append(this.highLowContainer.getKeyAtIndex(i), limited); - break; - } - } - return answer; - } - - /** - * In-place bitwise OR (union) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void or(final RoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - this.highLowContainer.setContainerAtIndex(pos1, highLowContainer.getContainerAtIndex(pos1) - .ior(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - highLowContainer.insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; + if (hasNext()) { + int v = idx0 * 8 + idx1; + idx1++; + if (idx1 >= 8) { + idx1 = 0; + idx0++; } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); + return v; } + return null; } - } - if (pos1 == length1) { - highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); - } - } - - /** - * Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be - * GetCardinality()). - * - * @param x upper limit - * @return the rank - */ - @Override - public long rankLong(int x) { - long size = 0; - short xhigh = Util.highbits(x); - - for (int i = 0; i < this.highLowContainer.size(); i++) { - short key = this.highLowContainer.getKeyAtIndex(i); - if (Util.compareUnsigned(key, xhigh) < 0) { - size += this.highLowContainer.getContainerAtIndex(i).getCardinality(); - } else { - return size + this.highLowContainer.getContainerAtIndex(i).rank(Util.lowbits(x)); - } - } - return size; - } - - @Override - public int rank(int x) { - return (int) rankLong(x); - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - this.highLowContainer.readExternal(in); - } - - /** - * If present remove the specified integer (effectively, sets its bit value to false) - * - * @param x integer value representing the index in a bitmap - */ - public void remove(final int x) { - final short hb = Util.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i < 0) { - return; - } - highLowContainer.setContainerAtIndex(i, - highLowContainer.getContainerAtIndex(i).remove(Util.lowbits(x))); - if (highLowContainer.getContainerAtIndex(i).getCardinality() == 0) { - highLowContainer.removeAtIndex(i); - } - } - - /** - * Remove from the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - */ - public void remove(final long rangeStart, final long rangeEnd) { - - rangeSanityCheck(rangeStart, rangeEnd); - - if (rangeStart >= rangeEnd) { - return; // empty range - } - - - final int hbStart = Util.toIntUnsigned(Util.highbits(rangeStart)); - final int lbStart = Util.toIntUnsigned(Util.lowbits(rangeStart)); - final int hbLast = Util.toIntUnsigned(Util.highbits(rangeEnd - 1)); - final int lbLast = Util.toIntUnsigned(Util.lowbits(rangeEnd - 1)); - if (hbStart == hbLast) { - final int i = highLowContainer.getIndex((short) hbStart); - if (i < 0) { - return; - } - final Container c = highLowContainer.getContainerAtIndex(i).iremove(lbStart, lbLast + 1); - if (c.getCardinality() > 0) { - highLowContainer.setContainerAtIndex(i, c); - } else { - highLowContainer.removeAtIndex(i); - } - return; - } - int ifirst = highLowContainer.getIndex((short) hbStart); - int ilast = highLowContainer.getIndex((short) hbLast); - if (ifirst >= 0) { - if (lbStart != 0) { - final Container c = highLowContainer.getContainerAtIndex(ifirst).iremove(lbStart, - Util.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - highLowContainer.setContainerAtIndex(ifirst, c); - ifirst++; - } - } - } else { - ifirst = -ifirst - 1; - } - if (ilast >= 0) { - if (lbLast != Util.maxLowBitAsInteger()) { - final Container c = highLowContainer.getContainerAtIndex(ilast).iremove(0, lbLast + 1); - if (c.getCardinality() > 0) { - highLowContainer.setContainerAtIndex(ilast, c); - } else { - ilast++; - } - } else { - ilast++; - } - } else { - ilast = -ilast - 1; - } - highLowContainer.removeIndexRange(ifirst, ilast); - } - - /** - * Remove from the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @deprecated use the version where longs specify the range - */ - @Deprecated - public void remove(final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - remove((long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - remove(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * Remove run-length encoding even when it is more space efficient - * - * @return whether a change was applied - */ - public boolean removeRunCompression() { - boolean answer = false; - for (int i = 0; i < this.highLowContainer.size(); i++) { - Container c = this.highLowContainer.getContainerAtIndex(i); - if (c instanceof RunContainer) { - Container newc = ((RunContainer) c).toBitmapOrArrayContainer(c.getCardinality()); - this.highLowContainer.setContainerAtIndex(i, newc); - answer = true; - } - } - return answer; - } - - // to be used with lazyor - public void repairAfterLazy() { - for (int k = 0; k < highLowContainer.size(); ++k) { - Container c = highLowContainer.getContainerAtIndex(k); - highLowContainer.setContainerAtIndex(k, c.repairAfterLazy()); - } - } - - /** - * Use a run-length encoding where it is more space efficient - * - * @return whether a change was applied - */ - public boolean runOptimize() { - boolean answer = false; - for (int i = 0; i < this.highLowContainer.size(); i++) { - Container c = this.highLowContainer.getContainerAtIndex(i).runOptimize(); - if (c instanceof RunContainer) { - answer = true; - } - this.highLowContainer.setContainerAtIndex(i, c); - } - return answer; - } - - /** - * Return the jth value stored in this bitmap. - * - * @param j index of the value - * @return the value - */ - @Override - public int select(int j) { - int leftover = j; - for (int i = 0; i < this.highLowContainer.size(); i++) { - Container c = this.highLowContainer.getContainerAtIndex(i); - int thiscard = c.getCardinality(); - if (thiscard > leftover) { - int keycontrib = this.highLowContainer.getKeyAtIndex(i) << 16; - int lowcontrib = Util.toIntUnsigned(c.select(leftover)); - return lowcontrib + keycontrib; - } - leftover -= thiscard; - } - throw new IllegalArgumentException( - "select " + j + " when the cardinality is " + this.getCardinality()); - } - - /** - * Serialize this bitmap. - *

- * Consider calling {@link #runOptimize} before serialization to improve compression. - *

- * The current bitmap is not modified. - *

- * Advanced example: To serialize your bitmap to a ByteBuffer, you can do the following. - *

- *

-     * {@code
-     *   //r is your bitmap
-     *
-     *   r.runOptimize(); // might improve compression
-     *   // next we create the ByteBuffer where the data will be stored
-     *   ByteBuffer outbb = ByteBuffer.allocate(r.serializedSizeInBytes());
-     *   // then we can serialize on a custom OutputStream
-     *   mrb.serialize(new DataOutputStream(new OutputStream(){
-     *       ByteBuffer mBB;
-     *       OutputStream init(ByteBuffer mbb) {mBB=mbb; return this;}
-     *       public void close() {}
-     *       public void flush() {}
-     *       public void write(int b) {
-     *         mBB.put((byte) b);}
-     *       public void write(byte[] b) {mBB.put(b);}
-     *       public void write(byte[] b, int off, int l) {mBB.put(b,off,l);}
-     *   }.init(outbb)));
-     *   // outbuff will now contain a serialized version of your bitmap
-     * }
-     * 
- *

- * Note: Java's data structures are in big endian format. Roaring serializes to a little endian - * format, so the bytes are flipped by the library during serialization to ensure that what is - * stored is in little endian---despite Java's big endianness. You can defeat this process by - * reflipping the bytes again in a custom DataOutput which could lead to serialized Roaring - * objects with an incorrect byte order. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - @Override - public void serialize(DataOutput out) throws IOException { - this.highLowContainer.serialize(out); - } - - /** - * Report the number of bytes required to serialize this bitmap. This is the number of bytes - * written out when using the serialize method. When using the writeExternal method, the count - * will be higher due to the overhead of Java serialization. - * - * @return the size in bytes - */ - @Override - public int serializedSizeInBytes() { - return this.highLowContainer.serializedSizeInBytes(); - } - - /** - * Return the set values as an array, if the cardinality is smaller than 2147483648. - * The integer values are in sorted order. - * - * @return array representing the set values. - */ - @Override - public int[] toArray() { - final int[] array = new int[(int) this.getCardinality()]; - int pos = 0, pos2 = 0; - while (pos < this.highLowContainer.size()) { - final int hs = this.highLowContainer.getKeyAtIndex(pos) << 16; - Container c = this.highLowContainer.getContainerAtIndex(pos++); - c.fillLeastSignificant16bits(array, pos2, hs); - pos2 += c.getCardinality(); - } - return array; - } - - - /** - * Convert (copies) to a mutable roaring bitmap. - * - * @return a copy of this bitmap as a MutableRoaringBitmap - */ - public MutableRoaringBitmap toMutableRoaringBitmap() { - return new MutableRoaringBitmap(this); - } - - /** - * A string describing the bitmap. - * - * @return the string - */ - @Override - public String toString() { - final StringBuilder answer = new StringBuilder(); - final IntIterator i = this.getIntIterator(); - answer.append("{"); - if (i.hasNext()) { - answer.append(i.next() & 0xFFFFFFFFL); - } - while (i.hasNext()) { - answer.append(","); - // to avoid using too much memory, we limit the size - if (answer.length() > 0x80000) { - answer.append("..."); - break; - } - answer.append(i.next() & 0xFFFFFFFFL); - - } - answer.append("}"); - return answer.toString(); + }; } - /** - * Recover allocated but unused memory. - */ - public void trim() { - for (int i = 0; i < this.highLowContainer.size(); i++) { - this.highLowContainer.getContainerAtIndex(i).trim(); + private void ensureCap(int n) { + int idx = (n + 7) / 8; + int len = value.length; + while (len < idx) { + len <<= 1; } - } - - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - this.highLowContainer.writeExternal(out); - } - - /** - * In-place bitwise XOR (symmetric difference) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void xor(final RoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - final Container c = highLowContainer.getContainerAtIndex(pos1) - .ixor(x2.highLowContainer.getContainerAtIndex(pos2)); - if (c.getCardinality() > 0) { - this.highLowContainer.setContainerAtIndex(pos1, c); - pos1++; - } else { - highLowContainer.removeAtIndex(pos1); - --length1; - } - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - highLowContainer.insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - highLowContainer.appendCopy(x2.highLowContainer, pos2, length2); + if (len > value.length) { + byte[] value2 = new byte[len]; + System.arraycopy(value, 0, value2, 0, value.length); + value = value2; } } - private final class RoaringIntIterator implements PeekableIntIterator { - private int hs = 0; - - private PeekableShortIterator iter; - - private int pos = 0; - - private RoaringIntIterator() { - nextContainer(); - } - - @Override - public PeekableIntIterator clone() { - try { - RoaringIntIterator x = (RoaringIntIterator) super.clone(); - x.iter = this.iter.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < RoaringBitmap.this.highLowContainer.size(); + private void checkIndex(int n) { + if (n < 0) { + throw new ArrayIndexOutOfBoundsException(); } - - @Override - public int next() { - final int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - ++pos; - nextContainer(); - } - return x; - } - - private void nextContainer() { - if (pos < RoaringBitmap.this.highLowContainer.size()) { - iter = RoaringBitmap.this.highLowContainer.getContainerAtIndex(pos).getShortIterator(); - hs = RoaringBitmap.this.highLowContainer.getKeyAtIndex(pos) << 16; - } - } - - @Override - public void advanceIfNeeded(int minval) { - while (hasNext() && ((hs >>> 16) < (minval >>> 16))) { - ++pos; - nextContainer(); - } - if (hasNext() && ((hs >>> 16) == (minval >>> 16))) { - iter.advanceIfNeeded(Util.lowbits(minval)); - if (!iter.hasNext()) { - ++pos; - nextContainer(); - } - } - } - - @Override - public int peekNext() { - return Util.toIntUnsigned(iter.peekNext()) | hs; - } - - } - private final class RoaringReverseIntIterator implements IntIterator { - - int hs = 0; - - ShortIterator iter; - - // don't need an int because we go to 0, not Short.MAX_VALUE, and signed shorts underflow well - // below zero - short pos = (short) (RoaringBitmap.this.highLowContainer.size() - 1); - - private RoaringReverseIntIterator() { - nextContainer(); - } - - @Override - public IntIterator clone() { - try { - RoaringReverseIntIterator clone = (RoaringReverseIntIterator) super.clone(); - clone.iter = this.iter.clone(); - return clone; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - @Override - public int next() { - final int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - --pos; - nextContainer(); + private static int countInByte(byte b) { + int count = 0; + while (b != 0) { + if ((b & 0x01) == 0x01) { + count++; } - return x; + b = (byte) ((b & 0xff) >> 1); } - - private void nextContainer() { - if (pos >= 0) { - iter = - RoaringBitmap.this.highLowContainer.getContainerAtIndex(pos).getReverseShortIterator(); - hs = RoaringBitmap.this.highLowContainer.getKeyAtIndex(pos) << 16; - } - } - + return count; } - - } + diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RunContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RunContainer.java deleted file mode 100644 index c078b52a8..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/RunContainer.java +++ /dev/null @@ -1,2518 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ -package com.fr.third.bitmap.roaringbitmap; - -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableContainer; -import com.fr.third.bitmap.roaringbitmap.buffer.MappeableRunContainer; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.ShortBuffer; -import java.util.Arrays; -import java.util.Iterator; - - -/** - * This container takes the form of runs of consecutive values (effectively, run-length encoding). - *

- * Adding and removing content from this container might make it wasteful so regular calls to - * "runOptimize" might be warranted. - */ -public final class RunContainer extends Container implements Cloneable { - private static final int DEFAULT_INIT_SIZE = 4; - private static final boolean ENABLE_GALLOPING_AND = false; - - private static final long serialVersionUID = 1L; - int nbrruns = 0;// how many runs, this number should fit in 16 bits. - private short[] valueslength;// we interleave values and lengths, so - - /** - * Create a container with default capacity - */ - public RunContainer() { - this(DEFAULT_INIT_SIZE); - } - - protected RunContainer(ArrayContainer arr, int nbrRuns) { - this.nbrruns = nbrRuns; - valueslength = new short[2 * nbrRuns]; - if (nbrRuns == 0) { - return; - } - - int prevVal = -2; - int runLen = 0; - int runCount = 0; - - for (int i = 0; i < arr.cardinality; i++) { - int curVal = Util.toIntUnsigned(arr.content[i]); - if (curVal == prevVal + 1) { - ++runLen; - } else { - if (runCount > 0) { - setLength(runCount - 1, (short) runLen); - } - setValue(runCount, (short) curVal); - runLen = 0; - ++runCount; - } - prevVal = curVal; - } - setLength(runCount - 1, (short) runLen); - } - - // convert a bitmap container to a run container somewhat efficiently. - protected RunContainer(BitmapContainer bc, int nbrRuns) { - this.nbrruns = nbrRuns; - valueslength = new short[2 * nbrRuns]; - if (nbrRuns == 0) { - return; - } - - int longCtr = 0; // index of current long in bitmap - long curWord = bc.bitmap[0]; // its value - int runCount = 0; - while (true) { - // potentially multiword advance to first 1 bit - while (curWord == 0L && longCtr < bc.bitmap.length - 1) { - curWord = bc.bitmap[++longCtr]; - } - - if (curWord == 0L) { - // wrap up, no more runs - return; - } - int localRunStart = Long.numberOfTrailingZeros(curWord); - int runStart = localRunStart + 64 * longCtr; - // stuff 1s into number's LSBs - long curWordWith1s = curWord | (curWord - 1); - - // find the next 0, potentially in a later word - int runEnd = 0; - while (curWordWith1s == -1L && longCtr < bc.bitmap.length - 1) { - curWordWith1s = bc.bitmap[++longCtr]; - } - - if (curWordWith1s == -1L) { - // a final unterminated run of 1s (32 of them) - runEnd = 64 + longCtr * 64; - setValue(runCount, (short) runStart); - setLength(runCount, (short) (runEnd - runStart - 1)); - return; - } - int localRunEnd = Long.numberOfTrailingZeros(~curWordWith1s); - runEnd = localRunEnd + longCtr * 64; - setValue(runCount, (short) runStart); - setLength(runCount, (short) (runEnd - runStart - 1)); - runCount++; - // now, zero out everything right of runEnd. - curWord = curWordWith1s & (curWordWith1s + 1); - // We've lathered and rinsed, so repeat... - } - } - // that if you have the values 11,12,13,14,15, you store that as 11,4 where 4 means that beyond 11 - // itself, there are - // 4 contiguous values that follows. - // Other example: e.g., 1, 10, 20,0, 31,2 would be a concise representation of 1, 2, ..., 11, 20, - // 31, 32, 33 - - /** - * Create an array container with specified capacity - * - * @param capacity The capacity of the container - */ - public RunContainer(final int capacity) { - valueslength = new short[2 * capacity]; - } - - - private RunContainer(int nbrruns, short[] valueslength) { - this.nbrruns = nbrruns; - this.valueslength = Arrays.copyOf(valueslength, valueslength.length); - } - - - /** - * Creates a new non-mappeable container from a mappeable one. This copies the data. - * - * @param bc the original container - */ - public RunContainer(MappeableRunContainer bc) { - this.nbrruns = bc.numberOfRuns(); - this.valueslength = bc.toShortArray(); - } - - /** - * Construct a new RunContainer backed by the provided array. Note that if you modify the - * RunContainer a new array may be produced. - * - * @param array array where the data is stored - * @param numRuns number of runs (each using 2 shorts in the buffer) - */ - public RunContainer(final short[] array, final int numRuns) { - if (array.length < 2 * numRuns) { - throw new RuntimeException("Mismatch between buffer and numRuns"); - } - this.nbrruns = numRuns; - this.valueslength = array; - } - - private static int branchyUnsignedInterleavedBinarySearch(final short[] array, final int begin, - final int end, final short k) { - int ikey = Util.toIntUnsigned(k); - int low = begin; - int high = end - 1; - while (low <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = Util.toIntUnsigned(array[2 * middleIndex]); - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - return -(low + 1); - } - - // starts with binary search and finishes with a sequential search - private static int hybridUnsignedInterleavedBinarySearch(final short[] array, final int begin, - final int end, final short k) { - int ikey = Util.toIntUnsigned(k); - int low = begin; - int high = end - 1; - // 16 in the next line matches the size of a cache line - while (low + 16 <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = Util.toIntUnsigned(array[2 * middleIndex]); - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - // we finish the job with a sequential search - int x = low; - for (; x <= high; ++x) { - final int val = Util.toIntUnsigned(array[2 * x]); - if (val >= ikey) { - if (val == ikey) { - return x; - } - break; - } - } - return -(x + 1); - } - - protected static int serializedSizeInBytes(int numberOfRuns) { - return 2 + 2 * 2 * numberOfRuns; // each run requires 2 2-byte entries. - } - - private static int unsignedInterleavedBinarySearch(final short[] array, final int begin, - final int end, final short k) { - if (Util.USE_HYBRID_BINSEARCH) { - return hybridUnsignedInterleavedBinarySearch(array, begin, end, k); - } else { - return branchyUnsignedInterleavedBinarySearch(array, begin, end, k); - } - - } - - @Override - public Container add(int begin, int end) { - RunContainer rc = (RunContainer) clone(); - return rc.iadd(begin, end); - } - - @Override - public Container add(short k) { - // TODO: it might be better and simpler to do return - // toBitmapOrArrayContainer(getCardinality()).add(k) - // but note that some unit tests use this method to build up test runcontainers without calling - // runOptimize - int index = unsignedInterleavedBinarySearch(valueslength, 0, nbrruns, k); - if (index >= 0) { - return this;// already there - } - index = -index - 2;// points to preceding value, possibly -1 - if (index >= 0) {// possible match - int offset = Util.toIntUnsigned(k) - Util.toIntUnsigned(getValue(index)); - int le = Util.toIntUnsigned(getLength(index)); - if (offset <= le) { - return this; - } - if (offset == le + 1) { - // we may need to fuse - if (index + 1 < nbrruns) { - if (Util.toIntUnsigned(getValue(index + 1)) == Util.toIntUnsigned(k) + 1) { - // indeed fusion is needed - setLength(index, - (short) (getValue(index + 1) + getLength(index + 1) - getValue(index))); - recoverRoomAtIndex(index + 1); - return this; - } - } - incrementLength(index); - return this; - } - if (index + 1 < nbrruns) { - // we may need to fuse - if (Util.toIntUnsigned(getValue(index + 1)) == Util.toIntUnsigned(k) + 1) { - // indeed fusion is needed - setValue(index + 1, k); - setLength(index + 1, (short) (getLength(index + 1) + 1)); - return this; - } - } - } - if (index == -1) { - // we may need to extend the first run - if (0 < nbrruns) { - if (getValue(0) == k + 1) { - incrementLength(0); - decrementValue(0); - return this; - } - } - } - makeRoomAtIndex(index + 1); - setValue(index + 1, k); - setLength(index + 1, (short) 0); - return this; - } - - @Override - public Container and(ArrayContainer x) { - ArrayContainer ac = new ArrayContainer(x.cardinality); - if (this.nbrruns == 0) { - return ac; - } - int rlepos = 0; - int arraypos = 0; - - int rleval = Util.toIntUnsigned(this.getValue(rlepos)); - int rlelength = Util.toIntUnsigned(this.getLength(rlepos)); - while (arraypos < x.cardinality) { - int arrayval = Util.toIntUnsigned(x.content[arraypos]); - while (rleval + rlelength < arrayval) {// this will frequently be false - ++rlepos; - if (rlepos == this.nbrruns) { - return ac;// we are done - } - rleval = Util.toIntUnsigned(this.getValue(rlepos)); - rlelength = Util.toIntUnsigned(this.getLength(rlepos)); - } - if (rleval > arrayval) { - arraypos = Util.advanceUntil(x.content, arraypos, x.cardinality, (short) rleval); - } else { - ac.content[ac.cardinality] = (short) arrayval; - ac.cardinality++; - arraypos++; - } - } - return ac; - } - - - @Override - public Container and(BitmapContainer x) { - // could be implemented as return toBitmapOrArrayContainer().iand(x); - int card = this.getCardinality(); - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - // result can only be an array (assuming that we never make a RunContainer) - if (card > x.cardinality) { - card = x.cardinality; - } - ArrayContainer answer = new ArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (x.contains((short) runValue)) {// it looks like contains() should be cheap enough if - // accessed sequentially - answer.content[answer.cardinality++] = (short) runValue; - } - } - } - return answer; - } - // we expect the answer to be a bitmap (if we are lucky) - BitmapContainer answer = x.clone(); - int start = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int end = Util.toIntUnsigned(this.getValue(rlepos)); - Util.resetBitmapRange(answer.bitmap, start, end); // had been x.bitmap - start = end + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - Util.resetBitmapRange(answer.bitmap, start, Util.maxLowBitAsInteger() + 1); // had been x.bitmap - answer.computeCardinality(); - if (answer.getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public Container and(RunContainer x) { - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.nbrruns)], 0); - int rlepos = 0; - int xrlepos = 0; - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - if (ENABLE_GALLOPING_AND) { - rlepos = skipAhead(this, rlepos, xstart); // skip over runs until we have end > xstart (or - // rlepos is advanced beyond end) - } else { - ++rlepos; - } - - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - if (ENABLE_GALLOPING_AND) { - xrlepos = skipAhead(x, xrlepos, start); - } else { - ++xrlepos; - } - - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else {// they overlap - final int lateststart = start > xstart ? start : xstart; - int earliestend; - if (end == xend) {// improbable - earliestend = end; - rlepos++; - xrlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else if (end < xend) { - earliestend = end; - rlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - - } else {// end > xend - earliestend = xend; - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } - answer.valueslength[2 * answer.nbrruns] = (short) lateststart; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (earliestend - lateststart - 1); - answer.nbrruns++; - } - } - return answer.toEfficientContainer(); // subsequent trim() may be required to avoid wasted - // space. - } - - @Override - public int andCardinality(ArrayContainer x) { - if (this.nbrruns == 0) { - return x.cardinality; - } - int rlepos = 0; - int arraypos = 0; - int andCardinality = 0; - int rleval = Util.toIntUnsigned(this.getValue(rlepos)); - int rlelength = Util.toIntUnsigned(this.getLength(rlepos)); - while (arraypos < x.cardinality) { - int arrayval = Util.toIntUnsigned(x.content[arraypos]); - while (rleval + rlelength < arrayval) {// this will frequently be false - ++rlepos; - if (rlepos == this.nbrruns) { - return andCardinality;// we are done - } - rleval = Util.toIntUnsigned(this.getValue(rlepos)); - rlelength = Util.toIntUnsigned(this.getLength(rlepos)); - } - if (rleval > arrayval) { - arraypos = Util.advanceUntil(x.content, arraypos, x.cardinality, this.getValue(rlepos)); - } else { - andCardinality++; - arraypos++; - } - } - return andCardinality; - } - - - @Override - public int andCardinality(BitmapContainer x) { - // could be implemented as return toBitmapOrArrayContainer().iand(x); - int cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (x.contains((short) runValue)) {// it looks like contains() should be cheap enough if - // accessed sequentially - cardinality++; - } - } - } - return cardinality; - } - - @Override - public int andCardinality(RunContainer x) { - int cardinality = 0; - int rlepos = 0; - int xrlepos = 0; - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - if (ENABLE_GALLOPING_AND) { - rlepos = skipAhead(this, rlepos, xstart); // skip over runs until we have end > xstart (or - // rlepos is advanced beyond end) - } else { - ++rlepos; - } - - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - if (ENABLE_GALLOPING_AND) { - xrlepos = skipAhead(x, xrlepos, start); - } else { - ++xrlepos; - } - - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else {// they overlap - final int lateststart = start > xstart ? start : xstart; - int earliestend; - if (end == xend) {// improbable - earliestend = end; - rlepos++; - xrlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else if (end < xend) { - earliestend = end; - rlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - - } else {// end > xend - earliestend = xend; - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } - // earliestend - lateststart are all values that are true. - cardinality += (short) (earliestend - lateststart); - } - } - return cardinality; - } - - @Override - public Container andNot(ArrayContainer x) { - // when x is small, we guess that the result will still be a run container - final int arbitrary_threshold = 32; // this is arbitrary - if (x.getCardinality() < arbitrary_threshold) { - return lazyandNot(x).toEfficientContainer(); - } - // otherwise we generate either an array or bitmap container - final int card = getCardinality(); - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - // if the cardinality is small, we construct the solution in place - ArrayContainer ac = new ArrayContainer(card); - ac.cardinality = - Util.unsignedDifference(this.getShortIterator(), x.getShortIterator(), ac.content); - return ac; - } - // otherwise, we generate a bitmap - return toBitmapOrArrayContainer(card).iandNot(x); - } - - @Override - public Container andNot(BitmapContainer x) { - // could be implemented as toTemporaryBitmap().iandNot(x); - int card = this.getCardinality(); - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - // result can only be an array (assuming that we never make a RunContainer) - ArrayContainer answer = new ArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (!x.contains((short) runValue)) {// it looks like contains() should be cheap enough if - // accessed sequentially - answer.content[answer.cardinality++] = (short) runValue; - } - } - } - return answer; - } - // we expect the answer to be a bitmap (if we are lucky) - BitmapContainer answer = x.clone(); - int lastPos = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.resetBitmapRange(answer.bitmap, lastPos, start); - Util.flipBitmapRange(answer.bitmap, start, end); - lastPos = end; - } - Util.resetBitmapRange(answer.bitmap, lastPos, answer.bitmap.length * 64); - answer.computeCardinality(); - if (answer.getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public Container andNot(RunContainer x) { - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.nbrruns)], 0); - int rlepos = 0; - int xrlepos = 0; - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - // output the first run - answer.valueslength[2 * answer.nbrruns] = (short) start; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else { - if (start < xstart) { - answer.valueslength[2 * answer.nbrruns] = (short) start; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (xstart - start - 1); - answer.nbrruns++; - } - if (xend < end) { - start = xend; - } else { - rlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } - } - } - if (rlepos < this.nbrruns) { - answer.valueslength[2 * answer.nbrruns] = (short) start; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - if (rlepos < this.nbrruns) { - System.arraycopy(this.valueslength, 2 * rlepos, answer.valueslength, 2 * answer.nbrruns, - 2 * (this.nbrruns - rlepos)); - answer.nbrruns = answer.nbrruns + this.nbrruns - rlepos; - } - } - return answer.toEfficientContainer(); - } - - // Append a value length with all values until a given value - private void appendValueLength(int value, int index) { - int previousValue = Util.toIntUnsigned(getValue(index)); - int length = Util.toIntUnsigned(getLength(index)); - int offset = value - previousValue; - if (offset > length) { - setLength(index, (short) offset); - } - } - - // To check if a value length can be prepended with a given value - private boolean canPrependValueLength(int value, int index) { - if (index < this.nbrruns) { - int nextValue = Util.toIntUnsigned(getValue(index)); - return nextValue == value + 1; - } - return false; - } - - @Override - public void clear() { - nbrruns = 0; - } - - @Override - public Container clone() { - return new RunContainer(nbrruns, valueslength); - } - - // To set the last value of a value length - private void closeValueLength(int value, int index) { - int initialValue = Util.toIntUnsigned(getValue(index)); - setLength(index, (short) (value - initialValue)); - } - - @Override - public boolean contains(short x) { - int index = unsignedInterleavedBinarySearch(valueslength, 0, nbrruns, x); - if (index >= 0) { - return true; - } - index = -index - 2; // points to preceding value, possibly -1 - if (index != -1) {// possible match - int offset = Util.toIntUnsigned(x) - Util.toIntUnsigned(getValue(index)); - int le = Util.toIntUnsigned(getLength(index)); - return offset <= le; - } - return false; - } - - - // a very cheap check... if you have more than 4096, then you should use a bitmap container. - // this function avoids computing the cardinality - private Container convertToLazyBitmapIfNeeded() { - // when nbrruns exceed ArrayContainer.DEFAULT_MAX_SIZE, then we know it should be stored as a - // bitmap, always - if (this.nbrruns > ArrayContainer.DEFAULT_MAX_SIZE) { - BitmapContainer answer = new BitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = -1; - return answer; - } - return this; - } - - - // Push all values length to the end of the array (resize array if needed) - private void copyToOffset(int offset) { - final int minCapacity = 2 * (offset + nbrruns); - if (valueslength.length < minCapacity) { - // expensive case where we need to reallocate - int newCapacity = valueslength.length; - while (newCapacity < minCapacity) { - newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE - : newCapacity < 64 ? newCapacity * 2 - : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4; - } - short[] newvalueslength = new short[newCapacity]; - copyValuesLength(this.valueslength, 0, newvalueslength, offset, nbrruns); - this.valueslength = newvalueslength; - } else { - // efficient case where we just copy - copyValuesLength(this.valueslength, 0, this.valueslength, offset, nbrruns); - } - } - - private void copyValuesLength(short[] src, int srcIndex, short[] dst, int dstIndex, int length) { - System.arraycopy(src, 2 * srcIndex, dst, 2 * dstIndex, 2 * length); - } - - private void decrementLength(int index) { - valueslength[2 * index + 1]--;// caller is responsible to ensure that value is non-zero - } - - - private void decrementValue(int index) { - valueslength[2 * index]--; - } - - @Override - public void deserialize(DataInput in) throws IOException { - nbrruns = Short.reverseBytes(in.readShort()); - if (valueslength.length < 2 * nbrruns) { - valueslength = new short[2 * nbrruns]; - } - for (int k = 0; k < 2 * nbrruns; ++k) { - this.valueslength[k] = Short.reverseBytes(in.readShort()); - } - } - - // not actually used anywhere, but potentially useful - protected void ensureCapacity(int minNbRuns) { - final int minCapacity = 2 * minNbRuns; - if (valueslength.length < minCapacity) { - int newCapacity = valueslength.length; - while (newCapacity < minCapacity) { - newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE - : newCapacity < 64 ? newCapacity * 2 - : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4; - } - short[] nv = new short[newCapacity]; - copyValuesLength(valueslength, 0, nv, 0, nbrruns); - valueslength = nv; - } - } - - @Override - public boolean equals(Object o) { - if (o instanceof RunContainer) { - RunContainer srb = (RunContainer) o; - if (srb.nbrruns != this.nbrruns) { - return false; - } - for (int i = 0; i < nbrruns; ++i) { - if (this.getValue(i) != srb.getValue(i)) { - return false; - } - if (this.getLength(i) != srb.getLength(i)) { - return false; - } - } - return true; - } else if (o instanceof Container) { - if (((Container) o).getCardinality() != this.getCardinality()) { - return false; // should be a frequent branch if they differ - } - // next bit could be optimized if needed: - ShortIterator me = this.getShortIterator(); - ShortIterator you = ((Container) o).getShortIterator(); - while (me.hasNext()) { - if (me.next() != you.next()) { - return false; - } - } - return true; - } - return false; - } - - @Override - public void fillLeastSignificant16bits(int[] x, int i, int mask) { - int pos = i; - for (int k = 0; k < this.nbrruns; ++k) { - final int limit = Util.toIntUnsigned(this.getLength(k)); - final int base = Util.toIntUnsigned(this.getValue(k)); - for (int le = 0; le <= limit; ++le) { - x[pos++] = (base + le) | mask; - } - } - } - - @Override - public Container flip(short x) { - if (this.contains(x)) { - return this.remove(x); - } else { - return this.add(x); - } - } - - @Override - protected int getArraySizeInBytes() { - return 2 + 4 * this.nbrruns; // "array" includes its size - } - - - @Override - public int getCardinality() { - int sum = nbrruns;// lengths are returned -1 - for (int k = 0; k < nbrruns; ++k) { - sum = sum + Util.toIntUnsigned(getLength(k))/* + 1 */; - } - return sum; - } - - short getLength(int index) { - return valueslength[2 * index + 1]; - } - - @Override - public ShortIterator getReverseShortIterator() { - return new ReverseRunContainerShortIterator(this); - } - - @Override - public PeekableShortIterator getShortIterator() { - return new RunContainerShortIterator(this); - } - - @Override - public int getSizeInBytes() { - return this.nbrruns * 4 + 4; - } - - short getValue(int index) { - return valueslength[2 * index]; - } - - @Override - public int hashCode() { - int hash = 0; - for (int k = 0; k < nbrruns * 2; ++k) { - hash += 31 * hash + valueslength[k]; - } - return hash; - } - - @Override - public Container iadd(int begin, int end) { - // TODO: it might be better and simpler to do return - // toBitmapOrArrayContainer(getCardinality()).iadd(begin,end) - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - - if (begin == end - 1) { - add((short) begin); - return this; - } - - int bIndex = unsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, (short) begin); - int eIndex = - unsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, (short) (end - 1)); - - if (bIndex >= 0 && eIndex >= 0) { - mergeValuesLength(bIndex, eIndex); - return this; - - } else if (bIndex >= 0 && eIndex < 0) { - eIndex = -eIndex - 2; - - if (canPrependValueLength(end - 1, eIndex + 1)) { - mergeValuesLength(bIndex, eIndex + 1); - return this; - } - - appendValueLength(end - 1, eIndex); - mergeValuesLength(bIndex, eIndex); - return this; - - } else if (bIndex < 0 && eIndex >= 0) { - bIndex = -bIndex - 2; - - if (bIndex >= 0) { - if (valueLengthContains(begin - 1, bIndex)) { - mergeValuesLength(bIndex, eIndex); - return this; - } - } - prependValueLength(begin, bIndex + 1); - mergeValuesLength(bIndex + 1, eIndex); - return this; - - } else { - bIndex = -bIndex - 2; - eIndex = -eIndex - 2; - - if (eIndex >= 0) { - if (bIndex >= 0) { - if (!valueLengthContains(begin - 1, bIndex)) { - if (bIndex == eIndex) { - if (canPrependValueLength(end - 1, eIndex + 1)) { - prependValueLength(begin, eIndex + 1); - return this; - } - makeRoomAtIndex(eIndex + 1); - setValue(eIndex + 1, (short) begin); - setLength(eIndex + 1, (short) (end - 1 - begin)); - return this; - - } else { - bIndex++; - prependValueLength(begin, bIndex); - } - } - } else { - bIndex = 0; - prependValueLength(begin, bIndex); - } - - if (canPrependValueLength(end - 1, eIndex + 1)) { - mergeValuesLength(bIndex, eIndex + 1); - return this; - } - - appendValueLength(end - 1, eIndex); - mergeValuesLength(bIndex, eIndex); - return this; - - } else { - if (canPrependValueLength(end - 1, 0)) { - prependValueLength(begin, 0); - } else { - makeRoomAtIndex(0); - setValue(0, (short) begin); - setLength(0, (short) (end - 1 - begin)); - } - return this; - } - } - } - - @Override - public Container iand(ArrayContainer x) { - return and(x); - } - - @Override - public Container iand(BitmapContainer x) { - return and(x); - } - - - @Override - public Container iand(RunContainer x) { - return and(x); - } - - - @Override - public Container iandNot(ArrayContainer x) { - return andNot(x); - } - - @Override - public Container iandNot(BitmapContainer x) { - return andNot(x); - } - - @Override - public Container iandNot(RunContainer x) { - return andNot(x); - } - - protected Container ilazyor(ArrayContainer x) { - if (isFull()) { - return this; // this can sometimes solve a lot of computation! - } - return ilazyorToRun(x); - } - - private Container ilazyorToRun(ArrayContainer x) { - if (isFull()) { - return this.clone(); - } - final int nbrruns = this.nbrruns; - final int offset = Math.max(nbrruns, x.getCardinality()); - copyToOffset(offset); - int rlepos = 0; - this.nbrruns = 0; - PeekableShortIterator i = x.getShortIterator(); - while (i.hasNext() && (rlepos < nbrruns)) { - if (Util.compareUnsigned(getValue(rlepos + offset), i.peekNext()) <= 0) { - smartAppend(getValue(rlepos + offset), getLength(rlepos + offset)); - rlepos++; - } else { - smartAppend(i.next()); - } - } - if (i.hasNext()) { - /* - * if(this.nbrruns>0) { // this might be useful if the run container has just one very large - * run int lastval = Util.toIntUnsigned(getValue(nbrruns + offset - 1)) + - * Util.toIntUnsigned(getLength(nbrruns + offset - 1)) + 1; i.advanceIfNeeded((short) - * lastval); } - */ - while (i.hasNext()) { - smartAppend(i.next()); - } - } else { - while (rlepos < nbrruns) { - smartAppend(getValue(rlepos + offset), getLength(rlepos + offset)); - rlepos++; - } - } - return convertToLazyBitmapIfNeeded(); - } - - private void increaseCapacity() { - int newCapacity = (valueslength.length == 0) ? DEFAULT_INIT_SIZE - : valueslength.length < 64 ? valueslength.length * 2 - : valueslength.length < 1024 ? valueslength.length * 3 / 2 - : valueslength.length * 5 / 4; - short[] nv = new short[newCapacity]; - System.arraycopy(valueslength, 0, nv, 0, 2 * nbrruns); - valueslength = nv; - } - - - private void incrementLength(int index) { - valueslength[2 * index + 1]++; - } - - - private void incrementValue(int index) { - valueslength[2 * index]++; - } - - // To set the first value of a value length - private void initValueLength(int value, int index) { - int initialValue = Util.toIntUnsigned(getValue(index)); - int length = Util.toIntUnsigned(getLength(index)); - setValue(index, (short) (value)); - setLength(index, (short) (length - (value - initialValue))); - } - - @Override - public Container inot(int rangeStart, int rangeEnd) { - if (rangeEnd <= rangeStart) { - return this; - } - - // TODO: write special case code for rangeStart=0; rangeEnd=65535 - // a "sliding" effect where each range records the gap adjacent it - // can probably be quite fast. Probably have 2 cases: start with a - // 0 run vs start with a 1 run. If you both start and end with 0s, - // you will require room for expansion. - - // the +1 below is needed in case the valueslength.length is odd - if (valueslength.length <= 2 * nbrruns + 1) { - // no room for expansion - // analyze whether this is a case that will require expansion (that we cannot do) - // this is a bit costly now (4 "contains" checks) - - boolean lastValueBeforeRange = false; - boolean firstValueInRange = false; - boolean lastValueInRange = false; - boolean firstValuePastRange = false; - - // contains is based on a binary search and is hopefully fairly fast. - // however, one binary search could *usually* suffice to find both - // lastValueBeforeRange AND firstValueInRange. ditto for - // lastVaueInRange and firstValuePastRange - - // find the start of the range - if (rangeStart > 0) { - lastValueBeforeRange = contains((short) (rangeStart - 1)); - } - firstValueInRange = contains((short) rangeStart); - - if (lastValueBeforeRange == firstValueInRange) { - // expansion is required if also lastValueInRange==firstValuePastRange - - // tougher to optimize out, but possible. - lastValueInRange = contains((short) (rangeEnd - 1)); - if (rangeEnd != 65536) { - firstValuePastRange = contains((short) rangeEnd); - } - - // there is definitely one more run after the operation. - if (lastValueInRange == firstValuePastRange) { - return not(rangeStart, rangeEnd); // can't do in-place: true space limit - } - } - } - // either no expansion required, or we have room to handle any required expansion for it. - - // remaining code is just a minor variation on not() - int myNbrRuns = nbrruns; - - RunContainer ans = this; // copy on top of self. - int k = 0; - ans.nbrruns = 0; // losing this.nbrruns, which is stashed in myNbrRuns. - - // could try using unsignedInterleavedBinarySearch(valueslength, 0, nbrruns, rangeStart) instead - // of sequential scan - // to find the starting location - - for (; (k < myNbrRuns) && (Util.toIntUnsigned(this.getValue(k)) < rangeStart); ++k) { - // since it is atop self, there is no copying needed - // ans.valueslength[2 * k] = this.valueslength[2 * k]; - // ans.valueslength[2 * k + 1] = this.valueslength[2 * k + 1]; - ans.nbrruns++; - } - // We will work left to right, with a read pointer that always stays - // left of the write pointer. However, we need to give the read pointer a head start. - // use local variables so we are always reading 1 location ahead. - - short bufferedValue = 0, bufferedLength = 0; // 65535 start and 65535 length would be illegal, - // could use as sentinel - short nextValue = 0, nextLength = 0; - if (k < myNbrRuns) { // prime the readahead variables - bufferedValue = getValue(k); - bufferedLength = getLength(k); - } - - ans.smartAppendExclusive((short) rangeStart, (short) (rangeEnd - rangeStart - 1)); - - for (; k < myNbrRuns; ++k) { - if (ans.nbrruns > k + 1) { - throw new RuntimeException( - "internal error in inot, writer has overtaken reader!! " + k + " " + ans.nbrruns); - } - if (k + 1 < myNbrRuns) { - nextValue = getValue(k + 1); // readahead for next iteration - nextLength = getLength(k + 1); - } - ans.smartAppendExclusive(bufferedValue, bufferedLength); - bufferedValue = nextValue; - bufferedLength = nextLength; - } - // the number of runs can increase by one, meaning (rarely) a bitmap will become better - // or the cardinality can decrease by a lot, making an array better - return ans.toEfficientContainer(); - } - - @Override - public boolean intersects(ArrayContainer x) { - if (this.nbrruns == 0) { - return false; - } - int rlepos = 0; - int arraypos = 0; - int rleval = Util.toIntUnsigned(this.getValue(rlepos)); - int rlelength = Util.toIntUnsigned(this.getLength(rlepos)); - while (arraypos < x.cardinality) { - int arrayval = Util.toIntUnsigned(x.content[arraypos]); - while (rleval + rlelength < arrayval) {// this will frequently be false - ++rlepos; - if (rlepos == this.nbrruns) { - return false; - } - rleval = Util.toIntUnsigned(this.getValue(rlepos)); - rlelength = Util.toIntUnsigned(this.getLength(rlepos)); - } - if (rleval > arrayval) { - arraypos = Util.advanceUntil(x.content, arraypos, x.cardinality, this.getValue(rlepos)); - } else { - return true; - } - } - return false; - } - - @Override - public boolean intersects(BitmapContainer x) { - // TODO: this is probably not optimally fast - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (x.contains((short) runValue)) { - return true; - } - } - } - return false; - } - - @Override - public boolean intersects(RunContainer x) { - int rlepos = 0; - int xrlepos = 0; - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - if (ENABLE_GALLOPING_AND) { - rlepos = skipAhead(this, rlepos, xstart); // skip over runs until we have end > xstart (or - // rlepos is advanced beyond end) - } else { - ++rlepos; - } - - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - if (ENABLE_GALLOPING_AND) { - xrlepos = skipAhead(x, xrlepos, start); - } else { - ++xrlepos; - } - - if (xrlepos < x.nbrruns) { - xstart = Util.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + Util.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else {// they overlap - return true; - } - } - return false; - } - - @Override - public Container ior(ArrayContainer x) { - if (isFull()) { - return this; - } - final int nbrruns = this.nbrruns; - final int offset = Math.max(nbrruns, x.getCardinality()); - copyToOffset(offset); - int rlepos = 0; - this.nbrruns = 0; - PeekableShortIterator i = x.getShortIterator(); - while (i.hasNext() && (rlepos < nbrruns)) { - if (Util.compareUnsigned(getValue(rlepos + offset), i.peekNext()) <= 0) { - smartAppend(getValue(rlepos + offset), getLength(rlepos + offset)); - rlepos++; - } else { - smartAppend(i.next()); - } - } - if (i.hasNext()) { - /* - * if(this.nbrruns>0) { // this might be useful if the run container has just one very large - * run int lastval = Util.toIntUnsigned(getValue(nbrruns + offset - 1)) + - * Util.toIntUnsigned(getLength(nbrruns + offset - 1)) + 1; i.advanceIfNeeded((short) - * lastval); } - */ - while (i.hasNext()) { - smartAppend(i.next()); - } - } else { - while (rlepos < nbrruns) { - smartAppend(getValue(rlepos + offset), getLength(rlepos + offset)); - rlepos++; - } - } - return toEfficientContainer(); - } - - @Override - public Container ior(BitmapContainer x) { - if (isFull()) { - return this; - } - return or(x); - } - - @Override - public Container ior(RunContainer x) { - if (isFull()) { - return this; - } - - final int nbrruns = this.nbrruns; - final int xnbrruns = x.nbrruns; - final int offset = Math.max(nbrruns, xnbrruns); - - // Push all values length to the end of the array (resize array if needed) - copyToOffset(offset); - // Aggregate and store the result at the beginning of the array - this.nbrruns = 0; - int rlepos = 0; - int xrlepos = 0; - - // Add values length (smaller first) - while ((rlepos < nbrruns) && (xrlepos < xnbrruns)) { - final short value = this.getValue(offset + rlepos); - final short xvalue = x.getValue(xrlepos); - final short length = this.getLength(offset + rlepos); - final short xlength = x.getLength(xrlepos); - - if (Util.compareUnsigned(value, xvalue) <= 0) { - this.smartAppend(value, length); - ++rlepos; - } else { - this.smartAppend(xvalue, xlength); - ++xrlepos; - } - } - - while (rlepos < nbrruns) { - this.smartAppend(this.getValue(offset + rlepos), this.getLength(offset + rlepos)); - ++rlepos; - } - - while (xrlepos < xnbrruns) { - this.smartAppend(x.getValue(xrlepos), x.getLength(xrlepos)); - ++xrlepos; - } - return this.toBitmapIfNeeded(); - } - - @Override - public Container iremove(int begin, int end) { - // TODO: it might be better and simpler to do return - // toBitmapOrArrayContainer(getCardinality()).iremove(begin,end) - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - if (begin == end - 1) { - remove((short) begin); - return this; - } - - int bIndex = unsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, (short) begin); - int eIndex = - unsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, (short) (end - 1)); - - // note, eIndex is looking for (end-1) - - if (bIndex >= 0) { // beginning marks beginning of a run - if (eIndex < 0) { - eIndex = -eIndex - 2; - } - // eIndex could be a run that begins exactly at "end" - // or it might be an earlier run - - // if the end is before the first run, we'd have eIndex==-1. But bIndex makes this impossible. - - if (valueLengthContains(end, eIndex)) { - initValueLength(end, eIndex); // there is something left in the run - recoverRoomsInRange(bIndex - 1, eIndex - 1); - } else { - recoverRoomsInRange(bIndex - 1, eIndex); // nothing left in the run - } - - } else if (bIndex < 0 && eIndex >= 0) { - // start does not coincide to a run start, but end does. - bIndex = -bIndex - 2; - - if (bIndex >= 0) { - if (valueLengthContains(begin, bIndex)) { - closeValueLength(begin - 1, bIndex); - } - } - - // last run is one shorter - if (getLength(eIndex) == 0) {// special case where we remove last run - recoverRoomsInRange(eIndex, eIndex + 1); - } else { - incrementValue(eIndex); - decrementLength(eIndex); - } - recoverRoomsInRange(bIndex, eIndex - 1); - - } else { - bIndex = -bIndex - 2; - eIndex = -eIndex - 2; - - if (eIndex >= 0) { // end-1 is not before first run. - if (bIndex >= 0) { // nor is begin - if (bIndex == eIndex) { // all removal nested properly between - // one run start and the next - if (valueLengthContains(begin, bIndex)) { - if (valueLengthContains(end, eIndex)) { - // proper nesting within a run, generates 2 sub-runs - makeRoomAtIndex(bIndex); - closeValueLength(begin - 1, bIndex); - initValueLength(end, bIndex + 1); - return this; - } - // removed area extends beyond run. - closeValueLength(begin - 1, bIndex); - } - } else { // begin in one run area, end in a later one. - if (valueLengthContains(begin, bIndex)) { - closeValueLength(begin - 1, bIndex); - // this cannot leave the bIndex run empty. - } - if (valueLengthContains(end, eIndex)) { - // there is additional stuff in the eIndex run - initValueLength(end, eIndex); - eIndex--; - } else { - // run ends at or before the range being removed, can deleteById it - } - recoverRoomsInRange(bIndex, eIndex); - } - - } else { - // removed range begins before the first run - if (valueLengthContains(end, eIndex)) { // had been end-1 - initValueLength(end, eIndex); - recoverRoomsInRange(bIndex, eIndex - 1); - } else { // removed range includes all the last run - recoverRoomsInRange(bIndex, eIndex); - } - } - - } else { - // eIndex == -1: whole range is before first run, nothing to deleteById... - } - - } - return this; - } - - protected boolean isFull() { - return (this.nbrruns == 1) && (this.getValue(0) == 0) && (this.getLength(0) == -1); - } - - @Override - public Iterator iterator() { - final ShortIterator i = getShortIterator(); - return new Iterator() { - - @Override - public boolean hasNext() { - return i.hasNext(); - } - - @Override - public Short next() { - return i.next(); - } - - @Override - public void remove() { - i.remove(); - } - }; - - } - - @Override - public Container ixor(ArrayContainer x) { - return xor(x); - } - - @Override - public Container ixor(BitmapContainer x) { - return xor(x); - } - - - @Override - public Container ixor(RunContainer x) { - return xor(x); - } - - private RunContainer lazyandNot(ArrayContainer x) { - if (x.getCardinality() == 0) { - return this; - } - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.cardinality)], 0); - int rlepos = 0; - int xrlepos = 0; - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = Util.toIntUnsigned(x.content[xrlepos]); - while ((rlepos < this.nbrruns) && (xrlepos < x.cardinality)) { - if (end <= xstart) { - // output the first run - answer.valueslength[2 * answer.nbrruns] = (short) start; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xstart + 1 <= start) { - // exit the second run - xrlepos++; - if (xrlepos < x.cardinality) { - xstart = Util.toIntUnsigned(x.content[xrlepos]); - } - } else { - if (start < xstart) { - answer.valueslength[2 * answer.nbrruns] = (short) start; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (xstart - start - 1); - answer.nbrruns++; - } - if (xstart + 1 < end) { - start = xstart + 1; - } else { - rlepos++; - if (rlepos < this.nbrruns) { - start = Util.toIntUnsigned(this.getValue(rlepos)); - end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } - } - } - if (rlepos < this.nbrruns) { - answer.valueslength[2 * answer.nbrruns] = (short) start; - answer.valueslength[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - if (rlepos < this.nbrruns) { - System.arraycopy(this.valueslength, 2 * rlepos, answer.valueslength, 2 * answer.nbrruns, - 2 * (this.nbrruns - rlepos)); - answer.nbrruns = answer.nbrruns + this.nbrruns - rlepos; - } - } - return answer; - } - - protected Container lazyor(ArrayContainer x) { - return lazyorToRun(x); - } - - private Container lazyorToRun(ArrayContainer x) { - if (isFull()) { - return this.clone(); - } - // TODO: should optimize for the frequent case where we have a single run - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.getCardinality())], 0); - int rlepos = 0; - PeekableShortIterator i = x.getShortIterator(); - - while (i.hasNext() && (rlepos < this.nbrruns)) { - if (Util.compareUnsigned(getValue(rlepos), i.peekNext()) <= 0) { - answer.smartAppend(getValue(rlepos), getLength(rlepos)); - // in theory, this next code could help, in practice it doesn't. - /* - * int lastval = Util.toIntUnsigned(answer.getValue(answer.nbrruns - 1)) + - * Util.toIntUnsigned(answer.getLength(answer.nbrruns - 1)) + 1; i.advanceIfNeeded((short) - * lastval); - */ - - rlepos++; - } else { - answer.smartAppend(i.next()); - } - } - if (i.hasNext()) { - /* - * if(answer.nbrruns>0) { this might be useful if the run container has just one very large - * run int lastval = Util.toIntUnsigned(answer.getValue(answer.nbrruns - 1)) + - * Util.toIntUnsigned(answer.getLength(answer.nbrruns - 1)) + 1; i.advanceIfNeeded((short) - * lastval); } - */ - while (i.hasNext()) { - answer.smartAppend(i.next()); - } - } else { - while (rlepos < this.nbrruns) { - answer.smartAppend(getValue(rlepos), getLength(rlepos)); - rlepos++; - } - } - return answer.convertToLazyBitmapIfNeeded(); - } - - private Container lazyxor(ArrayContainer x) { - if (x.getCardinality() == 0) { - return this; - } - if (this.nbrruns == 0) { - return x; - } - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.getCardinality())], 0); - int rlepos = 0; - ShortIterator i = x.getShortIterator(); - short cv = i.next(); - - while (true) { - if (Util.compareUnsigned(getValue(rlepos), cv) < 0) { - answer.smartAppendExclusive(getValue(rlepos), getLength(rlepos)); - rlepos++; - if (rlepos == this.nbrruns) { - answer.smartAppendExclusive(cv); - while (i.hasNext()) { - answer.smartAppendExclusive(i.next()); - } - break; - } - } else { - answer.smartAppendExclusive(cv); - if (!i.hasNext()) { - while (rlepos < this.nbrruns) { - answer.smartAppendExclusive(getValue(rlepos), getLength(rlepos)); - rlepos++; - } - break; - } else { - cv = i.next(); - } - } - } - return answer; - } - - - @Override - public Container limit(int maxcardinality) { - if (maxcardinality >= getCardinality()) { - return clone(); - } - - int r; - int cardinality = 0; - for (r = 0; r < this.nbrruns; ++r) { - cardinality += Util.toIntUnsigned(getLength(r)) + 1; - if (maxcardinality <= cardinality) { - break; - } - } - - RunContainer rc = new RunContainer(Arrays.copyOf(valueslength, 2 * (r + 1)), r + 1); - rc.setLength(r, - (short) (Util.toIntUnsigned(rc.getLength(r)) - cardinality + maxcardinality)); - return rc; - } - - private void makeRoomAtIndex(int index) { - if (2 * (nbrruns + 1) > valueslength.length) { - increaseCapacity(); - } - copyValuesLength(valueslength, index, valueslength, index + 1, nbrruns - index); - nbrruns++; - } - - // To merge values length from begin(inclusive) to end(inclusive) - private void mergeValuesLength(int begin, int end) { - if (begin < end) { - int bValue = Util.toIntUnsigned(getValue(begin)); - int eValue = Util.toIntUnsigned(getValue(end)); - int eLength = Util.toIntUnsigned(getLength(end)); - int newLength = eValue - bValue + eLength; - setLength(begin, (short) newLength); - recoverRoomsInRange(begin, end); - } - } - - @Override - public Container not(int rangeStart, int rangeEnd) { - if (rangeEnd <= rangeStart) { - return this.clone(); - } - RunContainer ans = new RunContainer(nbrruns + 1); - int k = 0; - for (; (k < this.nbrruns) && (Util.toIntUnsigned(this.getValue(k)) < rangeStart); ++k) { - ans.valueslength[2 * k] = this.valueslength[2 * k]; - ans.valueslength[2 * k + 1] = this.valueslength[2 * k + 1]; - ans.nbrruns++; - } - ans.smartAppendExclusive((short) rangeStart, (short) (rangeEnd - rangeStart - 1)); - for (; k < this.nbrruns; ++k) { - ans.smartAppendExclusive(getValue(k), getLength(k)); - } - // the number of runs can increase by one, meaning (rarely) a bitmap will become better - // or the cardinality can decrease by a lot, making an array better - return ans.toEfficientContainer(); - } - - @Override - public int numberOfRuns() { - return nbrruns; - } - - @Override - public Container or(ArrayContainer x) { - // we guess that, often, the result will still be efficiently expressed as a run container - return lazyor(x).repairAfterLazy(); - } - - @Override - public Container or(BitmapContainer x) { - if (isFull()) { - return clone(); - } - // could be implemented as return toTemporaryBitmap().ior(x); - BitmapContainer answer = x.clone(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.setBitmapRange(answer.bitmap, start, end); - } - answer.computeCardinality(); - return answer; - } - - @Override - public Container or(RunContainer x) { - if (isFull()) { - return clone(); - } - if (x.isFull()) { - return x.clone(); // cheap case that can save a lot of computation - } - // we really ought to optimize the rest of the code for the frequent case where there is a - // single run - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.nbrruns)], 0); - int rlepos = 0; - int xrlepos = 0; - - while ((xrlepos < x.nbrruns) && (rlepos < this.nbrruns)) { - if (Util.compareUnsigned(getValue(rlepos), x.getValue(xrlepos)) <= 0) { - answer.smartAppend(getValue(rlepos), getLength(rlepos)); - rlepos++; - } else { - answer.smartAppend(x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - } - } - while (xrlepos < x.nbrruns) { - answer.smartAppend(x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - } - while (rlepos < this.nbrruns) { - answer.smartAppend(getValue(rlepos), getLength(rlepos)); - rlepos++; - } - - return answer.toBitmapIfNeeded(); - } - - // Prepend a value length with all values starting from a given value - private void prependValueLength(int value, int index) { - int initialValue = Util.toIntUnsigned(getValue(index)); - int length = Util.toIntUnsigned(getLength(index)); - setValue(index, (short) value); - setLength(index, (short) (initialValue - value + length)); - } - - @Override - public int rank(short lowbits) { - int x = Util.toIntUnsigned(lowbits); - int answer = 0; - for (int k = 0; k < this.nbrruns; ++k) { - int value = Util.toIntUnsigned(getValue(k)); - int length = Util.toIntUnsigned(getLength(k)); - if (x < value) { - return answer; - } else if (value + length + 1 >= x) { - return answer + x - value + 1; - } - answer += length + 1; - } - return answer; - } - - @Override - public void readExternal(ObjectInput in) throws IOException { - deserialize(in); - } - - private void recoverRoomAtIndex(int index) { - copyValuesLength(valueslength, index + 1, valueslength, index, nbrruns - index - 1); - nbrruns--; - } - - // To recover rooms between begin(exclusive) and end(inclusive) - private void recoverRoomsInRange(int begin, int end) { - if (end + 1 < this.nbrruns) { - copyValuesLength(this.valueslength, end + 1, this.valueslength, begin + 1, - this.nbrruns - 1 - end); - } - this.nbrruns -= end - begin; - } - - @Override - public Container remove(int begin, int end) { - RunContainer rc = (RunContainer) clone(); - return rc.iremove(begin, end); - } - - @Override - public Container remove(short x) { - int index = unsignedInterleavedBinarySearch(valueslength, 0, nbrruns, x); - if (index >= 0) { - if (getLength(index) == 0) { - recoverRoomAtIndex(index); - } else { - incrementValue(index); - decrementLength(index); - } - return this;// already there - } - index = -index - 2;// points to preceding value, possibly -1 - if (index >= 0) {// possible match - int offset = Util.toIntUnsigned(x) - Util.toIntUnsigned(getValue(index)); - int le = Util.toIntUnsigned(getLength(index)); - if (offset < le) { - // need to break in two - this.setLength(index, (short) (offset - 1)); - // need to insert - int newvalue = Util.toIntUnsigned(x) + 1; - int newlength = le - offset - 1; - makeRoomAtIndex(index + 1); - this.setValue(index + 1, (short) newvalue); - this.setLength(index + 1, (short) newlength); - return this; - - } else if (offset == le) { - decrementLength(index); - } - } - // no match - return this; - } - - @Override - public Container repairAfterLazy() { - return toEfficientContainer(); - } - - /** - * Convert to Array or Bitmap container if the serialized form would be shorter. Exactly the same - * functionality as toEfficientContainer. - */ - - @Override - public Container runOptimize() { - return toEfficientContainer(); - } - - @Override - public short select(int j) { - int offset = 0; - for (int k = 0; k < this.nbrruns; ++k) { - int nextOffset = offset + Util.toIntUnsigned(getLength(k)) + 1; - if (nextOffset > j) { - return (short) (getValue(k) + (j - offset)); - } - offset = nextOffset; - } - throw new IllegalArgumentException( - "Cannot select " + j + " since cardinality is " + getCardinality()); - } - - @Override - public void serialize(DataOutput out) throws IOException { - writeArray(out); - } - - @Override - public int serializedSizeInBytes() { - return serializedSizeInBytes(nbrruns); - } - - private void setLength(int index, short v) { - setLength(valueslength, index, v); - } - - - private void setLength(short[] valueslength, int index, short v) { - valueslength[2 * index + 1] = v; - } - - private void setValue(int index, short v) { - setValue(valueslength, index, v); - } - - private void setValue(short[] valueslength, int index, short v) { - valueslength[2 * index] = v; - } - - - // bootstrapping (aka "galloping") binary search. Always skips at least one. - // On our "real data" benchmarks, enabling galloping is a minor loss - // .."ifdef ENABLE_GALLOPING_AND" :) - private int skipAhead(RunContainer skippingOn, int pos, int targetToExceed) { - int left = pos; - int span = 1; - int probePos = 0; - int end; - // jump ahead to find a spot where end > targetToExceed (if it exists) - do { - probePos = left + span; - if (probePos >= skippingOn.nbrruns - 1) { - // expect it might be quite common to find the container cannot be advanced as far as - // requested. Optimize for it. - probePos = skippingOn.nbrruns - 1; - end = Util.toIntUnsigned(skippingOn.getValue(probePos)) - + Util.toIntUnsigned(skippingOn.getLength(probePos)) + 1; - if (end <= targetToExceed) { - return skippingOn.nbrruns; - } - } - end = Util.toIntUnsigned(skippingOn.getValue(probePos)) - + Util.toIntUnsigned(skippingOn.getLength(probePos)) + 1; - span *= 2; - } while (end <= targetToExceed); - int right = probePos; - // left and right are both valid positions. Invariant: left <= targetToExceed && right > - // targetToExceed - // do a binary search to discover the spot where left and right are separated by 1, and - // invariant is maintained. - while (right - left > 1) { - int mid = (right + left) / 2; - int midVal = Util.toIntUnsigned(skippingOn.getValue(mid)) - + Util.toIntUnsigned(skippingOn.getLength(mid)) + 1; - if (midVal > targetToExceed) { - right = mid; - } else { - left = mid; - } - } - return right; - } - - private void smartAppend(short val) { - int oldend; - if ((nbrruns == 0) - || (Util.toIntUnsigned(val) > (oldend = Util.toIntUnsigned(valueslength[2 * (nbrruns - 1)]) - + Util.toIntUnsigned(valueslength[2 * (nbrruns - 1) + 1])) + 1)) { // we add a new one - valueslength[2 * nbrruns] = val; - valueslength[2 * nbrruns + 1] = 0; - nbrruns++; - return; - } - if (val == (short) (oldend + 1)) { // we merge - valueslength[2 * (nbrruns - 1) + 1]++; - } - } - - private void smartAppend(short start, short length) { - int oldend; - if ((nbrruns == 0) || (Util.toIntUnsigned(start) > (oldend = - Util.toIntUnsigned(getValue(nbrruns - 1)) + Util.toIntUnsigned(getLength(nbrruns - 1))) - + 1)) { // we add a new one - valueslength[2 * nbrruns] = start; - valueslength[2 * nbrruns + 1] = length; - nbrruns++; - return; - } - int newend = Util.toIntUnsigned(start) + Util.toIntUnsigned(length) + 1; - if (newend > oldend) { // we merge - setLength(nbrruns - 1, (short) (newend - 1 - Util.toIntUnsigned(getValue(nbrruns - 1)))); - } - } - - private void smartAppendExclusive(short val) { - int oldend; - if ((nbrruns == 0) - || (Util.toIntUnsigned(val) > (oldend = Util.toIntUnsigned(getValue(nbrruns - 1)) - + Util.toIntUnsigned(getLength(nbrruns - 1)) + 1))) { // we add a new one - valueslength[2 * nbrruns] = val; - valueslength[2 * nbrruns + 1] = 0; - nbrruns++; - return; - } - if (oldend == Util.toIntUnsigned(val)) { - // we merge - valueslength[2 * (nbrruns - 1) + 1]++; - return; - } - int newend = Util.toIntUnsigned(val) + 1; - - if (Util.toIntUnsigned(val) == Util.toIntUnsigned(getValue(nbrruns - 1))) { - // we wipe out previous - if (newend != oldend) { - setValue(nbrruns - 1, (short) newend); - setLength(nbrruns - 1, (short) (oldend - newend - 1)); - return; - } else { // they cancel out - nbrruns--; - return; - } - } - setLength(nbrruns - 1, (short) (val - Util.toIntUnsigned(getValue(nbrruns - 1)) - 1)); - if (newend < oldend) { - setValue(nbrruns, (short) newend); - setLength(nbrruns, (short) (oldend - newend - 1)); - nbrruns++; - } else if (oldend < newend) { - setValue(nbrruns, (short) oldend); - setLength(nbrruns, (short) (newend - oldend - 1)); - nbrruns++; - } - - } - - private void smartAppendExclusive(short start, short length) { - int oldend; - if ((nbrruns == 0) - || (Util.toIntUnsigned(start) > (oldend = Util.toIntUnsigned(getValue(nbrruns - 1)) - + Util.toIntUnsigned(getLength(nbrruns - 1)) + 1))) { // we add a new one - valueslength[2 * nbrruns] = start; - valueslength[2 * nbrruns + 1] = length; - nbrruns++; - return; - } - if (oldend == Util.toIntUnsigned(start)) { - // we merge - valueslength[2 * (nbrruns - 1) + 1] += length + 1; - return; - } - - int newend = Util.toIntUnsigned(start) + Util.toIntUnsigned(length) + 1; - - if (Util.toIntUnsigned(start) == Util.toIntUnsigned(getValue(nbrruns - 1))) { - // we wipe out previous - if (newend < oldend) { - setValue(nbrruns - 1, (short) newend); - setLength(nbrruns - 1, (short) (oldend - newend - 1)); - return; - } else if (newend > oldend) { - setValue(nbrruns - 1, (short) oldend); - setLength(nbrruns - 1, (short) (newend - oldend - 1)); - return; - } else { // they cancel out - nbrruns--; - return; - } - } - setLength(nbrruns - 1, (short) (start - Util.toIntUnsigned(getValue(nbrruns - 1)) - 1)); - if (newend < oldend) { - setValue(nbrruns, (short) newend); - setLength(nbrruns, (short) (oldend - newend - 1)); - nbrruns++; - } else if (newend > oldend) { - setValue(nbrruns, (short) oldend); - setLength(nbrruns, (short) (newend - oldend - 1)); - nbrruns++; - } - } - - // convert to bitmap *if needed* (useful if you know it can't be an array) - private Container toBitmapIfNeeded() { - int sizeAsRunContainer = RunContainer.serializedSizeInBytes(this.nbrruns); - int sizeAsBitmapContainer = BitmapContainer.serializedSizeInBytes(0); - if (sizeAsBitmapContainer > sizeAsRunContainer) { - return this; - } - return toBitmapContainer(); - } - - /** - * Convert the container to either a Bitmap or an Array Container, depending on the cardinality. - * - * @param card the current cardinality - * @return new container - */ - Container toBitmapOrArrayContainer(int card) { - // int card = this.getCardinality(); - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - ArrayContainer answer = new ArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(this.getLength(rlepos)); - - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - answer.content[answer.cardinality++] = (short) runValue; - } - } - return answer; - } - BitmapContainer answer = new BitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = card; - return answer; - } - - // convert to bitmap or array *if needed* - private Container toEfficientContainer() { - int sizeAsRunContainer = RunContainer.serializedSizeInBytes(this.nbrruns); - int sizeAsBitmapContainer = BitmapContainer.serializedSizeInBytes(0); - int card = this.getCardinality(); - int sizeAsArrayContainer = ArrayContainer.serializedSizeInBytes(card); - if (sizeAsRunContainer <= Math.min(sizeAsBitmapContainer, sizeAsArrayContainer)) { - return this; - } - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - ArrayContainer answer = new ArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = Util.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + Util.toIntUnsigned(this.getLength(rlepos)); - - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - answer.content[answer.cardinality++] = (short) runValue; - } - } - return answer; - } - BitmapContainer answer = new BitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = card; - return answer; - } - - @Override - public MappeableContainer toMappeableContainer() { - return new MappeableRunContainer(this); - } - - /** - * Return the content of this container as a ShortBuffer. This creates a copy and might be - * relatively slow. - * - * @return the ShortBuffer - */ - public ShortBuffer toShortBuffer() { - ShortBuffer sb = ShortBuffer.allocate(this.nbrruns * 2); - sb.put(this.valueslength, 0, this.nbrruns * 2); - return sb; - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - for (int k = 0; k < this.nbrruns; ++k) { - sb.append("["); - sb.append(Util.toIntUnsigned(this.getValue(k))); - sb.append(","); - sb.append(Util.toIntUnsigned(this.getValue(k)) + Util.toIntUnsigned(this.getLength(k))); - sb.append("]"); - } - return sb.toString(); - } - - - @Override - public void trim() { - if (valueslength.length == 2 * nbrruns) { - return; - } - valueslength = Arrays.copyOf(valueslength, 2 * nbrruns); - } - - - // To check if a value length contains a given value - private boolean valueLengthContains(int value, int index) { - int initialValue = Util.toIntUnsigned(getValue(index)); - int length = Util.toIntUnsigned(getLength(index)); - - return value <= initialValue + length; - } - - @Override - protected void writeArray(DataOutput out) throws IOException { - out.writeShort(Short.reverseBytes((short) this.nbrruns)); - for (int k = 0; k < 2 * this.nbrruns; ++k) { - out.writeShort(Short.reverseBytes(this.valueslength[k])); - } - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - serialize(out); - - } - - @Override - public Container xor(ArrayContainer x) { - // if the cardinality of the array is small, guess that the output will still be a run container - final int arbitrary_threshold = 32; // 32 is arbitrary here - if (x.getCardinality() < arbitrary_threshold) { - return lazyxor(x).repairAfterLazy(); - } - // otherwise, we expect the output to be either an array or bitmap - final int card = getCardinality(); - if (card <= ArrayContainer.DEFAULT_MAX_SIZE) { - // if the cardinality is small, we construct the solution in place - return x.xor(this.getShortIterator()); - } - // otherwise, we generate a bitmap (even if runcontainer would be better) - return toBitmapOrArrayContainer(card).ixor(x); - } - - @Override - public Container xor(BitmapContainer x) { - // could be implemented as return toTemporaryBitmap().ixor(x); - BitmapContainer answer = x.clone(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.flipBitmapRange(answer.bitmap, start, end); - } - answer.computeCardinality(); - if (answer.getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public Container xor(RunContainer x) { - if (x.nbrruns == 0) { - return this.clone(); - } - if (this.nbrruns == 0) { - return x.clone(); - } - RunContainer answer = new RunContainer(new short[2 * (this.nbrruns + x.nbrruns)], 0); - int rlepos = 0; - int xrlepos = 0; - - while (true) { - if (Util.compareUnsigned(getValue(rlepos), x.getValue(xrlepos)) < 0) { - answer.smartAppendExclusive(getValue(rlepos), getLength(rlepos)); - rlepos++; - - if (rlepos == this.nbrruns) { - while (xrlepos < x.nbrruns) { - answer.smartAppendExclusive(x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - } - break; - } - } else { - answer.smartAppendExclusive(x.getValue(xrlepos), x.getLength(xrlepos)); - - xrlepos++; - if (xrlepos == x.nbrruns) { - while (rlepos < this.nbrruns) { - answer.smartAppendExclusive(getValue(rlepos), getLength(rlepos)); - rlepos++; - } - break; - } - } - } - return answer.toEfficientContainer(); - } - - @Override - public void forEach(short msb, IntConsumer ic) { - int high = ((int) msb) << 16; - for (int k = 0; k < this.nbrruns; ++k) { - int base = (this.getValue(k) & 0xFFFF) | high; - int le = this.getLength(k) & 0xFFFF; - for (int l = base; l <= base + le; ++l) { - ic.accept(l); - } - } - } - - @Override - public BitmapContainer toBitmapContainer() { - int card = this.getCardinality(); - BitmapContainer answer = new BitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = Util.toIntUnsigned(this.getValue(rlepos)); - int end = start + Util.toIntUnsigned(this.getLength(rlepos)) + 1; - Util.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = card; - return answer; - } - -} - - -final class RunContainerShortIterator implements PeekableShortIterator { - int pos; - int le = 0; - int maxlength; - int base; - - RunContainer parent; - - RunContainerShortIterator() { - } - - RunContainerShortIterator(RunContainer p) { - wrap(p); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < parent.nbrruns; - } - - @Override - public short next() { - short ans = (short) (base + le); - le++; - if (le > maxlength) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public int nextAsInt() { - int ans = base + le; - le++; - if (le > maxlength) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public void remove() { - throw new RuntimeException("Not implemented");// TODO - } - - void wrap(RunContainer p) { - parent = p; - pos = 0; - le = 0; - if (pos < parent.nbrruns) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } - } - - @Override - public void advanceIfNeeded(short minval) { - while (base + maxlength < Util.toIntUnsigned(minval)) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } else { - return; - } - } - if (base > Util.toIntUnsigned(minval)) { - return; - } - le = Util.toIntUnsigned(minval) - base; - } - - - @Override - public short peekNext() { - return (short) (base + le); - } - -} - - -final class ReverseRunContainerShortIterator implements ShortIterator { - int pos; - int le; - RunContainer parent; - int maxlength; - int base; - - - ReverseRunContainerShortIterator() { - } - - ReverseRunContainerShortIterator(RunContainer p) { - wrap(p); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - @Override - public short next() { - short ans = (short) (base + maxlength - le); - le++; - if (le > maxlength) { - pos--; - le = 0; - if (pos >= 0) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public int nextAsInt() { - int ans = base + maxlength - le; - le++; - if (le > maxlength) { - pos--; - le = 0; - if (pos >= 0) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public void remove() { - throw new RuntimeException("Not implemented");// TODO - } - - void wrap(RunContainer p) { - parent = p; - pos = parent.nbrruns - 1; - le = 0; - if (pos >= 0) { - maxlength = Util.toIntUnsigned(parent.getLength(pos)); - base = Util.toIntUnsigned(parent.getValue(pos)); - } - } - -} - diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ShortIterator.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ShortIterator.java deleted file mode 100644 index 2e1591858..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/ShortIterator.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * Iterator over short values. - */ -public interface ShortIterator extends Cloneable { - /** - * Creates a copy of the iterator. - * - * @return a clone of the current iterator - */ - ShortIterator clone(); - - /** - * @return whether there is another value - */ - boolean hasNext(); - - - /** - * @return next short value - */ - short next(); - - /** - * @return next short value as int value (using the least significant 16 bits) - */ - int nextAsInt(); - - /** - * If possible, remove the current value - */ - void remove(); - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/Util.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/Util.java deleted file mode 100644 index fad7f9a62..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/Util.java +++ /dev/null @@ -1,931 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap; - -/** - * Various useful methods for roaring bitmaps. - */ -public final class Util { - - /** - * optimization flag: whether to use hybrid binary search: hybrid formats - * combine a binary search with a sequential search - */ - public static boolean USE_HYBRID_BINSEARCH = true; - - - /** - * Private constructor to prevent instantiation of utility class - */ - private Util() { - } - - /** - * Find the smallest integer larger than pos such that array[pos]>= min. If none can be found, - * return length. Based on code by O. Kaser. - * - * @param array array to search within - * @param pos starting position of the search - * @param length length of the array to search - * @param min minimum value - * @return x greater than pos such that array[pos] is at least as large as min, pos is is equal to - * length if it is not possible. - */ - public static int advanceUntil(short[] array, int pos, int length, short min) { - int lower = pos + 1; - - // special handling for a possibly common sequential case - if (lower >= length || toIntUnsigned(array[lower]) >= toIntUnsigned(min)) { - return lower; - } - - int spansize = 1; // could set larger - // bootstrap an upper limit - - while (lower + spansize < length - && toIntUnsigned(array[lower + spansize]) < toIntUnsigned(min)) { - spansize *= 2; // hoping for compiler will reduce to - } - // shift - int upper = (lower + spansize < length) ? lower + spansize : length - 1; - - // maybe we are lucky (could be common case when the seek ahead - // expected - // to be small and sequential will otherwise make us look bad) - if (array[upper] == min) { - return upper; - } - - if (toIntUnsigned(array[upper]) < toIntUnsigned(min)) {// means - // array - // has no - // item - // >= min - // pos = array.length; - return length; - } - - // we know that the next-smallest span was too small - lower += (spansize / 2); - - // else begin binary search - // invariant: array[lower]min - while (lower + 1 != upper) { - int mid = (lower + upper) / 2; - short arraymid = array[mid]; - if (arraymid == min) { - return mid; - } else if (toIntUnsigned(arraymid) < toIntUnsigned(min)) { - lower = mid; - } else { - upper = mid; - } - } - return upper; - - } - - protected static int branchyUnsignedBinarySearch(final short[] array, final int begin, - final int end, final short k) { - int ikey = toIntUnsigned(k); - // next line accelerates the possibly common case where the value would - // be inserted at the end - if ((end > 0) && (toIntUnsigned(array[end - 1]) < ikey)) { - return -end - 1; - } - int low = begin; - int high = end - 1; - while (low <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = toIntUnsigned(array[middleIndex]); - - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - return -(low + 1); - } - - /** - * Compares the two specified {@code short} values, treating them as unsigned values between - * {@code 0} and {@code 2^16 - 1} inclusive. - * - * @param a the first unsigned {@code short} to compare - * @param b the second unsigned {@code short} to compare - * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is - * greater than {@code b}; or zero if they are equal - */ - public static int compareUnsigned(short a, short b) { - return toIntUnsigned(a) - toIntUnsigned(b); - } - - /** - * Compute the bitwise AND between two long arrays and write the set bits in the container. - * - * @param container where we write - * @param bitmap1 first bitmap - * @param bitmap2 second bitmap - */ - public static void fillArrayAND(final short[] container, final long[] bitmap1, - final long[] bitmap2) { - int pos = 0; - if (bitmap1.length != bitmap2.length) { - throw new IllegalArgumentException("not supported"); - } - for (int k = 0; k < bitmap1.length; ++k) { - long bitset = bitmap1[k] & bitmap2[k]; - while (bitset != 0) { - long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } - - /** - * Compute the bitwise ANDNOT between two long arrays and write the set bits in the container. - * - * @param container where we write - * @param bitmap1 first bitmap - * @param bitmap2 second bitmap - */ - public static void fillArrayANDNOT(final short[] container, final long[] bitmap1, - final long[] bitmap2) { - int pos = 0; - if (bitmap1.length != bitmap2.length) { - throw new IllegalArgumentException("not supported"); - } - for (int k = 0; k < bitmap1.length; ++k) { - long bitset = bitmap1[k] & (~bitmap2[k]); - while (bitset != 0) { - long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } - - /** - * Compute the bitwise XOR between two long arrays and write the set bits in the container. - * - * @param container where we write - * @param bitmap1 first bitmap - * @param bitmap2 second bitmap - */ - public static void fillArrayXOR(final short[] container, final long[] bitmap1, - final long[] bitmap2) { - int pos = 0; - if (bitmap1.length != bitmap2.length) { - throw new IllegalArgumentException("not supported"); - } - for (int k = 0; k < bitmap1.length; ++k) { - long bitset = bitmap1[k] ^ bitmap2[k]; - while (bitset != 0) { - long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } - - /** - * flip bits at start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - public static void flipBitmapRange(long[] bitmap, int start, int end) { - if (start == end) { - return; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - bitmap[firstword] ^= ~(~0L << start); - for (int i = firstword; i < endword; i++) { - bitmap[i] = ~bitmap[i]; - } - bitmap[endword] ^= ~0L >>> -end; - } - - /** - * Hamming weight of the 64-bit words involved in the range - * start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return the hamming weight - */ - public static int cardinalityInBitmapWordRange(long[] bitmap, int start, int end) { - if (start == end) { - return 0; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - int answer = 0; - for (int i = firstword; i <= endword; i++) { - answer += Long.bitCount(bitmap[i]); - } - return answer; - } - - protected static short highbits(int x) { - return (short) (x >>> 16); - } - - protected static short highbits(long x) { - return (short) (x >>> 16); - } - - // starts with binary search and finishes with a sequential search - protected static int hybridUnsignedBinarySearch(final short[] array, final int begin, - final int end, final short k) { - int ikey = toIntUnsigned(k); - // next line accelerates the possibly common case where the value would - // be inserted at the end - if ((end > 0) && (toIntUnsigned(array[end - 1]) < ikey)) { - return -end - 1; - } - int low = begin; - int high = end - 1; - // 32 in the next line matches the size of a cache line - while (low + 32 <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = toIntUnsigned(array[middleIndex]); - - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - // we finish the job with a sequential search - int x = low; - for (; x <= high; ++x) { - final int val = toIntUnsigned(array[x]); - if (val >= ikey) { - if (val == ikey) { - return x; - } - break; - } - } - return -(x + 1); - } - - protected static short lowbits(int x) { - return (short) (x & 0xFFFF); - } - - protected static short lowbits(long x) { - return (short) (x & 0xFFFF); - } - - protected static short maxLowBit() { - return (short) 0xFFFF; - } - - protected static int maxLowBitAsInteger() { - return 0xFFFF; - } - - /** - * clear bits at start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - public static void resetBitmapRange(long[] bitmap, int start, int end) { - if (start == end) { - return; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - - if (firstword == endword) { - bitmap[firstword] &= ~((~0L << start) & (~0L >>> -end)); - return; - } - bitmap[firstword] &= ~(~0L << start); - for (int i = firstword + 1; i < endword; i++) { - bitmap[i] = 0; - } - bitmap[endword] &= ~(~0L >>> -end); - - } - - /** - * Given a word w, return the position of the jth true bit. - * - * @param w word - * @param j index - * @return position of jth true bit in w - */ - public static int select(long w, int j) { - int seen = 0; - // Divide 64bit - int part = (int) (w & 0xFFFFFFFF); - int n = Integer.bitCount(part); - if (n <= j) { - part = (int) (w >>> 32); - seen += 32; - j -= n; - } - int ww = part; - - // Divide 32bit - part = ww & 0xFFFF; - - n = Integer.bitCount(part); - if (n <= j) { - - part = ww >>> 16; - seen += 16; - j -= n; - } - ww = part; - - // Divide 16bit - part = ww & 0xFF; - n = Integer.bitCount(part); - if (n <= j) { - part = ww >>> 8; - seen += 8; - j -= n; - } - ww = part; - - // Lookup in final byte - int counter; - for (counter = 0; counter < 8; counter++) { - j -= (ww >>> counter) & 1; - if (j < 0) { - break; - } - } - return seen + counter; - } - - /** - * set bits at start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - public static void setBitmapRange(long[] bitmap, int start, int end) { - if (start == end) { - return; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - if (firstword == endword) { - bitmap[firstword] |= (~0L << start) & (~0L >>> -end); - return; - } - bitmap[firstword] |= ~0L << start; - for (int i = firstword + 1; i < endword; i++) { - bitmap[i] = ~0L; - } - bitmap[endword] |= ~0L >>> -end; - } - - /** - * set bits at start, start+1,..., end-1 and report the - * cardinality change - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return cardinality change - */ - public static int setBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end) { - int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end); - setBitmapRange(bitmap, start, end); - int cardafter = cardinalityInBitmapWordRange(bitmap, start, end); - return cardafter - cardbefore; - } - - /** - * flip bits at start, start+1,..., end-1 and report the - * cardinality change - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return cardinality change - */ - public static int flipBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end) { - int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end); - flipBitmapRange(bitmap, start, end); - int cardafter = cardinalityInBitmapWordRange(bitmap, start, end); - return cardafter - cardbefore; - } - - /** - * reset bits at start, start+1,..., end-1 and report the - * cardinality change - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return cardinality change - */ - public static int resetBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end) { - int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end); - resetBitmapRange(bitmap, start, end); - int cardafter = cardinalityInBitmapWordRange(bitmap, start, end); - return cardafter - cardbefore; - } - - protected static int toIntUnsigned(short x) { - return x & 0xFFFF; - } - - /** - * Look for value k in array in the range [begin,end). If the value is found, return its index. If - * not, return -(i+1) where i is the index where the value would be inserted. The array is assumed - * to contain sorted values where shorts are interpreted as unsigned integers. - * - * @param array array where we search - * @param begin first index (inclusive) - * @param end last index (exclusive) - * @param k value we search for - * @return count - */ - public static int unsignedBinarySearch(final short[] array, final int begin, final int end, - final short k) { - if (USE_HYBRID_BINSEARCH) { - return hybridUnsignedBinarySearch(array, begin, end, k); - } else { - return branchyUnsignedBinarySearch(array, begin, end, k); - } - } - - /** - * Compute the difference between two sorted lists and write the result to the provided output - * array - * - * @param set1 first array - * @param length1 length of first array - * @param set2 second array - * @param length2 length of second array - * @param buffer output array - * @return cardinality of the difference - */ - public static int unsignedDifference(final short[] set1, final int length1, final short[] set2, - final int length2, final short[] buffer) { - int pos = 0; - int k1 = 0, k2 = 0; - if (0 == length2) { - System.arraycopy(set1, 0, buffer, 0, length1); - return length1; - } - if (0 == length1) { - return 0; - } - short s1 = set1[k1]; - short s2 = set2[k2]; - while (true) { - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - buffer[pos++] = s1; - ++k1; - if (k1 >= length1) { - break; - } - s1 = set1[k1]; - } else if (toIntUnsigned(s1) == toIntUnsigned(s2)) { - ++k1; - ++k2; - if (k1 >= length1) { - break; - } - if (k2 >= length2) { - System.arraycopy(set1, k1, buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s1 = set1[k1]; - s2 = set2[k2]; - } else {// if (val1>val2) - ++k2; - if (k2 >= length2) { - System.arraycopy(set1, k1, buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s2 = set2[k2]; - } - } - return pos; - } - - /** - * Compute the difference between two sorted lists and write the result to the provided output - * array - * - * @param set1 first array - * @param set2 second array - * @param buffer output array - * @return cardinality of the difference - */ - public static int unsignedDifference(ShortIterator set1, ShortIterator set2, - final short[] buffer) { - int pos = 0; - if (!set2.hasNext()) { - while (set1.hasNext()) { - buffer[pos++] = set1.next(); - } - return pos; - } - if (!set1.hasNext()) { - return 0; - } - short v1 = set1.next(); - short v2 = set2.next(); - while (true) { - if (toIntUnsigned(v1) < toIntUnsigned(v2)) { - buffer[pos++] = v1; - if (!set1.hasNext()) { - return pos; - } - v1 = set1.next(); - } else if (v1 == v2) { - if (!set1.hasNext()) { - break; - } - if (!set2.hasNext()) { - while (set1.hasNext()) { - buffer[pos++] = set1.next(); - } - return pos; - } - v1 = set1.next(); - v2 = set2.next(); - } else {// if (val1>val2) - if (!set2.hasNext()) { - buffer[pos++] = v1; - while (set1.hasNext()) { - buffer[pos++] = set1.next(); - } - return pos; - } - v2 = set2.next(); - } - } - return pos; - } - - /** - * Compute the exclusive union of two sorted lists and write the result to the provided output - * array - * - * @param set1 first array - * @param length1 length of first array - * @param set2 second array - * @param length2 length of second array - * @param buffer output array - * @return cardinality of the exclusive union - */ - public static int unsignedExclusiveUnion2by2(final short[] set1, final int length1, - final short[] set2, final int length2, final short[] buffer) { - int pos = 0; - int k1 = 0, k2 = 0; - if (0 == length2) { - System.arraycopy(set1, 0, buffer, 0, length1); - return length1; - } - if (0 == length1) { - System.arraycopy(set2, 0, buffer, 0, length2); - return length2; - } - short s1 = set1[k1]; - short s2 = set2[k2]; - while (true) { - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - buffer[pos++] = s1; - ++k1; - if (k1 >= length1) { - System.arraycopy(set2, k2, buffer, pos, length2 - k2); - return pos + length2 - k2; - } - s1 = set1[k1]; - } else if (toIntUnsigned(s1) == toIntUnsigned(s2)) { - ++k1; - ++k2; - if (k1 >= length1) { - System.arraycopy(set2, k2, buffer, pos, length2 - k2); - return pos + length2 - k2; - } - if (k2 >= length2) { - System.arraycopy(set1, k1, buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s1 = set1[k1]; - s2 = set2[k2]; - } else {// if (val1>val2) - buffer[pos++] = s2; - ++k2; - if (k2 >= length2) { - System.arraycopy(set1, k1, buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s2 = set2[k2]; - } - } - // return pos; - } - - /** - * Intersect two sorted lists and write the result to the provided output array - * - * @param set1 first array - * @param length1 length of first array - * @param set2 second array - * @param length2 length of second array - * @param buffer output array - * @return cardinality of the intersection - */ - public static int unsignedIntersect2by2(final short[] set1, final int length1, final short[] set2, - final int length2, final short[] buffer) { - if (set1.length * 64 < set2.length) { - return unsignedOneSidedGallopingIntersect2by2(set1, length1, set2, length2, buffer); - } else if (set2.length * 64 < set1.length) { - return unsignedOneSidedGallopingIntersect2by2(set2, length2, set1, length1, buffer); - } else { - return unsignedLocalIntersect2by2(set1, length1, set2, length2, buffer); - } - } - - /** - * Checks if two arrays intersect - * - * @param set1 first array - * @param length1 length of first array - * @param set2 second array - * @param length2 length of second array - * @return true if they intersect - */ - public static boolean unsignedIntersects(short[] set1, int length1, short[] set2, int length2) { - // galloping might be faster, but we do not expect this function to be slow - if ((0 == length1) || (0 == length2)) { - return false; - } - int k1 = 0; - int k2 = 0; - short s1 = set1[k1]; - short s2 = set2[k2]; - mainwhile: - while (true) { - if (toIntUnsigned(s2) < toIntUnsigned(s1)) { - do { - ++k2; - if (k2 == length2) { - break mainwhile; - } - s2 = set2[k2]; - } while (toIntUnsigned(s2) < toIntUnsigned(s1)); - } - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - do { - ++k1; - if (k1 == length1) { - break mainwhile; - } - s1 = set1[k1]; - } while (toIntUnsigned(s1) < toIntUnsigned(s2)); - } else { - return true; - } - } - return false; - } - - protected static int unsignedLocalIntersect2by2(final short[] set1, final int length1, - final short[] set2, final int length2, final short[] buffer) { - if ((0 == length1) || (0 == length2)) { - return 0; - } - int k1 = 0; - int k2 = 0; - int pos = 0; - short s1 = set1[k1]; - short s2 = set2[k2]; - - mainwhile: - while (true) { - int v1 = toIntUnsigned(s1); - int v2 = toIntUnsigned(s2); - if (v2 < v1) { - do { - ++k2; - if (k2 == length2) { - break mainwhile; - } - s2 = set2[k2]; - v2 = toIntUnsigned(s2); - } while (v2 < v1); - } - if (v1 < v2) { - do { - ++k1; - if (k1 == length1) { - break mainwhile; - } - s1 = set1[k1]; - v1 = toIntUnsigned(s1); - } while (v1 < v2); - } else { - // (set2[k2] == set1[k1]) - buffer[pos++] = s1; - ++k1; - if (k1 == length1) { - break; - } - ++k2; - if (k2 == length2) { - break; - } - s1 = set1[k1]; - s2 = set2[k2]; - } - } - return pos; - } - - /** - * Compute the cardinality of the intersection - * - * @param set1 first set - * @param length1 how many values to consider in the first set - * @param set2 second set - * @param length2 how many values to consider in the second set - * @return cardinality of the intersection - */ - public static int unsignedLocalIntersect2by2Cardinality(final short[] set1, final int length1, - final short[] set2, final int length2) { - if ((0 == length1) || (0 == length2)) { - return 0; - } - int k1 = 0; - int k2 = 0; - int pos = 0; - short s1 = set1[k1]; - short s2 = set2[k2]; - - mainwhile: - while (true) { - int v1 = toIntUnsigned(s1); - int v2 = toIntUnsigned(s2); - if (v2 < v1) { - do { - ++k2; - if (k2 == length2) { - break mainwhile; - } - s2 = set2[k2]; - v2 = toIntUnsigned(s2); - } while (v2 < v1); - } - if (v1 < v2) { - do { - ++k1; - if (k1 == length1) { - break mainwhile; - } - s1 = set1[k1]; - v1 = toIntUnsigned(s1); - } while (v1 < v2); - } else { - // (set2[k2] == set1[k1]) - pos++; - ++k1; - if (k1 == length1) { - break; - } - ++k2; - if (k2 == length2) { - break; - } - s1 = set1[k1]; - s2 = set2[k2]; - } - } - return pos; - } - - protected static int unsignedOneSidedGallopingIntersect2by2(final short[] smallSet, - final int smallLength, final short[] largeSet, final int largeLength, final short[] buffer) { - if (0 == smallLength) { - return 0; - } - int k1 = 0; - int k2 = 0; - int pos = 0; - short s1 = largeSet[k1]; - short s2 = smallSet[k2]; - while (true) { - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - k1 = advanceUntil(largeSet, k1, largeLength, s2); - if (k1 == largeLength) { - break; - } - s1 = largeSet[k1]; - } - if (toIntUnsigned(s2) < toIntUnsigned(s1)) { - ++k2; - if (k2 == smallLength) { - break; - } - s2 = smallSet[k2]; - } else { - // (set2[k2] == set1[k1]) - buffer[pos++] = s2; - ++k2; - if (k2 == smallLength) { - break; - } - s2 = smallSet[k2]; - k1 = advanceUntil(largeSet, k1, largeLength, s2); - if (k1 == largeLength) { - break; - } - s1 = largeSet[k1]; - } - - } - return pos; - - } - - /** - * Unite two sorted lists and write the result to the provided output array - * - * @param set1 first array - * @param length1 length of first array - * @param set2 second array - * @param length2 length of second array - * @param buffer output array - * @return cardinality of the union - */ - public static int unsignedUnion2by2(final short[] set1, final int length1, final short[] set2, - final int length2, final short[] buffer) { - int pos = 0; - int k1 = 0, k2 = 0; - if (0 == length2) { - System.arraycopy(set1, 0, buffer, 0, length1); - return length1; - } - if (0 == length1) { - System.arraycopy(set2, 0, buffer, 0, length2); - return length2; - } - short s1 = set1[k1]; - short s2 = set2[k2]; - while (true) { - int v1 = toIntUnsigned(s1); - int v2 = toIntUnsigned(s2); - if (v1 < v2) { - buffer[pos++] = s1; - ++k1; - if (k1 >= length1) { - System.arraycopy(set2, k2, buffer, pos, length2 - k2); - return pos + length2 - k2; - } - s1 = set1[k1]; - } else if (v1 == v2) { - buffer[pos++] = s1; - ++k1; - ++k2; - if (k1 >= length1) { - System.arraycopy(set2, k2, buffer, pos, length2 - k2); - return pos + length2 - k2; - } - if (k2 >= length2) { - System.arraycopy(set1, k1, buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s1 = set1[k1]; - s2 = set2[k2]; - } else {// if (set1[k1]>set2[k2]) - buffer[pos++] = s2; - ++k2; - if (k2 >= length2) { - System.arraycopy(set1, k1, buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s2 = set2[k2]; - } - } - // return pos; - } - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferBitSetUtil.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferBitSetUtil.java deleted file mode 100644 index 3012c9a65..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferBitSetUtil.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.fr.third.bitmap.roaringbitmap.buffer; - - -import com.fr.third.bitmap.roaringbitmap.IntIterator; - -import java.nio.LongBuffer; -import java.nio.ShortBuffer; -import java.util.Arrays; -import java.util.BitSet; - - -/*** - * - * This class provides convenience functions to manipulate BitSet and MutableRoaringBitmap objects. - * - */ -public class BufferBitSetUtil { - // todo: add a method to convert an ImmutableRoaringBitmap to a BitSet using BitSet.valueOf - - // a block consists has a maximum of 1024 words, each representing 64 bits, - // thus representing at maximum 65536 bits - static final private int BLOCK_LENGTH = MappeableBitmapContainer.MAX_CAPACITY / Long.SIZE; // - // 64-bit - // word - - private static MappeableArrayContainer arrayContainerOf(final int from, final int to, - final int cardinality, final long[] words) { - // precondition: cardinality is max 4096 - final short[] content = new short[cardinality]; - int index = 0; - - for (int i = from, socket = 0; i < to; ++i, socket += Long.SIZE) { - long word = words[i]; - while (word != 0) { - long t = word & -word; - content[index++] = (short) (socket + Long.bitCount(t - 1)); - word ^= t; - } - } - return new MappeableArrayContainer(ShortBuffer.wrap(content), cardinality); - } - - /** - * Generate a MutableRoaringBitmap out of a long[], each long using little-endian representation - * of its bits - * - * @param words array of longs (will not be modified) - * @return roaring bitmap - * @see BitSet#toLongArray() for an equivalent - */ - public static MutableRoaringBitmap bitmapOf(final long[] words) { - // split long[] into blocks. - // each block becomes a single container, if any bit is set - final MutableRoaringBitmap ans = new MutableRoaringBitmap(); - int containerIndex = 0; - for (int from = 0; from < words.length; from += BLOCK_LENGTH) { - final int to = Math.min(from + BLOCK_LENGTH, words.length); - final int blockCardinality = cardinality(from, to, words); - if (blockCardinality > 0) { - ((MutableRoaringArray) ans.highLowContainer).insertNewKeyValueAt(containerIndex++, - BufferUtil.highbits(from * Long.SIZE), - BufferBitSetUtil.containerOf(from, to, blockCardinality, words)); - } - } - return ans; - } - - private static int cardinality(final int from, final int to, final long[] words) { - int sum = 0; - for (int i = from; i < to; i++) { - sum += Long.bitCount(words[i]); - } - return sum; - } - - - private static MappeableContainer containerOf(final int from, final int to, - final int blockCardinality, final long[] words) { - // find the best container available - if (blockCardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - // containers with DEFAULT_MAX_SIZE or less integers should be - // ArrayContainers - return arrayContainerOf(from, to, blockCardinality, words); - } else { - // otherwise use bitmap container - return new MappeableBitmapContainer( - LongBuffer.wrap(Arrays.copyOfRange(words, from, from + BLOCK_LENGTH)), blockCardinality); - } - } - - - /** - * Compares a RoaringBitmap and a BitSet. They are equal if and only if they contain the same set - * of integers. - * - * @param bitset first object to be compared - * @param bitmap second object to be compared - * @return whether they are equal - */ - public static boolean equals(final BitSet bitset, final ImmutableRoaringBitmap bitmap) { - if (bitset.cardinality() != bitmap.getCardinality()) { - return false; - } - final IntIterator it = bitmap.getIntIterator(); - while (it.hasNext()) { - int val = it.next(); - if (!bitset.get(val)) { - return false; - } - } - return true; - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferFastAggregation.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferFastAggregation.java deleted file mode 100644 index 78d609675..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferFastAggregation.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.PriorityQueue; - - -/** - * Fast algorithms to aggregate many bitmaps. - * - * @author Daniel Lemire - */ -public final class BufferFastAggregation { - - - /** - * Private constructor to prevent instantiation of utility class - */ - private BufferFastAggregation() { - } - - /** - * Compute the AND aggregate. - *

- * In practice, calls {#link naive_and} - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap and(ImmutableRoaringBitmap... bitmaps) { - return naive_and(bitmaps); - } - - /** - * Compute the AND aggregate. - *

- * In practice, calls {#link naive_and} - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - public static MutableRoaringBitmap and(@SuppressWarnings("rawtypes") Iterator bitmaps) { - return naive_and(bitmaps); - } - - /** - * Compute the AND aggregate. - *

- * In practice, calls {#link naive_and} - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap and(MutableRoaringBitmap... bitmaps) { - return and(convertToImmutable(bitmaps)); - } - - /** - * Convenience method converting one type of iterator into another, to avoid unnecessary warnings. - * - * @param i input bitmaps - * @return an iterator over the provided iterator, with a different type - */ - public static Iterator convertToImmutable( - final Iterator i) { - return new Iterator() { - - @Override - public boolean hasNext() { - return i.hasNext(); - } - - @Override - public ImmutableRoaringBitmap next() { - return i.next(); - } - - @Override - public void remove() { - } - - ; - - }; - - } - - private static ImmutableRoaringBitmap[] convertToImmutable(MutableRoaringBitmap[] array) { - ImmutableRoaringBitmap[] answer = new ImmutableRoaringBitmap[array.length]; - for (int k = 0; k < answer.length; ++k) { - answer[k] = array[k]; - } - return answer; - } - - /** - * Minimizes memory usage while computing the or aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #or(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap horizontal_or(ImmutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - if (bitmaps.length == 0) { - return answer; - } - PriorityQueue pq = new PriorityQueue(bitmaps.length); - for (int k = 0; k < bitmaps.length; ++k) { - MappeableContainerPointer x = bitmaps[k].highLowContainer.getContainerPointer(); - if (x.getContainer() != null) { - pq.add(x); - } - } - - while (!pq.isEmpty()) { - MappeableContainerPointer x1 = pq.poll(); - if (pq.isEmpty() || (pq.peek().key() != x1.key())) { - answer.getMappeableRoaringArray().append(x1.key(), x1.getContainer().clone()); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - continue; - } - MappeableContainerPointer x2 = pq.poll(); - MappeableContainer newc = x1.getContainer().lazyOR(x2.getContainer()); - while (!pq.isEmpty() && (pq.peek().key() == x1.key())) { - - MappeableContainerPointer x = pq.poll(); - newc = newc.lazyIOR(x.getContainer()); - x.advance(); - if (x.getContainer() != null) { - pq.add(x); - } else if (pq.isEmpty()) { - break; - } - } - newc = newc.repairAfterLazy(); - answer.getMappeableRoaringArray().append(x1.key(), newc); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - x2.advance(); - if (x2.getContainer() != null) { - pq.add(x2); - } - } - return answer; - } - - /** - * Calls naive_or. - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - @Deprecated - public static MutableRoaringBitmap horizontal_or(@SuppressWarnings("rawtypes") Iterator bitmaps) { - return naive_or(bitmaps); - } - - /** - * Minimizes memory usage while computing the or aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #or(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap horizontal_or(MutableRoaringBitmap... bitmaps) { - return horizontal_or(convertToImmutable(bitmaps)); - } - - /** - * Minimizes memory usage while computing the xor aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #xor(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap horizontal_xor(ImmutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - if (bitmaps.length == 0) { - return answer; - } - PriorityQueue pq = new PriorityQueue(bitmaps.length); - for (int k = 0; k < bitmaps.length; ++k) { - MappeableContainerPointer x = bitmaps[k].highLowContainer.getContainerPointer(); - if (x.getContainer() != null) { - pq.add(x); - } - } - - while (!pq.isEmpty()) { - MappeableContainerPointer x1 = pq.poll(); - if (pq.isEmpty() || (pq.peek().key() != x1.key())) { - answer.getMappeableRoaringArray().append(x1.key(), x1.getContainer().clone()); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - continue; - } - MappeableContainerPointer x2 = pq.poll(); - MappeableContainer newc = x1.getContainer().xor(x2.getContainer()); - while (!pq.isEmpty() && (pq.peek().key() == x1.key())) { - - MappeableContainerPointer x = pq.poll(); - newc = newc.ixor(x.getContainer()); - x.advance(); - if (x.getContainer() != null) { - pq.add(x); - } else if (pq.isEmpty()) { - break; - } - } - answer.getMappeableRoaringArray().append(x1.key(), newc); - x1.advance(); - if (x1.getContainer() != null) { - pq.add(x1); - } - x2.advance(); - if (x2.getContainer() != null) { - pq.add(x2); - } - } - return answer; - } - - /** - * Minimizes memory usage while computing the xor aggregate on a moderate number of bitmaps. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #xor(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap horizontal_xor(MutableRoaringBitmap... bitmaps) { - return horizontal_xor(convertToImmutable(bitmaps)); - } - - /** - * Compute overall AND between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_and(ImmutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer; - - if (bitmaps.length > 0) { - answer = (bitmaps[0]).toMutableRoaringBitmap(); - for (int k = 1; k < bitmaps.length; ++k) { - answer = ImmutableRoaringBitmap.and(answer, bitmaps[k]); - } - } else { - answer = new MutableRoaringBitmap(); - } - - return answer; - } - - /** - * Compute overall AND between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_and(@SuppressWarnings("rawtypes") Iterator bitmaps) { - if (!bitmaps.hasNext()) { - return new MutableRoaringBitmap(); - } - MutableRoaringBitmap answer = - ((ImmutableRoaringBitmap) bitmaps.next()).toMutableRoaringBitmap(); - while (bitmaps.hasNext()) { - answer.and((ImmutableRoaringBitmap) bitmaps.next()); - } - return answer; - } - - /** - * Compute overall AND between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_and(MutableRoaringBitmap... bitmaps) { - if (bitmaps.length == 0) { - return new MutableRoaringBitmap(); - } - MutableRoaringBitmap answer = bitmaps[0].clone(); - for (int k = 1; k < bitmaps.length; ++k) { - answer.and(bitmaps[k]); - } - return answer; - } - - /** - * Compute overall OR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_or(ImmutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - for (int k = 0; k < bitmaps.length; ++k) { - answer.naivelazyor(bitmaps[k]); - } - answer.repairAfterLazy(); - return answer; - } - - /** - * Compute overall OR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_or(@SuppressWarnings("rawtypes") Iterator bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - while (bitmaps.hasNext()) { - answer.naivelazyor((ImmutableRoaringBitmap) bitmaps.next()); - } - answer.repairAfterLazy(); - return answer; - } - - /** - * Compute overall OR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_or(MutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - for (int k = 0; k < bitmaps.length; ++k) { - answer.lazyor(bitmaps[k]); - } - answer.repairAfterLazy(); - return answer; - } - - /** - * Compute overall XOR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_xor(ImmutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - for (int k = 0; k < bitmaps.length; ++k) { - answer.xor(bitmaps[k]); - } - return answer; - } - - /** - * Compute overall XOR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_xor(@SuppressWarnings("rawtypes") Iterator bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - while (bitmaps.hasNext()) { - answer.xor((ImmutableRoaringBitmap) bitmaps.next()); - } - return answer; - } - - /** - * Compute overall XOR between bitmaps two-by-two. - *

- * This function runs in linear time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap naive_xor(MutableRoaringBitmap... bitmaps) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - for (int k = 0; k < bitmaps.length; ++k) { - answer.xor(bitmaps[k]); - } - return answer; - } - - /** - * Compute overall OR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps) { - return naive_or(bitmaps); - } - - /** - * Compute overall OR between bitmaps. - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - public static MutableRoaringBitmap or(@SuppressWarnings("rawtypes") Iterator bitmaps) { - return naive_or(bitmaps); - } - - /** - * Compute overall OR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap or(MutableRoaringBitmap... bitmaps) { - return naive_or(bitmaps); - } - - /** - * Uses a priority queue to compute the or aggregate. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #horizontal_or(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap priorityqueue_or(ImmutableRoaringBitmap... bitmaps) { - if (bitmaps.length == 0) { - return new MutableRoaringBitmap(); - } else if (bitmaps.length == 1) { - return bitmaps[0].toMutableRoaringBitmap(); - } - // we buffer the call to getLongSizeInBytes(), hence the code complexity - final ImmutableRoaringBitmap[] buffer = Arrays.copyOf(bitmaps, bitmaps.length); - final int[] sizes = new int[buffer.length]; - final boolean[] istmp = new boolean[buffer.length]; - for (int k = 0; k < sizes.length; ++k) { - sizes[k] = buffer[k].serializedSizeInBytes(); - } - PriorityQueue pq = new PriorityQueue(128, new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return sizes[a] - sizes[b]; - } - }); - for (int k = 0; k < sizes.length; ++k) { - pq.add(k); - } - while (pq.size() > 1) { - Integer x1 = pq.poll(); - Integer x2 = pq.poll(); - if (istmp[x1] && istmp[x2]) { - buffer[x1] = MutableRoaringBitmap.lazyorfromlazyinputs((MutableRoaringBitmap) buffer[x1], - (MutableRoaringBitmap) buffer[x2]); - sizes[x1] = buffer[x1].serializedSizeInBytes(); - pq.add(x1); - } else if (istmp[x2]) { - ((MutableRoaringBitmap) buffer[x2]).lazyor(buffer[x1]); - sizes[x2] = buffer[x2].serializedSizeInBytes(); - pq.add(x2); - } else if (istmp[x1]) { - ((MutableRoaringBitmap) buffer[x1]).lazyor(buffer[x2]); - sizes[x1] = buffer[x1].serializedSizeInBytes(); - pq.add(x1); - } else { - buffer[x1] = ImmutableRoaringBitmap.lazyor(buffer[x1], buffer[x2]); - sizes[x1] = buffer[x1].serializedSizeInBytes(); - istmp[x1] = true; - pq.add(x1); - } - } - MutableRoaringBitmap answer = (MutableRoaringBitmap) buffer[pq.poll()]; - answer.repairAfterLazy(); - return answer; - } - - /** - * Uses a priority queue to compute the or aggregate. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #horizontal_or(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap priorityqueue_or( - @SuppressWarnings("rawtypes") Iterator bitmaps) { - if (!bitmaps.hasNext()) { - return new MutableRoaringBitmap(); - } - // we buffer the call to getLongSizeInBytes(), hence the code complexity - ArrayList buffer = new ArrayList(); - while (bitmaps.hasNext()) { - buffer.add((ImmutableRoaringBitmap) bitmaps.next()); - } - final long[] sizes = new long[buffer.size()]; - final boolean[] istmp = new boolean[buffer.size()]; - for (int k = 0; k < sizes.length; ++k) { - sizes[k] = buffer.get(k).getLongSizeInBytes(); - } - PriorityQueue pq = new PriorityQueue(128, new Comparator() { - @Override - public int compare(Integer a, Integer b) { - return (int) (sizes[a] - sizes[b]); - } - }); - for (int k = 0; k < sizes.length; ++k) { - pq.add(k); - } - if (pq.size() == 1) { - return buffer.get(pq.poll()).toMutableRoaringBitmap(); - } - while (pq.size() > 1) { - Integer x1 = pq.poll(); - Integer x2 = pq.poll(); - if (istmp[x1] && istmp[x2]) { - buffer.set(x1, MutableRoaringBitmap.lazyorfromlazyinputs( - (MutableRoaringBitmap) buffer.get(x1), (MutableRoaringBitmap) buffer.get(x2))); - sizes[x1] = buffer.get(x1).getLongSizeInBytes(); - pq.add(x1); - } else if (istmp[x2]) { - ((MutableRoaringBitmap) buffer.get(x2)).lazyor(buffer.get(x1)); - sizes[x2] = buffer.get(x2).getLongSizeInBytes(); - pq.add(x2); - } else if (istmp[x1]) { - ((MutableRoaringBitmap) buffer.get(x1)).lazyor(buffer.get(x2)); - sizes[x1] = buffer.get(x1).getLongSizeInBytes(); - pq.add(x1); - } else { - buffer.set(x1, ImmutableRoaringBitmap.lazyor(buffer.get(x1), buffer.get(x2))); - sizes[x1] = buffer.get(x1).getLongSizeInBytes(); - istmp[x1] = true; - pq.add(x1); - } - } - MutableRoaringBitmap answer = (MutableRoaringBitmap) buffer.get(pq.poll()); - answer.repairAfterLazy(); - return answer; - } - - /** - * Uses a priority queue to compute the xor aggregate. - *

- * This function runs in linearithmic (O(n log n)) time with respect to the number of bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - * @see #horizontal_xor(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap priorityqueue_xor(ImmutableRoaringBitmap... bitmaps) { - // code could be faster, see priorityqueue_or - if (bitmaps.length < 2) { - throw new IllegalArgumentException("Expecting at least 2 bitmaps"); - } - final PriorityQueue pq = - new PriorityQueue(bitmaps.length, new Comparator() { - @Override - public int compare(ImmutableRoaringBitmap a, ImmutableRoaringBitmap b) { - return (int) (a.getLongSizeInBytes() - b.getLongSizeInBytes()); - } - }); - Collections.addAll(pq, bitmaps); - while (pq.size() > 1) { - final ImmutableRoaringBitmap x1 = pq.poll(); - final ImmutableRoaringBitmap x2 = pq.poll(); - pq.add(ImmutableRoaringBitmap.xor(x1, x2)); - } - return (MutableRoaringBitmap) pq.poll(); - } - - /** - * Compute overall XOR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap xor(ImmutableRoaringBitmap... bitmaps) { - return naive_xor(bitmaps); - } - - /** - * Compute overall XOR between bitmaps. - * - * @param bitmaps input bitmaps (ImmutableRoaringBitmap or MutableRoaringBitmap) - * @return aggregated bitmap - */ - public static MutableRoaringBitmap xor(@SuppressWarnings("rawtypes") Iterator bitmaps) { - return naive_xor(bitmaps); - } - - /** - * Compute overall XOR between bitmaps. - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap xor(MutableRoaringBitmap... bitmaps) { - return naive_xor(bitmaps); - } - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferIntIteratorFlyweight.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferIntIteratorFlyweight.java deleted file mode 100644 index c193a27d4..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferIntIteratorFlyweight.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.PeekableIntIterator; -import com.fr.third.bitmap.roaringbitmap.PeekableShortIterator; - -/** - * Fast iterator minimizing the stress on the garbage collector. You can create one reusable - * instance of this class and then {@link #wrap(ImmutableRoaringBitmap)} - *

- * For better performance, consider the {@link ImmutableRoaringBitmap#forEach} method. - * - * @author Borislav Ivanov - **/ -public class BufferIntIteratorFlyweight implements PeekableIntIterator { - - private int hs; - - private PeekableShortIterator iter; - - private MappeableArrayContainerShortIterator arrIter = new MappeableArrayContainerShortIterator(); - - private MappeableBitmapContainerShortIterator bitmapIter = - new MappeableBitmapContainerShortIterator(); - - private MappeableRunContainerShortIterator runIter = new MappeableRunContainerShortIterator(); - - - private int pos; - - private ImmutableRoaringBitmap roaringBitmap = null; - - /** - * Creates an instance that is not ready for iteration. You must first call - * {@link #wrap(ImmutableRoaringBitmap)}. - */ - public BufferIntIteratorFlyweight() { - - } - - /** - * Creates an instance that is ready for iteration. - * - * @param r bitmap to be iterated over - */ - public BufferIntIteratorFlyweight(ImmutableRoaringBitmap r) { - wrap(r); - } - - @Override - public PeekableIntIterator clone() { - try { - BufferIntIteratorFlyweight x = (BufferIntIteratorFlyweight) super.clone(); - x.iter = this.iter.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < this.roaringBitmap.highLowContainer.size(); - } - - @Override - public int next() { - int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - ++pos; - nextContainer(); - } - return x; - } - - private void nextContainer() { - if (pos < this.roaringBitmap.highLowContainer.size()) { - - MappeableContainer container = this.roaringBitmap.highLowContainer.getContainerAtIndex(pos); - - if (container instanceof MappeableBitmapContainer) { - bitmapIter.wrap((MappeableBitmapContainer) container); - iter = bitmapIter; - } else if (container instanceof MappeableRunContainer) { - runIter.wrap((MappeableRunContainer) container); - iter = runIter; - } else { - arrIter.wrap((MappeableArrayContainer) container); - iter = arrIter; - } - - hs = BufferUtil.toIntUnsigned(this.roaringBitmap.highLowContainer.getKeyAtIndex(pos)) << 16; - } - } - - /** - * Prepares a bitmap for iteration - * - * @param r bitmap to be iterated over - */ - public void wrap(ImmutableRoaringBitmap r) { - this.hs = 0; - this.pos = 0; - this.roaringBitmap = r; - this.nextContainer(); - } - - @Override - public void advanceIfNeeded(int minval) { - while (hasNext() && ((hs >>> 16) < (minval >>> 16))) { - ++pos; - nextContainer(); - } - if (hasNext() && ((hs >>> 16) == (minval >>> 16))) { - iter.advanceIfNeeded(BufferUtil.lowbits(minval)); - if (!iter.hasNext()) { - ++pos; - nextContainer(); - } - } - } - - @Override - public int peekNext() { - return BufferUtil.toIntUnsigned(iter.peekNext()) | hs; - } - - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferReverseIntIteratorFlyweight.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferReverseIntIteratorFlyweight.java deleted file mode 100644 index 677aba388..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferReverseIntIteratorFlyweight.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.IntIterator; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; - -/** - * Fast iterator minimizing the stress on the garbage collector. You can create one reusable - * instance of this class and then {@link #wrap(ImmutableRoaringBitmap)} - *

- * This iterator enumerates the stored values in reverse (starting from the end). - * - * @author Borislav Ivanov - **/ -public class BufferReverseIntIteratorFlyweight implements IntIterator { - - private int hs; - - private ShortIterator iter; - - private ReverseMappeableArrayContainerShortIterator arrIter = - new ReverseMappeableArrayContainerShortIterator(); - - private ReverseMappeableBitmapContainerShortIterator bitmapIter = - new ReverseMappeableBitmapContainerShortIterator(); - - private ReverseMappeableRunContainerShortIterator runIter = - new ReverseMappeableRunContainerShortIterator(); - - private short pos; - - private ImmutableRoaringBitmap roaringBitmap = null; - - - /** - * Creates an instance that is not ready for iteration. You must first call - * {@link #wrap(ImmutableRoaringBitmap)}. - */ - public BufferReverseIntIteratorFlyweight() { - - } - - /** - * Creates an instance that is ready for iteration. - * - * @param r bitmap to be iterated over - */ - public BufferReverseIntIteratorFlyweight(ImmutableRoaringBitmap r) { - wrap(r); - } - - @Override - public IntIterator clone() { - try { - BufferReverseIntIteratorFlyweight x = (BufferReverseIntIteratorFlyweight) super.clone(); - x.iter = this.iter.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - - @Override - public int next() { - final int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - --pos; - nextContainer(); - } - return x; - } - - private void nextContainer() { - - if (pos >= 0) { - - MappeableContainer container = this.roaringBitmap.highLowContainer.getContainerAtIndex(pos); - - if (container instanceof MappeableBitmapContainer) { - bitmapIter.wrap((MappeableBitmapContainer) container); - iter = bitmapIter; - } else if (container instanceof MappeableRunContainer) { - runIter.wrap((MappeableRunContainer) container); - iter = runIter; - } else { - arrIter.wrap((MappeableArrayContainer) container); - iter = arrIter; - } - - hs = BufferUtil.toIntUnsigned(this.roaringBitmap.highLowContainer.getKeyAtIndex(pos)) << 16; - } - } - - /** - * Prepares a bitmap for iteration - * - * @param r bitmap to be iterated over - */ - public void wrap(ImmutableRoaringBitmap r) { - this.roaringBitmap = r; - this.hs = 0; - this.pos = (short) (this.roaringBitmap.highLowContainer.size() - 1); - this.nextContainer(); - } - -} - diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferUtil.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferUtil.java deleted file mode 100644 index 7fd96590a..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/BufferUtil.java +++ /dev/null @@ -1,825 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.nio.Buffer; -import java.nio.LongBuffer; -import java.nio.ShortBuffer; - -/** - * Various useful methods for roaring bitmaps. - *

- * This class is similar to Util but meant to be used with memory mapping. - */ -public final class BufferUtil { - - - /** - * Private constructor to prevent instantiation of utility class - */ - private BufferUtil() { - } - - /** - * Find the smallest integer larger than pos such that array[pos]>= min. If none can be found, - * return length. Based on code by O. Kaser. - * - * @param array container where we search - * @param pos initial position - * @param min minimal threshold - * @param length how big should the array consider to be - * @return x greater than pos such that array[pos] is at least as large as min, pos is is equal to - * length if it is not possible. - */ - protected static int advanceUntil(ShortBuffer array, int pos, int length, short min) { - int lower = pos + 1; - - // special handling for a possibly common sequential case - if (lower >= length || toIntUnsigned(array.get(lower)) >= toIntUnsigned(min)) { - return lower; - } - - int spansize = 1; // could set larger - // bootstrap an upper limit - - while (lower + spansize < length - && toIntUnsigned(array.get(lower + spansize)) < toIntUnsigned(min)) { - spansize *= 2; // hoping for compiler will reduce to - } - // shift - int upper = (lower + spansize < length) ? lower + spansize : length - 1; - - // maybe we are lucky (could be common case when the seek ahead - // expected - // to be small and sequential will otherwise make us look bad) - if (array.get(upper) == min) { - return upper; - } - - if (toIntUnsigned(array.get(upper)) < toIntUnsigned(min)) {// means - // array - // has no - // item - // >= min - // pos = array.length; - return length; - } - - // we know that the next-smallest span was too small - lower += (spansize / 2); - - // else begin binary search - // invariant: array[lower]min - while (lower + 1 != upper) { - int mid = (lower + upper) / 2; - short arraymid = array.get(mid); - if (arraymid == min) { - return mid; - } else if (toIntUnsigned(arraymid) < toIntUnsigned(min)) { - lower = mid; - } else { - upper = mid; - } - } - return upper; - - } - - protected static void arraycopy(ShortBuffer src, int srcPos, ShortBuffer dest, int destPos, - int length) { - if (BufferUtil.isBackedBySimpleArray(src) && BufferUtil.isBackedBySimpleArray(dest)) { - System.arraycopy(src.array(), srcPos, dest.array(), destPos, length); - } else { - if (srcPos < destPos) { - for (int k = length - 1; k >= 0; --k) { - dest.put(destPos + k, src.get(k + srcPos)); - } - } else { - for (int k = 0; k < length; ++k) { - dest.put(destPos + k, src.get(k + srcPos)); - } - } - } - } - - protected static int branchyUnsignedBinarySearch(final ShortBuffer array, final int begin, - final int end, final short k) { - final int ikey = toIntUnsigned(k); - // next line accelerates the possibly common case where the value would be inserted at the end - if ((end > 0) && (toIntUnsigned(array.get(end - 1)) < ikey)) { - return -end - 1; - } - int low = begin; - int high = end - 1; - while (low <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = toIntUnsigned(array.get(middleIndex)); - - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - return -(low + 1); - } - - /** - * Compares the two specified {@code short} values, treating them as unsigned values between - * {@code 0} and {@code 2^16 - 1} inclusive. - * - * @param a the first unsigned {@code short} to compare - * @param b the second unsigned {@code short} to compare - * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is - * greater than {@code b}; or zero if they are equal - */ - public static int compareUnsigned(short a, short b) { - return toIntUnsigned(a) - toIntUnsigned(b); - } - - protected static void fillArrayAND(short[] container, LongBuffer bitmap1, LongBuffer bitmap2) { - int pos = 0; - if (bitmap1.limit() != bitmap2.limit()) { - throw new IllegalArgumentException("not supported"); - } - if (BufferUtil.isBackedBySimpleArray(bitmap1) && BufferUtil.isBackedBySimpleArray(bitmap2)) { - int len = bitmap1.limit(); - long[] b1 = bitmap1.array(); - long[] b2 = bitmap2.array(); - for (int k = 0; k < len; ++k) { - long bitset = b1[k] & b2[k]; - while (bitset != 0) { - final long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } else { - int len = bitmap1.limit(); - for (int k = 0; k < len; ++k) { - long bitset = bitmap1.get(k) & bitmap2.get(k); - while (bitset != 0) { - final long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } - } - - protected static void fillArrayANDNOT(short[] container, LongBuffer bitmap1, LongBuffer bitmap2) { - int pos = 0; - if (bitmap1.limit() != bitmap2.limit()) { - throw new IllegalArgumentException("not supported"); - } - if (BufferUtil.isBackedBySimpleArray(bitmap1) && BufferUtil.isBackedBySimpleArray(bitmap2)) { - int len = bitmap1.limit(); - long[] b1 = bitmap1.array(); - long[] b2 = bitmap2.array(); - for (int k = 0; k < len; ++k) { - long bitset = b1[k] & (~b2[k]); - while (bitset != 0) { - final long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } else { - int len = bitmap1.limit(); - for (int k = 0; k < len; ++k) { - long bitset = bitmap1.get(k) & (~bitmap2.get(k)); - while (bitset != 0) { - final long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } - } - - protected static void fillArrayXOR(short[] container, LongBuffer bitmap1, LongBuffer bitmap2) { - int pos = 0; - if (bitmap1.limit() != bitmap2.limit()) { - throw new IllegalArgumentException("not supported"); - } - if (BufferUtil.isBackedBySimpleArray(bitmap1) && BufferUtil.isBackedBySimpleArray(bitmap2)) { - Util.fillArrayXOR(container, bitmap1.array(), bitmap2.array()); - } else { - int len = bitmap1.limit(); - for (int k = 0; k < len; ++k) { - long bitset = bitmap1.get(k) ^ bitmap2.get(k); - while (bitset != 0) { - final long t = bitset & -bitset; - container[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - bitset ^= t; - } - } - } - } - - /** - * flip bits at start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - public static void flipBitmapRange(LongBuffer bitmap, int start, int end) { - if (isBackedBySimpleArray(bitmap)) { - Util.flipBitmapRange(bitmap.array(), start, end); - return; - } - if (start == end) { - return; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - bitmap.put(firstword, bitmap.get(firstword) ^ ~(~0L << start)); - for (int i = firstword; i < endword; i++) { - bitmap.put(i, ~bitmap.get(i)); - } - bitmap.put(endword, bitmap.get(endword) ^ (~0L >>> -end)); - } - - /** - * Hamming weight of the 64-bit words involved in the range start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - private static int cardinalityInBitmapWordRange(LongBuffer bitmap, int start, int end) { - if (isBackedBySimpleArray(bitmap)) { - return Util.cardinalityInBitmapWordRange(bitmap.array(), start, end); - } - if (start == end) { - return 0; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - int answer = 0; - for (int i = firstword; i <= endword; i++) { - answer += Long.bitCount(bitmap.get(i)); - } - return answer; - } - - /** - * set bits at start, start+1,..., end-1 and report the cardinality change - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return cardinality change - */ - public static int setBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end) { - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - return Util.setBitmapRangeAndCardinalityChange(bitmap.array(), start, end); - } - int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end); - setBitmapRange(bitmap, start, end); - int cardafter = cardinalityInBitmapWordRange(bitmap, start, end); - return cardafter - cardbefore; - } - - /** - * flip bits at start, start+1,..., end-1 and report the cardinality change - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return cardinality change - */ - public static int flipBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end) { - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - return Util.flipBitmapRangeAndCardinalityChange(bitmap.array(), start, end); - } - int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end); - flipBitmapRange(bitmap, start, end); - int cardafter = cardinalityInBitmapWordRange(bitmap, start, end); - return cardafter - cardbefore; - } - - /** - * reset bits at start, start+1,..., end-1 and report the cardinality change - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - * @return cardinality change - */ - public static int resetBitmapRangeAndCardinalityChange(LongBuffer bitmap, int start, int end) { - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - return Util.resetBitmapRangeAndCardinalityChange(bitmap.array(), start, end); - } - int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end); - resetBitmapRange(bitmap, start, end); - int cardafter = cardinalityInBitmapWordRange(bitmap, start, end); - return cardafter - cardbefore; - } - - /** - * From the cardinality of a container, compute the corresponding size in bytes of the container. - * Additional information is required if the container is run encoded. - * - * @param card the cardinality if this is not run encoded, otherwise ignored - * @param numRuns number of runs if run encoded, othewise ignored - * @param isRunEncoded boolean - * @return the size in bytes - */ - protected static int getSizeInBytesFromCardinalityEtc(int card, int numRuns, - boolean isRunEncoded) { - if (isRunEncoded) { - return 2 + numRuns * 2 * 2; // each run uses 2 shorts, plus the initial short giving num runs - } - boolean isBitmap = card > MappeableArrayContainer.DEFAULT_MAX_SIZE; - if (isBitmap) { - return MappeableBitmapContainer.MAX_CAPACITY / 8; - } else { - return card * 2; - } - - } - - protected static short highbits(int x) { - return (short) (x >>> 16); - } - - protected static short highbits(long x) { - return (short) (x >>> 16); - } - - /** - * Checks whether the Buffer is backed by a simple array. In java, a Buffer is an abstraction that - * can represent various data, from data on disk all the way to native Java arrays. Like all - * abstractions, a Buffer might carry a performance penalty. Thus, we sometimes check whether the - * Buffer is simply a wrapper around a Java array. In these instances, it might be best, from a - * performance point of view, to access the underlying array (using the array()) method. - * - * @param b the provided Buffer - * @return whether the Buffer is backed by a simple array - */ - protected static boolean isBackedBySimpleArray(Buffer b) { - return b.hasArray() && (b.arrayOffset() == 0); - } - - protected static short lowbits(int x) { - return (short) (x & 0xFFFF); - } - - protected static short lowbits(long x) { - return (short) (x & 0xFFFF); - } - - protected static short maxLowBit() { - return (short) 0xFFFF; - } - - protected static int maxLowBitAsInteger() { - return 0xFFFF; - } - - /** - * clear bits at start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - public static void resetBitmapRange(LongBuffer bitmap, int start, int end) { - if (isBackedBySimpleArray(bitmap)) { - Util.resetBitmapRange(bitmap.array(), start, end); - return; - } - if (start == end) { - return; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - if (firstword == endword) { - bitmap.put(firstword, bitmap.get(firstword) & ~((~0L << start) & (~0L >>> -end))); - return; - } - bitmap.put(firstword, bitmap.get(firstword) & (~(~0L << start))); - for (int i = firstword + 1; i < endword; i++) { - bitmap.put(i, 0L); - } - bitmap.put(endword, bitmap.get(endword) & (~(~0L >>> -end))); - } - - /** - * set bits at start, start+1,..., end-1 - * - * @param bitmap array of words to be modified - * @param start first index to be modified (inclusive) - * @param end last index to be modified (exclusive) - */ - public static void setBitmapRange(LongBuffer bitmap, int start, int end) { - if (isBackedBySimpleArray(bitmap)) { - Util.setBitmapRange(bitmap.array(), start, end); - return; - } - if (start == end) { - return; - } - int firstword = start / 64; - int endword = (end - 1) / 64; - if (firstword == endword) { - bitmap.put(firstword, bitmap.get(firstword) | ((~0L << start) & (~0L >>> -end))); - - return; - } - bitmap.put(firstword, bitmap.get(firstword) | (~0L << start)); - for (int i = firstword + 1; i < endword; i++) { - bitmap.put(i, ~0L); - } - bitmap.put(endword, bitmap.get(endword) | (~0L >>> -end)); - } - - protected static int toIntUnsigned(short x) { - return x & 0xFFFF; - } - - /** - * Look for value k in buffer in the range [begin,end). If the value is found, return its index. - * If not, return -(i+1) where i is the index where the value would be inserted. The buffer is - * assumed to contain sorted values where shorts are interpreted as unsigned integers. - * - * @param array buffer where we search - * @param begin first index (inclusive) - * @param end last index (exclusive) - * @param k value we search for - * @return count - */ - public static int unsignedBinarySearch(final ShortBuffer array, final int begin, final int end, - final short k) { - return branchyUnsignedBinarySearch(array, begin, end, k); - } - - protected static int unsignedDifference(final ShortBuffer set1, final int length1, - final ShortBuffer set2, final int length2, final short[] buffer) { - int pos = 0; - int k1 = 0, k2 = 0; - if (0 == length2) { - set1.get(buffer, 0, length1); - return length1; - } - if (0 == length1) { - return 0; - } - short s1 = set1.get(k1); - short s2 = set2.get(k2); - while (true) { - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - buffer[pos++] = s1; - ++k1; - if (k1 >= length1) { - break; - } - s1 = set1.get(k1); - } else if (toIntUnsigned(s1) == toIntUnsigned(s2)) { - ++k1; - ++k2; - if (k1 >= length1) { - break; - } - if (k2 >= length2) { - set1.position(k1); - set1.get(buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s1 = set1.get(k1); - s2 = set2.get(k2); - } else {// if (val1>val2) - ++k2; - if (k2 >= length2) { - set1.position(k1); - set1.get(buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s2 = set2.get(k2); - } - } - return pos; - } - - protected static int unsignedExclusiveUnion2by2(final ShortBuffer set1, final int length1, - final ShortBuffer set2, final int length2, final short[] buffer) { - int pos = 0; - int k1 = 0, k2 = 0; - if (0 == length2) { - set1.get(buffer, 0, length1); - return length1; - } - if (0 == length1) { - set2.get(buffer, 0, length2); - return length2; - } - short s1 = set1.get(k1); - short s2 = set2.get(k2); - while (true) { - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - buffer[pos++] = s1; - ++k1; - if (k1 >= length1) { - set2.position(k2); - set2.get(buffer, pos, length2 - k2); - return pos + length2 - k2; - } - s1 = set1.get(k1); - } else if (toIntUnsigned(s1) == toIntUnsigned(s2)) { - ++k1; - ++k2; - if (k1 >= length1) { - set2.position(k2); - set2.get(buffer, pos, length2 - k2); - return pos + length2 - k2; - } - if (k2 >= length2) { - set1.position(k1); - set1.get(buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s1 = set1.get(k1); - s2 = set2.get(k2); - } else {// if (val1>val2) - buffer[pos++] = s2; - ++k2; - if (k2 >= length2) { - set1.position(k1); - set1.get(buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s2 = set2.get(k2); - } - } - // return pos; - } - - protected static int unsignedIntersect2by2(final ShortBuffer set1, final int length1, - final ShortBuffer set2, final int length2, final short[] buffer) { - if (length1 * 64 < length2) { - return unsignedOneSidedGallopingIntersect2by2(set1, length1, set2, length2, buffer); - } else if (length2 * 64 < length1) { - return unsignedOneSidedGallopingIntersect2by2(set2, length2, set1, length1, buffer); - } else { - return unsignedLocalIntersect2by2(set1, length1, set2, length2, buffer); - } - } - - /** - * Checks if two arrays intersect - * - * @param set1 first array - * @param length1 length of first array - * @param set2 second array - * @param length2 length of second array - * @return true if they intersect - */ - public static boolean unsignedIntersects(ShortBuffer set1, int length1, ShortBuffer set2, - int length2) { - if ((0 == length1) || (0 == length2)) { - return false; - } - int k1 = 0; - int k2 = 0; - - // could be more efficient with galloping - short s1 = set1.get(k1); - short s2 = set2.get(k2); - - mainwhile: - while (true) { - if (toIntUnsigned(s2) < toIntUnsigned(s1)) { - do { - ++k2; - if (k2 == length2) { - break mainwhile; - } - s2 = set2.get(k2); - } while (toIntUnsigned(s2) < toIntUnsigned(s1)); - } - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - do { - ++k1; - if (k1 == length1) { - break mainwhile; - } - s1 = set1.get(k1); - } while (toIntUnsigned(s1) < toIntUnsigned(s2)); - } else { - return true; - } - } - return false; - } - - protected static int unsignedLocalIntersect2by2(final ShortBuffer set1, final int length1, - final ShortBuffer set2, final int length2, final short[] buffer) { - if ((0 == length1) || (0 == length2)) { - return 0; - } - int k1 = 0; - int k2 = 0; - int pos = 0; - short s1 = set1.get(k1); - short s2 = set2.get(k2); - - mainwhile: - while (true) { - if (toIntUnsigned(s2) < toIntUnsigned(s1)) { - do { - ++k2; - if (k2 == length2) { - break mainwhile; - } - s2 = set2.get(k2); - - } while (toIntUnsigned(s2) < toIntUnsigned(s1)); - } - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - do { - ++k1; - if (k1 == length1) { - break mainwhile; - } - s1 = set1.get(k1); - - } while (toIntUnsigned(s1) < toIntUnsigned(s2)); - } else { - // (set2.get(k2) == set1.get(k1)) - buffer[pos++] = s1; - ++k1; - if (k1 == length1) { - break; - } - s1 = set1.get(k1); - ++k2; - if (k2 == length2) { - break; - } - s2 = set2.get(k2); - - } - } - return pos; - } - - protected static int unsignedLocalIntersect2by2Cardinality(final ShortBuffer set1, - final int length1, final ShortBuffer set2, final int length2) { - if ((0 == length1) || (0 == length2)) { - return 0; - } - int k1 = 0; - int k2 = 0; - int pos = 0; - short s1 = set1.get(k1); - short s2 = set2.get(k2); - - mainwhile: - while (true) { - if (toIntUnsigned(s2) < toIntUnsigned(s1)) { - do { - ++k2; - if (k2 == length2) { - break mainwhile; - } - s2 = set2.get(k2); - - } while (toIntUnsigned(s2) < toIntUnsigned(s1)); - } - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - do { - ++k1; - if (k1 == length1) { - break mainwhile; - } - s1 = set1.get(k1); - - } while (toIntUnsigned(s1) < toIntUnsigned(s2)); - } else { - ++pos; - ++k1; - if (k1 == length1) { - break; - } - s1 = set1.get(k1); - ++k2; - if (k2 == length2) { - break; - } - s2 = set2.get(k2); - - } - } - return pos; - } - - protected static int unsignedOneSidedGallopingIntersect2by2(final ShortBuffer smallSet, - final int smallLength, final ShortBuffer largeSet, final int largeLength, - final short[] buffer) { - if (0 == smallLength) { - return 0; - } - int k1 = 0; - int k2 = 0; - int pos = 0; - - short s1 = largeSet.get(k1); - short s2 = smallSet.get(k2); - while (true) { - if (toIntUnsigned(s1) < toIntUnsigned(s2)) { - k1 = advanceUntil(largeSet, k1, largeLength, s2); - if (k1 == largeLength) { - break; - } - s1 = largeSet.get(k1); - } - if (toIntUnsigned(s2) < toIntUnsigned(s1)) { - ++k2; - if (k2 == smallLength) { - break; - } - s2 = smallSet.get(k2); - } else { - // (set2.get(k2) == set1.get(k1)) - buffer[pos++] = s2; - ++k2; - if (k2 == smallLength) { - break; - } - s2 = smallSet.get(k2); - k1 = advanceUntil(largeSet, k1, largeLength, s2); - if (k1 == largeLength) { - break; - } - s1 = largeSet.get(k1); - } - - } - return pos; - - } - - protected static int unsignedUnion2by2(final ShortBuffer set1, final int length1, - final ShortBuffer set2, final int length2, final short[] buffer) { - int pos = 0; - int k1 = 0, k2 = 0; - if (0 == length2) { - set1.get(buffer, 0, length1); - return length1; - } - if (0 == length1) { - set2.get(buffer, 0, length2); - return length2; - } - short s1 = set1.get(k1); - short s2 = set2.get(k2); - while (true) { - int v1 = toIntUnsigned(s1); - int v2 = toIntUnsigned(s2); - if (v1 < v2) { - buffer[pos++] = s1; - ++k1; - if (k1 >= length1) { - set2.position(k2); - set2.get(buffer, pos, length2 - k2); - return pos + length2 - k2; - } - s1 = set1.get(k1); - } else if (v1 == v2) { - buffer[pos++] = s1; - ++k1; - ++k2; - if (k1 >= length1) { - set2.position(k2); - set2.get(buffer, pos, length2 - k2); - return pos + length2 - k2; - } - if (k2 >= length2) { - set1.position(k1); - set1.get(buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s1 = set1.get(k1); - s2 = set2.get(k2); - } else {// if (set1.get(k1)>set2.get(k2)) - buffer[pos++] = s2; - ++k2; - if (k2 >= length2) { - set1.position(k1); - set1.get(buffer, pos, length1 - k1); - return pos + length1 - k1; - } - s2 = set2.get(k2); - } - } - // return pos; - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/ImmutableRoaringArray.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/ImmutableRoaringArray.java deleted file mode 100644 index 6cf43dee3..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/ImmutableRoaringArray.java +++ /dev/null @@ -1,463 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import java.io.DataOutput; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.LongBuffer; -import java.nio.ShortBuffer; -import java.nio.channels.Channels; -import java.nio.channels.WritableByteChannel; - - -/** - * This is the underlying data structure for an ImmutableRoaringBitmap. This class is not meant for - * end-users. - */ -public final class ImmutableRoaringArray implements PointableRoaringArray { - - protected static final short SERIAL_COOKIE = MutableRoaringArray.SERIAL_COOKIE; - protected static final short SERIAL_COOKIE_NO_RUNCONTAINER = - MutableRoaringArray.SERIAL_COOKIE_NO_RUNCONTAINER; - private final static int startofrunbitmap = 4; // if there is a runcontainer bitmap - - ByteBuffer buffer; - int size; - - /** - * Create an array based on a previously serialized ByteBuffer. The input ByteBuffer is - * effectively copied (with the slice operation) so you should expect the provided ByteBuffer to - * remain unchanged. - * - * @param bbf The source ByteBuffer - */ - protected ImmutableRoaringArray(ByteBuffer bbf) { - buffer = bbf.slice(); - buffer.order(ByteOrder.LITTLE_ENDIAN); - final int cookie = buffer.getInt(0); - if ((cookie & 0xFFFF) != SERIAL_COOKIE && cookie != SERIAL_COOKIE_NO_RUNCONTAINER) { - throw new RuntimeException("I failed to find one of the right cookies. " + cookie); - } - boolean hasRunContainers = (cookie & 0xFFFF) == SERIAL_COOKIE; - this.size = hasRunContainers ? (cookie >>> 16) + 1 : buffer.getInt(4); - int theLimit = size > 0 ? computeSerializedSizeInBytes() : headerSize(hasRunContainers); - buffer.limit(theLimit); - } - - @Override - public int advanceUntil(short x, int pos) { - int lower = pos + 1; - - // special handling for a possibly common sequential case - if (lower >= size || getKey(lower) >= BufferUtil.toIntUnsigned(x)) { - return lower; - } - - int spansize = 1; // could set larger - // bootstrap an upper limit - - while (lower + spansize < size && getKey(lower + spansize) < BufferUtil.toIntUnsigned(x)) { - spansize *= 2; // hoping for compiler will reduce to shift - } - int upper = (lower + spansize < size) ? lower + spansize : size - 1; - - // maybe we are lucky (could be common case when the seek ahead - // expected to be small and sequential will otherwise make us look bad) - if (getKey(upper) == BufferUtil.toIntUnsigned(x)) { - return upper; - } - - if (getKey(upper) < BufferUtil.toIntUnsigned(x)) {// means array has no item key >= x - return size; - } - - // we know that the next-smallest span was too small - lower += (spansize / 2); - - // else begin binary search - // invariant: array[lower]x - while (lower + 1 != upper) { - int mid = (lower + upper) / 2; - if (getKey(mid) == BufferUtil.toIntUnsigned(x)) { - return mid; - } else if (getKey(mid) < BufferUtil.toIntUnsigned(x)) { - lower = mid; - } else { - upper = mid; - } - } - return upper; - } - - private int branchyUnsignedBinarySearch(final short k) { - int low = 0; - int high = this.size - 1; - final int ikey = BufferUtil.toIntUnsigned(k); - while (low <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = getKey(middleIndex); - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - return -(low + 1); - } - - - @Override - public ImmutableRoaringArray clone() { - ImmutableRoaringArray sa; - try { - sa = (ImmutableRoaringArray) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// should never happen - } - return sa; - } - - - private int computeSerializedSizeInBytes() { - if (this.size == 0) { - return headerSize(hasRunCompression()); - } - int CardinalityOfLastContainer = getCardinality(this.size - 1); - int PositionOfLastContainer = getOffsetContainer(this.size - 1); - int SizeOfLastContainer; - boolean hasrun = hasRunCompression(); - if (isRunContainer(this.size - 1, hasrun)) { - int nbrruns = BufferUtil.toIntUnsigned(buffer.getShort(PositionOfLastContainer)); - SizeOfLastContainer = BufferUtil.getSizeInBytesFromCardinalityEtc(0, nbrruns, true); - } else { - SizeOfLastContainer = - BufferUtil.getSizeInBytesFromCardinalityEtc(CardinalityOfLastContainer, 0, false); - } - return SizeOfLastContainer + PositionOfLastContainer; - } - - @Override - public int getCardinality(int k) { - if ((k < 0) || (k >= this.size)) { - throw new IllegalArgumentException( - "out of range container index: " + k + " (report as a bug)"); - } - return BufferUtil.toIntUnsigned(buffer.getShort(this.getStartOfKeys() + 4 * k + 2)) + 1; - } - - - // involves a binary search - @Override - public MappeableContainer getContainer(short x) { - final int i = unsignedBinarySearch(x); - if (i < 0) { - return null; - } - return getContainerAtIndex(i); - } - - @Override - public MappeableContainer getContainerAtIndex(int i) { - int cardinality = getCardinality(i); - final boolean isBitmap = cardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE; // if not a - // runcontainer - ByteBuffer tmp = buffer.duplicate();// sad but ByteBuffer is not thread-safe so it is either a - // duplicate or a lock - // note that tmp will indeed be garbage-collected some time after the end of this function - tmp.order(buffer.order()); - tmp.position(getOffsetContainer(i)); - boolean hasrun = hasRunCompression(); - if (isRunContainer(i, hasrun)) { - // first, we have a short giving the number of runs - int nbrruns = BufferUtil.toIntUnsigned(tmp.getShort()); - final ShortBuffer shortArray = tmp.asShortBuffer(); - shortArray.limit(2 * nbrruns); - return new MappeableRunContainer(shortArray, nbrruns); - } - if (isBitmap) { - final LongBuffer bitmapArray = tmp.asLongBuffer(); - bitmapArray.limit(MappeableBitmapContainer.MAX_CAPACITY / 64); - return new MappeableBitmapContainer(bitmapArray, cardinality); - } else { - final ShortBuffer shortArray = tmp.asShortBuffer(); - shortArray.limit(cardinality); - return new MappeableArrayContainer(shortArray, cardinality); - } - } - - - @Override - public MappeableContainerPointer getContainerPointer() { - return getContainerPointer(0); - } - - @Override - public MappeableContainerPointer getContainerPointer(final int startIndex) { - final boolean hasrun = isEmpty() ? false : hasRunCompression(); - return new MappeableContainerPointer() { - int k = startIndex; - - @Override - public void advance() { - ++k; - } - - - @Override - public MappeableContainerPointer clone() { - try { - return (MappeableContainerPointer) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public int compareTo(MappeableContainerPointer o) { - if (key() != o.key()) { - return BufferUtil.toIntUnsigned(key()) - BufferUtil.toIntUnsigned(o.key()); - } - return o.getCardinality() - this.getCardinality(); - } - - @Override - public int getCardinality() { - return ImmutableRoaringArray.this.getCardinality(k); - } - - @Override - public MappeableContainer getContainer() { - if (k >= ImmutableRoaringArray.this.size) { - return null; - } - return ImmutableRoaringArray.this.getContainerAtIndex(k); - } - - - @Override - public int getSizeInBytes() { - // might be a tad expensive - if (ImmutableRoaringArray.this.isRunContainer(k, hasrun)) { - int pos = getOffsetContainer(k); - int nbrruns = BufferUtil.toIntUnsigned(buffer.getShort(pos)); - return BufferUtil.getSizeInBytesFromCardinalityEtc(0, nbrruns, true); - } else { - int CardinalityOfLastContainer = getCardinality(); - return BufferUtil.getSizeInBytesFromCardinalityEtc(CardinalityOfLastContainer, 0, false); - } - } - - @Override - public boolean hasContainer() { - return 0 <= k & k < ImmutableRoaringArray.this.size; - } - - @Override - public boolean isBitmapContainer() { - if (ImmutableRoaringArray.this.isRunContainer(k, hasrun)) { - return false; - } - return getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE; - } - - @Override - public boolean isRunContainer() { - return ImmutableRoaringArray.this.isRunContainer(k, hasrun); - } - - @Override - public short key() { - return ImmutableRoaringArray.this.getKeyAtIndex(k); - - } - - - @Override - public void previous() { - --k; - } - }; - } - - // involves a binary search - @Override - public int getIndex(short x) { - return unsignedBinarySearch(x); - } - - private int getKey(int k) { - return BufferUtil.toIntUnsigned(buffer.getShort(getStartOfKeys() + 4 * k)); - } - - @Override - public short getKeyAtIndex(int i) { - return buffer.getShort(4 * i + getStartOfKeys()); - } - - private int getOffsetContainer(int k) { - if ((k < 0) || (k >= this.size)) { - throw new IllegalArgumentException( - "out of range container index: " + k + " (report as a bug)"); - } - if (hasRunCompression()) { // account for size of runcontainer bitmap - if (this.size < MutableRoaringArray.NO_OFFSET_THRESHOLD) { - // we do it the hard way - return getOffsetContainerSlow(k); - } - return buffer.getInt(4 + 4 * this.size + ((this.size + 7) / 8) + 4 * k); - } else { - return buffer.getInt(4 + 4 + 4 * this.size + 4 * k); - } - } - - - private int getOffsetContainerSlow(int k) { - boolean hasrun = hasRunCompression(); - int pos = this.headerSize(hasrun); - for (int z = 0; z < k; ++z) { - if (isRunContainer(z, hasrun)) { - int nbrruns = BufferUtil.toIntUnsigned(buffer.getShort(pos)); - int SizeOfLastContainer = BufferUtil.getSizeInBytesFromCardinalityEtc(0, nbrruns, true); - pos += SizeOfLastContainer; - } else { - int CardinalityOfLastContainer = this.getCardinality(z); - int SizeOfLastContainer = - BufferUtil.getSizeInBytesFromCardinalityEtc(CardinalityOfLastContainer, 0, false); - pos += SizeOfLastContainer; - } - } - return pos; - } - - private int getStartOfKeys() { - if (hasRunCompression()) { // info is in the buffer - return 4 + ((this.size + 7) / 8); - } else { - return 8; - } - } - - @Override - public int hashCode() { - MappeableContainerPointer cp = this.getContainerPointer(); - int hashvalue = 0; - while (cp.hasContainer()) { - int th = cp.key() * 0xF0F0F0 + cp.getContainer().hashCode(); - hashvalue = 31 * hashvalue + th; - cp.advance(); - } - return hashvalue; - } - - @Override - public boolean hasRunCompression() { - return (buffer.getInt(0) & 0xFFFF) == SERIAL_COOKIE; - } - - // hasrun should be equal to hasRunCompression() - protected int headerSize(boolean hasrun) { - if (hasrun) { - if (size < MutableRoaringArray.NO_OFFSET_THRESHOLD) {// for small bitmaps, we omit the offsets - return 4 + (size + 7) / 8 + 4 * size; - } - return 4 + (size + 7) / 8 + 8 * size;// - 4 because we pack the size with the cookie - } else { - return 4 + 4 + 8 * size; - } - } - - // starts with binary search and finishes with a sequential search - /*private int hybridUnsignedBinarySearch(final short k) { - int low = 0; - int high = this.size - 1; - final int ikey = BufferUtil.toIntUnsigned(k); - // 32 in the next line matches the size of a cache line - while (low + 16 <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = getKey(middleIndex); - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - // we finish the job with a sequential search - int x = low; - for (; x <= high; ++x) { - final int val = getKey(x); - if (val >= ikey) { - if (val == ikey) { - return x; - } - break; - } - } - return -(x + 1); - }*/ - - /** - * Returns true if this bitmap is empty. - * - * @return true if empty - */ - public boolean isEmpty() { - return this.size == 0; - } - - // hasrun should be initialized with hasRunCompression() - private boolean isRunContainer(int i, boolean hasrun) { - if (hasrun) { // info is in the buffer - int j = buffer.get(startofrunbitmap + i / 8); - int mask = 1 << (i % 8); - return (j & mask) != 0; - } else { - return false; - } - } - - /** - * Serialize. - *

- * The current bitmap is not modified. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - @Override - public void serialize(DataOutput out) throws IOException { - if (buffer.hasArray()) { - out.write(buffer.array(), buffer.arrayOffset(), buffer.limit()); - } else { - ByteBuffer tmp = buffer.duplicate(); - tmp.position(0); - WritableByteChannel channel = Channels.newChannel((OutputStream) out); - channel.write(tmp); - } - } - - /** - * @return the size that the data structure occupies on disk - */ - @Override - public int serializedSizeInBytes() { - return buffer.limit(); - } - - @Override - public int size() { - return this.size; - } - - private int unsignedBinarySearch(short k) { - return branchyUnsignedBinarySearch(k); - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/ImmutableRoaringBitmap.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/ImmutableRoaringBitmap.java deleted file mode 100644 index d631a142d..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/ImmutableRoaringBitmap.java +++ /dev/null @@ -1,1320 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.ImmutableBitmapDataProvider; -import com.fr.third.bitmap.roaringbitmap.IntConsumer; -import com.fr.third.bitmap.roaringbitmap.IntIterator; -import com.fr.third.bitmap.roaringbitmap.PeekableIntIterator; -import com.fr.third.bitmap.roaringbitmap.PeekableShortIterator; -import com.fr.third.bitmap.roaringbitmap.RoaringBitmap; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.io.DataOutput; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Iterator; - -/** - * ImmutableRoaringBitmap provides a compressed immutable (cannot be modified) bitmap. It is meant - * to be used with MutableRoaringBitmap, a derived class that adds methods - * to modify the bitmap. - *

- *

- * {@code
- *       import com.fr.swift.bitmap.roaringbitmap.buffer.*;
- *
- *       //...
- *
- *       MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(1, 2, 3, 1000);
- *       MutableRoaringBitmap rr2 = MutableRoaringBitmap.bitmapOf( 2, 3, 1010);
- *       ByteArrayOutputStream bos = new ByteArrayOutputStream();
- *       DataOutputStream dos = new DataOutputStream(bos);
- *       // could call "rr1.runOptimize()" and "rr2.runOptimize" if there
- *       // there were runs to compress
- *       rr1.serialize(dos);
- *       rr2.serialize(dos);
- *       dos.close();
- *       ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
- *       ImmutableRoaringBitmap rrback1 = new ImmutableRoaringBitmap(bb);
- *       bb.position(bb.position() + rrback1.serializedSizeInBytes());
- *       ImmutableRoaringBitmap rrback2 = new ImmutableRoaringBitmap(bb);
- * }
- * 
- *

- * It can also be constructed from a ByteBuffer (useful for memory mapping). - *

- * Objects of this class may reside almost entirely in memory-map files. - * - * @see MutableRoaringBitmap - */ -public class ImmutableRoaringBitmap - implements Iterable, Cloneable, ImmutableBitmapDataProvider { - - PointableRoaringArray highLowContainer = null; - - - protected ImmutableRoaringBitmap() { - - } - - /** - * Constructs a new ImmutableRoaringBitmap starting at this ByteBuffer's position(). Only - * meta-data is loaded to RAM. The rest is mapped to the ByteBuffer. - *

- * It is not necessary that limit() on the input ByteBuffer indicates the end of the serialized - * data. - *

- * After creating this ImmutableRoaringBitmap, you can advance to the rest of the data (if there - * is more) by setting b.position(b.position() + bitmap.serializedSizeInBytes()); - *

- * Note that the input ByteBuffer is effectively copied (with the slice operation) so you should - * expect the provided ByteBuffer to remain unchanged. - * - * @param b data source - */ - public ImmutableRoaringBitmap(final ByteBuffer b) { - highLowContainer = new ImmutableRoaringArray(b); - } - - /** - * Computes AND between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - */ - public static MutableRoaringBitmap and(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - MutableRoaringBitmap.rangeSanityCheck(rangeStart, rangeEnd); - Iterator bitmapsIterator; - bitmapsIterator = selectRangeWithoutCopy(bitmaps, rangeStart, rangeEnd); - return BufferFastAggregation.and(bitmapsIterator); - } - - /** - * Computes AND between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - * @deprecated use the version where longs specify the range. Negative range end are illegal. - */ - @Deprecated - public static MutableRoaringBitmap and(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final int rangeStart, final int rangeEnd) { - return and(bitmaps, (long) rangeStart, (long) rangeEnd); - } - - /** - * Bitwise AND (intersection) operation. The provided bitmaps are *not* modified. This operation - * is thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - * @see BufferFastAggregation#and(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap and(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - if (s1 == s2) { - final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final MappeableContainer c = c1.and(c2); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().append(s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return answer; - } - - /** - * Cardinality of Bitwise AND (intersection) operation. The provided bitmaps are *not* modified. - * This operation is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return as if you did and(x2,x2).getCardinality() - * @see BufferFastAggregation#and(ImmutableRoaringBitmap...) - */ - public static int andCardinality(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - int answer = 0; - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - if (s1 == s2) { - final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - answer += c1.andCardinality(c2); - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return answer; - } - - /** - * Bitwise ANDNOT (difference) operation for the given range, rangeStart (inclusive) and rangeEnd - * (exclusive). The provided bitmaps are *not* modified. This operation is thread-safe as long as - * the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @param rangeStart beginning of the range (inclusive) - * @param rangeEnd end of range (exclusive) - * @return result of the operation - */ - public static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2, long rangeStart, long rangeEnd) { - MutableRoaringBitmap.rangeSanityCheck(rangeStart, rangeEnd); - MutableRoaringBitmap rb1 = selectRangeWithoutCopy(x1, rangeStart, rangeEnd); - MutableRoaringBitmap rb2 = selectRangeWithoutCopy(x2, rangeStart, rangeEnd); - return andNot(rb1, rb2); - } - - /** - * Bitwise ANDNOT (difference) operation for the given range, rangeStart (inclusive) and rangeEnd - * (exclusive). The provided bitmaps are *not* modified. This operation is thread-safe as long as - * the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @param rangeStart beginning of the range (inclusive) - * @param rangeEnd end of range (exclusive) - * @return result of the operation - * @deprecated use the version where longs specify the range. Negative values for range - * endpoints are not allowed. - */ - @Deprecated - public static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2, - final int rangeStart, final int rangeEnd) { - return andNot(x1, x2, (long) rangeStart, (long) rangeEnd); - } - - /** - * Bitwise ANDNOT (difference) operation. The provided bitmaps are *not* modified. This operation - * is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - */ - public static MutableRoaringBitmap andNot(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final MappeableContainer c = c1.andNot(c2); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().append(s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer, pos1, nextPos1); - pos1 = nextPos1; - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - if (pos2 == length2) { - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer, pos1, length1); - } - return answer; - } - - /** - * Generate a bitmap with the specified values set to true. The provided integers values don't - * have to be in sorted order, but it may be preferable to sort them from a performance point of - * view. - *

- * This function is equivalent to : - *

- *

-     * {@code
-     *       (ImmutableRoaringBitmap) MutableRoaringBitmap.bitmapOf(data)
-     * }
-     * 
- * - * @param data set values - * @return a new bitmap - */ - public static ImmutableRoaringBitmap bitmapOf(final int... data) { - return MutableRoaringBitmap.bitmapOf(data); - } - - /** - * Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The - * given bitmap is unchanged. - * - * @param bm bitmap being negated - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return a new Bitmap - */ - public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, final long rangeStart, - final long rangeEnd) { - MutableRoaringBitmap.rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - throw new RuntimeException("Invalid range " + rangeStart + " -- " + rangeEnd); - } - - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - final short hbStart = BufferUtil.highbits(rangeStart); - final short lbStart = BufferUtil.lowbits(rangeStart); - final short hbLast = BufferUtil.highbits(rangeEnd - 1); - final short lbLast = BufferUtil.lowbits(rangeEnd - 1); - - // copy the containers before the active area - answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, hbStart); - - final int max = BufferUtil.toIntUnsigned(BufferUtil.maxLowBit()); - for (short hb = hbStart; hb <= hbLast; ++hb) { - final int containerStart = (hb == hbStart) ? BufferUtil.toIntUnsigned(lbStart) : 0; - final int containerLast = (hb == hbLast) ? BufferUtil.toIntUnsigned(lbLast) : max; - - final int i = bm.highLowContainer.getIndex(hb); - final int j = answer.getMappeableRoaringArray().getIndex(hb); - assert j < 0; - - if (i >= 0) { - final MappeableContainer c = - bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, c); - } - - } else { // *think* the range of ones must never be - // empty. - answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, hb, - MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); - } - } - // copy the containers after the active area. - answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, hbLast); - - return answer; - } - - /** - * Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The - * given bitmap is unchanged. - * - * @param bm bitmap being negated - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return a new Bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static MutableRoaringBitmap flip(ImmutableRoaringBitmap bm, - final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return flip(bm, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return flip(bm, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * Return new iterator with only values from rangeStart (inclusive) to rangeEnd (exclusive) - * - * @param input bitmaps iterator - * @param rangeStart inclusive - * @param rangeEnd exclusive - * @return new iterator of bitmaps - */ - private static Iterator selectRangeWithoutCopy(final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - Iterator bitmapsIterator; - bitmapsIterator = new Iterator() { - @Override - public boolean hasNext() { - return bitmaps.hasNext(); - } - - @Override - public ImmutableRoaringBitmap next() { - ImmutableRoaringBitmap next = (ImmutableRoaringBitmap) bitmaps.next(); - return selectRangeWithoutCopy(next, rangeStart, rangeEnd); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Remove not supported"); - } - }; - return bitmapsIterator; - } - - /** - * Extracts the values in the specified range, rangeStart (inclusive) and rangeEnd (exclusive) - * while avoiding copies as much as possible. - * - * @param rb input bitmap - * @param rangeStart inclusive - * @param rangeEnd exclusive - * @return new bitmap - */ - - private static MutableRoaringBitmap selectRangeWithoutCopy(ImmutableRoaringBitmap rb, - final long rangeStart, final long rangeEnd) { - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - - if (rangeEnd <= rangeStart) { - return answer; - } - - if (hbStart == hbLast) { - final int i = rb.highLowContainer.getIndex((short) hbStart); - if (i >= 0) { - final MappeableContainer c = rb.highLowContainer.getContainerAtIndex(i).remove(0, lbStart) - .iremove(lbLast + 1, BufferUtil.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) answer.highLowContainer).append((short) hbStart, c); - } - } - return answer; - } - int ifirst = rb.highLowContainer.getIndex((short) hbStart); - int ilast = rb.highLowContainer.getIndex((short) hbLast); - if (ifirst >= 0) { - final MappeableContainer c = - rb.highLowContainer.getContainerAtIndex(ifirst).remove(0, lbStart); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) answer.highLowContainer).append((short) hbStart, c); - } - } - - for (int hb = hbStart + 1; hb <= hbLast - 1; ++hb) { - final int i = rb.highLowContainer.getIndex((short) hb); - final int j = answer.getMappeableRoaringArray().getIndex((short) hb); - assert j < 0; - - if (i >= 0) { - final MappeableContainer c = rb.highLowContainer.getContainerAtIndex(i); - answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, (short) hb, c); - } - } - - if (ilast >= 0) { - final MappeableContainer c = rb.highLowContainer.getContainerAtIndex(ilast).remove(lbLast + 1, - BufferUtil.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) answer.highLowContainer).append((short) hbLast, c); - } - } - return answer; - - } - - /** - * Checks whether the two bitmaps intersect. This can be much faster than calling "and" and - * checking the cardinality of the result. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return true if they intersect - */ - public static boolean intersects(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - if (s1 == s2) { - final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - if (c1.intersects(c2)) { - return true; - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return false; - } - - // important: inputs should not be reused - protected static MutableRoaringBitmap lazyor(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - MappeableContainerPointer i1 = x1.highLowContainer.getContainerPointer(); - MappeableContainerPointer i2 = x2.highLowContainer.getContainerPointer(); - main: - if (i1.hasContainer() && i2.hasContainer()) { - while (true) { - if (i1.key() == i2.key()) { - answer.getMappeableRoaringArray().append(i1.key(), - i1.getContainer().lazyOR(i2.getContainer())); - i1.advance(); - i2.advance(); - if (!i1.hasContainer() || !i2.hasContainer()) { - break main; - } - } else if (Util.compareUnsigned(i1.key(), i2.key()) < 0) { // i1.key() < i2.key() - answer.getMappeableRoaringArray().appendCopy(i1.key(), i1.getContainer()); - i1.advance(); - if (!i1.hasContainer()) { - break main; - } - } else { // i1.key() > i2.key() - answer.getMappeableRoaringArray().appendCopy(i2.key(), i2.getContainer()); - i2.advance(); - if (!i2.hasContainer()) { - break main; - } - } - } - } - if (!i1.hasContainer()) { - while (i2.hasContainer()) { - answer.getMappeableRoaringArray().appendCopy(i2.key(), i2.getContainer()); - i2.advance(); - } - } else if (!i2.hasContainer()) { - while (i1.hasContainer()) { - answer.getMappeableRoaringArray().appendCopy(i1.key(), i1.getContainer()); - i1.advance(); - } - } - return answer; - } - - /** - * Compute overall OR between bitmaps. - *

- * (Effectively calls {@link BufferFastAggregation#or}) - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps) { - return BufferFastAggregation.or(bitmaps); - } - - /** - * Bitwise OR (union) operation. The provided bitmaps are *not* modified. This operation is - * thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - * @see BufferFastAggregation#or(ImmutableRoaringBitmap...) - * @see BufferFastAggregation#horizontal_or(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap or(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - MappeableContainerPointer i1 = x1.highLowContainer.getContainerPointer(); - MappeableContainerPointer i2 = x2.highLowContainer.getContainerPointer(); - main: - if (i1.hasContainer() && i2.hasContainer()) { - while (true) { - if (i1.key() == i2.key()) { - answer.getMappeableRoaringArray().append(i1.key(), - i1.getContainer().or(i2.getContainer())); - i1.advance(); - i2.advance(); - if (!i1.hasContainer() || !i2.hasContainer()) { - break main; - } - } else if (Util.compareUnsigned(i1.key(), i2.key()) < 0) { // i1.key() < i2.key() - answer.getMappeableRoaringArray().appendCopy(i1.key(), i1.getContainer()); - i1.advance(); - if (!i1.hasContainer()) { - break main; - } - } else { // i1.key() > i2.key() - answer.getMappeableRoaringArray().appendCopy(i2.key(), i2.getContainer()); - i2.advance(); - if (!i2.hasContainer()) { - break main; - } - } - } - } - if (!i1.hasContainer()) { - while (i2.hasContainer()) { - answer.getMappeableRoaringArray().appendCopy(i2.key(), i2.getContainer()); - i2.advance(); - } - } else if (!i2.hasContainer()) { - while (i1.hasContainer()) { - answer.getMappeableRoaringArray().appendCopy(i1.key(), i1.getContainer()); - i1.advance(); - } - } - return answer; - } - - /** - * Compute overall OR between bitmaps. - *

- * (Effectively calls {@link BufferFastAggregation#or}) - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap or(@SuppressWarnings("rawtypes") Iterator bitmaps) { - return BufferFastAggregation.or(bitmaps); - } - - /** - * Computes OR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - */ - public static MutableRoaringBitmap or(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - MutableRoaringBitmap.rangeSanityCheck(rangeStart, rangeEnd); - Iterator bitmapsIterator; - bitmapsIterator = selectRangeWithoutCopy(bitmaps, rangeStart, rangeEnd); - return or(bitmapsIterator); - } - - /** - * Computes OR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - * @deprecated use the version where longs specify the range. - * Negative range points are forbidden. - */ - @Deprecated - public static MutableRoaringBitmap or(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final int rangeStart, final int rangeEnd) { - return or(bitmaps, (long) rangeStart, (long) rangeEnd); - } - - /** - * Cardinality of the bitwise OR (union) operation. The provided bitmaps are *not* modified. This - * operation is thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return cardinality of the union - * @see BufferFastAggregation#or(ImmutableRoaringBitmap...) - * @see BufferFastAggregation#horizontal_or(ImmutableRoaringBitmap...) - */ - public static int orCardinality(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - // we use the fact that the cardinality of the bitmaps is known so that - // the union is just the total cardinality minus the intersection - return x1.getCardinality() + x2.getCardinality() - andCardinality(x1, x2); - } - - /** - * Computes XOR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - */ - public static MutableRoaringBitmap xor(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final long rangeStart, final long rangeEnd) { - Iterator bitmapsIterator; - bitmapsIterator = selectRangeWithoutCopy(bitmaps, rangeStart, rangeEnd); - return BufferFastAggregation.xor(bitmapsIterator); - } - - /** - * Computes XOR between input bitmaps in the given range, from rangeStart (inclusive) to rangeEnd - * (exclusive) - * - * @param bitmaps input bitmaps, these are not modified - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new result bitmap - * @deprecated use the version where longs specify the range. - * Negative values not allowed for rangeStart and rangeEnd - */ - @Deprecated - public static MutableRoaringBitmap xor(@SuppressWarnings("rawtypes") final Iterator bitmaps, - final int rangeStart, final int rangeEnd) { - return xor(bitmaps, (long) rangeStart, (long) rangeEnd); - } - - /** - * Bitwise XOR (symmetric difference) operation. The provided bitmaps are *not* modified. This - * operation is thread-safe as long as the provided bitmaps remain unchanged. - *

- * If you have more than 2 bitmaps, consider using the FastAggregation class. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - * @see BufferFastAggregation#xor(ImmutableRoaringBitmap...) - * @see BufferFastAggregation#horizontal_xor(ImmutableRoaringBitmap...) - */ - public static MutableRoaringBitmap xor(final ImmutableRoaringBitmap x1, - final ImmutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - MappeableContainerPointer i1 = x1.highLowContainer.getContainerPointer(); - MappeableContainerPointer i2 = x2.highLowContainer.getContainerPointer(); - main: - if (i1.hasContainer() && i2.hasContainer()) { - while (true) { - if (i1.key() == i2.key()) { - final MappeableContainer c = i1.getContainer().xor(i2.getContainer()); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().append(i1.key(), c); - } - i1.advance(); - i2.advance(); - if (!i1.hasContainer() || !i2.hasContainer()) { - break main; - } - } else if (Util.compareUnsigned(i1.key(), i2.key()) < 0) { // i1.key() < i2.key() - answer.getMappeableRoaringArray().appendCopy(i1.key(), i1.getContainer()); - i1.advance(); - if (!i1.hasContainer()) { - break main; - } - } else { // i1.key() < i2.key() - answer.getMappeableRoaringArray().appendCopy(i2.key(), i2.getContainer()); - i2.advance(); - if (!i2.hasContainer()) { - break main; - } - } - } - } - if (!i1.hasContainer()) { - while (i2.hasContainer()) { - answer.getMappeableRoaringArray().appendCopy(i2.key(), i2.getContainer()); - i2.advance(); - } - } else if (!i2.hasContainer()) { - while (i1.hasContainer()) { - answer.getMappeableRoaringArray().appendCopy(i1.key(), i1.getContainer()); - i1.advance(); - } - } - - return answer; - } - - @Override - public ImmutableRoaringBitmap clone() { - try { - final ImmutableRoaringBitmap x = (ImmutableRoaringBitmap) super.clone(); - x.highLowContainer = highLowContainer.clone(); - return x; - } catch (final CloneNotSupportedException e) { - throw new RuntimeException("shouldn't happen with clone", e); - } - } - - /** - * Checks whether the value in included, which is equivalent to checking if the corresponding bit - * is set (get in BitSet class). - * - * @param x integer value - * @return whether the integer value is included. - */ - @Override - public boolean contains(final int x) { - final short hb = BufferUtil.highbits(x); - final MappeableContainer c = highLowContainer.getContainer(hb); - return c != null && c.contains(BufferUtil.lowbits(x)); - } - - @Override - public boolean equals(Object o) { - if (o instanceof ImmutableRoaringBitmap) { - if (this.highLowContainer.size() != ((ImmutableRoaringBitmap) o).highLowContainer.size()) { - return false; - } - MappeableContainerPointer mp1 = this.highLowContainer.getContainerPointer(); - MappeableContainerPointer mp2 = - ((ImmutableRoaringBitmap) o).highLowContainer.getContainerPointer(); - while (mp1.hasContainer()) { - if (mp1.key() != mp2.key()) { - return false; - } - if (mp1.getCardinality() != mp2.getCardinality()) { - return false; - } - if (!mp1.getContainer().equals(mp2.getContainer())) { - return false; - } - mp1.advance(); - mp2.advance(); - } - return true; - } - return false; - } - - /** - * Returns the number of distinct integers added to the bitmap (e.g., number of bits set). - * - * @return the cardinality - */ - @Override - public long getLongCardinality() { - long size = 0; - for (int i = 0; i < this.highLowContainer.size(); ++i) { - size += this.highLowContainer.getCardinality(i); - } - return size; - } - - @Override - public int getCardinality() { - return (int) getLongCardinality(); - } - - @Override - public void forEach(IntConsumer ic) { - for (int i = 0; i < this.highLowContainer.size(); i++) { - highLowContainer.getContainerAtIndex(i).forEach(highLowContainer.getKeyAtIndex(i), ic); - } - } - - /** - * Return a low-level container pointer that can be used to access the underlying data structure. - * - * @return container pointer - */ - public MappeableContainerPointer getContainerPointer() { - return this.highLowContainer.getContainerPointer(); - } - - /** - * For better performance, consider the Use the {@link #forEach forEach} method. - * - * @return a custom iterator over set bits, the bits are traversed in ascending sorted order - */ - @Override - public PeekableIntIterator getIntIterator() { - return new ImmutableRoaringIntIterator(); - } - - /** - * @return a custom iterator over set bits, the bits are traversed in descending sorted order - */ - @Override - public IntIterator getReverseIntIterator() { - return new ImmutableRoaringReverseIntIterator(); - } - - /** - * Estimate of the memory usage of this data structure. This can be expected to be within 1% of - * the true memory usage. If exact measures are needed, we recommend using dedicated libraries - * such as SizeOf. - *

- * When the bitmap is constructed from a ByteBuffer from a memory-mapped file, this estimate is - * invalid: we can expect the actual memory usage to be significantly (e.g., 10x) less. - * - * @return estimated memory usage. - */ - @Override - public long getLongSizeInBytes() { - long size = 4; - for (int i = 0; i < this.highLowContainer.size(); ++i) { - if (this.highLowContainer.getContainerAtIndex(i) instanceof MappeableRunContainer) { - MappeableRunContainer thisRunContainer = - (MappeableRunContainer) this.highLowContainer.getContainerAtIndex(i); - size += 4 + BufferUtil.getSizeInBytesFromCardinalityEtc(0, thisRunContainer.nbrruns, true); - } else { - size += 4 + BufferUtil - .getSizeInBytesFromCardinalityEtc(this.highLowContainer.getCardinality(i), 0, false); - } - } - return size; - } - - @Override - public int getSizeInBytes() { - return (int) getLongSizeInBytes(); - } - - @Override - public int hashCode() { - return highLowContainer.hashCode(); - } - - /** - * Check whether this bitmap has had its runs compressed. - * - * @return whether this bitmap has run compression - */ - public boolean hasRunCompression() { - return this.highLowContainer.hasRunCompression(); - } - - /** - * Checks whether the bitmap is empty. - * - * @return true if this bitmap contains no set bit - */ - @Override - public boolean isEmpty() { - return highLowContainer.size() == 0; - } - - /** - * iterate over the positions of the true values. - * - * @return the iterator - */ - @Override - public Iterator iterator() { - return new Iterator() { - int hs = 0; - - ShortIterator iter; - - short pos = 0; - - int x; - - @Override - public boolean hasNext() { - return pos < ImmutableRoaringBitmap.this.highLowContainer.size(); - } - - public Iterator init() { - if (pos < ImmutableRoaringBitmap.this.highLowContainer.size()) { - iter = ImmutableRoaringBitmap.this.highLowContainer.getContainerAtIndex(pos) - .getShortIterator(); - hs = BufferUtil - .toIntUnsigned(ImmutableRoaringBitmap.this.highLowContainer.getKeyAtIndex(pos)) << 16; - } - return this; - } - - @Override - public Integer next() { - x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - ++pos; - init(); - } - return x; - } - - @Override - public void remove() { - throw new RuntimeException("Cannot modify."); - } - - }.init(); - } - - /** - * Create a new Roaring bitmap containing at most maxcardinality integers. - * - * @param maxcardinality maximal cardinality - * @return a new bitmap with cardinality no more than maxcardinality - */ - @Override - public MutableRoaringBitmap limit(int maxcardinality) { - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int currentcardinality = 0; - for (int i = 0; (currentcardinality < maxcardinality) - && (i < this.highLowContainer.size()); i++) { - MappeableContainer c = this.highLowContainer.getContainerAtIndex(i); - if (c.getCardinality() + currentcardinality <= maxcardinality) { - ((MutableRoaringArray) answer.highLowContainer) - .append(this.highLowContainer.getKeyAtIndex(i), c.clone()); - currentcardinality += c.getCardinality(); - } else { - int leftover = maxcardinality - currentcardinality; - MappeableContainer limited = c.limit(leftover); - ((MutableRoaringArray) answer.highLowContainer) - .append(this.highLowContainer.getKeyAtIndex(i), limited); - break; - } - } - return answer; - } - - /** - * Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be - * GetCardinality()). - * - * @param x upper limit - * @return the rank - */ - @Override - public long rankLong(int x) { - long size = 0; - short xhigh = BufferUtil.highbits(x); - for (int i = 0; i < this.highLowContainer.size(); i++) { - short key = this.highLowContainer.getKeyAtIndex(i); - if (Util.compareUnsigned(key, xhigh) < 0) { - size += this.highLowContainer.getCardinality(i); - } else { - return size + this.highLowContainer.getContainerAtIndex(i).rank(BufferUtil.lowbits(x)); - } - } - return size; - } - - @Override - public int rank(int x) { - return (int) rankLong(x); - } - - /** - * Return the jth value stored in this bitmap. - * - * @param j index of the value - * @return the value - */ - @Override - public int select(int j) { - int leftover = j; - for (int i = 0; i < this.highLowContainer.size(); i++) { - int thiscard = this.highLowContainer.getCardinality(i); - if (thiscard > leftover) { - int keycontrib = this.highLowContainer.getKeyAtIndex(i) << 16; - MappeableContainer c = this.highLowContainer.getContainerAtIndex(i); - int lowcontrib = BufferUtil.toIntUnsigned(c.select(leftover)); - return lowcontrib + keycontrib; - } - leftover -= thiscard; - } - throw new IllegalArgumentException( - "select " + j + " when the cardinality is " + this.getCardinality()); - } - - /** - * Serialize this bitmap. - *

- * Consider calling {@link MutableRoaringBitmap#runOptimize} before serialization to improve - * compression if this is a MutableRoaringBitmap instance. - *

- * The current bitmap is not modified. - *

- * Advanced example: To serialize your bitmap to a ByteBuffer, you can do the following. - *

- *

-     * {
-     *   @code
-     *   // r is your bitmap
-     *
-     *   // r.runOptimize(); // might improve compression, only if you have a
-     *   // MutableRoaringBitmap instance.
-     *   // next we create the ByteBuffer where the data will be stored
-     *   ByteBuffer outbb = ByteBuffer.allocate(r.serializedSizeInBytes());
-     *   // then we can serialize on a custom OutputStream
-     *   mrb.serialize(new DataOutputStream(new OutputStream() {
-     *     ByteBuffer mBB;
-     *
-     *     OutputStream init(ByteBuffer mbb) {
-     *       mBB = mbb;
-     *       return this;
-     *     }
-     *
-     *     public void close() {}
-     *
-     *     public void flush() {}
-     *
-     *     public void write(int b) {
-     *       mBB.put((byte) b);
-     *     }
-     *
-     *     public void write(byte[] b) {
-     *       mBB.put(b);
-     *     }
-     *
-     *     public void write(byte[] b, int off, int l) {
-     *       mBB.put(b, off, l);
-     *     }
-     *   }.init(outbb)));
-     *   // outbuff will now contain a serialized version of your bitmap
-     * }
-     * 
- *

- * Note: Java's data structures are in big endian format. Roaring serializes to a little endian - * format, so the bytes are flipped by the library during serialization to ensure that what is - * stored is in little endian---despite Java's big endianness. You can defeat this process by - * reflipping the bytes again in a custom DataOutput which could lead to serialized Roaring - * objects with an incorrect byte order. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - @Override - public void serialize(DataOutput out) throws IOException { - this.highLowContainer.serialize(out); - } - - /** - * Report the number of bytes required for serialization. This count will match the bytes written - * when calling the serialize method. - * - * @return the size in bytes - */ - @Override - public int serializedSizeInBytes() { - return this.highLowContainer.serializedSizeInBytes(); - } - - /** - * Return the set values as an array if the cardinality is less - * than 2147483648. The integer values are in sorted order. - * - * @return array representing the set values. - */ - @Override - public int[] toArray() { - final int[] array = new int[(int) this.getCardinality()]; - int pos = 0, pos2 = 0; - while (pos < this.highLowContainer.size()) { - final int hs = BufferUtil.toIntUnsigned(this.highLowContainer.getKeyAtIndex(pos)) << 16; - final MappeableContainer c = this.highLowContainer.getContainerAtIndex(pos++); - c.fillLeastSignificant16bits(array, pos2, hs); - pos2 += c.getCardinality(); - } - return array; - } - - /** - * Copies the content of this bitmap to a bitmap that can be modified. - * - * @return a mutable bitmap. - */ - public MutableRoaringBitmap toMutableRoaringBitmap() { - MutableRoaringBitmap c = new MutableRoaringBitmap(); - MappeableContainerPointer mcp = highLowContainer.getContainerPointer(); - while (mcp.hasContainer()) { - c.getMappeableRoaringArray().appendCopy(mcp.key(), mcp.getContainer()); - mcp.advance(); - } - return c; - } - - /** - * Copies this bitmap to a mutable RoaringBitmap. - * - * @return a copy of this bitmap as a RoaringBitmap. - */ - public RoaringBitmap toRoaringBitmap() { - return new RoaringBitmap(this); - } - - /** - * A string describing the bitmap. - * - * @return the string - */ - @Override - public String toString() { - final StringBuilder answer = new StringBuilder(); - final IntIterator i = this.getIntIterator(); - answer.append("{"); - if (i.hasNext()) { - answer.append(i.next() & 0xFFFFFFFFL); - } - while (i.hasNext()) { - answer.append(","); - // to avoid using too much memory, we limit the size - if (answer.length() > 0x80000) { - answer.append("..."); - break; - } - answer.append(i.next() & 0xFFFFFFFFL); - } - answer.append("}"); - return answer.toString(); - } - - private final class ImmutableRoaringIntIterator implements PeekableIntIterator { - private MappeableContainerPointer cp = - ImmutableRoaringBitmap.this.highLowContainer.getContainerPointer(); - - private int hs = 0; - - private PeekableShortIterator iter; - - private boolean ok; - - public ImmutableRoaringIntIterator() { - nextContainer(); - } - - @Override - public PeekableIntIterator clone() { - try { - ImmutableRoaringIntIterator x = (ImmutableRoaringIntIterator) super.clone(); - x.iter = this.iter.clone(); - x.cp = this.cp.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return ok; - } - - @Override - public int next() { - int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - cp.advance(); - nextContainer(); - } - return x; - } - - - private void nextContainer() { - ok = cp.hasContainer(); - if (ok) { - iter = cp.getContainer().getShortIterator(); - hs = BufferUtil.toIntUnsigned(cp.key()) << 16; - } - } - - @Override - public void advanceIfNeeded(int minval) { - while (hasNext() && ((hs >>> 16) < (minval >>> 16))) { - cp.advance(); - nextContainer(); - } - if (ok && ((hs >>> 16) == (minval >>> 16))) { - iter.advanceIfNeeded(BufferUtil.lowbits(minval)); - if (!iter.hasNext()) { - cp.advance(); - nextContainer(); - } - } - } - - @Override - public int peekNext() { - return BufferUtil.toIntUnsigned(iter.peekNext()) | hs; - } - - - } - - private final class ImmutableRoaringReverseIntIterator implements IntIterator { - private MappeableContainerPointer cp = ImmutableRoaringBitmap.this.highLowContainer - .getContainerPointer(ImmutableRoaringBitmap.this.highLowContainer.size() - 1); - - private int hs = 0; - - private ShortIterator iter; - - private boolean ok; - - public ImmutableRoaringReverseIntIterator() { - nextContainer(); - } - - @Override - public IntIterator clone() { - try { - ImmutableRoaringReverseIntIterator x = (ImmutableRoaringReverseIntIterator) super.clone(); - x.iter = this.iter.clone(); - x.cp = this.cp.clone(); - return x; - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return ok; - } - - @Override - public int next() { - int x = iter.nextAsInt() | hs; - if (!iter.hasNext()) { - cp.previous(); - nextContainer(); - } - return x; - } - - - private void nextContainer() { - ok = cp.hasContainer(); - if (ok) { - iter = cp.getContainer().getReverseShortIterator(); - hs = BufferUtil.toIntUnsigned(cp.key()) << 16; - } - } - - - } - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableArrayContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableArrayContainer.java deleted file mode 100644 index 5a68357b1..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableArrayContainer.java +++ /dev/null @@ -1,1688 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.ArrayContainer; -import com.fr.third.bitmap.roaringbitmap.Container; -import com.fr.third.bitmap.roaringbitmap.IntConsumer; -import com.fr.third.bitmap.roaringbitmap.PeekableShortIterator; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.ShortBuffer; -import java.util.Arrays; -import java.util.Iterator; - -/** - * Simple container made of an array of 16-bit integers. Unlike ArrayContainer, - * this class uses a ShortBuffer to store data. - */ -public final class MappeableArrayContainer extends MappeableContainer implements Cloneable { - protected static final int DEFAULT_MAX_SIZE = 4096; // containers with DEFAULT_MAX_SZE or less - private static final int DEFAULT_INIT_SIZE = 4; - private static final int ARRAY_LAZY_LOWERBOUND = 1024; - // integers should be ArrayContainers - private static final long serialVersionUID = 1L; - protected int cardinality = 0; - protected ShortBuffer content; - - /** - * Create an array container with default capacity - */ - public MappeableArrayContainer() { - this(DEFAULT_INIT_SIZE); - } - - - /** - * Creates a new container from a non-mappeable one. This copies the data. - * - * @param bc the original container - */ - public MappeableArrayContainer(ArrayContainer bc) { - this.cardinality = bc.getCardinality(); - this.content = bc.toShortBuffer(); - } - - - /** - * Create an array container with specified capacity - * - * @param capacity The capacity of the container - */ - public MappeableArrayContainer(final int capacity) { - content = ShortBuffer.allocate(capacity); - } - - /** - * Create an array container with a run of ones from firstOfRun to lastOfRun, exclusive. Caller is - * responsible for making sure the range is small enough that ArrayContainer is appropriate. - * - * @param firstOfRun first index - * @param lastOfRun last index (range is exclusive) - */ - public MappeableArrayContainer(final int firstOfRun, final int lastOfRun) { - // TODO: this can be optimized for performance - final int valuesInRange = lastOfRun - firstOfRun; - content = ShortBuffer.allocate(valuesInRange); - short[] sarray = content.array(); - for (int i = 0; i < valuesInRange; ++i) { - sarray[i] = (short) (firstOfRun + i); - } - cardinality = valuesInRange; - } - - - private MappeableArrayContainer(int newCard, ShortBuffer newContent) { - this.cardinality = newCard; - ShortBuffer tmp = newContent.duplicate();// for thread-safety - this.content = ShortBuffer.allocate(Math.max(newCard, tmp.limit())); - tmp.rewind(); - this.content.put(tmp); - } - - /** - * Construct a new ArrayContainer backed by the provided ShortBuffer. Note that if you modify the - * ArrayContainer a new ShortBuffer may be produced. - * - * @param array ShortBuffer where the data is stored - * @param cardinality cardinality (number of values stored) - */ - public MappeableArrayContainer(final ShortBuffer array, final int cardinality) { - if (array.limit() != cardinality) { - throw new RuntimeException("Mismatch between buffer and cardinality"); - } - this.cardinality = cardinality; - this.content = array; - } - - protected static int getArraySizeInBytes(int cardinality) { - return cardinality * 2; - } - - protected static int serializedSizeInBytes(int cardinality) { - return cardinality * 2 + 2; - } - - @Override - public MappeableContainer add(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = end - begin; - int newcardinality = indexstart + (cardinality - indexend) + rangelength; - if (newcardinality > DEFAULT_MAX_SIZE) { - MappeableBitmapContainer a = this.toBitmapContainer(); - return a.iadd(begin, end); - } - MappeableArrayContainer answer = new MappeableArrayContainer(newcardinality, content); - if (!BufferUtil.isBackedBySimpleArray(answer.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - BufferUtil.arraycopy(content, indexend, answer.content, indexstart + rangelength, - cardinality - indexend); - short[] answerarray = answer.content.array(); - for (int k = 0; k < rangelength; ++k) { - answerarray[k + indexstart] = (short) (begin + k); - } - answer.cardinality = newcardinality; - return answer; - } - - /** - * running time is in O(n) time if insert is not in order. - */ - @Override - // not thread-safe - public MappeableContainer add(final short x) { - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] sarray = content.array(); - - int loc = Util.unsignedBinarySearch(sarray, 0, cardinality, x); - if (loc < 0) { - // Transform the ArrayContainer to a BitmapContainer - // when cardinality exceeds DEFAULT_MAX_SIZE - if (cardinality >= DEFAULT_MAX_SIZE) { - final MappeableBitmapContainer a = this.toBitmapContainer(); - a.add(x); - return a; - } - if (cardinality >= sarray.length) { - increaseCapacity(); - sarray = content.array(); - } - // insertion : shift the elements > x by one - // position to - // the right - // and put x in it's appropriate place - System.arraycopy(sarray, -loc - 1, sarray, -loc, cardinality + loc + 1); - sarray[-loc - 1] = x; - ++cardinality; - } - } else { - - final int loc = BufferUtil.unsignedBinarySearch(content, 0, cardinality, x); - if (loc < 0) { - // Transform the ArrayContainer to a BitmapContainer - // when cardinality exceeds DEFAULT_MAX_SIZE - if (cardinality >= DEFAULT_MAX_SIZE) { - final MappeableBitmapContainer a = this.toBitmapContainer(); - a.add(x); - return a; - } - if (cardinality >= this.content.limit()) { - increaseCapacity(); - } - // insertion : shift the elements > x by one - // position to - // the right - // and put x in it's appropriate place - for (int k = cardinality; k > -loc - 1; --k) { - content.put(k, content.get(k - 1)); - } - content.put(-loc - 1, x); - - ++cardinality; - } - } - return this; - } - - private int advance(ShortIterator it) { - if (it.hasNext()) { - return BufferUtil.toIntUnsigned(it.next()); - } else { - return -1; - } - } - - - @Override - public MappeableArrayContainer and(final MappeableArrayContainer value2) { - - MappeableArrayContainer value1 = this; - final int desiredCapacity = Math.min(value1.getCardinality(), value2.getCardinality()); - MappeableArrayContainer answer = new MappeableArrayContainer(desiredCapacity); - if (BufferUtil.isBackedBySimpleArray(this.content) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - answer.cardinality = Util.unsignedIntersect2by2(value1.content.array(), - value1.getCardinality(), value2.content.array(), value2.getCardinality(), - answer.content.array()); - } else { - answer.cardinality = BufferUtil.unsignedIntersect2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content.array()); - } - return answer; - } - - @Override - public MappeableContainer and(MappeableBitmapContainer x) { - return x.and(this); - } - - @Override - public MappeableContainer and(final MappeableRunContainer value2) { - return value2.and(this); - } - - - @Override - public MappeableArrayContainer andNot(final MappeableArrayContainer value2) { - final MappeableArrayContainer value1 = this; - final int desiredCapacity = value1.getCardinality(); - final MappeableArrayContainer answer = new MappeableArrayContainer(desiredCapacity); - if (BufferUtil.isBackedBySimpleArray(value1.content) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - answer.cardinality = - Util.unsignedDifference(value1.content.array(), value1.getCardinality(), - value2.content.array(), value2.getCardinality(), answer.content.array()); - } else { - answer.cardinality = BufferUtil.unsignedDifference(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content.array()); - } - return answer; - } - - @Override - public MappeableArrayContainer andNot(MappeableBitmapContainer value2) { - - final MappeableArrayContainer answer = new MappeableArrayContainer(content.limit()); - int pos = 0; - short[] sarray = answer.content.array(); - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] c = content.array(); - for (int k = 0; k < cardinality; ++k) { - short v = c[k]; - if (!value2.contains(v)) { - sarray[pos++] = v; - } - } - } else { - for (int k = 0; k < cardinality; ++k) { - short v = this.content.get(k); - if (!value2.contains(v)) { - sarray[pos++] = v; - } - } - } - answer.cardinality = pos; - return answer; - } - - @Override - public MappeableContainer andNot(final MappeableRunContainer x) { - int writeLocation = 0; - int runStart, runEnd; // the current or upcoming run. - if (x.nbrruns == 0) { - return clone(); - } - - ShortBuffer buffer = ShortBuffer.allocate(cardinality); - - runStart = BufferUtil.toIntUnsigned(x.getValue(0)); - runEnd = runStart + BufferUtil.toIntUnsigned(x.getLength(0)); - int whichRun = 0; - - short val; - for (int i = 0; i < cardinality; ++i) { - val = content.get(i); - int valInt = BufferUtil.toIntUnsigned(val); - if (valInt < runStart) { - buffer.put(writeLocation++, val); - } else if (valInt <= runEnd) { - ; // don't want item - } else { - // greater than this run, need to do an advanceUntil on runs - // done sequentially for now (no galloping attempts). - do { - if (whichRun + 1 < x.nbrruns) { - whichRun++; - runStart = BufferUtil.toIntUnsigned(x.getValue(whichRun)); - runEnd = runStart + BufferUtil.toIntUnsigned(x.getLength(whichRun)); - } else { - runStart = runEnd = (1 << 16) + 1; // infinity.... - } - } while (valInt > runEnd); - --i; // need to re-process this val - } - } - return new MappeableArrayContainer(writeLocation, buffer); - } - - @Override - public void clear() { - cardinality = 0; - } - - @Override - public MappeableArrayContainer clone() { - return new MappeableArrayContainer(this.cardinality, this.content); - } - - @Override - public boolean contains(final short x) { - return BufferUtil.unsignedBinarySearch(content, 0, cardinality, x) >= 0; - } - - // in order - // not thread-safe - private void emit(short val) { - if (cardinality == content.limit()) { - increaseCapacity(true); - } - content.put(cardinality++, val); - } - - @Override - public boolean equals(Object o) { - if (o instanceof MappeableArrayContainer) { - final MappeableArrayContainer srb = (MappeableArrayContainer) o; - if (srb.cardinality != this.cardinality) { - return false; - } - if (BufferUtil.isBackedBySimpleArray(this.content) - && BufferUtil.isBackedBySimpleArray(srb.content)) { - short[] t = this.content.array(); - short[] sr = srb.content.array(); - - for (int i = 0; i < this.cardinality; ++i) { - if (t[i] != sr[i]) { - return false; - } - } - - } else { - for (int i = 0; i < this.cardinality; ++i) { - if (this.content.get(i) != srb.content.get(i)) { - return false; - } - } - } - return true; - } else if (o instanceof MappeableRunContainer) { - return o.equals(this); - } - return false; - } - - - @Override - public void fillLeastSignificant16bits(int[] x, int i, int mask) { - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] c = this.content.array(); - for (int k = 0; k < this.cardinality; ++k) { - x[k + i] = BufferUtil.toIntUnsigned(c[k]) | mask; - } - - } else { - for (int k = 0; k < this.cardinality; ++k) { - x[k + i] = BufferUtil.toIntUnsigned(this.content.get(k)) | mask; - } - } - } - - @Override - // not thread-safe - public MappeableContainer flip(short x) { - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] sarray = content.array(); - int loc = Util.unsignedBinarySearch(sarray, 0, cardinality, x); - if (loc < 0) { - // Transform the ArrayContainer to a BitmapContainer - // when cardinality = DEFAULT_MAX_SIZE - if (cardinality >= DEFAULT_MAX_SIZE) { - MappeableBitmapContainer a = this.toBitmapContainer(); - a.add(x); - return a; - } - if (cardinality >= sarray.length) { - increaseCapacity(); - sarray = content.array(); - } - // insertion : shift the elements > x by one position to - // the right - // and put x in it's appropriate place - System.arraycopy(sarray, -loc - 1, sarray, -loc, cardinality + loc + 1); - sarray[-loc - 1] = x; - ++cardinality; - } else { - System.arraycopy(sarray, loc + 1, sarray, loc, cardinality - loc - 1); - --cardinality; - } - return this; - - } else { - int loc = BufferUtil.unsignedBinarySearch(content, 0, cardinality, x); - if (loc < 0) { - // Transform the ArrayContainer to a BitmapContainer - // when cardinality = DEFAULT_MAX_SIZE - if (cardinality >= DEFAULT_MAX_SIZE) { - MappeableBitmapContainer a = this.toBitmapContainer(); - a.add(x); - return a; - } - if (cardinality >= content.limit()) { - increaseCapacity(); - } - // insertion : shift the elements > x by one position to - // the right - // and put x in it's appropriate place - for (int k = cardinality; k > -loc - 1; --k) { - content.put(k, content.get(k - 1)); - } - content.put(-loc - 1, x); - ++cardinality; - } else { - for (int k = loc + 1; k < cardinality; --k) { - content.put(k - 1, content.get(k)); - } - --cardinality; - } - return this; - } - } - - @Override - protected int getArraySizeInBytes() { - return getArraySizeInBytes(cardinality); - } - - @Override - public int getCardinality() { - return cardinality; - } - - @Override - public ShortIterator getReverseShortIterator() { - if (this.isArrayBacked()) { - return new RawReverseArrayContainerShortIterator(this); - } - return new ReverseMappeableArrayContainerShortIterator(this); - } - - @Override - public PeekableShortIterator getShortIterator() { - if (this.isArrayBacked()) { - return new RawArrayContainerShortIterator(this); - } - return new MappeableArrayContainerShortIterator(this); - } - - @Override - public int getSizeInBytes() { - return this.cardinality * 2; - } - - @Override - public int hashCode() { - int hash = 0; - for (int k = 0; k < cardinality; ++k) { - hash += 31 * hash + content.get(k); - } - return hash; - } - - @Override - // not thread-safe - public MappeableContainer iadd(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = end - begin; - int newcardinality = indexstart + (cardinality - indexend) + rangelength; - if (newcardinality > DEFAULT_MAX_SIZE) { - MappeableBitmapContainer a = this.toBitmapContainer(); - return a.iadd(begin, end); - } - if (newcardinality >= this.content.limit()) { - increaseCapacity(newcardinality); - } - BufferUtil.arraycopy(content, indexend, content, indexstart + rangelength, - cardinality - indexend); - if (BufferUtil.isBackedBySimpleArray(content)) { - short[] contentarray = content.array(); - for (int k = 0; k < rangelength; ++k) { - contentarray[k + indexstart] = (short) (begin + k); - } - } else { - for (int k = 0; k < rangelength; ++k) { - content.put(k + indexstart, (short) (begin + k)); - } - } - cardinality = newcardinality; - return this; - } - - @Override - public MappeableArrayContainer iand(final MappeableArrayContainer value2) { - final MappeableArrayContainer value1 = this; - if (!BufferUtil.isBackedBySimpleArray(value1.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - value1.cardinality = BufferUtil.unsignedIntersect2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), value1.content.array()); - return this; - } - - - @Override - public MappeableContainer iand(MappeableBitmapContainer value2) { - int pos = 0; - for (int k = 0; k < cardinality; ++k) { - short v = this.content.get(k); - if (value2.contains(v)) { - this.content.put(pos++, v); - } - } - cardinality = pos; - return this; - } - - - // Note it is never inplace, may wish to fix - @Override - public MappeableContainer iand(final MappeableRunContainer value2) { - return value2.and(this); - } - - @Override - public MappeableArrayContainer iandNot(final MappeableArrayContainer value2) { - if (!BufferUtil.isBackedBySimpleArray(this.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - this.cardinality = - Util.unsignedDifference(this.content.array(), this.getCardinality(), - value2.content.array(), value2.getCardinality(), this.content.array()); - } else { - this.cardinality = BufferUtil.unsignedDifference(this.content, this.getCardinality(), - value2.content, value2.getCardinality(), this.content.array()); - } - - return this; - } - - @Override - public MappeableArrayContainer iandNot(MappeableBitmapContainer value2) { - if (!BufferUtil.isBackedBySimpleArray(this.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - short[] c = this.content.array(); - int pos = 0; - for (int k = 0; k < cardinality; ++k) { - short v = c[k]; - if (!value2.contains(v)) { - c[pos++] = v; - } - } - this.cardinality = pos; - return this; - } - - @Override - public MappeableContainer iandNot(final MappeableRunContainer value2) { // not inplace, revisit? - return andNot(value2); - } - - private void increaseCapacity() { - increaseCapacity(false); - } - - // temporarily allow an illegally large size, as long as the operation creating - // the illegal container does not return it. - // not thread safe! - private void increaseCapacity(boolean allowIllegalSize) { - int len = this.content.limit(); - int newCapacity = (len == 0) ? DEFAULT_INIT_SIZE - : len < 64 ? len * 2 : this.content.limit() < 1067 ? len * 3 / 2 : len * 5 / 4; - // do not allocate more than we will ever need - if (newCapacity > MappeableArrayContainer.DEFAULT_MAX_SIZE && !allowIllegalSize) { - newCapacity = MappeableArrayContainer.DEFAULT_MAX_SIZE; - } - // if we are within 1/16th of the max., go to max right away to avoid further reallocations - if (newCapacity > MappeableArrayContainer.DEFAULT_MAX_SIZE - - MappeableArrayContainer.DEFAULT_MAX_SIZE / 16 && !allowIllegalSize) { - newCapacity = MappeableArrayContainer.DEFAULT_MAX_SIZE; - } - final ShortBuffer newContent = ShortBuffer.allocate(newCapacity); - this.content.rewind(); - newContent.put(this.content); - this.content = newContent; - } - - - // not thread safe! - private void increaseCapacity(int min) { - int len = this.content.limit(); - int newCapacity = (len == 0) ? DEFAULT_INIT_SIZE - : len < 64 ? len * 2 : len < 1024 ? len * 3 / 2 : len * 5 / 4; - if (newCapacity < min) { - newCapacity = min; - } - if (newCapacity > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - newCapacity = MappeableArrayContainer.DEFAULT_MAX_SIZE; - } - if (newCapacity > MappeableArrayContainer.DEFAULT_MAX_SIZE - - MappeableArrayContainer.DEFAULT_MAX_SIZE / 16) { - newCapacity = MappeableArrayContainer.DEFAULT_MAX_SIZE; - } - final ShortBuffer newContent = ShortBuffer.allocate(newCapacity); - this.content.rewind(); - newContent.put(this.content); - this.content = newContent; - } - - @Override - // not thread safe! (duh!) - public MappeableContainer inot(final int firstOfRange, final int lastOfRange) { - // TODO: may need to convert to a RunContainer - // TODO: this can be optimized for performance - // determine the span of array indices to be affected - int startIndex = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) firstOfRange); - if (startIndex < 0) { - startIndex = -startIndex - 1; - } - int lastIndex = - BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (lastOfRange - 1)); - if (lastIndex < 0) { - lastIndex = -lastIndex - 1 - 1; - } - final int currentValuesInRange = lastIndex - startIndex + 1; - final int spanToBeFlipped = lastOfRange - firstOfRange; - final int newValuesInRange = spanToBeFlipped - currentValuesInRange; - final ShortBuffer buffer = ShortBuffer.allocate(newValuesInRange); - final int cardinalityChange = newValuesInRange - currentValuesInRange; - final int newCardinality = cardinality + cardinalityChange; - - if (cardinalityChange > 0) { // expansion, right shifting needed - if (newCardinality > content.limit()) { - // so big we need a bitmap? - if (newCardinality > DEFAULT_MAX_SIZE) { - return toBitmapContainer().inot(firstOfRange, lastOfRange); - } - final ShortBuffer co = ShortBuffer.allocate(newCardinality); - content.rewind(); - co.put(content); - content = co; - } - // slide right the contents after the range - for (int pos = cardinality - 1; pos > lastIndex; --pos) { - content.put(pos + cardinalityChange, content.get(pos)); - } - negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange); - } else { // no expansion needed - negateRange(buffer, startIndex, lastIndex, firstOfRange, lastOfRange); - if (cardinalityChange < 0) { - // Leave array oversize - for (int i = startIndex + newValuesInRange; i < newCardinality; ++i) { - content.put(i, content.get(i - cardinalityChange)); - } - } - } - cardinality = newCardinality; - return this; - } - - @Override - public boolean intersects(MappeableArrayContainer value2) { - MappeableArrayContainer value1 = this; - return BufferUtil.unsignedIntersects(value1.content, value1.getCardinality(), value2.content, - value2.getCardinality()); - } - - @Override - public boolean intersects(MappeableBitmapContainer x) { - return x.intersects(this); - } - - @Override - public boolean intersects(MappeableRunContainer x) { - return x.intersects(this); - } - - @Override - public MappeableContainer ior(final MappeableArrayContainer value2) { - return this.or(value2); - } - - @Override - public MappeableContainer ior(MappeableBitmapContainer x) { - return x.or(this); - } - - @Override - public MappeableContainer ior(final MappeableRunContainer value2) { - // not inplace - return value2.or(this); - } - - @Override - public MappeableContainer iremove(int begin, int end) { - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = indexend - indexstart; - BufferUtil.arraycopy(content, indexstart + rangelength, content, indexstart, - cardinality - indexstart - rangelength); - cardinality -= rangelength; - return this; - } - - @Override - protected boolean isArrayBacked() { - return BufferUtil.isBackedBySimpleArray(this.content); - } - - - @Override - public Iterator iterator() { - - return new Iterator() { - short pos = 0; - - @Override - public boolean hasNext() { - return pos < MappeableArrayContainer.this.cardinality; - } - - @Override - public Short next() { - return MappeableArrayContainer.this.content.get(pos++); - } - - @Override - public void remove() { - MappeableArrayContainer.this.remove((short) (pos - 1)); - pos--; - } - }; - } - - @Override - public MappeableContainer ixor(final MappeableArrayContainer value2) { - return this.xor(value2); - } - - - @Override - public MappeableContainer ixor(MappeableBitmapContainer x) { - return x.xor(this); - } - - @Override - public MappeableContainer ixor(final MappeableRunContainer value2) { - return value2.xor(this); - } - - @Override - public MappeableContainer limit(int maxcardinality) { - if (maxcardinality < this.getCardinality()) { - return new MappeableArrayContainer(maxcardinality, this.content); - } else { - return clone(); - } - } - - - protected void loadData(final MappeableBitmapContainer bitmapContainer) { - this.cardinality = bitmapContainer.cardinality; - if (!BufferUtil.isBackedBySimpleArray(this.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - bitmapContainer.fillArray(content.array()); - } - - // for use in inot range known to be nonempty - private void negateRange(final ShortBuffer buffer, final int startIndex, final int lastIndex, - final int startRange, final int lastRange) { - // compute the negation into buffer - - int outPos = 0; - int inPos = startIndex; // value here always >= valInRange, - // until it is exhausted - // n.b., we can start initially exhausted. - - int valInRange = startRange; - for (; valInRange < lastRange && inPos <= lastIndex; ++valInRange) { - if ((short) valInRange != content.get(inPos)) { - buffer.put(outPos++, (short) valInRange); - } else { - ++inPos; - } - } - - // if there are extra items (greater than the biggest - // pre-existing one in range), buffer them - for (; valInRange < lastRange; ++valInRange) { - buffer.put(outPos++, (short) valInRange); - } - - if (outPos != buffer.limit()) { - throw new RuntimeException( - "negateRange: outPos " + outPos + " whereas buffer.length=" + buffer.limit()); - } - assert outPos == buffer.limit(); - // copy back from buffer...caller must ensure there is room - int i = startIndex; - int len = buffer.limit(); - for (int k = 0; k < len; ++k) { - final short item = buffer.get(k); - content.put(i++, item); - } - } - - // shares lots of code with inot; candidate for refactoring - @Override - public MappeableContainer not(final int firstOfRange, final int lastOfRange) { - // TODO: may need to convert to a RunContainer - // TODO: this can be optimized for performance - if (firstOfRange >= lastOfRange) { - return clone(); // empty range - } - - // determine the span of array indices to be affected - int startIndex = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) firstOfRange); - if (startIndex < 0) { - startIndex = -startIndex - 1; - } - int lastIndex = - BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (lastOfRange - 1)); - if (lastIndex < 0) { - lastIndex = -lastIndex - 2; - } - final int currentValuesInRange = lastIndex - startIndex + 1; - final int spanToBeFlipped = lastOfRange - firstOfRange; - final int newValuesInRange = spanToBeFlipped - currentValuesInRange; - final int cardinalityChange = newValuesInRange - currentValuesInRange; - final int newCardinality = cardinality + cardinalityChange; - - if (newCardinality > DEFAULT_MAX_SIZE) { - return toBitmapContainer().not(firstOfRange, lastOfRange); - } - - final MappeableArrayContainer answer = new MappeableArrayContainer(newCardinality); - if (!BufferUtil.isBackedBySimpleArray(answer.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - short[] sarray = answer.content.array(); - - for (int i = 0; i < startIndex; ++i) { - // copy stuff before the active area - sarray[i] = content.get(i); - } - - int outPos = startIndex; - int inPos = startIndex; // item at inPos always >= valInRange - - int valInRange = firstOfRange; - for (; valInRange < lastOfRange && inPos <= lastIndex; ++valInRange) { - if ((short) valInRange != content.get(inPos)) { - sarray[outPos++] = (short) valInRange; - } else { - ++inPos; - } - } - - for (; valInRange < lastOfRange; ++valInRange) { - answer.content.put(outPos++, (short) valInRange); - } - - // content after the active range - for (int i = lastIndex + 1; i < cardinality; ++i) { - answer.content.put(outPos++, content.get(i)); - } - answer.cardinality = newCardinality; - return answer; - } - - @Override - int numberOfRuns() { - if (cardinality == 0) { - return 0; // should never happen - } - - if (BufferUtil.isBackedBySimpleArray(content)) { - short[] c = content.array(); - int numRuns = 1; - int oldv = BufferUtil.toIntUnsigned(c[0]); - for (int i = 1; i < cardinality; i++) { - int newv = BufferUtil.toIntUnsigned(c[i]); - if (oldv + 1 != newv) { - ++numRuns; - } - oldv = newv; - } - return numRuns; - } else { - int numRuns = 1; - int previous = BufferUtil.toIntUnsigned(content.get(0)); - // we do not proceed like above for fear that calling "get" twice per loop would be too much - for (int i = 1; i < cardinality; i++) { - int val = BufferUtil.toIntUnsigned(content.get(i)); - if (val != previous + 1) { - ++numRuns; - } - previous = val; - } - return numRuns; - } - } - - - @Override - public MappeableContainer or(final MappeableArrayContainer value2) { - final MappeableArrayContainer value1 = this; - final int totalCardinality = value1.getCardinality() + value2.getCardinality(); - if (totalCardinality > DEFAULT_MAX_SIZE) {// it could be a bitmap! - final MappeableBitmapContainer bc = new MappeableBitmapContainer(); - if (!BufferUtil.isBackedBySimpleArray(bc.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = bc.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] sarray = value2.content.array(); - for (int k = 0; k < value2.cardinality; ++k) { - short v = sarray[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] |= (1L << v); - } - } else { - for (int k = 0; k < value2.cardinality; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - bitArray[i] |= (1L << v2); - } - } - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] sarray = this.content.array(); - for (int k = 0; k < this.cardinality; ++k) { - short v = sarray[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] |= (1L << v); - } - } else { - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content.get(k); - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] |= (1L << v); - } - } - bc.cardinality = 0; - int len = bc.bitmap.limit(); - for (int index = 0; index < len; ++index) { - bc.cardinality += Long.bitCount(bitArray[index]); - } - if (bc.cardinality <= DEFAULT_MAX_SIZE) { - return bc.toArrayContainer(); - } - return bc; - } - final MappeableArrayContainer answer = new MappeableArrayContainer(totalCardinality); - if (BufferUtil.isBackedBySimpleArray(value1.content) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - answer.cardinality = - Util.unsignedUnion2by2(value1.content.array(), value1.getCardinality(), - value2.content.array(), value2.getCardinality(), answer.content.array()); - } else { - answer.cardinality = BufferUtil.unsignedUnion2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content.array()); - } - return answer; - } - - protected MappeableContainer lazyor(final MappeableArrayContainer value2) { - final MappeableArrayContainer value1 = this; - final int totalCardinality = value1.getCardinality() + value2.getCardinality(); - if (totalCardinality > ARRAY_LAZY_LOWERBOUND) {// it could be a bitmap! - final MappeableBitmapContainer bc = new MappeableBitmapContainer(); - if (!BufferUtil.isBackedBySimpleArray(bc.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = bc.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] sarray = value2.content.array(); - for (int k = 0; k < value2.cardinality; ++k) { - short v = sarray[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] |= (1L << v); - } - } else { - for (int k = 0; k < value2.cardinality; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - bitArray[i] |= (1L << v2); - } - } - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] sarray = this.content.array(); - for (int k = 0; k < this.cardinality; ++k) { - short v = sarray[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] |= (1L << v); - } - } else { - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content.get(k); - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] |= (1L << v); - } - } - bc.cardinality = -1; - return bc; - } - final MappeableArrayContainer answer = new MappeableArrayContainer(totalCardinality); - if (BufferUtil.isBackedBySimpleArray(value1.content) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - answer.cardinality = - Util.unsignedUnion2by2(value1.content.array(), value1.getCardinality(), - value2.content.array(), value2.getCardinality(), answer.content.array()); - } else { - answer.cardinality = BufferUtil.unsignedUnion2by2(value1.content, value1.getCardinality(), - value2.content, value2.getCardinality(), answer.content.array()); - } - return answer; - } - - - @Override - public MappeableContainer or(MappeableBitmapContainer x) { - return x.or(this); - } - - @Override - public MappeableContainer or(final MappeableRunContainer value2) { - return value2.or(this); - } - - protected MappeableContainer or(ShortIterator it) { - return or(it, false); - } - - /** - * it must return items in (unsigned) sorted order. Possible candidate for Container interface? - **/ - private MappeableContainer or(ShortIterator it, boolean exclusive) { - MappeableArrayContainer ac = new MappeableArrayContainer(); - int myItPos = 0; - ac.cardinality = 0; - // do a merge. int -1 denotes end of input. - int myHead = (myItPos == cardinality) ? -1 : BufferUtil.toIntUnsigned(content.get(myItPos++)); - int hisHead = advance(it); - - while (myHead != -1 && hisHead != -1) { - if (myHead < hisHead) { - ac.emit((short) myHead); - myHead = (myItPos == cardinality) ? -1 : BufferUtil.toIntUnsigned(content.get(myItPos++)); - } else if (myHead > hisHead) { - ac.emit((short) hisHead); - hisHead = advance(it); - } else { - if (!exclusive) { - ac.emit((short) hisHead); - } - hisHead = advance(it); - myHead = (myItPos == cardinality) ? -1 : BufferUtil.toIntUnsigned(content.get(myItPos++)); - } - } - - while (myHead != -1) { - ac.emit((short) myHead); - myHead = (myItPos == cardinality) ? -1 : BufferUtil.toIntUnsigned(content.get(myItPos++)); - } - - while (hisHead != -1) { - ac.emit((short) hisHead); - hisHead = advance(it); - } - - if (ac.cardinality > DEFAULT_MAX_SIZE) { - return ac.toBitmapContainer(); - } else { - return ac; - } - } - - @Override - public int rank(short lowbits) { - int answer = BufferUtil.unsignedBinarySearch(content, 0, cardinality, lowbits); - if (answer >= 0) { - return answer + 1; - } else { - return -answer - 1; - } - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // little endian - this.cardinality = 0xFFFF & Short.reverseBytes(in.readShort()); - if (this.content.limit() < this.cardinality) { - this.content = ShortBuffer.allocate(this.cardinality); - } - for (int k = 0; k < this.cardinality; ++k) { - this.content.put(k, Short.reverseBytes(in.readShort())); - } - } - - @Override - public MappeableContainer remove(int begin, int end) { - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); - if (indexstart < 0) { - indexstart = -indexstart - 1; - } - int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); - if (indexend < 0) { - indexend = -indexend - 1; - } else { - indexend++; - } - int rangelength = indexend - indexstart; - MappeableArrayContainer answer = clone(); - BufferUtil.arraycopy(content, indexstart + rangelength, answer.content, indexstart, - cardinality - indexstart - rangelength); - answer.cardinality = cardinality - rangelength; - return answer; - } - - - @Override - public MappeableContainer remove(final short x) { - if (BufferUtil.isBackedBySimpleArray(this.content)) { - final int loc = Util.unsignedBinarySearch(content.array(), 0, cardinality, x); - if (loc >= 0) { - // insertion - System.arraycopy(content.array(), loc + 1, content.array(), loc, cardinality - loc - 1); - --cardinality; - } - return this; - } else { - final int loc = BufferUtil.unsignedBinarySearch(content, 0, cardinality, x); - if (loc >= 0) { - // insertion - for (int k = loc + 1; k < cardinality; --k) { - content.put(k - 1, content.get(k)); - } - --cardinality; - } - return this; - - } - } - - @Override - public MappeableContainer repairAfterLazy() { - return this; - } - - - @Override - public MappeableContainer runOptimize() { - int numRuns = numberOfRuns(); - int sizeAsRunContainer = MappeableRunContainer.getArraySizeInBytes(numRuns); - if (getArraySizeInBytes() > sizeAsRunContainer) { - return new MappeableRunContainer(this, numRuns); // this could be - // maybe faster if - // initial - // container is a - // bitmap - } else { - return this; - } - } - - @Override - public short select(int j) { - return this.content.get(j); - } - - @Override - public int serializedSizeInBytes() { - return serializedSizeInBytes(cardinality); - } - - /** - * Copies the data in a bitmap container. - * - * @return the bitmap container - */ - public MappeableBitmapContainer toBitmapContainer() { - final MappeableBitmapContainer bc = new MappeableBitmapContainer(); - bc.loadData(this); - return bc; - } - - @Override - public Container toContainer() { - return new ArrayContainer(this); - } - - /** - * Create a copy of the content of this container as a short array. This creates a copy. - * - * @return copy of the content as a short array - */ - public short[] toShortArray() { - short[] answer = new short[cardinality]; - content.rewind(); - content.get(answer); - return answer; - } - - @Override - public String toString() { - if (this.cardinality == 0) { - return "{}"; - } - final StringBuilder sb = new StringBuilder(); - sb.append("{"); - for (int i = 0; i < this.cardinality - 1; i++) { - sb.append(this.content.get(i)); - sb.append(","); - } - sb.append(this.content.get(this.cardinality - 1)); - sb.append("}"); - return sb.toString(); - } - - @Override - public void trim() { - if (this.content.limit() == this.cardinality) { - return; - } - if (BufferUtil.isBackedBySimpleArray(content)) { - this.content = ShortBuffer.wrap(Arrays.copyOf(content.array(), cardinality)); - } else { - final ShortBuffer co = ShortBuffer.allocate(this.cardinality); - // can assume that new co is array backed - short[] x = co.array(); - for (int k = 0; k < this.cardinality; ++k) { - x[k] = this.content.get(k); - } - this.content = co; - } - } - - @Override - protected void writeArray(DataOutput out) throws IOException { - // little endian - if (BufferUtil.isBackedBySimpleArray(content)) { - short[] a = content.array(); - for (int k = 0; k < this.cardinality; ++k) { - out.writeShort(Short.reverseBytes(a[k])); - } - } else { - for (int k = 0; k < this.cardinality; ++k) { - out.writeShort(Short.reverseBytes(content.get(k))); - } - } - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - out.write(this.cardinality & 0xFF); - out.write((this.cardinality >>> 8) & 0xFF); - if (BufferUtil.isBackedBySimpleArray(content)) { - short[] a = content.array(); - for (int k = 0; k < this.cardinality; ++k) { - out.writeShort(Short.reverseBytes(a[k])); - } - } else { - for (int k = 0; k < this.cardinality; ++k) { - out.writeShort(Short.reverseBytes(content.get(k))); - } - } - } - - @Override - public MappeableContainer xor(final MappeableArrayContainer value2) { - final MappeableArrayContainer value1 = this; - final int totalCardinality = value1.getCardinality() + value2.getCardinality(); - if (totalCardinality > DEFAULT_MAX_SIZE) {// it could be a bitmap! - final MappeableBitmapContainer bc = new MappeableBitmapContainer(); - if (!BufferUtil.isBackedBySimpleArray(bc.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = bc.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] sarray = value2.content.array(); - for (int k = 0; k < value2.cardinality; ++k) { - short v = sarray[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] ^= (1L << v); - } - } else { - for (int k = 0; k < value2.cardinality; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - bitArray[i] ^= (1L << v2); - } - } - if (BufferUtil.isBackedBySimpleArray(this.content)) { - short[] sarray = this.content.array(); - for (int k = 0; k < this.cardinality; ++k) { - short v = sarray[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] ^= (1L << v); - } - } else { - for (int k = 0; k < this.cardinality; ++k) { - short v = this.content.get(k); - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - bitArray[i] ^= (1L << v); - } - } - - bc.cardinality = 0; - int len = bc.bitmap.limit(); - for (int index = 0; index < len; ++index) { - bc.cardinality += Long.bitCount(bitArray[index]); - } - if (bc.cardinality <= DEFAULT_MAX_SIZE) { - return bc.toArrayContainer(); - } - return bc; - } - final MappeableArrayContainer answer = new MappeableArrayContainer(totalCardinality); - if (BufferUtil.isBackedBySimpleArray(value1.content) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - answer.cardinality = Util.unsignedExclusiveUnion2by2(value1.content.array(), - value1.getCardinality(), value2.content.array(), value2.getCardinality(), - answer.content.array()); - } else { - answer.cardinality = BufferUtil.unsignedExclusiveUnion2by2(value1.content, - value1.getCardinality(), value2.content, value2.getCardinality(), answer.content.array()); - } - return answer; - } - - @Override - public MappeableContainer xor(MappeableBitmapContainer x) { - return x.xor(this); - } - - @Override - public MappeableContainer xor(final MappeableRunContainer value2) { - return value2.xor(this); - } - - - protected MappeableContainer xor(ShortIterator it) { - return or(it, true); - } - - @Override - public void forEach(short msb, IntConsumer ic) { - int high = ((int) msb) << 16; - if (BufferUtil.isBackedBySimpleArray(content)) { - short[] c = content.array(); - for (int k = 0; k < cardinality; ++k) { - ic.accept((c[k] & 0xFFFF) | high); - } - } else { - for (int k = 0; k < cardinality; ++k) { - ic.accept((content.get(k) & 0xFFFF) | high); - } - } - } - - @Override - public int andCardinality(MappeableArrayContainer value2) { - if (BufferUtil.isBackedBySimpleArray(content) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - return Util.unsignedLocalIntersect2by2Cardinality(content.array(), cardinality, - value2.content.array(), value2.getCardinality()); - } - return BufferUtil.unsignedLocalIntersect2by2Cardinality(content, cardinality, - value2.content, value2.getCardinality()); - } - - @Override - public int andCardinality(MappeableBitmapContainer x) { - return x.andCardinality(this); - } - - @Override - // see andNot for an approach that might be better. - public int andCardinality(MappeableRunContainer x) { - return x.andCardinality(this); - } - - -} - - -final class MappeableArrayContainerShortIterator implements PeekableShortIterator { - int pos; - MappeableArrayContainer parent; - - MappeableArrayContainerShortIterator() { - } - - - MappeableArrayContainerShortIterator(MappeableArrayContainer p) { - wrap(p); - } - - @Override - public void advanceIfNeeded(short minval) { - pos = BufferUtil.advanceUntil(parent.content, pos - 1, parent.cardinality, minval); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < parent.cardinality; - } - - @Override - public short next() { - return parent.content.get(pos++); - } - - - @Override - public int nextAsInt() { - return BufferUtil.toIntUnsigned(parent.content.get(pos++)); - } - - @Override - public short peekNext() { - return parent.content.get(pos); - } - - - @Override - public void remove() { - parent.remove((short) (pos - 1)); - pos--; - } - - void wrap(MappeableArrayContainer p) { - parent = p; - pos = 0; - } - - -} - - -final class RawArrayContainerShortIterator implements PeekableShortIterator { - int pos; - MappeableArrayContainer parent; - short[] content; - - - RawArrayContainerShortIterator(MappeableArrayContainer p) { - parent = p; - if (!p.isArrayBacked()) { - throw new RuntimeException("internal bug"); - } - content = p.content.array(); - pos = 0; - } - - - @Override - public void advanceIfNeeded(short minval) { - pos = Util.advanceUntil(content, pos - 1, parent.cardinality, minval); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < parent.cardinality; - } - - @Override - public short next() { - return content[pos++]; - } - - @Override - public int nextAsInt() { - return BufferUtil.toIntUnsigned(content[pos++]); - } - - @Override - public short peekNext() { - return content[pos]; - } - - @Override - public void remove() { - parent.remove((short) (pos - 1)); - pos--; - } - -} - - -final class RawReverseArrayContainerShortIterator implements ShortIterator { - int pos; - MappeableArrayContainer parent; - short[] content; - - - RawReverseArrayContainerShortIterator(MappeableArrayContainer p) { - parent = p; - if (!p.isArrayBacked()) { - throw new RuntimeException("internal bug"); - } - content = p.content.array(); - pos = parent.cardinality - 1; - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - - @Override - public short next() { - return content[pos--]; - } - - @Override - public int nextAsInt() { - return BufferUtil.toIntUnsigned(content[pos--]); - } - - @Override - public void remove() { - parent.remove((short) (pos + 1)); - pos++; - } - -}; - - -final class ReverseMappeableArrayContainerShortIterator implements ShortIterator { - - int pos; - - MappeableArrayContainer parent; - - ReverseMappeableArrayContainerShortIterator() { - } - - - ReverseMappeableArrayContainerShortIterator(MappeableArrayContainer p) { - wrap(p); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - @Override - public short next() { - return parent.content.get(pos--); - } - - - @Override - public int nextAsInt() { - return BufferUtil.toIntUnsigned(parent.content.get(pos--)); - } - - @Override - public void remove() { - parent.remove((short) (pos + 1)); - pos++; - } - - void wrap(MappeableArrayContainer p) { - parent = p; - pos = parent.cardinality - 1; - } - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableBitmapContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableBitmapContainer.java deleted file mode 100644 index 9d1178aab..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableBitmapContainer.java +++ /dev/null @@ -1,2012 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.BitmapContainer; -import com.fr.third.bitmap.roaringbitmap.Container; -import com.fr.third.bitmap.roaringbitmap.IntConsumer; -import com.fr.third.bitmap.roaringbitmap.PeekableShortIterator; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.LongBuffer; -import java.util.Iterator; - -/** - * Simple bitset-like container. Unlike BitmapContainer, this class uses a - * LongBuffer to store data. - */ -public final class MappeableBitmapContainer extends MappeableContainer implements Cloneable { - /** - * optimization flag: whether the cardinality of the bitmaps is maintained through branchless - * operation - */ - public static final boolean USE_BRANCHLESS = true; - protected static final int MAX_CAPACITY = 1 << 16; - private static final long serialVersionUID = 2L; - // 64 words can have max 32 runs per word, max 2k runs - // bail out early when the number of runs is excessive, without - // an exact count (just a decent lower bound) - private static final int BLOCKSIZE = 128; - // nruns value for which RunContainer.serializedSizeInBytes == - // BitmapContainer.getArraySizeInBytes() - private final int MAXRUNS = (getArraySizeInBytes() - 2) / 4; - LongBuffer bitmap; - - int cardinality; - - /** - * Create a bitmap container with all bits set to false - */ - public MappeableBitmapContainer() { - this.cardinality = 0; - this.bitmap = LongBuffer.allocate(MAX_CAPACITY / 64); - } - - /** - * Creates a new bitmap container from a non-mappeable one. This copies the data. - * - * @param bc the original container - */ - public MappeableBitmapContainer(BitmapContainer bc) { - this.cardinality = bc.getCardinality(); - this.bitmap = bc.toLongBuffer(); - } - - /** - * Create a bitmap container with a run of ones from firstOfRun to lastOfRun, inclusive caller - * must ensure that the range isn't so small that an ArrayContainer should have been created - * instead - * - * @param firstOfRun first index - * @param lastOfRun last index (range is exclusive) - */ - public MappeableBitmapContainer(final int firstOfRun, final int lastOfRun) { - // TODO: this can be optimized for performance - this.cardinality = lastOfRun - firstOfRun; - this.bitmap = LongBuffer.allocate(MAX_CAPACITY / 64); - Util.setBitmapRange(bitmap.array(), firstOfRun, lastOfRun); - } - - MappeableBitmapContainer(int newCardinality, LongBuffer newBitmap) { - this.cardinality = newCardinality; - LongBuffer tmp = newBitmap.duplicate(); // for thread safety - this.bitmap = LongBuffer.allocate(tmp.limit()); - tmp.rewind(); - this.bitmap.put(tmp); - } - - - /** - * Construct a new BitmapContainer backed by the provided LongBuffer. - * - * @param array LongBuffer where the data is stored - * @param initCardinality cardinality (number of values stored) - */ - public MappeableBitmapContainer(final LongBuffer array, final int initCardinality) { - if (array.limit() != MAX_CAPACITY / 64) { - throw new RuntimeException("Mismatch between buffer and storage requirements: " - + array.limit() + " vs. " + MAX_CAPACITY / 64); - } - this.cardinality = initCardinality; - this.bitmap = array; - } - - // the parameter is for overloading and symmetry with ArrayContainer - protected static int serializedSizeInBytes(int unusedCardinality) { - return MAX_CAPACITY / 8; - } - - @Override - public MappeableContainer add(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - MappeableBitmapContainer answer = clone(); - BufferUtil.setBitmapRange(answer.bitmap, begin, end); - answer.computeCardinality(); - return answer; - } - - - @Override - public MappeableContainer add(final short i) { - final int x = BufferUtil.toIntUnsigned(i); - final long previous = bitmap.get(x / 64); - final long newv = previous | (1L << x); - bitmap.put(x / 64, newv); - if (USE_BRANCHLESS) { - cardinality += (previous ^ newv) >>> x; - } else if (previous != newv) { - cardinality++; - } - return this; - } - - @Override - public MappeableArrayContainer and(final MappeableArrayContainer value2) { - - final MappeableArrayContainer answer = new MappeableArrayContainer(value2.content.limit()); - if (!BufferUtil.isBackedBySimpleArray(answer.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - short[] sarray = answer.content.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] c = value2.content.array(); - int ca = value2.cardinality; - for (int k = 0; k < ca; ++k) { - short v = c[k]; - if (this.contains(v)) { - sarray[answer.cardinality++] = v; - } - } - - } else { - int ca = value2.cardinality; - for (int k = 0; k < ca; ++k) { - short v = value2.content.get(k); - if (this.contains(v)) { - sarray[answer.cardinality++] = v; - } - } - } - return answer; - } - - @Override - public MappeableContainer and(final MappeableBitmapContainer value2) { - int newCardinality = 0; - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] tb = this.bitmap.array(); - long[] v2b = value2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(tb[k] & v2b[k]); - } - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(this.bitmap.get(k) & value2.bitmap.get(k)); - } - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - final MappeableBitmapContainer answer = new MappeableBitmapContainer(); - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = answer.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] tb = this.bitmap.array(); - long[] v2b = value2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitArray[k] = tb[k] & v2b[k]; - } - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitArray[k] = this.bitmap.get(k) & value2.bitmap.get(k); - } - } - answer.cardinality = newCardinality; - return answer; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - Util.fillArrayAND(ac.content.array(), this.bitmap.array(), - value2.bitmap.array()); - } else { - BufferUtil.fillArrayAND(ac.content.array(), this.bitmap, value2.bitmap); - } - ac.cardinality = newCardinality; - return ac; - } - - @Override - public MappeableContainer and(final MappeableRunContainer value2) { - return value2.and(this); - } - - - @Override - public MappeableContainer andNot(final MappeableArrayContainer value2) { - final MappeableBitmapContainer answer = clone(); - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = answer.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content) - && BufferUtil.isBackedBySimpleArray(this.bitmap)) { - short[] v2 = value2.content.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = v2[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - long w = bitArray[i]; - long aft = w & (~(1L << v)); - bitArray[i] = aft; - answer.cardinality -= (w ^ aft) >>> v; - } - } else { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - long w = bitArray[i]; - long aft = bitArray[i] & (~(1L << v2)); - bitArray[i] = aft; - answer.cardinality -= (w ^ aft) >>> v2; - } - } - if (answer.cardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer.toArrayContainer(); - } - return answer; - } - - - @Override - public MappeableContainer andNot(final MappeableBitmapContainer value2) { - - int newCardinality = 0; - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] b = this.bitmap.array(); - long[] v2 = value2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(b[k] & (~v2[k])); - } - - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(this.bitmap.get(k) & (~value2.bitmap.get(k))); - } - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - final MappeableBitmapContainer answer = new MappeableBitmapContainer(); - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = answer.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] b = this.bitmap.array(); - long[] v2 = value2.bitmap.array(); - int len = answer.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitArray[k] = b[k] & (~v2[k]); - } - } else { - int len = answer.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitArray[k] = this.bitmap.get(k) & (~value2.bitmap.get(k)); - } - } - answer.cardinality = newCardinality; - return answer; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - Util.fillArrayANDNOT(ac.content.array(), this.bitmap.array(), - value2.bitmap.array()); - } else { - BufferUtil.fillArrayANDNOT(ac.content.array(), this.bitmap, value2.bitmap); - } - ac.cardinality = newCardinality; - return ac; - } - - @Override - public MappeableContainer andNot(final MappeableRunContainer value2) { - MappeableBitmapContainer answer = this.clone(); - if (BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - long[] b = answer.bitmap.array(); - for (int rlepos = 0; rlepos < value2.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(value2.getValue(rlepos)); - int end = BufferUtil.toIntUnsigned(value2.getValue(rlepos)) - + BufferUtil.toIntUnsigned(value2.getLength(rlepos)) + 1; - Util.resetBitmapRange(b, start, end); - } - } else { - for (int rlepos = 0; rlepos < value2.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(value2.getValue(rlepos)); - int end = BufferUtil.toIntUnsigned(value2.getValue(rlepos)) - + BufferUtil.toIntUnsigned(value2.getLength(rlepos)) + 1; - BufferUtil.resetBitmapRange(answer.bitmap, start, end); - } - } - answer.computeCardinality(); - if (answer.getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public void clear() { - if (cardinality != 0) { - cardinality = 0; - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitmap.put(k, 0); - } - } - } - - - @Override - public MappeableBitmapContainer clone() { - return new MappeableBitmapContainer(this.cardinality, this.bitmap); - } - - /** - * Recomputes the cardinality of the bitmap. - */ - protected void computeCardinality() { - this.cardinality = 0; - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = this.bitmap.array(); - for (int k = 0; k < b.length; k++) { - this.cardinality += Long.bitCount(b[k]); - } - } else { - int m = this.bitmap.limit(); - for (int k = 0; k < m; k++) { - this.cardinality += Long.bitCount(this.bitmap.get(k)); - } - } - } - - @Override - public boolean contains(final short i) { - final int x = BufferUtil.toIntUnsigned(i); - return (bitmap.get(x / 64) & (1L << x)) != 0; - } - - @Override - - public boolean equals(Object o) { - if (o instanceof MappeableBitmapContainer) { - final MappeableBitmapContainer srb = (MappeableBitmapContainer) o; - if (srb.cardinality != this.cardinality) { - return false; - } - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(srb.bitmap)) { - long[] b = this.bitmap.array(); - long[] s = srb.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - if (b[k] != s[k]) { - return false; - } - } - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - if (this.bitmap.get(k) != srb.bitmap.get(k)) { - return false; - } - } - } - return true; - - } else if (o instanceof MappeableRunContainer) { - return o.equals(this); - } - return false; - } - - /** - * Fill the array with set bits - * - * @param array container (should be sufficiently large) - */ - protected void fillArray(final short[] array) { - int pos = 0; - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = bitmap.array(); - int base = 0; - for (int k = 0; k < b.length; ++k) { - long bitset = b[k]; - while (bitset != 0) { - final long t = bitset & -bitset; - array[pos++] = (short) (base + Long.bitCount(t - 1)); - bitset ^= t; - } - base += 64; - } - - } else { - int len = this.bitmap.limit(); - int base = 0; - for (int k = 0; k < len; ++k) { - long bitset = bitmap.get(k); - while (bitset != 0) { - final long t = bitset & -bitset; - array[pos++] = (short) (base + Long.bitCount(t - 1)); - bitset ^= t; - } - base += 64; - } - } - } - - @Override - public void fillLeastSignificant16bits(int[] x, int i, int mask) { - int pos = i; - int base = mask; - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - long bitset = b[k]; - while (bitset != 0) { - final long t = bitset & -bitset; - x[pos++] = base + Long.bitCount(t - 1); - bitset ^= t; - } - base += 64; - } - - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - long bitset = bitmap.get(k); - while (bitset != 0) { - final long t = bitset & -bitset; - x[pos++] = base + Long.bitCount(t - 1); - bitset ^= t; - } - base += 64; - } - } - } - - @Override - public MappeableContainer flip(short i) { - final int x = BufferUtil.toIntUnsigned(i); - final long bef = bitmap.get(x / 64); - final long mask = 1L << x; - if (cardinality == MappeableArrayContainer.DEFAULT_MAX_SIZE + 1) {// this - // is - // the - // uncommon - // path - if ((bef & mask) != 0) { - --cardinality; - bitmap.put(x / 64, bef & ~mask); - return this.toArrayContainer(); - } - } - long aft = bef ^ mask; - ; - // TODO: check whether a branchy version could be faster - cardinality += 1 - 2 * ((bef & mask) >>> x); - bitmap.put(x / 64, aft); - return this; - } - - - @Override - protected int getArraySizeInBytes() { - return MAX_CAPACITY / 8; - } - - - @Override - public int getCardinality() { - return cardinality; - } - - @Override - public ShortIterator getReverseShortIterator() { - if (this.isArrayBacked()) { - return BitmapContainer.getReverseShortIterator(bitmap.array()); - } - return new ReverseMappeableBitmapContainerShortIterator(this); - } - - @Override - public PeekableShortIterator getShortIterator() { - if (this.isArrayBacked()) { - return BitmapContainer.getShortIterator(bitmap.array()); - } - return new MappeableBitmapContainerShortIterator(this); - } - - @Override - public int getSizeInBytes() { - return this.bitmap.limit() * 8; - } - - @Override - public int hashCode() { - long hash = 0; - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - hash += 31 * hash + this.bitmap.get(k); - } - return (int) hash; - } - - @Override - public MappeableContainer iadd(int begin, int end) { - // TODO: may need to convert to a RunContainer - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - BufferUtil.setBitmapRange(bitmap, begin, end); - computeCardinality(); - return this; - } - - @Override - public MappeableContainer iand(final MappeableArrayContainer b2) { - return b2.and(this);// no inplace possible - } - - - @Override - public MappeableContainer iand(final MappeableBitmapContainer b2) { - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(b2.bitmap)) { - int newCardinality = 0; - long[] tb = this.bitmap.array(); - long[] tb2 = b2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(tb[k] & tb2[k]); - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < len; ++k) { - tb[k] &= tb2[k]; - } - this.cardinality = newCardinality; - return this; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - BufferUtil.fillArrayAND(ac.content.array(), this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } else { - int newCardinality = 0; - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(this.bitmap.get(k) & b2.bitmap.get(k)); - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < len; ++k) { - this.bitmap.put(k, this.bitmap.get(k) & b2.bitmap.get(k)); - } - this.cardinality = newCardinality; - return this; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - BufferUtil.fillArrayAND(ac.content.array(), this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - } - - @Override - public MappeableContainer iand(final MappeableRunContainer x) { - final int card = x.getCardinality(); - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - // no point in doing it in-place - MappeableArrayContainer answer = new MappeableArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(x.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (this.contains((short) runValue)) { - answer.content.put(answer.cardinality++, (short) runValue); - } - } - } - return answer; - } - int start = 0; - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int end = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - BufferUtil.resetBitmapRange(this.bitmap, start, end); - start = end + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - } - BufferUtil.resetBitmapRange(this.bitmap, start, BufferUtil.maxLowBitAsInteger() + 1); - computeCardinality(); - if (getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - } - - @Override - public MappeableContainer iandNot(final MappeableArrayContainer b2) { - for (int k = 0; k < b2.cardinality; ++k) { - this.remove(b2.content.get(k)); - } - if (cardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this.toArrayContainer(); - } - return this; - } - - - @Override - public MappeableContainer iandNot(final MappeableBitmapContainer b2) { - int newCardinality = 0; - if (!BufferUtil.isBackedBySimpleArray(bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = this.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(b2.bitmap)) { - long[] b2Arr = b2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(b[k] & (~b2Arr[k])); - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < len; ++k) { - this.bitmap.put(k, b[k] & (~b2Arr[k])); - } - this.cardinality = newCardinality; - return this; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - Util.fillArrayANDNOT(ac.content.array(), b, b2Arr); - ac.cardinality = newCardinality; - return ac; - - } - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(b[k] & (~b2.bitmap.get(k))); - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < len; ++k) { - b[k] &= (~b2.bitmap.get(k)); - } - this.cardinality = newCardinality; - return this; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - - BufferUtil.fillArrayANDNOT(ac.content.array(), this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public MappeableContainer iandNot(final MappeableRunContainer x) { - if (BufferUtil.isBackedBySimpleArray(this.bitmap)) { - long[] b = this.bitmap.array(); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.resetBitmapRange(b, start, end); - } - computeCardinality(); - if (getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - } - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - BufferUtil.resetBitmapRange(this.bitmap, start, end); - } - computeCardinality(); - if (getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - - } - - protected MappeableContainer ilazyor(MappeableArrayContainer value2) { - this.cardinality = -1;// invalid - if (!BufferUtil.isBackedBySimpleArray(bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = this.bitmap.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - b[i] |= (1L << v2); - } - return this; - } - - protected MappeableContainer ilazyor(MappeableBitmapContainer x) { - if (BufferUtil.isBackedBySimpleArray(x.bitmap)) { - long[] b = this.bitmap.array(); - long[] b2 = x.bitmap.array(); - for (int k = 0; k < b.length; k++) { - b[k] |= b2[k]; - } - } else { - final int m = this.bitmap.limit(); - for (int k = 0; k < m; k++) { - this.bitmap.put(k, this.bitmap.get(k) | x.bitmap.get(k)); - } - } - this.cardinality = -1;// invalid - return this; - } - - - protected MappeableContainer ilazyor(MappeableRunContainer x) { - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(this.bitmap, start, end); - } - this.cardinality = -1; - return this; - } - - @Override - public MappeableContainer inot(final int firstOfRange, final int lastOfRange) { - if (lastOfRange - firstOfRange == MAX_CAPACITY) { - BufferUtil.flipBitmapRange(bitmap, firstOfRange, lastOfRange); - cardinality = MAX_CAPACITY - cardinality; - } else if (lastOfRange - firstOfRange > MAX_CAPACITY / 2) { - BufferUtil.flipBitmapRange(bitmap, firstOfRange, lastOfRange); - computeCardinality(); - } else { - cardinality += - BufferUtil.flipBitmapRangeAndCardinalityChange(bitmap, firstOfRange, lastOfRange); - } - if (cardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return toArrayContainer(); - } - return this; - } - - - @Override - public boolean intersects(MappeableArrayContainer value2) { - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] c = value2.content.array(); - int ca = value2.cardinality; - for (int k = 0; k < ca; ++k) { - if (this.contains(c[k])) { - return true; - } - } - - } else { - int ca = value2.cardinality; - for (int k = 0; k < ca; ++k) { - short v = value2.content.get(k); - if (this.contains(v)) { - return true; - } - } - } - return false; - } - - @Override - public boolean intersects(MappeableBitmapContainer value2) { - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] tb = this.bitmap.array(); - long[] v2b = value2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - if ((tb[k] & v2b[k]) != 0) { - return true; - } - } - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - if ((this.bitmap.get(k) & value2.bitmap.get(k)) != 0) { - return true; - } - } - } - return false; - } - - @Override - public boolean intersects(MappeableRunContainer x) { - return x.intersects(this); - } - - - @Override - public MappeableBitmapContainer ior(final MappeableArrayContainer value2) { - if (!BufferUtil.isBackedBySimpleArray(this.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = this.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] v2 = value2.content.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - final int i = BufferUtil.toIntUnsigned(v2[k]) >>> 6; - long bef = b[i]; - long aft = bef | (1L << v2[k]); - b[i] = aft; - if (USE_BRANCHLESS) { - cardinality += (bef - aft) >>> 63; - } else { - if (aft != bef) { - cardinality++; - } - } - } - return this; - } - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - long bef = b[i]; - long aft = bef | (1L << v2); - b[i] = aft; - if (USE_BRANCHLESS) { - cardinality += (bef - aft) >>> 63; - } else { - if (aft != bef) { - cardinality++; - } - } - } - return this; - } - - @Override - public MappeableContainer ior(final MappeableBitmapContainer b2) { - if (!BufferUtil.isBackedBySimpleArray(bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = this.bitmap.array(); - this.cardinality = 0; - if (BufferUtil.isBackedBySimpleArray(b2.bitmap)) { - long[] b2Arr = b2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; k++) { - long w = b[k] | b2Arr[k]; - b[k] = w; - this.cardinality += Long.bitCount(w); - } - return this; - } - int len = this.bitmap.limit(); - for (int k = 0; k < len; k++) { - long w = b[k] | b2.bitmap.get(k); - b[k] = w; - this.cardinality += Long.bitCount(w); - } - return this; - } - - @Override - public MappeableContainer ior(final MappeableRunContainer x) { - if (BufferUtil.isBackedBySimpleArray(this.bitmap)) { - long[] b = this.bitmap.array(); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.setBitmapRange(b, start, end); - } - } else { - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(this.bitmap, start, end); - } - } - computeCardinality(); - return this; - } - - @Override - public MappeableContainer iremove(int begin, int end) { - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - BufferUtil.resetBitmapRange(bitmap, begin, end); - computeCardinality(); - if (getCardinality() < MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return toArrayContainer(); - } - return this; - } - - @Override - protected boolean isArrayBacked() { - return BufferUtil.isBackedBySimpleArray(this.bitmap); - } - - @Override - public Iterator iterator() { - return new Iterator() { - final ShortIterator si = MappeableBitmapContainer.this.getShortIterator(); - - @Override - public boolean hasNext() { - return si.hasNext(); - } - - @Override - public Short next() { - return si.next(); - } - - @Override - public void remove() { - // TODO: implement - throw new RuntimeException("unsupported operation: remove"); - } - }; - } - - @Override - public MappeableContainer ixor(final MappeableArrayContainer value2) { - if (!BufferUtil.isBackedBySimpleArray(bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] v2 = value2.content.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short vc = v2[k]; - long mask = 1L << v2[k]; - final int index = BufferUtil.toIntUnsigned(vc) >>> 6; - long ba = b[index]; - // TODO: check whether a branchy version could be faster - this.cardinality += 1 - 2 * ((ba & mask) >>> vc); - b[index] = ba ^ mask; - } - - } else { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - long mask = 1L << v2; - final int index = BufferUtil.toIntUnsigned(v2) >>> 6; - long ba = b[index]; - // TODO: check whether a branchy version could be faster - this.cardinality += 1 - 2 * ((ba & mask) >>> v2); - b[index] = ba ^ mask; - } - } - if (this.cardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this.toArrayContainer(); - } - return this; - } - - @Override - public MappeableContainer ixor(MappeableBitmapContainer b2) { - if (!BufferUtil.isBackedBySimpleArray(bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(b2.bitmap)) { - long[] b2Arr = b2.bitmap.array(); - - int newCardinality = 0; - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(b[k] ^ b2Arr[k]); - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < len; ++k) { - b[k] ^= b2Arr[k]; - } - this.cardinality = newCardinality; - return this; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - - Util.fillArrayXOR(ac.content.array(), b, b2Arr); - ac.cardinality = newCardinality; - return ac; - - } - int newCardinality = 0; - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(b[k] ^ b2.bitmap.get(k)); - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - for (int k = 0; k < len; ++k) { - b[k] ^= b2.bitmap.get(k); - } - this.cardinality = newCardinality; - return this; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - - BufferUtil.fillArrayXOR(ac.content.array(), this.bitmap, b2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public MappeableContainer ixor(final MappeableRunContainer x) { - if (BufferUtil.isBackedBySimpleArray(this.bitmap)) { - long[] b = this.bitmap.array(); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.flipBitmapRange(b, start, end); - } - } else { - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - BufferUtil.flipBitmapRange(this.bitmap, start, end); - } - } - computeCardinality(); - if (this.getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this; - } else { - return toArrayContainer(); - } - } - - protected MappeableContainer lazyor(MappeableArrayContainer value2) { - MappeableBitmapContainer answer = clone(); - answer.cardinality = -1;// invalid - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = answer.bitmap.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - b[i] |= 1L << v2; - } - return answer; - } - - protected MappeableContainer lazyor(MappeableBitmapContainer x) { - MappeableBitmapContainer answer = new MappeableBitmapContainer(); - answer.cardinality = -1;// invalid - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] b = answer.bitmap.array(); - for (int k = 0; k < b.length; k++) { - b[k] = this.bitmap.get(k) | x.bitmap.get(k); - } - return answer; - } - - protected MappeableContainer lazyor(MappeableRunContainer x) { - MappeableBitmapContainer bc = clone(); - bc.cardinality = -1; - if (BufferUtil.isBackedBySimpleArray(bc.bitmap)) { - long[] b = bc.bitmap.array(); - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - Util.setBitmapRange(b, start, end); - } - return bc; - - } - for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(x.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(x.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(bc.bitmap, start, end); - } - return bc; - } - - @Override - public MappeableContainer limit(int maxcardinality) { - if (maxcardinality >= this.cardinality) { - return clone(); - } - if (maxcardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - MappeableArrayContainer ac = new MappeableArrayContainer(maxcardinality); - int pos = 0; - if (!BufferUtil.isBackedBySimpleArray(ac.content)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - short[] cont = ac.content.array(); - int len = this.bitmap.limit(); - for (int k = 0; (ac.cardinality < maxcardinality) && (k < len); ++k) { - long bitset = bitmap.get(k); - while ((ac.cardinality < maxcardinality) && (bitset != 0)) { - long t = bitset & -bitset; - cont[pos++] = (short) (k * 64 + Long.bitCount(t - 1)); - ac.cardinality++; - bitset ^= t; - } - } - return ac; - } - MappeableBitmapContainer bc = new MappeableBitmapContainer(maxcardinality, this.bitmap); - int s = BufferUtil.toIntUnsigned(select(maxcardinality)); - int usedwords = (s + 63) / 64; - int len = this.bitmap.limit(); - int todelete = len - usedwords; - for (int k = 0; k < todelete; ++k) { - bc.bitmap.put(len - 1 - k, 0); - } - int lastword = s % 64; - if (lastword != 0) { - bc.bitmap.put(s / 64, (bc.bitmap.get(s / 64) & (0xFFFFFFFFFFFFFFFFL >>> (64 - lastword)))); - } - return bc; - } - - protected void loadData(final MappeableArrayContainer arrayContainer) { - this.cardinality = arrayContainer.cardinality; - if (!BufferUtil.isBackedBySimpleArray(bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(bitmap) - && BufferUtil.isBackedBySimpleArray(arrayContainer.content)) { - long[] b = bitmap.array(); - short[] ac = arrayContainer.content.array(); - for (int k = 0; k < arrayContainer.cardinality; ++k) { - final short x = ac[k]; - bitArray[BufferUtil.toIntUnsigned(x) / 64] = - b[BufferUtil.toIntUnsigned(x) / 64] | (1L << x); - } - - } else { - for (int k = 0; k < arrayContainer.cardinality; ++k) { - final short x = arrayContainer.content.get(k); - bitArray[BufferUtil.toIntUnsigned(x) / 64] = - bitmap.get(BufferUtil.toIntUnsigned(x) / 64) | (1L << x); - } - } - } - - /** - * Find the index of the next set bit greater or equal to i, returns -1 if none found. - * - * @param i starting index - * @return index of the next set bit - */ - public int nextSetBit(final int i) { - int x = i >> 6; // signed i / 64 - long w = bitmap.get(x); - w >>>= i; - if (w != 0) { - return i + Long.numberOfTrailingZeros(w); - } - // for speed, replaced bitmap.limit() with hardcoded MAX_CAPACITY / 64 - for (++x; x < MAX_CAPACITY / 64; ++x) { - long X = bitmap.get(x); - if (X != 0) { - return x * 64 + Long.numberOfTrailingZeros(X); - } - } - return -1; - } - - /** - * Find the index of the next unset bit greater or equal to i, returns -1 if none found. - * - * @param i starting index - * @return index of the next unset bit - */ - public short nextUnsetBit(final int i) { - int x = i / 64; - long w = ~bitmap.get(x); - w >>>= i; - if (w != 0) { - return (short) (i + Long.numberOfTrailingZeros(w)); - } - ++x; - // for speed, replaced bitmap.limit() with hardcoded MAX_CAPACITY / 64 - for (; x < MAX_CAPACITY / 64; ++x) { - long X = bitmap.get(x); - if (X != ~0L) { - return (short) (x * 64 + Long.numberOfTrailingZeros(~X)); - } - } - return -1; - } - - @Override - public MappeableContainer not(final int firstOfRange, final int lastOfRange) { - MappeableBitmapContainer answer = clone(); - return answer.inot(firstOfRange, lastOfRange); - } - - - @Override - int numberOfRuns() { - if (BufferUtil.isBackedBySimpleArray(this.bitmap)) { - long[] src = this.bitmap.array(); - int numRuns = 0; - long nextWord = src[0]; - - for (int i = 0; i < src.length - 1; i++) { - long word = nextWord; - nextWord = src[i + 1]; - numRuns += Long.bitCount((~word) & (word << 1)) + ((word >>> 63) & ~nextWord); - } - - long word = nextWord; - numRuns += Long.bitCount((~word) & (word << 1)); - if ((word & 0x8000000000000000L) != 0) { - numRuns++; - } - - return numRuns; - } else { - int numRuns = 0; - long nextWord = bitmap.get(0); - int len = bitmap.limit(); - - for (int i = 0; i < len - 1; i++) { - long word = nextWord; - nextWord = bitmap.get(i + 1); - numRuns += Long.bitCount((~word) & (word << 1)) + ((word >>> 63) & ~nextWord); - } - - long word = nextWord; - numRuns += Long.bitCount((~word) & (word << 1)); - if ((word & 0x8000000000000000L) != 0) { - numRuns++; - } - - return numRuns; - - } - } - - /** - * Computes the number of runs - * - * @return the number of runs - */ - public int numberOfRunsAdjustment() { - int ans = 0; - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = bitmap.array(); - long nextWord = b[0]; - for (int i = 0; i < b.length - 1; i++) { - final long word = nextWord; - - nextWord = b[i + 1]; - ans += ((word >>> 63) & ~nextWord); - } - - final long word = nextWord; - - if ((word & 0x8000000000000000L) != 0) { - ans++; - } - - } else { - long nextWord = bitmap.get(0); - int len = bitmap.limit(); - for (int i = 0; i < len - 1; i++) { - final long word = nextWord; - - nextWord = bitmap.get(i + 1); - ans += ((word >>> 63) & ~nextWord); - } - - final long word = nextWord; - - if ((word & 0x8000000000000000L) != 0) { - ans++; - } - } - return ans; - } - - /** - * Counts how many runs there is in the bitmap, up to a maximum - * - * @param mustNotExceed maximum of runs beyond which counting is pointless - * @return estimated number of courses - */ - public int numberOfRunsLowerBound(int mustNotExceed) { - int numRuns = 0; - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = bitmap.array(); - - for (int blockOffset = 0; blockOffset < b.length; blockOffset += BLOCKSIZE) { - - for (int i = blockOffset; i < blockOffset + BLOCKSIZE; i++) { - long word = b[i]; - numRuns += Long.bitCount((~word) & (word << 1)); - } - if (numRuns > mustNotExceed) { - return numRuns; - } - } - } else { - int len = bitmap.limit(); - for (int blockOffset = 0; blockOffset < len; blockOffset += BLOCKSIZE) { - - for (int i = blockOffset; i < blockOffset + BLOCKSIZE; i++) { - long word = bitmap.get(i); - numRuns += Long.bitCount((~word) & (word << 1)); - } - if (numRuns > mustNotExceed) { - return numRuns; - } - } - } - return numRuns; - } - - - @Override - public MappeableBitmapContainer or(final MappeableArrayContainer value2) { - final MappeableBitmapContainer answer = clone(); - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = answer.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(answer.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.content)) { - long[] ab = answer.bitmap.array(); - short[] v2 = value2.content.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = v2[k]; - final int i = BufferUtil.toIntUnsigned(v) >>> 6; - long w = ab[i]; - long aft = w | (1L << v); - bitArray[i] = aft; - if (USE_BRANCHLESS) { - answer.cardinality += (w - aft) >>> 63; - } else { - if (w != aft) { - answer.cardinality++; - } - } - } - } else { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - final int i = BufferUtil.toIntUnsigned(v2) >>> 6; - long w = answer.bitmap.get(i); - long aft = w | (1L << v2); - bitArray[i] = aft; - if (USE_BRANCHLESS) { - answer.cardinality += (w - aft) >>> 63; - } else { - if (w != aft) { - answer.cardinality++; - } - } - } - } - return answer; - } - - - @Override - public MappeableContainer or(final MappeableBitmapContainer value2) { - final MappeableBitmapContainer value1 = this.clone(); - return value1.ior(value2); - } - - @Override - public MappeableContainer or(final MappeableRunContainer value2) { - return value2.or(this); - } - - - /** - * Find the index of the previous set bit less than or equal to i, returns -1 if none found. - * - * @param i starting index - * @return index of the previous set bit - */ - public int prevSetBit(final int i) { - int x = i >> 6; // signed i / 64 - long w = bitmap.get(x); - w <<= 64 - i - 1; - if (w != 0) { - return i - Long.numberOfLeadingZeros(w); - } - for (--x; x >= 0; --x) { - long X = bitmap.get(x); - if (X != 0) { - return x * 64 + 63 - Long.numberOfLeadingZeros(X); - } - } - return -1; - } - - @Override - public int rank(short lowbits) { - int x = BufferUtil.toIntUnsigned(lowbits); - int leftover = (x + 1) & 63; - int answer = 0; - if (BufferUtil.isBackedBySimpleArray(this.bitmap)) { - long[] b = this.bitmap.array(); - for (int k = 0; k < (x + 1) / 64; ++k) { - answer += Long.bitCount(b[k]); - } - if (leftover != 0) { - answer += Long.bitCount(b[(x + 1) / 64] << (64 - leftover)); - } - } else { - for (int k = 0; k < (x + 1) / 64; ++k) { - answer += Long.bitCount(bitmap.get(k)); - } - if (leftover != 0) { - answer += Long.bitCount(bitmap.get((x + 1) / 64) << (64 - leftover)); - } - } - return answer; - } - - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // little endian - this.cardinality = 0; - int len = this.bitmap.limit(); - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = this.bitmap.array(); - for (int k = 0; k < len; ++k) { - long w = Long.reverseBytes(in.readLong()); - b[k] = w; - this.cardinality += Long.bitCount(w); - } - } else { - for (int k = 0; k < len; ++k) { - long w = Long.reverseBytes(in.readLong()); - bitmap.put(k, w); - this.cardinality += Long.bitCount(w); - } - } - } - - @Override - public MappeableContainer remove(int begin, int end) { - if (end == begin) { - return clone(); - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - MappeableBitmapContainer answer = clone(); - BufferUtil.resetBitmapRange(answer.bitmap, begin, end); - answer.computeCardinality(); - if (answer.getCardinality() < MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer.toArrayContainer(); - } - return answer; - } - - - @Override - public MappeableContainer remove(final short i) { - final int x = BufferUtil.toIntUnsigned(i); - long X = bitmap.get(x / 64); - long mask = 1L << x; - - if (cardinality == MappeableArrayContainer.DEFAULT_MAX_SIZE + 1) {// this is - // the - // uncommon - // path - if ((X & mask) != 0) { - --cardinality; - bitmap.put(x / 64, X & (~mask)); - return this.toArrayContainer(); - } - } - long aft = X & ~(mask); - cardinality -= (aft - X) >>> 63; - bitmap.put(x / 64, aft); - return this; - } - - - @Override - public MappeableContainer repairAfterLazy() { - if (getCardinality() < 0) { - computeCardinality(); - if (getCardinality() <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return this.toArrayContainer(); - } - } - return this; - } - - @Override - public MappeableContainer runOptimize() { - int numRuns = numberOfRunsLowerBound(MAXRUNS); // decent choice - - int sizeAsRunContainerLowerBound = MappeableRunContainer.serializedSizeInBytes(numRuns); - - if (sizeAsRunContainerLowerBound >= getArraySizeInBytes()) { - return this; - } - // else numRuns is a relatively tight bound that needs to be exact - // in some cases (or if we need to make the runContainer the right - // size) - numRuns += numberOfRunsAdjustment(); - int sizeAsRunContainer = MappeableRunContainer.serializedSizeInBytes(numRuns); - - if (getArraySizeInBytes() > sizeAsRunContainer) { - return new MappeableRunContainer(this, numRuns); - } else { - return this; - } - } - - @Override - public short select(int j) { - int leftover = j; - if (BufferUtil.isBackedBySimpleArray(this.bitmap)) { - long[] b = this.bitmap.array(); - - for (int k = 0; k < b.length; ++k) { - int w = Long.bitCount(b[k]); - if (w > leftover) { - return (short) (k * 64 + Util.select(b[k], leftover)); - } - leftover -= w; - } - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - long X = bitmap.get(k); - int w = Long.bitCount(X); - if (w > leftover) { - return (short) (k * 64 + Util.select(X, leftover)); - } - leftover -= w; - } - } - throw new IllegalArgumentException("Insufficient cardinality."); - } - - @Override - public int serializedSizeInBytes() { - return serializedSizeInBytes(0); - } - - /** - * Copies the data to an array container - * - * @return the array container - */ - public MappeableArrayContainer toArrayContainer() { - final MappeableArrayContainer ac = new MappeableArrayContainer(cardinality); - ac.loadData(this); - if (ac.getCardinality() != cardinality) { - throw new RuntimeException("Internal error."); - } - return ac; - } - - @Override - public Container toContainer() { - return new BitmapContainer(this); - } - - /** - * Create a copy of the content of this container as a long array. This creates a copy. - * - * @return copy of the content as a long array - */ - public long[] toLongArray() { - long[] answer = new long[bitmap.limit()]; - bitmap.rewind(); - bitmap.get(answer); - return answer; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - final ShortIterator i = this.getShortIterator(); - sb.append("{"); - while (i.hasNext()) { - sb.append(i.next()); - if (i.hasNext()) { - sb.append(","); - } - } - sb.append("}"); - return sb.toString(); - } - - @Override - public void trim() { - } - - @Override - protected void writeArray(DataOutput out) throws IOException { - // little endian - int len = this.bitmap.limit(); - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = bitmap.array(); - for (int k = 0; k < len; ++k) { - out.writeLong(Long.reverseBytes(b[k])); - } - } else { - for (int k = 0; k < len; ++k) { - final long w = bitmap.get(k); - out.writeLong(Long.reverseBytes(w)); - } - } - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - writeArray(out); - } - - @Override - public MappeableContainer xor(final MappeableArrayContainer value2) { - final MappeableBitmapContainer answer = clone(); - if (!BufferUtil.isBackedBySimpleArray(answer.bitmap)) { - throw new RuntimeException("Should not happen. Internal bug."); - } - long[] bitArray = answer.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(value2.content)) { - short[] v2 = value2.content.array(); - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short vc = v2[k]; - long mask = 1L << vc; - final int index = BufferUtil.toIntUnsigned(vc) >>> 6; - long ba = bitArray[index]; - // TODO: check whether a branchy version could be faster - answer.cardinality += 1 - 2 * ((ba & mask) >>> vc); - bitArray[index] = ba ^ mask; - } - } else { - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v2 = value2.content.get(k); - long mask = 1L << v2; - final int index = BufferUtil.toIntUnsigned(v2) >>> 6; - long ba = bitArray[index]; - // TODO: check whether a branchy version could be faster - answer.cardinality += 1 - 2 * ((ba & mask) >>> v2); - bitArray[index] = ba ^ mask; - } - } - if (answer.cardinality <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer.toArrayContainer(); - } - return answer; - } - - @Override - public MappeableContainer xor(MappeableBitmapContainer value2) { - int newCardinality = 0; - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] b = this.bitmap.array(); - long[] v2 = value2.bitmap.array(); - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(b[k] ^ v2[k]); - } - } else { - int len = this.bitmap.limit(); - for (int k = 0; k < len; ++k) { - newCardinality += Long.bitCount(this.bitmap.get(k) ^ value2.bitmap.get(k)); - } - } - if (newCardinality > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - final MappeableBitmapContainer answer = new MappeableBitmapContainer(); - long[] bitArray = answer.bitmap.array(); - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] b = this.bitmap.array(); - long[] v2 = value2.bitmap.array(); - int len = answer.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitArray[k] = b[k] ^ v2[k]; - } - } else { - int len = answer.bitmap.limit(); - for (int k = 0; k < len; ++k) { - bitArray[k] = this.bitmap.get(k) ^ value2.bitmap.get(k); - } - } - answer.cardinality = newCardinality; - return answer; - } - final MappeableArrayContainer ac = new MappeableArrayContainer(newCardinality); - BufferUtil.fillArrayXOR(ac.content.array(), this.bitmap, value2.bitmap); - ac.cardinality = newCardinality; - return ac; - } - - @Override - public MappeableContainer xor(final MappeableRunContainer value2) { - return value2.xor(this); - } - - @Override - public void forEach(short msb, IntConsumer ic) { - int high = ((int) msb) << 16; - if (BufferUtil.isBackedBySimpleArray(bitmap)) { - long[] b = bitmap.array(); - for (int x = 0; x < b.length; ++x) { - long w = b[x]; - while (w != 0) { - long t = w & -w; - ic.accept((x * 64 + Long.bitCount(t - 1)) | high); - w ^= t; - } - } - } else { - int l = bitmap.limit(); - for (int x = 0; x < l; ++x) { - long w = bitmap.get(x); - while (w != 0) { - long t = w & -w; - ic.accept((x * 64 + Long.bitCount(t - 1)) | high); - w ^= t; - } - } - } - } - - - @Override - public int andCardinality(final MappeableArrayContainer value2) { - int answer = 0; - int c = value2.cardinality; - for (int k = 0; k < c; ++k) { - short v = value2.content.get(k); - if (this.contains(v)) { - answer++; - } - } - return answer; - } - - @Override - public int andCardinality(final MappeableBitmapContainer value2) { - int newCardinality = 0; - if (BufferUtil.isBackedBySimpleArray(this.bitmap) - && BufferUtil.isBackedBySimpleArray(value2.bitmap)) { - long[] b1 = this.bitmap.array(); - long[] b2 = value2.bitmap.array(); - for (int k = 0; k < b1.length; ++k) { - newCardinality += Long.bitCount(b1[k] & b2[k]); - } - } else { - final int size = this.bitmap.limit(); - for (int k = 0; k < size; ++k) { - newCardinality += Long.bitCount(this.bitmap.get(k) & value2.bitmap.get(k)); - } - } - return newCardinality; - } - - @Override - public int andCardinality(MappeableRunContainer x) { - return x.andCardinality(this); - } - - @Override - public MappeableBitmapContainer toBitmapContainer() { - return this; - } - - -} - - -final class MappeableBitmapContainerShortIterator implements PeekableShortIterator { - final static int len = MappeableBitmapContainer.MAX_CAPACITY / 64;// hard coded for speed - long w; - int x; - - - MappeableBitmapContainer parent; - - MappeableBitmapContainerShortIterator() { - } - - MappeableBitmapContainerShortIterator(MappeableBitmapContainer p) { - wrap(p); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return x < len; - } - - @Override - public short next() { - long t = w & -w; - short answer = (short) (x * 64 + Long.bitCount(t - 1)); - w ^= t; - while (w == 0) { - ++x; - if (x == len) { - break; - } - w = parent.bitmap.get(x); - } - return answer; - } - - @Override - public int nextAsInt() { - long t = w & -w; - int answer = x * 64 + Long.bitCount(t - 1); - w ^= t; - while (w == 0) { - ++x; - if (x == len) { - break; - } - w = parent.bitmap.get(x); - } - return answer; - } - - @Override - public void remove() { - // TODO: implement - throw new RuntimeException("unsupported operation: remove"); - } - - void wrap(MappeableBitmapContainer p) { - parent = p; - for (x = 0; x < len; ++x) { - if ((w = parent.bitmap.get(x)) != 0) { - break; - } - } - } - - @Override - public void advanceIfNeeded(short minval) { - if (BufferUtil.toIntUnsigned(minval) >= (x + 1) * 64) { - x = BufferUtil.toIntUnsigned(minval) / 64; - w = parent.bitmap.get(x); - while (w == 0) { - ++x; - if (x == len) { - return; - } - w = parent.bitmap.get(x); - } - } - while (hasNext() && (BufferUtil.toIntUnsigned(peekNext()) < BufferUtil.toIntUnsigned(minval))) { - next(); // could be optimized - } - - } - - @Override - public short peekNext() { - long t = w & -w; - return (short) (x * 64 + Long.bitCount(t - 1)); - } -} - - -final class ReverseMappeableBitmapContainerShortIterator implements ShortIterator { - - final static int len = MappeableBitmapContainer.MAX_CAPACITY / 64;// hard coded for speed - long w; - int x; - - MappeableBitmapContainer parent; - - ReverseMappeableBitmapContainerShortIterator() { - } - - ReverseMappeableBitmapContainerShortIterator(MappeableBitmapContainer p) { - wrap(p); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } - } - - @Override - public boolean hasNext() { - return x >= 0; - } - - @Override - public short next() { - long t = w & -w; - short answer = (short) ((x + 1) * 64 - 1 - Long.bitCount(t - 1)); - w ^= t; - while (w == 0) { - --x; - if (x < 0) { - break; - } - w = Long.reverse(parent.bitmap.get(x)); - } - return answer; - } - - @Override - public int nextAsInt() { - long t = w & -w; - int answer = (x + 1) * 64 - 1 - Long.bitCount(t - 1); - w ^= t; - while (w == 0) { - --x; - if (x < 0) { - break; - } - w = Long.reverse(parent.bitmap.get(x)); - } - return answer; - } - - @Override - public void remove() { - // TODO: implement - throw new RuntimeException("unsupported operation: remove"); - } - - public void wrap(MappeableBitmapContainer p) { - parent = p; - for (x = len - 1; x >= 0; --x) { - if ((w = Long.reverse(parent.bitmap.get(x))) != 0) { - break; - } - } - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableContainer.java deleted file mode 100644 index cb5d1fd85..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableContainer.java +++ /dev/null @@ -1,759 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.Container; -import com.fr.third.bitmap.roaringbitmap.IntConsumer; -import com.fr.third.bitmap.roaringbitmap.PeekableShortIterator; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; - -import java.io.DataOutput; -import java.io.Externalizable; -import java.io.IOException; - -/** - * Base container class. This class is similar to Container but meant to be used - * with memory mapping. - */ -public abstract class MappeableContainer implements Iterable, Cloneable, Externalizable { - /** - * Name of the various possible containers - */ - public static String ContainerNames[] = {"mappeablebitmap", "mappeablearray", "mappeablerun"}; - - /** - * Create a container initialized with a range of consecutive values - * - * @param start first index - * @param last last index (range is exclusive) - * @return a new container initialized with the specified values - */ - public static MappeableContainer rangeOfOnes(final int start, final int last) { - final int sizeAsArrayContainer = MappeableArrayContainer.serializedSizeInBytes(last - start); - final int sizeAsRunContainer = MappeableRunContainer.serializedSizeInBytes(1); - MappeableContainer answer = sizeAsRunContainer < sizeAsArrayContainer - ? new MappeableRunContainer() : new MappeableArrayContainer(); - answer = answer.iadd(start, last); - return answer; - } - - /** - * Return a new container with all shorts in [begin,end) added using an unsigned interpretation. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract MappeableContainer add(int begin, int end); - - /** - * Add a short to the container. May generate a new container. - * - * @param x short to be added - * @return the new container - */ - public abstract MappeableContainer add(short x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer and(MappeableArrayContainer x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer and(MappeableBitmapContainer x); - - protected MappeableContainer and(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return and((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return and((MappeableRunContainer) x); - } - return and((MappeableBitmapContainer) x); - - } - - protected abstract int andCardinality(MappeableArrayContainer x); - - protected abstract int andCardinality(MappeableBitmapContainer x); - - protected abstract int andCardinality(MappeableRunContainer x); - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public int andCardinality(MappeableContainer x) { - if (this.getCardinality() == 0) { - return 0; - } else if (x.getCardinality() == 0) { - return 0; - } else { - if (x instanceof MappeableArrayContainer) { - return andCardinality((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return andCardinality((MappeableBitmapContainer) x); - } - return andCardinality((MappeableRunContainer) x); - } - } - - /** - * Computes the bitwise AND of this container with another (intersection). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer and(MappeableRunContainer x); - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer andNot(MappeableArrayContainer x); - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer andNot(MappeableBitmapContainer x); - - protected MappeableContainer andNot(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return andNot((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return andNot((MappeableRunContainer) x); - } - - return andNot((MappeableBitmapContainer) x); - } - - /** - * Computes the bitwise ANDNOT of this container with another (difference). This container as well - * as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer andNot(MappeableRunContainer x); - - /** - * Empties the container - */ - public abstract void clear(); - - @Override - public abstract MappeableContainer clone(); - - /** - * Checks whether the contain contains the provided value - * - * @param x value to check - * @return whether the value is in the container - */ - public abstract boolean contains(short x); - - /** - * Fill the least significant 16 bits of the integer array, starting at index index, with the - * short values from this container. The caller is responsible to allocate enough room. The most - * significant 16 bits of each integer are given by the most significant bits of the provided - * mask. - * - * @param x provided array - * @param i starting index - * @param mask indicates most significant bits - */ - public abstract void fillLeastSignificant16bits(int[] x, int i, int mask); - - /** - * Add a short to the container if it is not present, otherwise remove it. May generate a new - * container. - * - * @param x short to be added - * @return the new container - */ - public abstract MappeableContainer flip(short x); - - /** - * Size of the underlying array - * - * @return size in bytes - */ - protected abstract int getArraySizeInBytes(); - - /** - * Computes the distinct number of short values in the container. Can be expected to run in - * constant time. - * - * @return the cardinality - */ - public abstract int getCardinality(); - - /** - * Get the name of this container. - * - * @return name of the container - */ - public String getContainerName() { - if (this instanceof MappeableBitmapContainer) { - return ContainerNames[0]; - } else if (this instanceof MappeableArrayContainer) { - return ContainerNames[1]; - } else { - return ContainerNames[2]; - } - } - - /** - * Iterator to visit the short values in the container in descending order. - * - * @return iterator - */ - public abstract ShortIterator getReverseShortIterator(); - - - /** - * Iterator to visit the short values in the container in ascending order. - * - * @return iterator - */ - public abstract PeekableShortIterator getShortIterator(); - - - /** - * Iterate through the values of this container and pass them - * along to the IntConsumer, using msb as the 16 most significant bits. - * - * @param msb 16 most significant bits - * @param ic consumer - */ - public abstract void forEach(short msb, IntConsumer ic); - - /** - * Computes an estimate of the memory usage of this container. The estimate is not meant to be - * exact. - * - * @return estimated memory usage in bytes - */ - public abstract int getSizeInBytes(); - - /** - * Add all shorts in [begin,end) using an unsigned interpretation. May generate a new container. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract MappeableContainer iadd(int begin, int end); - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer iand(MappeableArrayContainer x); - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer iand(MappeableBitmapContainer x); - - - protected MappeableContainer iand(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return iand((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return iand((MappeableRunContainer) x); - } - - return iand((MappeableBitmapContainer) x); - - } - - /** - * Computes the in-place bitwise AND of this container with another (intersection). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer iand(MappeableRunContainer x); - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer iandNot(MappeableArrayContainer x); - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer iandNot(MappeableBitmapContainer x); - - protected MappeableContainer iandNot(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return iandNot((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return iandNot((MappeableRunContainer) x); - } - - return iandNot((MappeableBitmapContainer) x); - } - - /** - * Computes the in-place bitwise ANDNOT of this container with another (difference). The current - * container is generally modified, whereas the provided container (x) is unaffected. May generate - * a new container. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer iandNot(MappeableRunContainer x); - - - /** - * Computes the in-place bitwise NOT of this container (complement). Only those bits within the - * range are affected. The current container is generally modified. May generate a new container. - * - * @param rangeStart beginning of range (inclusive); 0 is beginning of this container. - * @param rangeEnd ending of range (exclusive) - * @return (partially) completmented container - */ - public abstract MappeableContainer inot(int rangeStart, int rangeEnd); - - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public abstract boolean intersects(MappeableArrayContainer x); - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public abstract boolean intersects(MappeableBitmapContainer x); - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public boolean intersects(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return intersects((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return intersects((MappeableBitmapContainer) x); - } - return intersects((MappeableRunContainer) x); - } - - /** - * Returns true if the current container intersects the other container. - * - * @param x other container - * @return whether they intersect - */ - public abstract boolean intersects(MappeableRunContainer x); - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer ior(MappeableArrayContainer x); - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer ior(MappeableBitmapContainer x); - - protected MappeableContainer ior(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return ior((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return ior((MappeableRunContainer) x); - } - - return ior((MappeableBitmapContainer) x); - } - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer ior(MappeableRunContainer x); - - /** - * Remove shorts in [begin,end) using an unsigned interpretation. May generate a new container. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract MappeableContainer iremove(int begin, int end); - - protected abstract boolean isArrayBacked(); - - - /** - * Computes the in-place bitwise XOR of this container with another (symmetric difference). The - * current container is generally modified, whereas the provided container (x) is unaffected. May - * generate a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer ixor(MappeableArrayContainer x); - - /** - * Computes the in-place bitwise XOR of this container with another (symmetric difference). The - * current container is generally modified, whereas the provided container (x) is unaffected. May - * generate a new container. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer ixor(MappeableBitmapContainer x); - - protected MappeableContainer ixor(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return ixor((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return ixor((MappeableRunContainer) x); - } - - return ixor((MappeableBitmapContainer) x); - - } - - - /** - * Computes the in-place bitwise XOR of this container with another (symmetric difference). The - * current container is generally modified, whereas the provided container (x) is unaffected. May - * generate a new container. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer ixor(MappeableRunContainer x); - - - /** - * Computes the in-place bitwise OR of this container with another (union). The current container - * is generally modified, whereas the provided container (x) is unaffected. May generate a new - * container. The resulting container may not track its cardinality correctly. The resulting - * container may not track its cardinality correctly. This can be fixed as follows: - * if(c.getCardinality()<0) ((MappeableBitmapContainer)c).computeCardinality(); - * - * @param x other container - * @return aggregated container - */ - public MappeableContainer lazyIOR(MappeableContainer x) { - if (this instanceof MappeableArrayContainer) { - if (x instanceof MappeableArrayContainer) { - return ((MappeableArrayContainer) this).lazyor((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return ((MappeableBitmapContainer) x).lazyor((MappeableArrayContainer) this); - } - return ((MappeableRunContainer) x).lazyor((MappeableArrayContainer) this); - } else if (this instanceof MappeableRunContainer) { - if (x instanceof MappeableArrayContainer) { - return ((MappeableRunContainer) this).ilazyor((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return ((MappeableBitmapContainer) x).lazyor((MappeableRunContainer) this); - } - return ior((MappeableRunContainer) x); - } else { - if (x instanceof MappeableArrayContainer) { - return ((MappeableBitmapContainer) this).ilazyor((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return ((MappeableBitmapContainer) this).ilazyor((MappeableBitmapContainer) x); - } - return ((MappeableBitmapContainer) this).ilazyor((MappeableRunContainer) x); - } - } - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. The resulting container may not track its cardinality - * correctly. This can be fixed as follows: if(c.getCardinality()<0) - * ((MappeableBitmapContainer)c).computeCardinality(); - * - * @param x other container - * @return aggregated container - */ - public MappeableContainer lazyOR(MappeableContainer x) { - if (this instanceof MappeableArrayContainer) { - if (x instanceof MappeableArrayContainer) { - return ((MappeableArrayContainer) this).lazyor((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return ((MappeableBitmapContainer) x).lazyor((MappeableArrayContainer) this); - } - return ((MappeableRunContainer) x).lazyor((MappeableArrayContainer) this); - } else if (this instanceof MappeableRunContainer) { - if (x instanceof MappeableArrayContainer) { - return ((MappeableRunContainer) this).lazyor((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return ((MappeableBitmapContainer) x).lazyor((MappeableRunContainer) this); - } - return or((MappeableRunContainer) x); - } else { - if (x instanceof MappeableArrayContainer) { - return ((MappeableBitmapContainer) this).lazyor((MappeableArrayContainer) x); - } else if (x instanceof MappeableBitmapContainer) { - return ((MappeableBitmapContainer) this).lazyor((MappeableBitmapContainer) x); - } - return ((MappeableBitmapContainer) this).lazyor((MappeableRunContainer) x); - } - } - - /** - * Create a new MappeableContainer containing at most maxcardinality integers. - * - * @param maxcardinality maximal cardinality - * @return a new bitmap with cardinality no more than maxcardinality - */ - public abstract MappeableContainer limit(int maxcardinality); - - /** - * Computes the bitwise NOT of this container (complement). Only those bits within the range are - * affected. The current container is left unaffected. - * - * @param rangeStart beginning of range (inclusive); 0 is beginning of this container. - * @param rangeEnd ending of range (exclusive) - * @return (partially) completmented container - */ - public abstract MappeableContainer not(int rangeStart, int rangeEnd); - - abstract int numberOfRuns(); - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer or(MappeableArrayContainer x); - - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer or(MappeableBitmapContainer x); - - - protected MappeableContainer or(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return or((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return or((MappeableRunContainer) x); - } - - return or((MappeableBitmapContainer) x); - } - - /** - * Computes the bitwise OR of this container with another (union). This container as well as the - * provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - - public abstract MappeableContainer or(MappeableRunContainer x); - - /** - * Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be - * GetCardinality()). - * - * @param lowbits upper limit - * @return the rank - */ - public abstract int rank(short lowbits); - - /** - * Return a new container with all shorts in [begin,end) remove using an unsigned interpretation. - * - * @param begin start of range (inclusive) - * @param end end of range (exclusive) - * @return the new container - */ - public abstract MappeableContainer remove(int begin, int end); - - /** - * Remove the short from this container. May create a new container. - * - * @param x to be removed - * @return New container - */ - public abstract MappeableContainer remove(short x); - - /** - * The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it. - * - * @return a new valid container - */ - public abstract MappeableContainer repairAfterLazy(); - - /** - * Convert to MappeableRunContainers, when the result is smaller. Overridden by - * MappeableRunContainer to possibly switch from MappeableRunContainer to a smaller alternative. - * - * @return the new container - */ - public abstract MappeableContainer runOptimize(); - - - /** - * Return the jth value - * - * @param j index of the value - * @return the value - */ - public abstract short select(int j); - - - /** - * Report the number of bytes required to serialize this container. - * - * @return the size in bytes - */ - public abstract int serializedSizeInBytes(); - - - /** - * Convert to a non-mappeable container. - * - * @return the non-mappeable container - */ - public abstract Container toContainer(); - - /** - * If possible, recover wasted memory. - */ - public abstract void trim(); - - - /** - * Write just the underlying array. - * - * @param out output stream - * @throws IOException in case of failure - */ - protected abstract void writeArray(DataOutput out) throws IOException; - - /** - * Computes the bitwise XOR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer xor(MappeableArrayContainer x); - - /** - * Computes the bitwise XOR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other container - * @return aggregated container - */ - public abstract MappeableContainer xor(MappeableBitmapContainer x); - - protected MappeableContainer xor(MappeableContainer x) { - if (x instanceof MappeableArrayContainer) { - return xor((MappeableArrayContainer) x); - } else if (x instanceof MappeableRunContainer) { - return xor((MappeableRunContainer) x); - } - - return xor((MappeableBitmapContainer) x); - - } - - /** - * Computes the bitwise XOR of this container with another (symmetric difference). This container - * as well as the provided container are left unaffected. - * - * @param x other parameter - * @return aggregated container - */ - public abstract MappeableContainer xor(MappeableRunContainer x); - - /** - * Convert the current container to a BitmapContainer, if a conversion is needed. - * If the container is already a bitmap, the container is returned unchanged. - * - * @return a bitmap container - */ - public abstract MappeableBitmapContainer toBitmapContainer(); - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableContainerPointer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableContainerPointer.java deleted file mode 100644 index 3a26415fc..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableContainerPointer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -/** - * This interface allows you to iterate over the containers in a roaring bitmap. - */ -public interface MappeableContainerPointer - extends Comparable, Cloneable { - /** - * Move to the next container - */ - void advance(); - - /** - * Create a copy - * - * @return return a clone of this pointer - */ - MappeableContainerPointer clone(); - - /** - * Returns the cardinality of the current container. Can be faster than loading the container - * first. - * - * @return cardinality of the current container - */ - int getCardinality(); - - /** - * This method can be used to check whether there is current a valid container as it returns null - * when there is not. - * - * @return null or the current container - */ - MappeableContainer getContainer(); - - /** - * Get the size in bytes of the container. Used for sorting. - * - * @return the size in bytes - */ - int getSizeInBytes(); - - /** - * @return whether there is a container at the current position - */ - boolean hasContainer(); - - /** - * Returns true if it is a bitmap container (MappeableBitmapContainer). - * - * @return boolean indicated if it is a bitmap container - */ - public boolean isBitmapContainer(); - - /** - * Returns true if it is a run container (MappeableRunContainer). - * - * @return boolean indicated if it is a run container - */ - boolean isRunContainer(); - - /** - * The key is a 16-bit integer that indicates the position of the container in the roaring bitmap. - * To be interpreted as an unsigned integer. - * - * @return the key - */ - short key(); - - /** - * Move to the previous container - */ - void previous(); - - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableRunContainer.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableRunContainer.java deleted file mode 100644 index a373bad5d..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MappeableRunContainer.java +++ /dev/null @@ -1,2798 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ -package com.fr.third.bitmap.roaringbitmap.buffer; - - -import com.fr.third.bitmap.roaringbitmap.Container; -import com.fr.third.bitmap.roaringbitmap.IntConsumer; -import com.fr.third.bitmap.roaringbitmap.PeekableShortIterator; -import com.fr.third.bitmap.roaringbitmap.RunContainer; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.io.DataOutput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.ShortBuffer; -import java.util.Arrays; -import java.util.Iterator; - -/** - * This container takes the form of runs of consecutive values (effectively, run-length encoding). - * Uses a ShortBuffer to store data, unlike RunContainer. Otherwise similar. - *

- *

- * Adding and removing content from this container might make it wasteful so regular calls to - * "runOptimize" might be warranted. - */ -public final class MappeableRunContainer extends MappeableContainer implements Cloneable { - private static final int DEFAULT_INIT_SIZE = 4; - private static final long serialVersionUID = 1L; - protected ShortBuffer valueslength; - protected int nbrruns = 0;// how many runs, this number should fit in 16 bits. - - /** - * Create a container with default capacity - */ - public MappeableRunContainer() { - this(DEFAULT_INIT_SIZE); - } - - /** - * Create an array container with specified capacity - * - * @param capacity The capacity of the container - */ - public MappeableRunContainer(final int capacity) { - valueslength = ShortBuffer.allocate(2 * capacity); - } - - - private MappeableRunContainer(int nbrruns, final ShortBuffer valueslength) { - this.nbrruns = nbrruns; - ShortBuffer tmp = valueslength.duplicate();// for thread safety - this.valueslength = ShortBuffer.allocate(Math.max(2 * nbrruns, tmp.limit())); - tmp.rewind(); - this.valueslength.put(tmp); // may copy more than it needs to?? - } - - protected MappeableRunContainer(MappeableArrayContainer arr, int nbrRuns) { - this.nbrruns = nbrRuns; - valueslength = ShortBuffer.allocate(2 * nbrRuns); - short[] vl = valueslength.array(); - if (nbrRuns == 0) { - return; - } - - int prevVal = -2; - int runLen = 0; - int runCount = 0; - if (BufferUtil.isBackedBySimpleArray(arr.content)) { - short[] a = arr.content.array(); - for (int i = 0; i < arr.cardinality; i++) { - int curVal = BufferUtil.toIntUnsigned(a[i]); - if (curVal == prevVal + 1) { - ++runLen; - } else { - if (runCount > 0) { - vl[2 * (runCount - 1) + 1] = (short) runLen; - } - // setLength(runCount - 1, (short) runLen); - vl[2 * runCount] = (short) curVal; - // setValue(runCount, (short) curVal); - runLen = 0; - ++runCount; - } - prevVal = curVal; - } - - } else { - for (int i = 0; i < arr.cardinality; i++) { - int curVal = BufferUtil.toIntUnsigned(arr.content.get(i)); - if (curVal == prevVal + 1) { - ++runLen; - } else { - if (runCount > 0) { - vl[2 * (runCount - 1) + 1] = (short) runLen; - } - // setLength(runCount - 1, (short) runLen); - vl[2 * runCount] = (short) curVal; - // setValue(runCount, (short) curVal); - runLen = 0; - ++runCount; - } - prevVal = curVal; - } - } - // setLength(runCount-1, (short) runLen); - vl[2 * (runCount - 1) + 1] = (short) runLen; - } - - // convert a bitmap container to a run container somewhat efficiently. - protected MappeableRunContainer(MappeableBitmapContainer bc, int nbrRuns) { - this.nbrruns = nbrRuns; - valueslength = ShortBuffer.allocate(2 * nbrRuns); - if (!BufferUtil.isBackedBySimpleArray(valueslength)) { - throw new RuntimeException("Unexpected internal error."); - } - short[] vl = valueslength.array(); - if (nbrRuns == 0) { - return; - } - if (bc.isArrayBacked()) { - long[] b = bc.bitmap.array(); - int longCtr = 0; // index of current long in bitmap - long curWord = b[0]; // its value - int runCount = 0; - final int len = bc.bitmap.limit(); - while (true) { - // potentially multiword advance to first 1 bit - while (curWord == 0L && longCtr < len - 1) { - curWord = b[++longCtr]; - } - - if (curWord == 0L) { - // wrap up, no more runs - return; - } - int localRunStart = Long.numberOfTrailingZeros(curWord); - int runStart = localRunStart + 64 * longCtr; - // stuff 1s into number's LSBs - long curWordWith1s = curWord | (curWord - 1); - - // find the next 0, potentially in a later word - int runEnd = 0; - while (curWordWith1s == -1L && longCtr < len - 1) { - curWordWith1s = b[++longCtr]; - } - - if (curWordWith1s == -1L) { - // a final unterminated run of 1s (32 of them) - runEnd = 64 + longCtr * 64; - // setValue(runCount, (short) runStart); - vl[2 * runCount] = (short) runStart; - // setLength(runCount, (short) (runEnd-runStart-1)); - vl[2 * runCount + 1] = (short) (runEnd - runStart - 1); - return; - } - int localRunEnd = Long.numberOfTrailingZeros(~curWordWith1s); - runEnd = localRunEnd + longCtr * 64; - // setValue(runCount, (short) runStart); - vl[2 * runCount] = (short) runStart; - // setLength(runCount, (short) (runEnd-runStart-1)); - vl[2 * runCount + 1] = (short) (runEnd - runStart - 1); - runCount++; - // now, zero out everything right of runEnd. - curWord = curWordWith1s & (curWordWith1s + 1); - // We've lathered and rinsed, so repeat... - } - } else { - int longCtr = 0; // index of current long in bitmap - long curWord = bc.bitmap.get(0); // its value - int runCount = 0; - final int len = bc.bitmap.limit(); - while (true) { - // potentially multiword advance to first 1 bit - while (curWord == 0L && longCtr < len - 1) { - curWord = bc.bitmap.get(++longCtr); - } - - if (curWord == 0L) { - // wrap up, no more runs - return; - } - int localRunStart = Long.numberOfTrailingZeros(curWord); - int runStart = localRunStart + 64 * longCtr; - // stuff 1s into number's LSBs - long curWordWith1s = curWord | (curWord - 1); - - // find the next 0, potentially in a later word - int runEnd = 0; - while (curWordWith1s == -1L && longCtr < len - 1) { - curWordWith1s = bc.bitmap.get(++longCtr); - } - - if (curWordWith1s == -1L) { - // a final unterminated run of 1s (32 of them) - runEnd = 64 + longCtr * 64; - // setValue(runCount, (short) runStart); - vl[2 * runCount] = (short) runStart; - // setLength(runCount, (short) (runEnd-runStart-1)); - vl[2 * runCount + 1] = (short) (runEnd - runStart - 1); - return; - } - int localRunEnd = Long.numberOfTrailingZeros(~curWordWith1s); - runEnd = localRunEnd + longCtr * 64; - // setValue(runCount, (short) runStart); - vl[2 * runCount] = (short) runStart; - // setLength(runCount, (short) (runEnd-runStart-1)); - vl[2 * runCount + 1] = (short) (runEnd - runStart - 1); - runCount++; - // now, zero out everything right of runEnd. - - curWord = curWordWith1s & (curWordWith1s + 1); - // We've lathered and rinsed, so repeat... - } - - } - } - - /** - * Creates a new container from a non-mappeable one. This copies the data. - * - * @param bc the original container - */ - public MappeableRunContainer(RunContainer bc) { - this.nbrruns = bc.numberOfRuns(); - this.valueslength = bc.toShortBuffer(); - } - - - /** - * Construct a new RunContainer backed by the provided ShortBuffer. Note that if you modify the - * RunContainer a new ShortBuffer may be produced. - * - * @param array ShortBuffer where the data is stored - * @param numRuns number of runs (each using 2 shorts in the buffer) - */ - public MappeableRunContainer(final ShortBuffer array, final int numRuns) { - if (array.limit() < 2 * numRuns) { - throw new RuntimeException("Mismatch between buffer and numRuns"); - } - this.nbrruns = numRuns; - this.valueslength = array; - } - - private static int branchyBufferedUnsignedInterleavedBinarySearch(final ShortBuffer sb, - final int begin, final int end, final short k) { - int ikey = BufferUtil.toIntUnsigned(k); - int low = begin; - int high = end - 1; - while (low <= high) { - final int middleIndex = (low + high) >>> 1; - final int middleValue = BufferUtil.toIntUnsigned(sb.get(2 * middleIndex)); - if (middleValue < ikey) { - low = middleIndex + 1; - } else if (middleValue > ikey) { - high = middleIndex - 1; - } else { - return middleIndex; - } - } - return -(low + 1); - } - - private static int bufferedUnsignedInterleavedBinarySearch(final ShortBuffer sb, final int begin, - final int end, final short k) { - return branchyBufferedUnsignedInterleavedBinarySearch(sb, begin, end, k); - } - - protected static int getArraySizeInBytes(int nbrruns) { - return 2 + 4 * nbrruns; - } - - static short getLength(short[] vl, int index) { - return vl[2 * index + 1]; - } - - static short getValue(short[] vl, int index) { - return vl[2 * index]; - } - - protected static int serializedSizeInBytes(int numberOfRuns) { - return 2 + 2 * 2 * numberOfRuns; // each run requires 2 2-byte entries. - } - - @Override - public MappeableContainer add(int begin, int end) { - MappeableRunContainer rc = (MappeableRunContainer) clone(); - return rc.iadd(begin, end); - } - - @Override - // not thread-safe - public MappeableContainer add(short k) { - // TODO: it might be better and simpler to do return - // toBitmapOrArrayContainer(getCardinality()).add(k) - int index = bufferedUnsignedInterleavedBinarySearch(valueslength, 0, nbrruns, k); - if (index >= 0) { - return this;// already there - } - index = -index - 2;// points to preceding value, possibly -1 - if (index >= 0) {// possible match - int offset = BufferUtil.toIntUnsigned(k) - BufferUtil.toIntUnsigned(getValue(index)); - int le = BufferUtil.toIntUnsigned(getLength(index)); - if (offset <= le) { - return this; - } - if (offset == le + 1) { - // we may need to fuse - if (index + 1 < nbrruns) { - if (BufferUtil.toIntUnsigned(getValue(index + 1)) == BufferUtil.toIntUnsigned(k) + 1) { - // indeed fusion is needed - setLength(index, - (short) (getValue(index + 1) + getLength(index + 1) - getValue(index))); - recoverRoomAtIndex(index + 1); - return this; - } - } - incrementLength(index); - return this; - } - if (index + 1 < nbrruns) { - // we may need to fuse - if (BufferUtil.toIntUnsigned(getValue(index + 1)) == BufferUtil.toIntUnsigned(k) + 1) { - // indeed fusion is needed - setValue(index + 1, k); - setLength(index + 1, (short) (getLength(index + 1) + 1)); - return this; - } - } - } - if (index == -1) { - // we may need to extend the first run - if (0 < nbrruns) { - if (getValue(0) == k + 1) { - incrementLength(0); - decrementValue(0); - return this; - } - } - } - makeRoomAtIndex(index + 1); - setValue(index + 1, k); - setLength(index + 1, (short) 0); - return this; - } - - - @Override - public MappeableContainer and(MappeableArrayContainer x) { - MappeableArrayContainer ac = new MappeableArrayContainer(x.cardinality); - if (this.nbrruns == 0) { - return ac; - } - int rlepos = 0; - int arraypos = 0; - - int rleval = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int rlelength = BufferUtil.toIntUnsigned(this.getLength(rlepos)); - while (arraypos < x.cardinality) { - int arrayval = BufferUtil.toIntUnsigned(x.content.get(arraypos)); - while (rleval + rlelength < arrayval) {// this will frequently be false - ++rlepos; - if (rlepos == this.nbrruns) { - return ac;// we are done - } - rleval = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - rlelength = BufferUtil.toIntUnsigned(this.getLength(rlepos)); - } - if (rleval > arrayval) { - arraypos = - BufferUtil.advanceUntil(x.content, arraypos, x.cardinality, (short) rleval); - } else { - ac.content.put(ac.cardinality, (short) arrayval); - ac.cardinality++; - arraypos++; - } - } - return ac; - } - - @Override - public MappeableContainer and(MappeableBitmapContainer x) { - int card = this.getCardinality(); - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - // result can only be an array (assuming that we never make a RunContainer) - if (card > x.cardinality) { - card = x.cardinality; - } - MappeableArrayContainer answer = new MappeableArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (x.contains((short) runValue)) { - answer.content.put(answer.cardinality++, (short) runValue); - } - } - } - return answer; - } - // we expect the answer to be a bitmap (if we are lucky) - - MappeableBitmapContainer answer = x.clone(); - int start = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int end = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - BufferUtil.resetBitmapRange(answer.bitmap, start, end); - start = end + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - BufferUtil.resetBitmapRange(answer.bitmap, start, BufferUtil.maxLowBitAsInteger() + 1); - answer.computeCardinality(); - if (answer.getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - - } - - @Override - public MappeableContainer and(MappeableRunContainer x) { - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.nbrruns)), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - int xrlepos = 0; - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - // exit the first run - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else {// they overlap - final int lateststart = start > xstart ? start : xstart; - int earliestend; - if (end == xend) {// improbable - earliestend = end; - rlepos++; - xrlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else if (end < xend) { - earliestend = end; - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - - } else {// end > xend - earliestend = xend; - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } - vl[2 * answer.nbrruns] = (short) lateststart; - vl[2 * answer.nbrruns + 1] = (short) (earliestend - lateststart - 1); - answer.nbrruns++; - } - } - return answer; - } - - @Override - public MappeableContainer andNot(MappeableArrayContainer x) { - // when x is small, we guess that the result will still be a run container - final int arbitrary_threshold = 32; // this is arbitrary - if (x.getCardinality() < arbitrary_threshold) { - return lazyandNot(x).toEfficientContainer(); - } - // otherwise we generate either an array or bitmap container - final int card = getCardinality(); - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - // if the cardinality is small, we construct the solution in place - MappeableArrayContainer ac = new MappeableArrayContainer(card); - ac.cardinality = Util.unsignedDifference(this.getShortIterator(), - x.getShortIterator(), ac.content.array()); - return ac; - } - // otherwise, we generate a bitmap - return toBitmapOrArrayContainer(card).iandNot(x); - } - - @Override - public MappeableContainer andNot(MappeableBitmapContainer x) { - int card = this.getCardinality(); - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - // result can only be an array (assuming that we never make a RunContainer) - MappeableArrayContainer answer = new MappeableArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (!x.contains((short) runValue)) { - answer.content.put(answer.cardinality++, (short) runValue); - } - } - } - return answer; - } - // we expect the answer to be a bitmap (if we are lucky) - MappeableBitmapContainer answer = x.clone(); - int lastPos = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.resetBitmapRange(answer.bitmap, lastPos, start); - BufferUtil.flipBitmapRange(answer.bitmap, start, end); - lastPos = end; - } - BufferUtil.resetBitmapRange(answer.bitmap, lastPos, answer.bitmap.capacity() * 64); - answer.computeCardinality(); - if (answer.getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public MappeableContainer andNot(MappeableRunContainer x) { - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.nbrruns)), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - int xrlepos = 0; - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - // output the first run - vl[2 * answer.nbrruns] = (short) start; - vl[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else { - if (start < xstart) { - vl[2 * answer.nbrruns] = (short) start; - vl[2 * answer.nbrruns + 1] = (short) (xstart - start - 1); - answer.nbrruns++; - } - if (xend < end) { - start = xend; - } else { - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } - } - } - if (rlepos < this.nbrruns) { - vl[2 * answer.nbrruns] = (short) start; - vl[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - for (; rlepos < this.nbrruns; ++rlepos) { - vl[2 * answer.nbrruns] = this.valueslength.get(2 * rlepos); - vl[2 * answer.nbrruns + 1] = this.valueslength.get(2 * rlepos + 1); - answer.nbrruns++; - } - // next bit would be faster but not thread-safe because of the "position" - // if(rlepos < this.nbrruns) { - // this.valueslength.position(2 * rlepos); - // this.valueslength.get(vl, 2 * answer.nbrruns, 2*(this.nbrruns-rlepos )); - // answer.nbrruns = answer.nbrruns + this.nbrruns - rlepos; - // } - } - return answer; - } - - // Append a value length with all values until a given value - private void appendValueLength(int value, int index) { - int previousValue = BufferUtil.toIntUnsigned(getValue(index)); - int length = BufferUtil.toIntUnsigned(getLength(index)); - int offset = value - previousValue; - if (offset > length) { - setLength(index, (short) offset); - } - } - - - // To check if a value length can be prepended with a given value - private boolean canPrependValueLength(int value, int index) { - if (index < this.nbrruns) { - int nextValue = BufferUtil.toIntUnsigned(getValue(index)); - if (nextValue == value + 1) { - return true; - } - } - return false; - } - - - @Override - public void clear() { - nbrruns = 0; - } - - - @Override - public MappeableContainer clone() { - return new MappeableRunContainer(nbrruns, valueslength); - } - - - // To set the last value of a value length - private void closeValueLength(int value, int index) { - int initialValue = BufferUtil.toIntUnsigned(getValue(index)); - setLength(index, (short) (value - initialValue)); - } - - @Override - public boolean contains(short x) { - int index = bufferedUnsignedInterleavedBinarySearch(valueslength, 0, nbrruns, x); - if (index >= 0) { - return true; - } - index = -index - 2; // points to preceding value, possibly -1 - if (index != -1) {// possible match - int offset = BufferUtil.toIntUnsigned(x) - BufferUtil.toIntUnsigned(getValue(index)); - int le = BufferUtil.toIntUnsigned(getLength(index)); - if (offset <= le) { - return true; - } - } - return false; - } - - // a very cheap check... if you have more than 4096, then you should use a bitmap container. - // this function avoids computing the cardinality - private MappeableContainer convertToLazyBitmapIfNeeded() { - // when nbrruns exceed MappeableArrayContainer.DEFAULT_MAX_SIZE, then we know it should be - // stored as a bitmap, always - if (this.nbrruns > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - MappeableBitmapContainer answer = new MappeableBitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = -1; - return answer; - } - return this; - } - - // Push all values length to the end of the array (resize array if needed) - private void copyToOffset(int offset) { - final int minCapacity = 2 * (offset + nbrruns); - if (valueslength.capacity() < minCapacity) { - // expensive case where we need to reallocate - int newCapacity = valueslength.capacity(); - while (newCapacity < minCapacity) { - newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE - : newCapacity < 64 ? newCapacity * 2 - : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4; - } - ShortBuffer newvalueslength = ShortBuffer.allocate(newCapacity); - copyValuesLength(this.valueslength, 0, newvalueslength, offset, nbrruns); - this.valueslength = newvalueslength; - } else { - // efficient case where we just copy - copyValuesLength(this.valueslength, 0, this.valueslength, offset, nbrruns); - } - } - - private void copyValuesLength(ShortBuffer src, int srcIndex, ShortBuffer dst, int dstIndex, - int length) { - if (BufferUtil.isBackedBySimpleArray(src) && BufferUtil.isBackedBySimpleArray(dst)) { - // common case. - System.arraycopy(src.array(), 2 * srcIndex, dst.array(), 2 * dstIndex, 2 * length); - return; - } - // source and destination may overlap - // consider specialized code for various cases, rather than using a second buffer - ShortBuffer temp = ShortBuffer.allocate(2 * length); - for (int i = 0; i < 2 * length; ++i) { - temp.put(src.get(2 * srcIndex + i)); - } - temp.flip(); - for (int i = 0; i < 2 * length; ++i) { - dst.put(2 * dstIndex + i, temp.get()); - } - } - - private void decrementLength(int index) { - // caller is responsible to ensure that value is non-zero - valueslength.put(2 * index + 1, (short) (valueslength.get(2 * index + 1) - 1)); - } - - - private void decrementValue(int index) { - valueslength.put(2 * index, (short) (valueslength.get(2 * index) - 1)); - } - - // not thread safe! - // not actually used anywhere, but potentially useful - protected void ensureCapacity(int minNbRuns) { - final int minCapacity = 2 * minNbRuns; - if (valueslength.capacity() < minCapacity) { - int newCapacity = valueslength.capacity(); - while (newCapacity < minCapacity) { - newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE - : newCapacity < 64 ? newCapacity * 2 - : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4; - } - final ShortBuffer nv = ShortBuffer.allocate(newCapacity); - valueslength.rewind(); - nv.put(valueslength); - valueslength = nv; - } - } - - @Override - public boolean equals(Object o) { - if (o instanceof MappeableRunContainer) { - MappeableRunContainer srb = (MappeableRunContainer) o; - if (srb.nbrruns != this.nbrruns) { - return false; - } - for (int i = 0; i < nbrruns; ++i) { - if (this.getValue(i) != srb.getValue(i)) { - return false; - } - if (this.getLength(i) != srb.getLength(i)) { - return false; - } - } - return true; - } else if (o instanceof MappeableContainer) { - if (((MappeableContainer) o).getCardinality() != this.getCardinality()) { - return false; // should be a frequent branch if they differ - } - // next bit could be optimized if needed: - ShortIterator me = this.getShortIterator(); - ShortIterator you = ((MappeableContainer) o).getShortIterator(); - while (me.hasNext()) { - if (me.next() != you.next()) { - return false; - } - } - return true; - } - return false; - } - - @Override - public void fillLeastSignificant16bits(int[] x, int i, int mask) { - int pos = i; - for (int k = 0; k < this.nbrruns; ++k) { - final int limit = BufferUtil.toIntUnsigned(this.getLength(k)); - final int base = BufferUtil.toIntUnsigned(this.getValue(k)); - for (int le = 0; le <= limit; ++le) { - x[pos++] = (base + le) | mask; - } - } - } - - - @Override - public MappeableContainer flip(short x) { - if (this.contains(x)) { - return this.remove(x); - } else { - return this.add(x); - } - } - - @Override - protected int getArraySizeInBytes() { - return 2 + 4 * this.nbrruns; // "array" includes its size - } - - @Override - public int getCardinality() { - int sum = nbrruns; // lengths are stored -1 - if (isArrayBacked()) { - short[] vl = valueslength.array(); - for (int k = 0; k < nbrruns; ++k) { - sum = sum + BufferUtil.toIntUnsigned(vl[2 * k + 1])/* + 1 */; - } - } else { - for (int k = 0; k < nbrruns; ++k) { - sum = sum + BufferUtil.toIntUnsigned(getLength(k))/* + 1 */; - } - } - return sum; - } - - short getLength(int index) { - return valueslength.get(2 * index + 1); - } - - @Override - public ShortIterator getReverseShortIterator() { - if (isArrayBacked()) { - return new RawReverseMappeableRunContainerShortIterator(this); - } - return new ReverseMappeableRunContainerShortIterator(this); - } - - @Override - public PeekableShortIterator getShortIterator() { - if (isArrayBacked()) { - return new RawMappeableRunContainerShortIterator(this); - } - return new MappeableRunContainerShortIterator(this); - } - - @Override - public int getSizeInBytes() { - return this.nbrruns * 4 + 4; // not sure about how exact it will be - } - - short getValue(int index) { - return valueslength.get(2 * index); - } - - @Override - public int hashCode() { - int hash = 0; - for (int k = 0; k < nbrruns * 2; ++k) { - hash += 31 * hash + valueslength.get(k); - } - return hash; - } - - @Override - // not thread-safe - public MappeableContainer iadd(int begin, int end) { - // TODO: it might be better and simpler to do return - // toBitmapOrArrayContainer(getCardinality()).iadd(begin,end) - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - if (begin == end - 1) { - add((short) begin); - return this; - } - - int bIndex = - bufferedUnsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, (short) begin); - int eIndex = bufferedUnsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, - (short) (end - 1)); - - if (bIndex >= 0 && eIndex >= 0) { - mergeValuesLength(bIndex, eIndex); - return this; - - } else if (bIndex >= 0 && eIndex < 0) { - eIndex = -eIndex - 2; - - if (canPrependValueLength(end - 1, eIndex + 1)) { - mergeValuesLength(bIndex, eIndex + 1); - return this; - } - - appendValueLength(end - 1, eIndex); - mergeValuesLength(bIndex, eIndex); - return this; - - } else if (bIndex < 0 && eIndex >= 0) { - bIndex = -bIndex - 2; - - if (bIndex >= 0) { - if (valueLengthContains(begin - 1, bIndex)) { - mergeValuesLength(bIndex, eIndex); - return this; - } - } - prependValueLength(begin, bIndex + 1); - mergeValuesLength(bIndex + 1, eIndex); - return this; - - } else { - bIndex = -bIndex - 2; - eIndex = -eIndex - 2; - - if (eIndex >= 0) { - if (bIndex >= 0) { - if (!valueLengthContains(begin - 1, bIndex)) { - if (bIndex == eIndex) { - if (canPrependValueLength(end - 1, eIndex + 1)) { - prependValueLength(begin, eIndex + 1); - return this; - } - makeRoomAtIndex(eIndex + 1); - setValue(eIndex + 1, (short) begin); - setLength(eIndex + 1, (short) (end - 1 - begin)); - return this; - - } else { - bIndex++; - prependValueLength(begin, bIndex); - } - } - } else { - bIndex = 0; - prependValueLength(begin, bIndex); - } - - if (canPrependValueLength(end - 1, eIndex + 1)) { - mergeValuesLength(bIndex, eIndex + 1); - return this; - } - - appendValueLength(end - 1, eIndex); - mergeValuesLength(bIndex, eIndex); - return this; - - } else { - if (canPrependValueLength(end - 1, 0)) { - prependValueLength(begin, 0); - } else { - makeRoomAtIndex(0); - setValue(0, (short) begin); - setLength(0, (short) (end - 1 - begin)); - } - return this; - } - } - } - - - @Override - public MappeableContainer iand(MappeableArrayContainer x) { - return and(x); - } - - @Override - public MappeableContainer iand(MappeableBitmapContainer x) { - return and(x); - } - - - @Override - public MappeableContainer iand(MappeableRunContainer x) { - return and(x); - } - - @Override - public MappeableContainer iandNot(MappeableArrayContainer x) { - return andNot(x); - } - - @Override - public MappeableContainer iandNot(MappeableBitmapContainer x) { - return andNot(x); - } - - @Override - public MappeableContainer iandNot(MappeableRunContainer x) { - return andNot(x); - } - - protected MappeableContainer ilazyor(MappeableArrayContainer x) { - if (isFull()) { - return this; // this can sometimes solve a lot of computation! - } - return ilazyorToRun(x); - } - - - private MappeableContainer ilazyorToRun(MappeableArrayContainer x) { - if (isFull()) { - return this.clone(); - } - final int nbrruns = this.nbrruns; - final int offset = Math.max(nbrruns, x.getCardinality()); - copyToOffset(offset); - short[] vl = valueslength.array(); - int rlepos = 0; - this.nbrruns = 0; - PeekableShortIterator i = (PeekableShortIterator) x.getShortIterator(); - while (i.hasNext() && (rlepos < nbrruns)) { - if (BufferUtil.compareUnsigned(getValue(vl, rlepos + offset), i.peekNext()) <= 0) { - smartAppend(vl, getValue(vl, rlepos + offset), getLength(vl, rlepos + offset)); - rlepos++; - } else { - smartAppend(vl, i.next()); - } - } - if (i.hasNext()) { - /* - * if(this.nbrruns>0) { // this might be useful if the run container has just one very large - * run int lastval = BufferUtil.toIntUnsigned(getValue(vl,nbrruns + offset - 1)) + - * BufferUtil.toIntUnsigned(getLength(vl,nbrruns + offset - 1)) + 1; i.advanceIfNeeded((short) - * lastval); } - */ - while (i.hasNext()) { - smartAppend(vl, i.next()); - } - } else { - while (rlepos < nbrruns) { - smartAppend(vl, getValue(vl, rlepos + offset), getLength(vl, rlepos + offset)); - rlepos++; - } - } - return convertToLazyBitmapIfNeeded(); - } - - // not thread safe! - private void increaseCapacity() { - int newCapacity = (valueslength.capacity() == 0) ? DEFAULT_INIT_SIZE - : valueslength.capacity() < 64 ? valueslength.capacity() * 2 - : valueslength.capacity() < 1024 ? valueslength.capacity() * 3 / 2 - : valueslength.capacity() * 5 / 4; - - final ShortBuffer nv = ShortBuffer.allocate(newCapacity); - valueslength.rewind(); - nv.put(valueslength); - valueslength = nv; - } - - private void incrementLength(int index) { - valueslength.put(2 * index + 1, (short) (1 + valueslength.get(2 * index + 1))); - } - - private void incrementValue(int index) { - valueslength.put(2 * index, (short) (1 + valueslength.get(2 * index))); - } - - // To set the first value of a value length - private void initValueLength(int value, int index) { - int initialValue = BufferUtil.toIntUnsigned(getValue(index)); - int length = BufferUtil.toIntUnsigned(getLength(index)); - setValue(index, (short) (value)); - setLength(index, (short) (length - (value - initialValue))); - } - - - @Override - public MappeableContainer inot(int rangeStart, int rangeEnd) { - if (rangeEnd <= rangeStart) { - return this; - } - short[] vl = this.valueslength.array(); - - // TODO: write special case code for rangeStart=0; rangeEnd=65535 - // a "sliding" effect where each range records the gap adjacent it - // can probably be quite fast. Probably have 2 cases: start with a - // 0 run vs start with a 1 run. If you both start and end with 0s, - // you will require room for expansion. - - // the +1 below is needed in case the valueslength.length is odd - if (vl.length <= 2 * nbrruns + 1) { - // no room for expansion - // analyze whether this is a case that will require expansion (that we cannot do) - // this is a bit costly now (4 "contains" checks) - - boolean lastValueBeforeRange = false; - boolean firstValueInRange = false; - boolean lastValueInRange = false; - boolean firstValuePastRange = false; - - // contains is based on a binary search and is hopefully fairly fast. - // however, one binary search could *usually* suffice to find both - // lastValueBeforeRange AND firstValueInRange. ditto for - // lastVaueInRange and firstValuePastRange - - // find the start of the range - if (rangeStart > 0) { - lastValueBeforeRange = contains((short) (rangeStart - 1)); - } - firstValueInRange = contains((short) rangeStart); - - if (lastValueBeforeRange == firstValueInRange) { - // expansion is required if also lastValueInRange==firstValuePastRange - - // tougher to optimize out, but possible. - lastValueInRange = contains((short) (rangeEnd - 1)); - if (rangeEnd != 65536) { - firstValuePastRange = contains((short) rangeEnd); - } - - // there is definitely one more run after the operation. - if (lastValueInRange == firstValuePastRange) { - return not(rangeStart, rangeEnd); // can't do in-place: true space limit - } - } - } - // either no expansion required, or we have room to handle any required expansion for it. - - // remaining code is just a minor variation on not() - int myNbrRuns = nbrruns; - - MappeableRunContainer ans = this; // copy on top of self. - int k = 0; - ans.nbrruns = 0; // losing this.nbrruns, which is stashed in myNbrRuns. - - // could try using unsignedInterleavedBinarySearch(valueslength, 0, nbrruns, rangeStart) instead - // of sequential scan - // to find the starting location - - for (; k < myNbrRuns && BufferUtil.toIntUnsigned(this.getValue(k)) < rangeStart; ++k) { - // since it is atop self, there is no copying needed - // ans.valueslength[2 * k] = this.valueslength[2 * k]; - // ans.valueslength[2 * k + 1] = this.valueslength[2 * k + 1]; - ans.nbrruns++; - } - // We will work left to right, with a read pointer that always stays - // left of the write pointer. However, we need to give the read pointer a head start. - // use local variables so we are always reading 1 location ahead. - - short bufferedValue = 0, bufferedLength = 0; // 65535 start and 65535 length would be illegal, - // could use as sentinel - short nextValue = 0, nextLength = 0; - if (k < myNbrRuns) { // prime the readahead variables - bufferedValue = vl[2 * k];// getValue(k); - bufferedLength = vl[2 * k + 1];// getLength(k); - } - - ans.smartAppendExclusive(vl, (short) rangeStart, (short) (rangeEnd - rangeStart - 1)); - - for (; k < myNbrRuns; ++k) { - if (ans.nbrruns > k + 1) { - throw new RuntimeException( - "internal error in inot, writer has overtaken reader!! " + k + " " + ans.nbrruns); - } - if (k + 1 < myNbrRuns) { - nextValue = vl[2 * (k + 1)];// getValue(k+1); // readahead for next iteration - nextLength = vl[2 * (k + 1) + 1];// getLength(k+1); - } - ans.smartAppendExclusive(vl, bufferedValue, bufferedLength); - bufferedValue = nextValue; - bufferedLength = nextLength; - } - // the number of runs can increase by one, meaning (rarely) a bitmap will become better - // or the cardinality can decrease by a lot, making an array better - return ans.toEfficientContainer(); - } - - @Override - public boolean intersects(MappeableArrayContainer x) { - if (this.nbrruns == 0) { - return false; - } - int rlepos = 0; - int arraypos = 0; - - int rleval = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int rlelength = BufferUtil.toIntUnsigned(this.getLength(rlepos)); - while (arraypos < x.cardinality) { - int arrayval = BufferUtil.toIntUnsigned(x.content.get(arraypos)); - while (rleval + rlelength < arrayval) {// this will frequently be false - ++rlepos; - if (rlepos == this.nbrruns) { - return false; - } - rleval = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - rlelength = BufferUtil.toIntUnsigned(this.getLength(rlepos)); - } - if (rleval > arrayval) { - arraypos = - BufferUtil.advanceUntil(x.content, arraypos, x.cardinality, this.getValue(rlepos)); - } else { - return true; - } - } - return false; - } - - @Override - public boolean intersects(MappeableBitmapContainer x) { - // possibly inefficient - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (x.contains((short) runValue)) { - return true; - } - } - } - return false; - } - - @Override - public boolean intersects(MappeableRunContainer x) { - int rlepos = 0; - int xrlepos = 0; - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - // exit the first run - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - // exit the second run - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else {// they overlap - return true; - } - } - return false; - } - - @Override - public MappeableContainer ior(MappeableArrayContainer x) { - if (isFull()) { - return this; - } - final int nbrruns = this.nbrruns; - final int offset = Math.max(nbrruns, x.getCardinality()); - copyToOffset(offset); - short[] vl = this.valueslength.array(); - int rlepos = 0; - this.nbrruns = 0; - PeekableShortIterator i = (PeekableShortIterator) x.getShortIterator(); - while (i.hasNext() && (rlepos < nbrruns)) { - if (BufferUtil.compareUnsigned(getValue(vl, rlepos + offset), i.peekNext()) <= 0) { - smartAppend(vl, getValue(vl, rlepos + offset), getLength(vl, rlepos + offset)); - rlepos++; - } else { - smartAppend(vl, i.next()); - } - } - if (i.hasNext()) { - /* - * if(this.nbrruns>0) { // this might be useful if the run container has just one very large - * run int lastval = BufferUtil.toIntUnsigned(getValue(nbrruns + offset - 1)) + - * BufferUtil.toIntUnsigned(getLength(nbrruns + offset - 1)) + 1; i.advanceIfNeeded((short) - * lastval); } - */ - while (i.hasNext()) { - smartAppend(vl, i.next()); - } - } else { - while (rlepos < nbrruns) { - smartAppend(vl, getValue(vl, rlepos + offset), getLength(vl, rlepos + offset)); - rlepos++; - } - } - return toEfficientContainer(); - } - - @Override - public MappeableContainer ior(MappeableBitmapContainer x) { - if (isFull()) { - return this; - } - return or(x); - } - - @Override - public MappeableContainer ior(MappeableRunContainer x) { - if (isFull()) { - return this; - } - - final int nbrruns = this.nbrruns; - final int xnbrruns = x.nbrruns; - final int offset = Math.max(nbrruns, xnbrruns); - - // Push all values length to the end of the array (resize array if needed) - copyToOffset(offset); - - // Aggregate and store the result at the beginning of the array - this.nbrruns = 0; - int rlepos = 0; - int xrlepos = 0; - short[] vl = this.valueslength.array(); - - // Add values length (smaller first) - while ((rlepos < nbrruns) && (xrlepos < xnbrruns)) { - final short value = getValue(vl, offset + rlepos); - final short xvalue = x.getValue(xrlepos); - final short length = getLength(vl, offset + rlepos); - final short xlength = x.getLength(xrlepos); - - if (BufferUtil.compareUnsigned(value, xvalue) <= 0) { - this.smartAppend(vl, value, length); - ++rlepos; - } else { - this.smartAppend(vl, xvalue, xlength); - ++xrlepos; - } - } - while (rlepos < nbrruns) { - this.smartAppend(vl, getValue(vl, offset + rlepos), getLength(vl, offset + rlepos)); - ++rlepos; - } - while (xrlepos < xnbrruns) { - this.smartAppend(vl, x.getValue(xrlepos), x.getLength(xrlepos)); - ++xrlepos; - } - return this.toBitmapIfNeeded(); - } - - @Override - // not thread-safe - public MappeableContainer iremove(int begin, int end) { - // TODO: it might be better and simpler to do return - // toBitmapOrArrayContainer(getCardinality()).iremove(begin,end) - if (end == begin) { - return this; - } - if ((begin > end) || (end > (1 << 16))) { - throw new IllegalArgumentException("Invalid range [" + begin + "," + end + ")"); - } - if (begin == end - 1) { - remove((short) begin); - return this; - } - - int bIndex = - bufferedUnsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, (short) begin); - int eIndex = bufferedUnsignedInterleavedBinarySearch(this.valueslength, 0, this.nbrruns, - (short) (end - 1)); - - if (bIndex >= 0) { - if (eIndex < 0) { - eIndex = -eIndex - 2; - } - - if (valueLengthContains(end, eIndex)) { - initValueLength(end, eIndex); - recoverRoomsInRange(bIndex - 1, eIndex - 1); - } else { - recoverRoomsInRange(bIndex - 1, eIndex); - } - - } else if (bIndex < 0 && eIndex >= 0) { - bIndex = -bIndex - 2; - - if (bIndex >= 0) { - if (valueLengthContains(begin, bIndex)) { - closeValueLength(begin - 1, bIndex); - } - } - // last run is one shorter - if (getLength(eIndex) == 0) {// special case where we remove last run - recoverRoomsInRange(eIndex, eIndex + 1); - } else { - incrementValue(eIndex); - decrementLength(eIndex); - } - recoverRoomsInRange(bIndex, eIndex - 1); - - } else { - bIndex = -bIndex - 2; - eIndex = -eIndex - 2; - - if (eIndex >= 0) { - if (bIndex >= 0) { - if (bIndex == eIndex) { - if (valueLengthContains(begin, bIndex)) { - if (valueLengthContains(end, eIndex)) { - makeRoomAtIndex(bIndex); - closeValueLength(begin - 1, bIndex); - initValueLength(end, bIndex + 1); - return this; - } - closeValueLength(begin - 1, bIndex); - } - } else { - if (valueLengthContains(begin, bIndex)) { - closeValueLength(begin - 1, bIndex); - } - if (valueLengthContains(end, eIndex)) { - initValueLength(end, eIndex); - eIndex--; - } - recoverRoomsInRange(bIndex, eIndex); - } - - } else { - if (valueLengthContains(end, eIndex)) { // was end-1 - initValueLength(end, eIndex); - recoverRoomsInRange(bIndex, eIndex - 1); - } else { - recoverRoomsInRange(bIndex, eIndex); - } - } - - } - - } - return this; - } - - @Override - protected boolean isArrayBacked() { - return BufferUtil.isBackedBySimpleArray(this.valueslength); - } - - protected boolean isFull() { - return (this.nbrruns == 1) && (this.getValue(0) == 0) && (this.getLength(0) == -1); - } - - @Override - public Iterator iterator() { - final ShortIterator i = getShortIterator(); - return new Iterator() { - - @Override - public boolean hasNext() { - return i.hasNext(); - } - - @Override - public Short next() { - return i.next(); - } - - @Override - public void remove() { - i.remove(); - } - }; - - } - - @Override - public MappeableContainer ixor(MappeableArrayContainer x) { - return xor(x); - } - - - @Override - public MappeableContainer ixor(MappeableBitmapContainer x) { - return xor(x); - } - - @Override - public MappeableContainer ixor(MappeableRunContainer x) { - return xor(x); - } - - private MappeableRunContainer lazyandNot(MappeableArrayContainer x) { - if (x.getCardinality() == 0) { - return this; - } - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.cardinality)), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - int xrlepos = 0; - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = BufferUtil.toIntUnsigned(x.content.get(xrlepos)); - while ((rlepos < this.nbrruns) && (xrlepos < x.cardinality)) { - if (end <= xstart) { - // output the first run - vl[2 * answer.nbrruns] = (short) start; - vl[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xstart + 1 <= start) { - // exit the second run - xrlepos++; - if (xrlepos < x.cardinality) { - xstart = BufferUtil.toIntUnsigned(x.content.get(xrlepos)); - } - } else { - if (start < xstart) { - vl[2 * answer.nbrruns] = (short) start; - vl[2 * answer.nbrruns + 1] = (short) (xstart - start - 1); - answer.nbrruns++; - } - if (xstart + 1 < end) { - start = xstart + 1; - } else { - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } - } - } - if (rlepos < this.nbrruns) { - vl[2 * answer.nbrruns] = (short) start; - vl[2 * answer.nbrruns + 1] = (short) (end - start - 1); - answer.nbrruns++; - rlepos++; - for (; rlepos < this.nbrruns; ++rlepos) { - vl[2 * answer.nbrruns] = this.valueslength.get(2 * rlepos); - vl[2 * answer.nbrruns + 1] = this.valueslength.get(2 * rlepos + 1); - answer.nbrruns++; - } - // next bit would be faster, but not thread-safe because of the "position" - // if(rlepos < this.nbrruns) { - // this.valueslength.position(2 * rlepos); - // this.valueslength.get(vl, 2 * answer.nbrruns, 2*(this.nbrruns-rlepos )); - // answer.nbrruns = answer.nbrruns + this.nbrruns - rlepos; - // } - } - return answer; - } - - - protected MappeableContainer lazyor(MappeableArrayContainer x) { - return lazyorToRun(x); - } - - private MappeableContainer lazyorToRun(MappeableArrayContainer x) { - if (isFull()) { - return this.clone(); - } - // TODO: should optimize for the frequent case where we have a single run - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.getCardinality())), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - PeekableShortIterator i = (PeekableShortIterator) x.getShortIterator(); - - while ((rlepos < this.nbrruns) && i.hasNext()) { - if (BufferUtil.compareUnsigned(getValue(rlepos), i.peekNext()) <= 0) { - answer.smartAppend(vl, getValue(rlepos), getLength(rlepos)); - // could call i.advanceIfNeeded(minval); - rlepos++; - } else { - answer.smartAppend(vl, i.next()); - } - } - if (i.hasNext()) { - /* - * if(answer.nbrruns>0) { // this might be useful if the run container has just one very large - * run int lastval = BufferUtil.toIntUnsigned(answer.getValue(answer.nbrruns - 1)) + - * BufferUtil.toIntUnsigned(answer.getLength(answer.nbrruns - 1)) + 1; - * i.advanceIfNeeded((short) lastval); } - */ - while (i.hasNext()) { - answer.smartAppend(vl, i.next()); - } - } else { - - while (rlepos < this.nbrruns) { - answer.smartAppend(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - } - } - return answer.convertToLazyBitmapIfNeeded(); - } - - private MappeableContainer lazyxor(MappeableArrayContainer x) { - if (x.getCardinality() == 0) { - return this; - } - if (this.nbrruns == 0) { - return x; - } - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.getCardinality())), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - ShortIterator i = x.getShortIterator(); - short cv = i.next(); - while (true) { - if (BufferUtil.compareUnsigned(getValue(rlepos), cv) < 0) { - answer.smartAppendExclusive(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - if (rlepos == this.nbrruns) { - answer.smartAppendExclusive(vl, cv); - while (i.hasNext()) { - answer.smartAppendExclusive(vl, i.next()); - } - break; - } - } else { - answer.smartAppendExclusive(vl, cv); - if (!i.hasNext()) { - while (rlepos < this.nbrruns) { - answer.smartAppendExclusive(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - } - break; - } else { - cv = i.next(); - } - } - } - return answer; - } - - @Override - public MappeableContainer limit(int maxcardinality) { - if (maxcardinality >= getCardinality()) { - return clone(); - } - - int r; - int cardinality = 0; - for (r = 0; r < this.nbrruns; ++r) { - cardinality += BufferUtil.toIntUnsigned(getLength(r)) + 1; - if (maxcardinality <= cardinality) { - break; - } - } - - ShortBuffer newBuf = ShortBuffer.allocate(2 * (r + 1)); - for (int i = 0; i < 2 * (r + 1); ++i) { - newBuf.put(valueslength.get(i)); // could be optimized - } - MappeableRunContainer rc = new MappeableRunContainer(newBuf, r + 1); - - rc.setLength(r, - (short) (BufferUtil.toIntUnsigned(rc.getLength(r)) - cardinality + maxcardinality)); - return rc; - } - - // not thread-safe - private void makeRoomAtIndex(int index) { - if (2 * (nbrruns + 1) > valueslength.capacity()) { - increaseCapacity(); - } - copyValuesLength(valueslength, index, valueslength, index + 1, nbrruns - index); - nbrruns++; - } - - // To merge values length from begin(inclusive) to end(inclusive) - private void mergeValuesLength(int begin, int end) { - if (begin < end) { - int bValue = BufferUtil.toIntUnsigned(getValue(begin)); - int eValue = BufferUtil.toIntUnsigned(getValue(end)); - int eLength = BufferUtil.toIntUnsigned(getLength(end)); - int newLength = eValue - bValue + eLength; - setLength(begin, (short) newLength); - recoverRoomsInRange(begin, end); - } - } - - @Override - public MappeableContainer not(int rangeStart, int rangeEnd) { - if (rangeEnd <= rangeStart) { - return this.clone(); - } - MappeableRunContainer ans = new MappeableRunContainer(nbrruns + 1); - if (!ans.isArrayBacked()) { - throw new RuntimeException("internal bug"); - } - short[] vl = ans.valueslength.array(); - int k = 0; - - if (isArrayBacked()) { - short[] myVl = valueslength.array(); - for (; k < this.nbrruns && BufferUtil.toIntUnsigned(getValue(myVl, k)) < rangeStart; ++k) { - vl[2 * k] = myVl[2 * k]; - vl[2 * k + 1] = myVl[2 * k + 1]; - ans.nbrruns++; - } - ans.smartAppendExclusive(vl, (short) rangeStart, (short) (rangeEnd - rangeStart - 1)); - for (; k < this.nbrruns; ++k) { - ans.smartAppendExclusive(vl, getValue(myVl, k), getLength(myVl, k)); - } - } else { // not array backed - - for (; k < this.nbrruns && BufferUtil.toIntUnsigned(this.getValue(k)) < rangeStart; ++k) { - vl[2 * k] = getValue(k); - vl[2 * k + 1] = getLength(k); - ans.nbrruns++; - } - ans.smartAppendExclusive(vl, (short) rangeStart, (short) (rangeEnd - rangeStart - 1)); - for (; k < this.nbrruns; ++k) { - ans.smartAppendExclusive(vl, getValue(k), getLength(k)); - } - } - return ans.toEfficientContainer(); - } - - @Override - public int numberOfRuns() { - return this.nbrruns; - } - - @Override - public MappeableContainer or(MappeableArrayContainer x) { - // we guess that, often, the result will still be efficiently expressed as a run container - return lazyorToRun(x).repairAfterLazy(); - } - - @Override - public MappeableContainer or(MappeableBitmapContainer x) { - if (isFull()) { - return clone(); - } - MappeableBitmapContainer answer = x.clone(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(answer.bitmap, start, end); - } - answer.computeCardinality(); - return answer; - } - - @Override - public MappeableContainer or(MappeableRunContainer x) { - if (isFull()) { - return clone(); - } - if (x.isFull()) { - return x.clone(); // cheap case that can save a lot of computation - } - // we really ought to optimize the rest of the code for the frequent case where there is a - // single run - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.nbrruns)), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - int xrlepos = 0; - - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (BufferUtil.compareUnsigned(getValue(rlepos), x.getValue(xrlepos)) <= 0) { - answer.smartAppend(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - } else { - answer.smartAppend(vl, x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - } - } - while (xrlepos < x.nbrruns) { - answer.smartAppend(vl, x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - } - while (rlepos < this.nbrruns) { - answer.smartAppend(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - } - return answer.toBitmapIfNeeded(); - } - - // Prepend a value length with all values starting from a given value - private void prependValueLength(int value, int index) { - int initialValue = BufferUtil.toIntUnsigned(getValue(index)); - int length = BufferUtil.toIntUnsigned(getLength(index)); - setValue(index, (short) value); - setLength(index, (short) (initialValue - value + length)); - } - - @Override - public int rank(short lowbits) { - int x = BufferUtil.toIntUnsigned(lowbits); - int answer = 0; - for (int k = 0; k < this.nbrruns; ++k) { - int value = BufferUtil.toIntUnsigned(getValue(k)); - int length = BufferUtil.toIntUnsigned(getLength(k)); - if (x < value) { - return answer; - } else if (value + length + 1 >= x) { - return answer + x - value + 1; - } - answer += length + 1; - } - return answer; - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // little endian - this.nbrruns = 0xFFFF & Short.reverseBytes(in.readShort()); - if (this.valueslength.capacity() < 2 * this.nbrruns) { - this.valueslength = ShortBuffer.allocate(2 * this.nbrruns); - } - for (int k = 0; k < 2 * this.nbrruns; ++k) { - this.valueslength.put(k, Short.reverseBytes(in.readShort())); - } - } - - private void recoverRoomAtIndex(int index) { - copyValuesLength(valueslength, index + 1, valueslength, index, nbrruns - index - 1); - nbrruns--; - } - - // To recover rooms between begin(exclusive) and end(inclusive) - private void recoverRoomsInRange(int begin, int end) { - if (end + 1 < nbrruns) { - copyValuesLength(valueslength, end + 1, valueslength, begin + 1, nbrruns - 1 - end); - } - nbrruns -= end - begin; - } - - @Override - public MappeableContainer remove(int begin, int end) { - MappeableRunContainer rc = (MappeableRunContainer) clone(); - return rc.iremove(begin, end); - } - - @Override - // not thread-safe - public MappeableContainer remove(short x) { - int index = bufferedUnsignedInterleavedBinarySearch(valueslength, 0, nbrruns, x); - if (index >= 0) { - if (getLength(index) == 0) { - recoverRoomAtIndex(index); - } else { - incrementValue(index); - decrementLength(index); - } - return this;// already there - } - index = -index - 2;// points to preceding value, possibly -1 - if (index >= 0) {// possible match - int offset = BufferUtil.toIntUnsigned(x) - BufferUtil.toIntUnsigned(getValue(index)); - int le = BufferUtil.toIntUnsigned(getLength(index)); - if (offset < le) { - // need to break in two - this.setLength(index, (short) (offset - 1)); - // need to insert - int newvalue = BufferUtil.toIntUnsigned(x) + 1; - int newlength = le - offset - 1; - makeRoomAtIndex(index + 1); - this.setValue(index + 1, (short) newvalue); - this.setLength(index + 1, (short) newlength); - return this; - } else if (offset == le) { - decrementLength(index); - } - } - // no match - return this; - } - - @Override - public MappeableContainer repairAfterLazy() { - return toEfficientContainer(); - } - - /** - * Convert to Array or Bitmap container if the serialized form would be shorter - */ - - @Override - public MappeableContainer runOptimize() { - return toEfficientContainer(); // which had the same functionality. - } - - @Override - public short select(int j) { - int offset = 0; - for (int k = 0; k < this.nbrruns; ++k) { - int nextOffset = offset + BufferUtil.toIntUnsigned(getLength(k)) + 1; - if (nextOffset > j) { - return (short) (getValue(k) + (j - offset)); - } - offset = nextOffset; - } - throw new IllegalArgumentException( - "Cannot select " + j + " since cardinality is " + getCardinality()); - } - - @Override - public int serializedSizeInBytes() { - return serializedSizeInBytes(nbrruns); - } - - - private void setLength(int index, short v) { - setLength(valueslength, index, v); - } - - - private void setLength(ShortBuffer valueslength, int index, short v) { - valueslength.put(2 * index + 1, v); - } - - - private void setValue(int index, short v) { - setValue(valueslength, index, v); - } - - private void setValue(ShortBuffer valueslength, int index, short v) { - valueslength.put(2 * index, v); - } - - - // assume that the (maybe) inplace operations - // will never actually *be* in place if they are - // to return ArrayContainer or BitmapContainer - - private void smartAppend(short[] vl, short val) { - int oldend; - if ((nbrruns == 0) || (BufferUtil - .toIntUnsigned(val) > (oldend = BufferUtil.toIntUnsigned(vl[2 * (nbrruns - 1)]) - + BufferUtil.toIntUnsigned(vl[2 * (nbrruns - 1) + 1])) + 1)) { // we add a new one - vl[2 * nbrruns] = val; - vl[2 * nbrruns + 1] = 0; - nbrruns++; - return; - } - if (val == (short) (oldend + 1)) { // we merge - vl[2 * (nbrruns - 1) + 1]++; - } - } - - private void smartAppend(short[] vl, short start, short length) { - int oldend; - if ((nbrruns == 0) || (BufferUtil - .toIntUnsigned(start) > (oldend = BufferUtil.toIntUnsigned(vl[2 * (nbrruns - 1)]) - + BufferUtil.toIntUnsigned(vl[2 * (nbrruns - 1) + 1])) + 1)) { // we add a new one - vl[2 * nbrruns] = start; - vl[2 * nbrruns + 1] = length; - nbrruns++; - return; - } - int newend = BufferUtil.toIntUnsigned(start) + BufferUtil.toIntUnsigned(length) + 1; - if (newend > oldend) { // we merge - vl[2 * (nbrruns - 1) + 1] = - (short) (newend - 1 - BufferUtil.toIntUnsigned(vl[2 * (nbrruns - 1)])); - } - } - - private void smartAppendExclusive(short[] vl, short val) { - int oldend; - if ((nbrruns == 0) || (BufferUtil - .toIntUnsigned(val) > (oldend = BufferUtil.toIntUnsigned(getValue(nbrruns - 1)) - + BufferUtil.toIntUnsigned(getLength(nbrruns - 1)) + 1))) { // we add a new one - vl[2 * nbrruns] = val; - vl[2 * nbrruns + 1] = 0; - nbrruns++; - return; - } - if (oldend == BufferUtil.toIntUnsigned(val)) { - // we merge - vl[2 * (nbrruns - 1) + 1]++; - return; - } - - - int newend = BufferUtil.toIntUnsigned(val) + 1; - - if (BufferUtil.toIntUnsigned(val) == BufferUtil.toIntUnsigned(getValue(nbrruns - 1))) { - // we wipe out previous - if (newend != oldend) { - setValue(nbrruns - 1, (short) newend); - setLength(nbrruns - 1, (short) (oldend - newend - 1)); - return; - } else { // they cancel out - nbrruns--; - return; - } - } - setLength(nbrruns - 1, (short) (val - BufferUtil.toIntUnsigned(getValue(nbrruns - 1)) - 1)); - - if (newend < oldend) { - setValue(nbrruns, (short) newend); - setLength(nbrruns, (short) (oldend - newend - 1)); - nbrruns++; - } else if (oldend < newend) { - setValue(nbrruns, (short) oldend); - setLength(nbrruns, (short) (newend - oldend - 1)); - nbrruns++; - } - } - - private void smartAppendExclusive(short[] vl, short start, short length) { - int oldend; - if ((nbrruns == 0) || (BufferUtil - .toIntUnsigned(start) > (oldend = BufferUtil.toIntUnsigned(getValue(nbrruns - 1)) - + BufferUtil.toIntUnsigned(getLength(nbrruns - 1)) + 1))) { // we add a new one - vl[2 * nbrruns] = start; - vl[2 * nbrruns + 1] = length; - nbrruns++; - return; - } - if (oldend == BufferUtil.toIntUnsigned(start)) { - // we merge - vl[2 * (nbrruns - 1) + 1] += length + 1; - return; - } - - - int newend = BufferUtil.toIntUnsigned(start) + BufferUtil.toIntUnsigned(length) + 1; - - if (BufferUtil.toIntUnsigned(start) == BufferUtil.toIntUnsigned(getValue(nbrruns - 1))) { - // we wipe out previous - if (newend < oldend) { - setValue(nbrruns - 1, (short) newend); - setLength(nbrruns - 1, (short) (oldend - newend - 1)); - return; - } else if (newend > oldend) { - setValue(nbrruns - 1, (short) oldend); - setLength(nbrruns - 1, (short) (newend - oldend - 1)); - return; - } else { // they cancel out - nbrruns--; - return; - } - } - setLength(nbrruns - 1, (short) (start - BufferUtil.toIntUnsigned(getValue(nbrruns - 1)) - 1)); - - if (newend < oldend) { - setValue(nbrruns, (short) newend); - setLength(nbrruns, (short) (oldend - newend - 1)); - nbrruns++; - } else if (newend > oldend) { - setValue(nbrruns, (short) oldend); - setLength(nbrruns, (short) (newend - oldend - 1)); - nbrruns++; - } - } - - - // convert to bitmap *if needed* (useful if you know it can't be an array) - private MappeableContainer toBitmapIfNeeded() { - int sizeAsRunContainer = MappeableRunContainer.serializedSizeInBytes(this.nbrruns); - int sizeAsBitmapContainer = MappeableBitmapContainer.serializedSizeInBytes(0); - if (sizeAsBitmapContainer > sizeAsRunContainer) { - return this; - } - return toBitmapContainer(); - } - - /** - * Convert the container to either a Bitmap or an Array Container, depending on the cardinality. - * - * @param card the current cardinality - * @return new container - */ - MappeableContainer toBitmapOrArrayContainer(int card) { - // int card = this.getCardinality(); - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - MappeableArrayContainer answer = new MappeableArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(this.getLength(rlepos)); - - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - answer.content.put(answer.cardinality++, (short) runValue); - } - } - return answer; - } - MappeableBitmapContainer answer = new MappeableBitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = card; - return answer; - } - - @Override - public Container toContainer() { - return new RunContainer(this); - } - - - // convert to bitmap or array *if needed* - private MappeableContainer toEfficientContainer() { - int sizeAsRunContainer = MappeableRunContainer.serializedSizeInBytes(this.nbrruns); - int sizeAsBitmapContainer = MappeableBitmapContainer.serializedSizeInBytes(0); - int card = this.getCardinality(); - int sizeAsArrayContainer = MappeableArrayContainer.serializedSizeInBytes(card); - if (sizeAsRunContainer <= Math.min(sizeAsBitmapContainer, sizeAsArrayContainer)) { - return this; - } - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - MappeableArrayContainer answer = new MappeableArrayContainer(card); - answer.cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(this.getLength(rlepos)); - // next bit could potentially be faster, test - if (BufferUtil.isBackedBySimpleArray(answer.content)) { - short[] ba = answer.content.array(); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - ba[answer.cardinality++] = (short) runValue; - } - } else { - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - answer.content.put(answer.cardinality++, (short) runValue); - } - } - } - return answer; - } - MappeableBitmapContainer answer = new MappeableBitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = card; - return answer; - } - - /** - * Create a copy of the content of this container as a short array. This creates a copy. - * - * @return copy of the content as a short array - */ - public short[] toShortArray() { - short[] answer = new short[2 * nbrruns]; - valueslength.rewind(); - valueslength.get(answer); - return answer; - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - for (int k = 0; k < this.nbrruns; ++k) { - sb.append("["); - sb.append(BufferUtil.toIntUnsigned(this.getValue(k))); - sb.append(","); - sb.append(BufferUtil.toIntUnsigned(this.getValue(k)) - + BufferUtil.toIntUnsigned(this.getLength(k)) + 1); - sb.append("]"); - } - return sb.toString(); - } - - @Override - public void trim() { - if (valueslength.limit() == 2 * nbrruns) { - return; - } - if (BufferUtil.isBackedBySimpleArray(valueslength)) { - this.valueslength = ShortBuffer.wrap(Arrays.copyOf(valueslength.array(), 2 * nbrruns)); - } else { - - final ShortBuffer co = ShortBuffer.allocate(2 * nbrruns); - short[] a = co.array(); - for (int k = 0; k < 2 * nbrruns; ++k) { - a[k] = this.valueslength.get(k); - } - this.valueslength = co; - } - } - - // To check if a value length contains a given value - private boolean valueLengthContains(int value, int index) { - int initialValue = BufferUtil.toIntUnsigned(getValue(index)); - int length = BufferUtil.toIntUnsigned(getLength(index)); - - if (value <= initialValue + length) { - return true; - } - return false; - } - - @Override - protected void writeArray(DataOutput out) throws IOException { - out.writeShort(Short.reverseBytes((short) this.nbrruns)); - for (int k = 0; k < 2 * this.nbrruns; ++k) { - out.writeShort(Short.reverseBytes(this.valueslength.get(k))); - } - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - out.writeShort(Short.reverseBytes((short) this.nbrruns)); - for (int k = 0; k < 2 * this.nbrruns; ++k) { - out.writeShort(Short.reverseBytes(this.valueslength.get(k))); - } - } - - @Override - public MappeableContainer xor(MappeableArrayContainer x) { - // if the cardinality of the array is small, guess that the output will still be a run container - final int arbitrary_threshold = 32; // 32 is arbitrary here - if (x.getCardinality() < arbitrary_threshold) { - return lazyxor(x).repairAfterLazy(); - } - // otherwise, we expect the output to be either an array or bitmap - final int card = getCardinality(); - if (card <= MappeableArrayContainer.DEFAULT_MAX_SIZE) { - // if the cardinality is small, we construct the solution in place - return x.xor(this.getShortIterator()); - } - // otherwise, we generate a bitmap - return toBitmapOrArrayContainer(card).ixor(x); - } - - @Override - public MappeableContainer xor(MappeableBitmapContainer x) { - MappeableBitmapContainer answer = x.clone(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.flipBitmapRange(answer.bitmap, start, end); - } - answer.computeCardinality(); - if (answer.getCardinality() > MappeableArrayContainer.DEFAULT_MAX_SIZE) { - return answer; - } else { - return answer.toArrayContainer(); - } - } - - @Override - public MappeableContainer xor(MappeableRunContainer x) { - if (x.nbrruns == 0) { - return this.clone(); - } - if (this.nbrruns == 0) { - return x.clone(); - } - MappeableRunContainer answer = - new MappeableRunContainer(ShortBuffer.allocate(2 * (this.nbrruns + x.nbrruns)), 0); - short[] vl = answer.valueslength.array(); - int rlepos = 0; - int xrlepos = 0; - - while (true) { - if (BufferUtil.compareUnsigned(getValue(rlepos), x.getValue(xrlepos)) < 0) { - answer.smartAppendExclusive(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - if (rlepos == this.nbrruns) { - while (xrlepos < x.nbrruns) { - answer.smartAppendExclusive(vl, x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - } - break; - } - } else { - answer.smartAppendExclusive(vl, x.getValue(xrlepos), x.getLength(xrlepos)); - xrlepos++; - if (xrlepos == x.nbrruns) { - while (rlepos < this.nbrruns) { - answer.smartAppendExclusive(vl, getValue(rlepos), getLength(rlepos)); - rlepos++; - } - break; - } - } - } - return answer.toEfficientContainer(); - } - - - @Override - public void forEach(short msb, IntConsumer ic) { - int high = ((int) msb) << 16; - for (int k = 0; k < this.nbrruns; ++k) { - int base = (this.getValue(k) & 0xFFFF) | high; - int le = this.getLength(k) & 0xFFFF; - for (int l = base; l <= base + le; ++l) { - ic.accept(l); - } - } - } - - - @Override - public int andCardinality(MappeableArrayContainer x) { - if (this.nbrruns == 0) { - return 0; - } - int rlepos = 0; - int arraypos = 0; - int andCardinality = 0; - int rleval = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int rlelength = BufferUtil.toIntUnsigned(this.getLength(rlepos)); - while (arraypos < x.cardinality) { - int arrayval = BufferUtil.toIntUnsigned(x.content.get(arraypos)); - while (rleval + rlelength < arrayval) {// this will frequently be false - ++rlepos; - if (rlepos == this.nbrruns) { - return andCardinality;// we are done - } - rleval = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - rlelength = BufferUtil.toIntUnsigned(this.getLength(rlepos)); - } - if (rleval > arrayval) { - arraypos = BufferUtil.advanceUntil(x.content, arraypos, - x.cardinality, this.getValue(rlepos)); - } else { - andCardinality++; - arraypos++; - } - } - return andCardinality; - } - - - @Override - public int andCardinality(MappeableBitmapContainer x) { - // could be implemented as return toBitmapOrArrayContainer().iand(x); - int cardinality = 0; - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int runStart = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int runEnd = runStart + BufferUtil.toIntUnsigned(this.getLength(rlepos)); - for (int runValue = runStart; runValue <= runEnd; ++runValue) { - if (x.contains((short) runValue)) {// it looks like contains() should be cheap enough if - // accessed sequentially - cardinality++; - } - } - } - return cardinality; - } - - @Override - public int andCardinality(MappeableRunContainer x) { - int cardinality = 0; - int rlepos = 0; - int xrlepos = 0; - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - int xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - int xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - while ((rlepos < this.nbrruns) && (xrlepos < x.nbrruns)) { - if (end <= xstart) { - ++rlepos; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - } else if (xend <= start) { - ++xrlepos; - - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else {// they overlap - final int lateststart = start > xstart ? start : xstart; - int earliestend; - if (end == xend) {// improbable - earliestend = end; - rlepos++; - xrlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } else if (end < xend) { - earliestend = end; - rlepos++; - if (rlepos < this.nbrruns) { - start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - } - - } else {// end > xend - earliestend = xend; - xrlepos++; - if (xrlepos < x.nbrruns) { - xstart = BufferUtil.toIntUnsigned(x.getValue(xrlepos)); - xend = xstart + BufferUtil.toIntUnsigned(x.getLength(xrlepos)) + 1; - } - } - // earliestend - lateststart are all values that are true. - cardinality += (short) (earliestend - lateststart); - } - } - return cardinality; - } - - - @Override - public MappeableBitmapContainer toBitmapContainer() { - int card = this.getCardinality(); - MappeableBitmapContainer answer = new MappeableBitmapContainer(); - for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) { - int start = BufferUtil.toIntUnsigned(this.getValue(rlepos)); - int end = start + BufferUtil.toIntUnsigned(this.getLength(rlepos)) + 1; - BufferUtil.setBitmapRange(answer.bitmap, start, end); - } - answer.cardinality = card; - return answer; - } - - -} - - -final class MappeableRunContainerShortIterator implements PeekableShortIterator { - int pos; - int le = 0; - int maxlength; - int base; - - MappeableRunContainer parent; - - MappeableRunContainerShortIterator() { - } - - MappeableRunContainerShortIterator(MappeableRunContainer p) { - wrap(p); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos < parent.nbrruns; - } - - @Override - public short next() { - short ans = (short) (base + le); - le++; - if (le > maxlength) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public int nextAsInt() { - int ans = base + le; - le++; - if (le > maxlength) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public void remove() { - throw new RuntimeException("Not implemented");// TODO - } - - void wrap(MappeableRunContainer p) { - parent = p; - pos = 0; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } - } - - @Override - public void advanceIfNeeded(short minval) { - while (base + maxlength < BufferUtil.toIntUnsigned(minval)) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } else { - return; - } - } - if (base > BufferUtil.toIntUnsigned(minval)) { - return; - } - le = BufferUtil.toIntUnsigned(minval) - base; - } - - @Override - public short peekNext() { - return (short) (base + le); - } - -}; - - -final class RawMappeableRunContainerShortIterator implements PeekableShortIterator { - int pos; - int le = 0; - int maxlength; - int base; - - MappeableRunContainer parent; - short[] vl; - - - RawMappeableRunContainerShortIterator(MappeableRunContainer p) { - wrap(p); - } - - @Override - public PeekableShortIterator clone() { - try { - return (PeekableShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - short getLength(int index) { - return vl[2 * index + 1]; - } - - short getValue(int index) { - return vl[2 * index]; - } - - @Override - public boolean hasNext() { - return pos < parent.nbrruns; - } - - @Override - public short next() { - short ans = (short) (base + le); - le++; - if (le > maxlength) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(getLength(pos)); - base = BufferUtil.toIntUnsigned(getValue(pos)); - } - } - return ans; - } - - - @Override - public int nextAsInt() { - int ans = base + le; - le++; - if (le > maxlength) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(getLength(pos)); - base = BufferUtil.toIntUnsigned(getValue(pos)); - } - } - return ans; - } - - @Override - public void remove() { - throw new RuntimeException("Not implemented");// TODO - } - - void wrap(MappeableRunContainer p) { - parent = p; - if (!parent.isArrayBacked()) { - throw new RuntimeException("internal error"); - } - vl = parent.valueslength.array(); - pos = 0; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(getLength(pos)); - base = BufferUtil.toIntUnsigned(getValue(pos)); - } - } - - @Override - public void advanceIfNeeded(short minval) { - while (base + maxlength < BufferUtil.toIntUnsigned(minval)) { - pos++; - le = 0; - if (pos < parent.nbrruns) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } else { - return; - } - } - if (base > BufferUtil.toIntUnsigned(minval)) { - return; - } - le = BufferUtil.toIntUnsigned(minval) - base; - } - - @Override - public short peekNext() { - return (short) (base + le); - } - -} - - -final class RawReverseMappeableRunContainerShortIterator implements ShortIterator { - int pos; - int le; - int maxlength; - int base; - MappeableRunContainer parent; - short[] vl; - - - RawReverseMappeableRunContainerShortIterator(MappeableRunContainer p) { - wrap(p); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - short getLength(int index) { - return vl[2 * index + 1]; - } - - short getValue(int index) { - return vl[2 * index]; - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - @Override - public short next() { - short ans = (short) (base + maxlength - le); - le++; - if (le > maxlength) { - pos--; - le = 0; - if (pos >= 0) { - maxlength = BufferUtil.toIntUnsigned(getLength(pos)); - base = BufferUtil.toIntUnsigned(getValue(pos)); - } - } - return ans; - } - - @Override - public int nextAsInt() { - int ans = base + maxlength - le; - le++; - if (le > maxlength) { - pos--; - le = 0; - if (pos >= 0) { - maxlength = BufferUtil.toIntUnsigned(getLength(pos)); - base = BufferUtil.toIntUnsigned(getValue(pos)); - } - } - return ans; - } - - @Override - public void remove() { - throw new RuntimeException("Not implemented");// TODO - } - - void wrap(MappeableRunContainer p) { - parent = p; - if (!parent.isArrayBacked()) { - throw new RuntimeException("internal error"); - } - vl = parent.valueslength.array(); - pos = parent.nbrruns - 1; - le = 0; - if (pos >= 0) { - maxlength = BufferUtil.toIntUnsigned(getLength(pos)); - base = BufferUtil.toIntUnsigned(getValue(pos)); - } - } - -}; - - -final class ReverseMappeableRunContainerShortIterator implements ShortIterator { - int pos; - int le; - int maxlength; - int base; - MappeableRunContainer parent; - - - ReverseMappeableRunContainerShortIterator() { - } - - ReverseMappeableRunContainerShortIterator(MappeableRunContainer p) { - wrap(p); - } - - @Override - public ShortIterator clone() { - try { - return (ShortIterator) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public boolean hasNext() { - return pos >= 0; - } - - @Override - public short next() { - short ans = (short) (base + maxlength - le); - le++; - if (le > maxlength) { - pos--; - le = 0; - if (pos >= 0) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public int nextAsInt() { - int ans = base + maxlength - le; - le++; - if (le > maxlength) { - pos--; - le = 0; - if (pos >= 0) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } - } - return ans; - } - - @Override - public void remove() { - throw new RuntimeException("Not implemented");// TODO - } - - void wrap(MappeableRunContainer p) { - parent = p; - pos = parent.nbrruns - 1; - le = 0; - if (pos >= 0) { - maxlength = BufferUtil.toIntUnsigned(parent.getLength(pos)); - base = BufferUtil.toIntUnsigned(parent.getValue(pos)); - } - } - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MutableRoaringArray.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MutableRoaringArray.java deleted file mode 100644 index 39706dfe4..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MutableRoaringArray.java +++ /dev/null @@ -1,573 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - - -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.nio.LongBuffer; -import java.nio.ShortBuffer; -import java.util.Arrays; - - -/** - * Specialized array to store the containers used by a RoaringBitmap. This class is similar to - * RoaringArray but meant to be used with memory mapping. This is not meant to be - * used by end users. - *

- * Objects of this class reside in RAM. - */ -public final class MutableRoaringArray implements Cloneable, Externalizable, PointableRoaringArray { - - protected static final int INITIAL_CAPACITY = 4; - - protected static final short SERIAL_COOKIE_NO_RUNCONTAINER = 12346; - protected static final short SERIAL_COOKIE = 12347; - - protected static final int NO_OFFSET_THRESHOLD = 4; - - private static final long serialVersionUID = 5L; // TODO: OFK was 4L, not sure - protected boolean mayHaveRunContainers = false; // does not necessarily have them, after - // optimization - - - short[] keys = null; - MappeableContainer[] values = null; - - int size = 0; - - protected MutableRoaringArray() { - this.keys = new short[INITIAL_CAPACITY]; - this.values = new MappeableContainer[INITIAL_CAPACITY]; - } - - - @Override - public int advanceUntil(short x, int pos) { - int lower = pos + 1; - - // special handling for a possibly common sequential case - if (lower >= size || BufferUtil.toIntUnsigned(keys[lower]) >= BufferUtil.toIntUnsigned(x)) { - return lower; - } - - int spansize = 1; // could set larger - // bootstrap an upper limit - - while (lower + spansize < size - && BufferUtil.toIntUnsigned(keys[lower + spansize]) < BufferUtil.toIntUnsigned(x)) { - spansize *= 2; // hoping for compiler will reduce to shift - } - int upper = (lower + spansize < size) ? lower + spansize : size - 1; - - // maybe we are lucky (could be common case when the seek ahead - // expected to be small and sequential will otherwise make us look bad) - if (keys[upper] == x) { - return upper; - } - - if (BufferUtil.toIntUnsigned(keys[upper]) < BufferUtil.toIntUnsigned(x)) {// means array has no - // item key >= x - return size; - } - - // we know that the next-smallest span was too small - lower += (spansize / 2); - - // else begin binary search - // invariant: array[lower]x - while (lower + 1 != upper) { - int mid = (lower + upper) / 2; - if (keys[mid] == x) { - return mid; - } else if (BufferUtil.toIntUnsigned(keys[mid]) < BufferUtil.toIntUnsigned(x)) { - lower = mid; - } else { - upper = mid; - } - } - return upper; - } - - protected void append(short key, MappeableContainer value) { - extendArray(1); - this.keys[this.size] = key; - this.values[this.size] = value; - this.size++; - } - - /** - * Append copies of the values AFTER a specified key (may or may not be present) to end. - * - * @param highLowContainer the other array - * @param beforeStart given key is the largest key that we won't copy - */ - protected void appendCopiesAfter(PointableRoaringArray highLowContainer, short beforeStart) { - - int startLocation = highLowContainer.getIndex(beforeStart); - if (startLocation >= 0) { - startLocation++; - } else { - startLocation = -startLocation - 1; - } - extendArray(highLowContainer.size() - startLocation); - - for (int i = startLocation; i < highLowContainer.size(); ++i) { - this.keys[this.size] = highLowContainer.getKeyAtIndex(i); - this.values[this.size] = highLowContainer.getContainerAtIndex(i).clone(); - this.size++; - } - } - - /** - * Append copies of the values from another array, from the start - * - * @param highLowContainer the other array - * @param stoppingKey any equal or larger key in other array will terminate copying - */ - protected void appendCopiesUntil(PointableRoaringArray highLowContainer, short stoppingKey) { - final int stopKey = BufferUtil.toIntUnsigned(stoppingKey); - MappeableContainerPointer cp = highLowContainer.getContainerPointer(); - while (cp.hasContainer()) { - if (BufferUtil.toIntUnsigned(cp.key()) >= stopKey) { - break; - } - extendArray(1); - this.keys[this.size] = cp.key(); - this.values[this.size] = cp.getContainer().clone(); - this.size++; - cp.advance(); - } - } - - /** - * Append copies of the values from another array - * - * @param highLowContainer other array - * @param startingIndex starting index in the other array - * @param end last index array in the other array - */ - protected void appendCopy(PointableRoaringArray highLowContainer, int startingIndex, int end) { - extendArray(end - startingIndex); - for (int i = startingIndex; i < end; ++i) { - this.keys[this.size] = highLowContainer.getKeyAtIndex(i); - this.values[this.size] = highLowContainer.getContainerAtIndex(i).clone(); - this.size++; - } - } - - protected void appendCopy(short key, MappeableContainer value) { - extendArray(1); - this.keys[this.size] = key; - this.values[this.size] = value.clone(); - this.size++; - } - - private int binarySearch(int begin, int end, short key) { - return Util.unsignedBinarySearch(keys, begin, end, key); - } - - protected void clear() { - this.keys = null; - this.values = null; - this.size = 0; - } - - @Override - public MutableRoaringArray clone() { - MutableRoaringArray sa; - try { - sa = (MutableRoaringArray) super.clone(); - - // OFK: do we need runcontainer bitmap? Guess not, this is just a directory - // and each container knows what kind it is. - sa.keys = Arrays.copyOf(this.keys, this.size); - sa.values = Arrays.copyOf(this.values, this.size); - for (int k = 0; k < this.size; ++k) { - sa.values[k] = sa.values[k].clone(); - } - sa.size = this.size; - return sa; - - } catch (CloneNotSupportedException e) { - return null; - } - } - - protected void copyRange(int begin, int end, int newBegin) { - // assuming begin <= end and newBegin < begin - final int range = end - begin; - System.arraycopy(this.keys, begin, this.keys, newBegin, range); - System.arraycopy(this.values, begin, this.values, newBegin, range); - } - - /** - * Deserialize. - * - * @param in the DataInput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void deserialize(DataInput in) throws IOException { - this.clear(); - // little endian - final int cookie = Integer.reverseBytes(in.readInt()); - if ((cookie & 0xFFFF) != SERIAL_COOKIE && cookie != SERIAL_COOKIE_NO_RUNCONTAINER) { - throw new IOException("I failed to find the one of the right cookies."); - } - this.size = ((cookie & 0xFFFF) == SERIAL_COOKIE) ? (cookie >>> 16) + 1 - : Integer.reverseBytes(in.readInt()); - if ((this.keys == null) || (this.keys.length < this.size)) { - this.keys = new short[this.size]; - this.values = new MappeableContainer[this.size]; - } - - byte[] bitmapOfRunContainers = null; - boolean hasrun = (cookie & 0xFFFF) == SERIAL_COOKIE; - if (hasrun) { - bitmapOfRunContainers = new byte[(size + 7) / 8]; - in.readFully(bitmapOfRunContainers); - } - - final short keys[] = new short[this.size]; - final int cardinalities[] = new int[this.size]; - final boolean isBitmap[] = new boolean[this.size]; - for (int k = 0; k < this.size; ++k) { - keys[k] = Short.reverseBytes(in.readShort()); - cardinalities[k] = 1 + (0xFFFF & Short.reverseBytes(in.readShort())); - isBitmap[k] = cardinalities[k] > MappeableArrayContainer.DEFAULT_MAX_SIZE; - if (bitmapOfRunContainers != null && (bitmapOfRunContainers[k / 8] & (1 << (k % 8))) != 0) { - isBitmap[k] = false; - } - } - if ((!hasrun) || (this.size >= NO_OFFSET_THRESHOLD)) { - // skipping the offsets - in.skipBytes(this.size * 4); - } - // Reading the containers - for (int k = 0; k < this.size; ++k) { - MappeableContainer val; - if (isBitmap[k]) { - final LongBuffer bitmapArray = - LongBuffer.allocate(MappeableBitmapContainer.MAX_CAPACITY / 64); - // little endian - for (int l = 0; l < bitmapArray.limit(); ++l) { - bitmapArray.put(l, Long.reverseBytes(in.readLong())); - } - val = new MappeableBitmapContainer(bitmapArray, cardinalities[k]); - } else if (bitmapOfRunContainers != null - && ((bitmapOfRunContainers[k / 8] & (1 << (k % 8))) != 0)) { - int nbrruns = BufferUtil.toIntUnsigned(Short.reverseBytes(in.readShort())); - final ShortBuffer shortArray = ShortBuffer.allocate(2 * nbrruns); - for (int l = 0; l < shortArray.limit(); ++l) { - shortArray.put(l, Short.reverseBytes(in.readShort())); - } - val = new MappeableRunContainer(shortArray, nbrruns); - } else { - final ShortBuffer shortArray = ShortBuffer.allocate(cardinalities[k]); - for (int l = 0; l < shortArray.limit(); ++l) { - shortArray.put(l, Short.reverseBytes(in.readShort())); - } - val = new MappeableArrayContainer(shortArray, cardinalities[k]); - } - this.keys[k] = keys[k]; - this.values[k] = val; - } - } - - // make sure there is capacity for at least k more elements - protected void extendArray(int k) { - // size + 1 could overflow - if (this.size + k >= this.keys.length) { - int newCapacity; - if (this.keys.length < 1024) { - newCapacity = 2 * (this.size + k); - } else { - newCapacity = 5 * (this.size + k) / 4; - } - this.keys = Arrays.copyOf(this.keys, newCapacity); - this.values = Arrays.copyOf(this.values, newCapacity); - } - } - - @Override - public int getCardinality(int i) { - return getContainerAtIndex(i).getCardinality(); - } - - // involves a binary search - @Override - public MappeableContainer getContainer(short x) { - final int i = this.binarySearch(0, size, x); - if (i < 0) { - return null; - } - return this.values[i]; - } - - @Override - public MappeableContainer getContainerAtIndex(int i) { - return this.values[i]; - } - - @Override - public MappeableContainerPointer getContainerPointer() { - return getContainerPointer(0); - } - - @Override - public MappeableContainerPointer getContainerPointer(final int startIndex) { - return new MappeableContainerPointer() { - int k = startIndex; - - @Override - public void advance() { - ++k; - } - - @Override - public MappeableContainerPointer clone() { - try { - return (MappeableContainerPointer) super.clone(); - } catch (CloneNotSupportedException e) { - return null;// will not happen - } - } - - @Override - public int compareTo(MappeableContainerPointer o) { - if (key() != o.key()) { - return BufferUtil.toIntUnsigned(key()) - BufferUtil.toIntUnsigned(o.key()); - } - return o.getCardinality() - this.getCardinality(); - } - - @Override - public int getCardinality() { - return getContainer().getCardinality(); - } - - @Override - public MappeableContainer getContainer() { - if (k >= MutableRoaringArray.this.size) { - return null; - } - return MutableRoaringArray.this.values[k]; - } - - @Override - public int getSizeInBytes() { - return getContainer().getArraySizeInBytes(); - } - - @Override - public boolean hasContainer() { - return 0 <= k & k < MutableRoaringArray.this.size; - } - - @Override - public boolean isBitmapContainer() { - return getContainer() instanceof MappeableBitmapContainer; - } - - @Override - public boolean isRunContainer() { - return getContainer() instanceof MappeableRunContainer; - } - - @Override - public short key() { - return MutableRoaringArray.this.keys[k]; - - } - - - @Override - public void previous() { - --k; - } - }; - - } - - // involves a binary search - @Override - public int getIndex(short x) { - // before the binary search, we optimize for frequent cases - if ((size == 0) || (keys[size - 1] == x)) { - return size - 1; - } - // no luck we have to go through the list - return this.binarySearch(0, size, x); - } - - @Override - public short getKeyAtIndex(int i) { - return this.keys[i]; - } - - @Override - public int hashCode() { - int hashvalue = 0; - for (int k = 0; k < this.size; ++k) { - hashvalue = 31 * hashvalue + keys[k] * 0xF0F0F0 + values[k].hashCode(); - } - return hashvalue; - } - - @Override - public boolean hasRunCompression() { - for (int k = 0; k < size; ++k) { - MappeableContainer ck = values[k]; - if (ck instanceof MappeableRunContainer) { - return true; - } - } - return false; - } - - protected int headerSize() { - if (hasRunCompression()) { - if (size < NO_OFFSET_THRESHOLD) {// for small bitmaps, we omit the offsets - return 4 + (size + 7) / 8 + 4 * size; - } - return 4 + (size + 7) / 8 + 8 * size;// - 4 because we pack the size with the cookie - } else { - return 4 + 4 + 8 * size; - } - } - - // insert a new key, it is assumed that it does not exist - protected void insertNewKeyValueAt(int i, short key, MappeableContainer value) { - extendArray(1); - System.arraycopy(keys, i, keys, i + 1, size - i); - System.arraycopy(values, i, values, i + 1, size - i); - keys[i] = key; - values[i] = value; - size++; - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - deserialize(in); - } - - protected void removeAtIndex(int i) { - System.arraycopy(keys, i + 1, keys, i, size - i - 1); - keys[size - 1] = 0; - System.arraycopy(values, i + 1, values, i, size - i - 1); - values[size - 1] = null; - size--; - } - - - protected void removeIndexRange(int begin, int end) { - if (end <= begin) { - return; - } - final int range = end - begin; - System.arraycopy(keys, end, keys, begin, size - end); - System.arraycopy(values, end, values, begin, size - end); - for (int i = 1; i <= range; ++i) { - keys[size - i] = 0; - values[size - i] = null; - } - size -= range; - } - - protected void replaceKeyAndContainerAtIndex(int i, short key, MappeableContainer c) { - this.keys[i] = key; - this.values[i] = c; - } - - - protected void resize(int newLength) { - Arrays.fill(this.keys, newLength, this.size, (short) 0); - Arrays.fill(this.values, newLength, this.size, null); - this.size = newLength; - } - - /** - * Serialize. - *

- * The current bitmap is not modified. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - @Override - public void serialize(DataOutput out) throws IOException { - int startOffset = 0; - boolean hasrun = hasRunCompression(); - if (hasrun) { - out.writeInt(Integer.reverseBytes(SERIAL_COOKIE | ((this.size - 1) << 16))); - byte[] bitmapOfRunContainers = new byte[(size + 7) / 8]; - for (int i = 0; i < size; ++i) { - if (this.values[i] instanceof MappeableRunContainer) { - bitmapOfRunContainers[i / 8] |= (1 << (i % 8)); - } - } - out.write(bitmapOfRunContainers); - if (this.size < NO_OFFSET_THRESHOLD) { - startOffset = 4 + 4 * this.size + bitmapOfRunContainers.length; - } else { - startOffset = 4 + 8 * this.size + bitmapOfRunContainers.length; - } - } else { // backwards compatibilility - out.writeInt(Integer.reverseBytes(SERIAL_COOKIE_NO_RUNCONTAINER)); - out.writeInt(Integer.reverseBytes(size)); - startOffset = 4 + 4 + this.size * 4 + this.size * 4; - } - for (int k = 0; k < size; ++k) { - out.writeShort(Short.reverseBytes(this.keys[k])); - out.writeShort(Short.reverseBytes((short) (this.values[k].getCardinality() - 1))); - } - if ((!hasrun) || (this.size >= NO_OFFSET_THRESHOLD)) { - for (int k = 0; k < this.size; k++) { - out.writeInt(Integer.reverseBytes(startOffset)); - startOffset = startOffset + values[k].getArraySizeInBytes(); - } - } - for (int k = 0; k < size; ++k) { - values[k].writeArray(out); - } - - } - - /** - * Report the number of bytes required for serialization. - * - * @return the size in bytes - */ - @Override - public int serializedSizeInBytes() { - int count = headerSize(); - // for each container, we store cardinality (16 bits), key (16 bits) and location offset (32 - // bits). - for (int k = 0; k < this.size; ++k) { - count += values[k].getArraySizeInBytes(); - } - return count; - } - - protected void setContainerAtIndex(int i, MappeableContainer c) { - this.values[i] = c; - } - - @Override - public int size() { - return this.size; - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - serialize(out); - } -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MutableRoaringBitmap.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MutableRoaringBitmap.java deleted file mode 100644 index 902e421a7..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/MutableRoaringBitmap.java +++ /dev/null @@ -1,1420 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import com.fr.third.bitmap.roaringbitmap.BitmapDataProvider; -import com.fr.third.bitmap.roaringbitmap.ContainerPointer; -import com.fr.third.bitmap.roaringbitmap.RoaringBitmap; -import com.fr.third.bitmap.roaringbitmap.ShortIterator; -import com.fr.third.bitmap.roaringbitmap.Util; - -import java.io.DataInput; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serializable; -import java.util.Iterator; - -/** - * MutableRoaringBitmap, a compressed alternative to the BitSet. It is similar to - * RoaringBitmap, but it differs in that it can interact with - * ImmutableRoaringBitmap objects. - *

- * A MutableRoaringBitmap is an instance of an ImmutableRoaringBitmap (where methods like - * "serialize" are implemented). That is, they both share the same core (immutable) methods, but a - * MutableRoaringBitmap adds methods that allow you to modify the object. This design allows us to - * use MutableRoaringBitmap as ImmutableRoaringBitmap instances when needed. - *

- * A MutableRoaringBitmap can be used much like an RoaringBitmap instance, and - * they serialize to the same output. The RoaringBitmap instance will be faster since it does not - * carry the overhead of a ByteBuffer back-end, but the MutableRoaringBitmap can be used as an - * ImmutableRoaringBitmap instance. Thus, if you use ImmutableRoaringBitmap, you probably need to - * use MutableRoaringBitmap instances as well; if you do not use ImmutableRoaringBitmap, you - * probably want to use only RoaringBitmap instances. - *

- *

- * {@code
- *      import com.fr.swift.bitmap.roaringbitmap.buffer.*;
- *
- *      //...
- *
- *      MutableRoaringBitmap rr = MutableRoaringBitmap.bitmapOf(1,2,3,1000);
- *      MutableRoaringBitmap rr2 = new MutableRoaringBitmap();
- *      for(int k = 4000; k<4255;++k) rr2.add(k);
- *
- *      RoaringBitmap rror = RoaringBitmap.or(rr, rr2);
- *
- *      //...
- *      DataOutputStream wheretoserialize = ...
- *      rr.runOptimize(); // can help compression
- *      rr.serialize(wheretoserialize);
- * }
- * 
- * - * @see ImmutableRoaringBitmap - * @see RoaringBitmap - */ -public class MutableRoaringBitmap extends ImmutableRoaringBitmap - implements Cloneable, Serializable, Iterable, Externalizable, BitmapDataProvider { - private static final long serialVersionUID = 4L; // 3L; bumped by ofk for runcontainers - - - /** - * Create an empty bitmap - */ - public MutableRoaringBitmap() { - highLowContainer = new MutableRoaringArray(); - } - - /** - * Create a MutableRoaringBitmap from a RoaringBitmap. The RoaringBitmap is not modified. - * - * @param rb the original bitmap - */ - public MutableRoaringBitmap(RoaringBitmap rb) { - highLowContainer = new MutableRoaringArray(); - ContainerPointer cp = rb.getContainerPointer(); - while (cp.getContainer() != null) { - ((MutableRoaringArray) highLowContainer).append(cp.key(), - cp.getContainer().toMappeableContainer()); - cp.advance(); - } - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) added. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - */ - public static MutableRoaringBitmap add(MutableRoaringBitmap rb, final long rangeStart, - final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return rb.clone(); // empty range - } - - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - ((MutableRoaringArray) answer.highLowContainer).appendCopiesUntil(rb.highLowContainer, - (short) hbStart); - - if (hbStart == hbLast) { - final int i = rb.highLowContainer.getIndex((short) hbStart); - final MappeableContainer c = - i >= 0 ? rb.highLowContainer.getContainerAtIndex(i).add(lbStart, lbLast + 1) - : MappeableContainer.rangeOfOnes(lbStart, lbLast + 1); - ((MutableRoaringArray) answer.highLowContainer).append((short) hbStart, c); - ((MutableRoaringArray) answer.highLowContainer).appendCopiesAfter(rb.highLowContainer, - (short) hbLast); - return answer; - } - int ifirst = rb.highLowContainer.getIndex((short) hbStart); - int ilast = rb.highLowContainer.getIndex((short) hbLast); - - { - final MappeableContainer c = ifirst >= 0 - ? rb.highLowContainer.getContainerAtIndex(ifirst).add(lbStart, - BufferUtil.maxLowBitAsInteger() + 1) - : MappeableContainer.rangeOfOnes(lbStart, BufferUtil.maxLowBitAsInteger() + 1); - ((MutableRoaringArray) answer.highLowContainer).append((short) hbStart, c); - } - for (int hb = hbStart + 1; hb < hbLast; ++hb) { - MappeableContainer c = MappeableContainer.rangeOfOnes(0, BufferUtil.maxLowBitAsInteger() + 1); - ((MutableRoaringArray) answer.highLowContainer).append((short) hb, c); - } - { - final MappeableContainer c = - ilast >= 0 ? rb.highLowContainer.getContainerAtIndex(ilast).add(0, lbLast + 1) - : MappeableContainer.rangeOfOnes(0, lbLast + 1); - ((MutableRoaringArray) answer.highLowContainer).append((short) hbLast, c); - } - ((MutableRoaringArray) answer.highLowContainer).appendCopiesAfter(rb.highLowContainer, - (short) hbLast); - return answer; - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) added. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static MutableRoaringBitmap add(MutableRoaringBitmap rb, - final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return add(rb, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return add(rb, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * Bitwise AND (intersection) operation. The provided bitmaps are *not* modified. This operation - * is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - */ - public static MutableRoaringBitmap and(final MutableRoaringBitmap x1, - final MutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - if (s1 == s2) { - final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final MappeableContainer c = c1.and(c2); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().append(s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = x1.highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - return answer; - } - - /** - * Bitwise ANDNOT (difference) operation. The provided bitmaps are *not* modified. This operation - * is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - */ - public static MutableRoaringBitmap andNot(final MutableRoaringBitmap x1, - final MutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final MappeableContainer c = c1.andNot(c2); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().append(s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - final int nextPos1 = x1.highLowContainer.advanceUntil(s2, pos1); - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer, pos1, nextPos1); - pos1 = nextPos1; - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - if (pos2 == length2) { - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer, pos1, length1); - } - return answer; - } - - /** - * Generate a bitmap with the specified values set to true. The provided integers values don't - * have to be in sorted order, but it may be preferable to sort them from a performance point of - * view. - * - * @param dat set values - * @return a new bitmap - */ - public static MutableRoaringBitmap bitmapOf(final int... dat) { - final MutableRoaringBitmap ans = new MutableRoaringBitmap(); - ans.add(dat); - return ans; - } - - protected static void rangeSanityCheck(final long rangeStart, final long rangeEnd) { - if (rangeStart < 0 || rangeStart > (1L << 32) - 1) { - throw new IllegalArgumentException("rangeStart=" + rangeStart - + " should be in [0, 0xffffffff]"); - } - if (rangeEnd > (1L << 32) || rangeEnd < 0) { - throw new IllegalArgumentException("rangeEnd=" + rangeEnd - + " should be in [0, 0xffffffff + 1]"); - } - } - - /** - * Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The - * given bitmap is unchanged. - * - * @param bm bitmap being negated - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return a new Bitmap - */ - public static MutableRoaringBitmap flip(MutableRoaringBitmap bm, final long rangeStart, - final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return bm.clone(); - } - - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - - - // copy the containers before the active area - answer.getMappeableRoaringArray().appendCopiesUntil(bm.highLowContainer, (short) hbStart); - - for (int hb = hbStart; hb <= hbLast; ++hb) { - final int containerStart = (hb == hbStart) ? lbStart : 0; - final int containerLast = (hb == hbLast) ? lbLast : BufferUtil.maxLowBitAsInteger(); - - final int i = bm.highLowContainer.getIndex((short) hb); - final int j = answer.highLowContainer.getIndex((short) hb); - assert j < 0; - - if (i >= 0) { - final MappeableContainer c = - bm.highLowContainer.getContainerAtIndex(i).not(containerStart, containerLast + 1); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, (short) hb, c); - } - - } else { // *think* the range of ones must never be - // empty. - answer.getMappeableRoaringArray().insertNewKeyValueAt(-j - 1, (short) hb, - MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); - } - } - // copy the containers after the active area. - answer.getMappeableRoaringArray().appendCopiesAfter(bm.highLowContainer, (short) hbLast); - - return answer; - } - - /** - * Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The - * given bitmap is unchanged. - * - * @param rb bitmap being negated - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return a new Bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static MutableRoaringBitmap flip(MutableRoaringBitmap rb, - final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return flip(rb, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return flip(rb, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - // important: inputs should not have been computed lazily - protected static MutableRoaringBitmap lazyorfromlazyinputs(final MutableRoaringBitmap x1, - final MutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - MappeableContainerPointer i1 = x1.highLowContainer.getContainerPointer(); - MappeableContainerPointer i2 = x2.highLowContainer.getContainerPointer(); - main: - if (i1.hasContainer() && i2.hasContainer()) { - while (true) { - if (i1.key() == i2.key()) { - MappeableContainer c1 = i1.getContainer(); - MappeableContainer c2 = i2.getContainer(); - if ((c2 instanceof MappeableBitmapContainer) - && (!(c1 instanceof MappeableBitmapContainer))) { - MappeableContainer tmp = c1; - c1 = c2; - c2 = tmp; - } - answer.getMappeableRoaringArray().append(i1.key(), c1.lazyIOR(c2)); - i1.advance(); - i2.advance(); - if (!i1.hasContainer() || !i2.hasContainer()) { - break main; - } - } else if (Util.compareUnsigned(i1.key(), i2.key()) < 0) { // i1.key() < i2.key() - answer.getMappeableRoaringArray().append(i1.key(), i1.getContainer()); - i1.advance(); - if (!i1.hasContainer()) { - break main; - } - } else { // i1.key() > i2.key() - answer.getMappeableRoaringArray().append(i2.key(), i2.getContainer()); - i2.advance(); - if (!i2.hasContainer()) { - break main; - } - } - } - } - if (!i1.hasContainer()) { - while (i2.hasContainer()) { - answer.getMappeableRoaringArray().append(i2.key(), i2.getContainer()); - i2.advance(); - } - } else if (!i2.hasContainer()) { - while (i1.hasContainer()) { - answer.getMappeableRoaringArray().append(i1.key(), i1.getContainer()); - i1.advance(); - } - } - return answer; - } - - /** - * Compute overall OR between bitmaps. - *

- * (Effectively calls {@link BufferFastAggregation#or}) - * - * @param bitmaps input bitmaps - * @return aggregated bitmap - */ - public static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps) { - return BufferFastAggregation.or(bitmaps); - } - - /** - * Bitwise OR (union) operation. The provided bitmaps are *not* modified. This operation is - * thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - */ - public static MutableRoaringBitmap or(final MutableRoaringBitmap x1, - final MutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - answer.getMappeableRoaringArray().append(s1, x1.highLowContainer.getContainerAtIndex(pos1) - .or(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer.getKeyAtIndex(pos1), - x1.highLowContainer.getContainerAtIndex(pos1)); - pos1++; - if (pos1 == length1) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - answer.getMappeableRoaringArray().appendCopy(x2.highLowContainer.getKeyAtIndex(pos2), - x2.highLowContainer.getContainerAtIndex(pos2)); - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - answer.getMappeableRoaringArray().appendCopy(x2.highLowContainer, pos2, length2); - } else if (pos2 == length2) { - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer, pos1, length1); - } - return answer; - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - */ - public static MutableRoaringBitmap remove(MutableRoaringBitmap rb, final long rangeStart, - final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return rb.clone(); // empty range - } - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - MutableRoaringBitmap answer = new MutableRoaringBitmap(); - ((MutableRoaringArray) answer.highLowContainer).appendCopiesUntil(rb.highLowContainer, - (short) hbStart); - - if (hbStart == hbLast) { - final int i = rb.highLowContainer.getIndex((short) hbStart); - if (i >= 0) { - final MappeableContainer c = - rb.highLowContainer.getContainerAtIndex(i).remove(lbStart, lbLast + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) answer.highLowContainer).append((short) hbStart, c); - } - } - ((MutableRoaringArray) answer.highLowContainer).appendCopiesAfter(rb.highLowContainer, - (short) hbLast); - return answer; - } - int ifirst = rb.highLowContainer.getIndex((short) hbStart); - int ilast = rb.highLowContainer.getIndex((short) hbLast); - if ((ifirst >= 0) && (lbStart != 0)) { - final MappeableContainer c = rb.highLowContainer.getContainerAtIndex(ifirst).remove(lbStart, - BufferUtil.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) answer.highLowContainer).append((short) hbStart, c); - } - } - if ((ilast >= 0) && (lbLast != BufferUtil.maxLowBitAsInteger())) { - final MappeableContainer c = - rb.highLowContainer.getContainerAtIndex(ilast).remove(0, lbLast + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) answer.highLowContainer).append((short) hbLast, c); - } - } - ((MutableRoaringArray) answer.highLowContainer).appendCopiesAfter(rb.highLowContainer, - (short) hbLast); - return answer; - } - - /** - * Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed. - * - * @param rb initial bitmap (will not be modified) - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @return new bitmap - * @deprecated use the version where longs specify the range - */ - @Deprecated - public static MutableRoaringBitmap remove(MutableRoaringBitmap rb, - final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - return remove(rb, (long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - return remove(rb, rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * Bitwise XOR (symmetric difference) operation. The provided bitmaps are *not* modified. This - * operation is thread-safe as long as the provided bitmaps remain unchanged. - * - * @param x1 first bitmap - * @param x2 other bitmap - * @return result of the operation - */ - public static MutableRoaringBitmap xor(final MutableRoaringBitmap x1, - final MutableRoaringBitmap x2) { - final MutableRoaringBitmap answer = new MutableRoaringBitmap(); - int pos1 = 0, pos2 = 0; - final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size(); - - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = x1.highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - final MappeableContainer c = x1.highLowContainer.getContainerAtIndex(pos1) - .xor(x2.highLowContainer.getContainerAtIndex(pos2)); - if (c.getCardinality() > 0) { - answer.getMappeableRoaringArray().append(s1, c); - } - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer.getKeyAtIndex(pos1), - x1.highLowContainer.getContainerAtIndex(pos1)); - pos1++; - if (pos1 == length1) { - break main; - } - s1 = x1.highLowContainer.getKeyAtIndex(pos1); - } else if (s1 > s2) { - answer.getMappeableRoaringArray().appendCopy(x2.highLowContainer.getKeyAtIndex(pos2), - x2.highLowContainer.getContainerAtIndex(pos2)); - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - answer.getMappeableRoaringArray().appendCopy(x2.highLowContainer, pos2, length2); - } else if (pos2 == length2) { - answer.getMappeableRoaringArray().appendCopy(x1.highLowContainer, pos1, length1); - } - - return answer; - } - - /** - * Assume that one wants to store "cardinality" integers in [0, universe_size), - * this function returns an upper bound on the serialized size in bytes. - *

- * This function is identical to RoaringBitmap.maximumSerializedSize. - * - * @param cardinality maximal cardinality - * @param universe_size maximal value - * @return upper bound on the serialized size in bytes of the bitmap - */ - public static long maximumSerializedSize(int cardinality, int universe_size) { - return RoaringBitmap.maximumSerializedSize(cardinality, universe_size); - } - - /** - * Set all the specified values to true. This can be expected to be slightly - * faster than calling "add" repeatedly. The provided integers values don't - * have to be in sorted order, but it may be preferable to sort them from a performance point of - * view. - * - * @param dat set values - */ - public void add(final int... dat) { - MutableRoaringArray mra = (MutableRoaringArray) highLowContainer; - MappeableContainer currentcont = null; - short currenthb = 0; - int currentcontainerindex = 0; - int j = 0; - if (j < dat.length) { - int val = dat[j]; - currenthb = BufferUtil.highbits(val); - currentcontainerindex = highLowContainer.getIndex(currenthb); - if (currentcontainerindex >= 0) { - currentcont = highLowContainer.getContainerAtIndex(currentcontainerindex); - MappeableContainer newcont = currentcont.add(BufferUtil.lowbits(val)); - if (newcont != currentcont) { - mra.setContainerAtIndex(currentcontainerindex, newcont); - currentcont = newcont; - } - } else { - currentcontainerindex = -currentcontainerindex - 1; - final MappeableArrayContainer newac = new MappeableArrayContainer(); - currentcont = newac.add(BufferUtil.lowbits(val)); - mra.insertNewKeyValueAt(currentcontainerindex, currenthb, currentcont); - } - j++; - } - for (; j < dat.length; ++j) { - int val = dat[j]; - short newhb = BufferUtil.highbits(val); - if (currenthb == newhb) {// easy case - // this could be quite frequent - MappeableContainer newcont = currentcont.add(BufferUtil.lowbits(val)); - if (newcont != currentcont) { - mra.setContainerAtIndex(currentcontainerindex, newcont); - currentcont = newcont; - } - } else { - currenthb = newhb; - currentcontainerindex = highLowContainer.getIndex(currenthb); - if (currentcontainerindex >= 0) { - currentcont = highLowContainer.getContainerAtIndex(currentcontainerindex); - MappeableContainer newcont = currentcont.add(BufferUtil.lowbits(val)); - if (newcont != currentcont) { - mra.setContainerAtIndex(currentcontainerindex, newcont); - currentcont = newcont; - } - } else { - currentcontainerindex = -currentcontainerindex - 1; - final MappeableArrayContainer newac = new MappeableArrayContainer(); - currentcont = newac.add(BufferUtil.lowbits(val)); - mra.insertNewKeyValueAt(currentcontainerindex, currenthb, currentcont); - } - } - } - } - - /** - * Add the value to the container (set the value to "true"), whether it already appears or not. - * - * @param x integer value - */ - @Override - public void add(final int x) { - final short hb = BufferUtil.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i >= 0) { - getMappeableRoaringArray().setContainerAtIndex(i, - highLowContainer.getContainerAtIndex(i).add(BufferUtil.lowbits(x))); - } else { - final MappeableArrayContainer newac = new MappeableArrayContainer(); - getMappeableRoaringArray().insertNewKeyValueAt(-i - 1, hb, newac.add(BufferUtil.lowbits(x))); - } - } - - /** - * Add to the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - */ - public void add(final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return; // empty range - } - - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - for (int hb = hbStart; hb <= hbLast; ++hb) { - - // first container may contain partial range - final int containerStart = (hb == hbStart) ? lbStart : 0; - // last container may contain partial range - final int containerLast = (hb == hbLast) ? lbLast : BufferUtil.maxLowBitAsInteger(); - final int i = highLowContainer.getIndex((short) hb); - - if (i >= 0) { - final MappeableContainer c = - highLowContainer.getContainerAtIndex(i).iadd(containerStart, containerLast + 1); - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(i, c); - } else { - ((MutableRoaringArray) highLowContainer).insertNewKeyValueAt(-i - 1, (short) hb, - MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); - } - } - } - - /** - * Add to the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @deprecated use the version where longs specify the range - */ - @Deprecated - public void add(final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - add((long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - add(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * In-place bitwise AND (intersection) operation. The current bitmap is modified. - * - * @param array other bitmap - */ - public void and(final ImmutableRoaringBitmap array) { - int pos1 = 0, pos2 = 0, intersectionSize = 0; - final int length1 = highLowContainer.size(), length2 = array.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = highLowContainer.getKeyAtIndex(pos1); - final short s2 = array.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final MappeableContainer c1 = highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = array.highLowContainer.getContainerAtIndex(pos2); - final MappeableContainer c = c1.iand(c2); - if (c.getCardinality() > 0) { - getMappeableRoaringArray().replaceKeyAndContainerAtIndex(intersectionSize++, s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1 = highLowContainer.advanceUntil(s2, pos1); - } else { // s1 > s2 - pos2 = array.highLowContainer.advanceUntil(s1, pos2); - } - } - getMappeableRoaringArray().resize(intersectionSize); - } - - /** - * In-place bitwise ANDNOT (difference) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void andNot(final ImmutableRoaringBitmap x2) { - int pos1 = 0, pos2 = 0, intersectionSize = 0; - final int length1 = highLowContainer.size(), length2 = x2.highLowContainer.size(); - - while (pos1 < length1 && pos2 < length2) { - final short s1 = highLowContainer.getKeyAtIndex(pos1); - final short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - if (s1 == s2) { - final MappeableContainer c1 = highLowContainer.getContainerAtIndex(pos1); - final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2); - final MappeableContainer c = c1.iandNot(c2); - if (c.getCardinality() > 0) { - getMappeableRoaringArray().replaceKeyAndContainerAtIndex(intersectionSize++, s1, c); - } - ++pos1; - ++pos2; - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - if (pos1 != intersectionSize) { - final MappeableContainer c1 = highLowContainer.getContainerAtIndex(pos1); - getMappeableRoaringArray().replaceKeyAndContainerAtIndex(intersectionSize, s1, c1); - } - ++intersectionSize; - ++pos1; - } else { // s1 > s2 - pos2 = x2.highLowContainer.advanceUntil(s1, pos2); - } - } - if (pos1 < length1) { - getMappeableRoaringArray().copyRange(pos1, length1, intersectionSize); - intersectionSize += length1 - pos1; - } - getMappeableRoaringArray().resize(intersectionSize); - } - - /** - * Add the value to the container (set the value to "true"), whether it already appears or not. - * - * @param x integer value - * @return true if the added int wasn't already contained in the bitmap. False otherwise. - */ - public boolean checkedAdd(final int x) { - final short hb = BufferUtil.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i >= 0) { - MappeableContainer C = highLowContainer.getContainerAtIndex(i); - int oldcard = C.getCardinality(); - C = C.add(BufferUtil.lowbits(x)); - getMappeableRoaringArray().setContainerAtIndex(i, C); - return C.getCardinality() > oldcard; - } else { - final MappeableArrayContainer newac = new MappeableArrayContainer(); - getMappeableRoaringArray().insertNewKeyValueAt(-i - 1, hb, newac.add(BufferUtil.lowbits(x))); - return true; - } - } - - /** - * If present remove the specified integer (effectively, sets its bit value to false) - * - * @param x integer value representing the index in a bitmap - * @return true if the unset bit was already in the bitmap - */ - public boolean checkedRemove(final int x) { - final short hb = BufferUtil.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i < 0) { - return false; - } - MappeableContainer C = highLowContainer.getContainerAtIndex(i); - int oldcard = C.getCardinality(); - C.remove(BufferUtil.lowbits(x)); - int newcard = C.getCardinality(); - if (newcard == oldcard) { - return false; - } - if (newcard > 0) { - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(i, C); - } else { - ((MutableRoaringArray) highLowContainer).removeAtIndex(i); - } - return true; - } - - /** - * reset to an empty bitmap; result occupies as much space a newly created bitmap. - */ - public void clear() { - highLowContainer = new MutableRoaringArray(); // lose references - } - - @Override - public MutableRoaringBitmap clone() { - final MutableRoaringBitmap x = (MutableRoaringBitmap) super.clone(); - x.highLowContainer = highLowContainer.clone(); - return x; - - } - - /** - * Deserialize the bitmap (retrieve from the input stream). The current bitmap is overwritten. - * - * @param in the DataInput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void deserialize(DataInput in) throws IOException { - getMappeableRoaringArray().deserialize(in); - } - - /** - * Add the value if it is not already present, otherwise remove it. - * - * @param x integer value - */ - public void flip(final int x) { - final short hb = BufferUtil.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i >= 0) { - MappeableContainer c = highLowContainer.getContainerAtIndex(i); - c = c.flip(BufferUtil.lowbits(x)); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(i, c); - } else { - ((MutableRoaringArray) highLowContainer).removeAtIndex(i); - } - } else { - final MappeableArrayContainer newac = new MappeableArrayContainer(); - ((MutableRoaringArray) highLowContainer).insertNewKeyValueAt(-i - 1, hb, - newac.add(BufferUtil.lowbits(x))); - } - } - - /** - * Modifies the current bitmap by complementing the bits in the given range, from rangeStart - * (inclusive) rangeEnd (exclusive). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - */ - public void flip(final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return; // empty range - } - - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - - for (int hb = hbStart; hb <= hbLast; ++hb) { - // first container may contain partial range - final int containerStart = (hb == hbStart) ? lbStart : 0; - // last container may contain partial range - final int containerLast = (hb == hbLast) ? lbLast : BufferUtil.maxLowBitAsInteger(); - final int i = highLowContainer.getIndex((short) hb); - - if (i >= 0) { - final MappeableContainer c = - highLowContainer.getContainerAtIndex(i).inot(containerStart, containerLast + 1); - if (c.getCardinality() > 0) { - getMappeableRoaringArray().setContainerAtIndex(i, c); - } else { - getMappeableRoaringArray().removeAtIndex(i); - } - } else { - getMappeableRoaringArray().insertNewKeyValueAt(-i - 1, (short) hb, - MappeableContainer.rangeOfOnes(containerStart, containerLast + 1)); - } - } - } - - /** - * Modifies the current bitmap by complementing the bits in the given range, from rangeStart - * (inclusive) rangeEnd (exclusive). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @deprecated use the version where longs specify the range - */ - @Deprecated - public void flip(final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - flip((long) rangeStart, (long) rangeEnd); - } else { - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - flip(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - } - - /** - * @return a mutable copy of this bitmap - */ - public MutableRoaringArray getMappeableRoaringArray() { - return (MutableRoaringArray) highLowContainer; - } - - @Override - public int hashCode() { - return highLowContainer.hashCode(); - } - - /** - * iterate over the positions of the true values. - * - * @return the iterator - */ - @Override - public Iterator iterator() { - return new Iterator() { - private int hs = 0; - - private ShortIterator iter; - - private int pos = 0; - - private int x; - - @Override - public boolean hasNext() { - return pos < MutableRoaringBitmap.this.highLowContainer.size(); - } - - private Iterator init() { - if (pos < MutableRoaringBitmap.this.highLowContainer.size()) { - iter = MutableRoaringBitmap.this.highLowContainer.getContainerAtIndex(pos) - .getShortIterator(); - hs = BufferUtil - .toIntUnsigned(MutableRoaringBitmap.this.highLowContainer.getKeyAtIndex(pos)) << 16; - } - return this; - } - - @Override - public Integer next() { - x = BufferUtil.toIntUnsigned(iter.next()) | hs; - if (!iter.hasNext()) { - ++pos; - init(); - } - return x; - } - - @Override - public void remove() { - if ((x & hs) == hs) {// still in same container - iter.remove(); - } else { - MutableRoaringBitmap.this.remove(x); - } - } - - }.init(); - } - - // call repairAfterLazy on result, eventually - // important: x2 should not have been computed lazily - protected void lazyor(final ImmutableRoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - getMappeableRoaringArray().setContainerAtIndex(pos1, highLowContainer - .getContainerAtIndex(pos1).lazyIOR(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - getMappeableRoaringArray().insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - getMappeableRoaringArray().appendCopy(x2.highLowContainer, pos2, length2); - } - } - - // call repairAfterLazy on result, eventually - // important: x2 should not have been computed lazily - // this method is like lazyor except that it will convert - // the current container to a bitset - public void naivelazyor(final ImmutableRoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - MappeableContainer c1 = highLowContainer - .getContainerAtIndex(pos1); - c1 = c1.toBitmapContainer(); - getMappeableRoaringArray().setContainerAtIndex(pos1, - c1.lazyIOR(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - getMappeableRoaringArray().insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - getMappeableRoaringArray().appendCopy(x2.highLowContainer, pos2, length2); - } - } - - /** - * In-place bitwise OR (union) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void or(final ImmutableRoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - getMappeableRoaringArray().setContainerAtIndex(pos1, highLowContainer - .getContainerAtIndex(pos1).ior(x2.highLowContainer.getContainerAtIndex(pos2))); - pos1++; - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - getMappeableRoaringArray().insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - getMappeableRoaringArray().appendCopy(x2.highLowContainer, pos2, length2); - } - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - getMappeableRoaringArray().readExternal(in); - - } - - /** - * If present remove the specified integers (effectively, sets its bit value to false) - * - * @param x integer value representing the index in a bitmap - */ - @Override - public void remove(final int x) { - final short hb = BufferUtil.highbits(x); - final int i = highLowContainer.getIndex(hb); - if (i < 0) { - return; - } - getMappeableRoaringArray().setContainerAtIndex(i, - highLowContainer.getContainerAtIndex(i).remove(BufferUtil.lowbits(x))); - if (highLowContainer.getContainerAtIndex(i).getCardinality() == 0) { - getMappeableRoaringArray().removeAtIndex(i); - } - } - - /** - * Remove from the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - */ - public void remove(final long rangeStart, final long rangeEnd) { - rangeSanityCheck(rangeStart, rangeEnd); - if (rangeStart >= rangeEnd) { - return; // empty range - } - final int hbStart = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeStart)); - final int lbStart = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeStart)); - final int hbLast = BufferUtil.toIntUnsigned(BufferUtil.highbits(rangeEnd - 1)); - final int lbLast = BufferUtil.toIntUnsigned(BufferUtil.lowbits(rangeEnd - 1)); - if (hbStart == hbLast) { - final int i = highLowContainer.getIndex((short) hbStart); - if (i < 0) { - return; - } - final MappeableContainer c = - highLowContainer.getContainerAtIndex(i).iremove(lbStart, lbLast + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(i, c); - } else { - ((MutableRoaringArray) highLowContainer).removeAtIndex(i); - } - return; - } - int ifirst = highLowContainer.getIndex((short) hbStart); - int ilast = highLowContainer.getIndex((short) hbLast); - if (ifirst >= 0) { - if (lbStart != 0) { - final MappeableContainer c = highLowContainer.getContainerAtIndex(ifirst).iremove(lbStart, - BufferUtil.maxLowBitAsInteger() + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(ifirst, c); - ifirst++; - } - } - } else { - ifirst = -ifirst - 1; - } - if (ilast >= 0) { - if (lbLast != BufferUtil.maxLowBitAsInteger()) { - final MappeableContainer c = - highLowContainer.getContainerAtIndex(ilast).iremove(0, lbLast + 1); - if (c.getCardinality() > 0) { - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(ilast, c); - } else { - ilast++; - } - } else { - ilast++; - } - } else { - ilast = -ilast - 1; - } - ((MutableRoaringArray) highLowContainer).removeIndexRange(ifirst, ilast); - } - - /** - * Remove from the current bitmap all integers in [rangeStart,rangeEnd). - * - * @param rangeStart inclusive beginning of range - * @param rangeEnd exclusive ending of range - * @deprecated use the version where longs specify the range - */ - @Deprecated - public void remove(final int rangeStart, final int rangeEnd) { - if (rangeStart >= 0) { - remove((long) rangeStart, (long) rangeEnd); - } - // rangeStart being -ve and rangeEnd being positive is not expected) - // so assume both -ve - remove(rangeStart & 0xFFFFFFFFL, rangeEnd & 0xFFFFFFFFL); - } - - /** - * Remove run-length encoding even when it is more space efficient - * - * @return whether a change was applied - */ - public boolean removeRunCompression() { - boolean answer = false; - for (int i = 0; i < this.highLowContainer.size(); i++) { - MappeableContainer c = getMappeableRoaringArray().getContainerAtIndex(i); - if (c instanceof MappeableRunContainer) { - MappeableContainer mc = - ((MappeableRunContainer) c).toBitmapOrArrayContainer(c.getCardinality()); - getMappeableRoaringArray().setContainerAtIndex(i, mc); - answer = true; - } - } - return answer; - } - - // to be used with lazyor - public void repairAfterLazy() { - for (int k = 0; k < highLowContainer.size(); ++k) { - MappeableContainer c = highLowContainer.getContainerAtIndex(k); - ((MutableRoaringArray) highLowContainer).setContainerAtIndex(k, c.repairAfterLazy()); - } - } - - /** - * Use a run-length encoding where it is estimated as more space efficient - * - * @return whether a change was applied - */ - public boolean runOptimize() { - boolean answer = false; - for (int i = 0; i < this.highLowContainer.size(); i++) { - MappeableContainer c = getMappeableRoaringArray().getContainerAtIndex(i).runOptimize(); - if (c instanceof MappeableRunContainer) { - answer = true; - } - getMappeableRoaringArray().setContainerAtIndex(i, c); - } - return answer; - } - - /** - * Convenience method, effectively casts the object to an object of class ImmutableRoaringBitmap. - *

- *

- * This function is equivalent to : - *

- *

-     * {@code
-     *       (ImmutableRoaringBitmap) bitmap
-     * }
-     * 
- * - * @return a cast of this object - */ - public ImmutableRoaringBitmap toImmutableRoaringBitmap() { - return this; - - } - - /** - * Recover allocated but unused memory. - */ - @Override - public void trim() { - for (int i = 0; i < this.highLowContainer.size(); i++) { - this.highLowContainer.getContainerAtIndex(i).trim(); - } - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - getMappeableRoaringArray().writeExternal(out); - } - - /** - * In-place bitwise XOR (symmetric difference) operation. The current bitmap is modified. - * - * @param x2 other bitmap - */ - public void xor(final ImmutableRoaringBitmap x2) { - int pos1 = 0, pos2 = 0; - int length1 = highLowContainer.size(); - final int length2 = x2.highLowContainer.size(); - - main: - if (pos1 < length1 && pos2 < length2) { - short s1 = highLowContainer.getKeyAtIndex(pos1); - short s2 = x2.highLowContainer.getKeyAtIndex(pos2); - - while (true) { - if (s1 == s2) { - final MappeableContainer c = highLowContainer.getContainerAtIndex(pos1) - .ixor(x2.highLowContainer.getContainerAtIndex(pos2)); - if (c.getCardinality() > 0) { - this.getMappeableRoaringArray().setContainerAtIndex(pos1, c); - pos1++; - } else { - getMappeableRoaringArray().removeAtIndex(pos1); - --length1; - } - pos2++; - if ((pos1 == length1) || (pos2 == length2)) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2 - pos1++; - if (pos1 == length1) { - break main; - } - s1 = highLowContainer.getKeyAtIndex(pos1); - } else { // s1 > s2 - getMappeableRoaringArray().insertNewKeyValueAt(pos1, s2, - x2.highLowContainer.getContainerAtIndex(pos2).clone()); - pos1++; - length1++; - pos2++; - if (pos2 == length2) { - break main; - } - s2 = x2.highLowContainer.getKeyAtIndex(pos2); - } - } - } - if (pos1 == length1) { - getMappeableRoaringArray().appendCopy(x2.highLowContainer, pos2, length2); - } - } - - -} diff --git a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/PointableRoaringArray.java b/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/PointableRoaringArray.java deleted file mode 100644 index c9cd8fa7d..000000000 --- a/fine-roaringbitmap/src/main/java/com/fr/third/bitmap/roaringbitmap/buffer/PointableRoaringArray.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * (c) the authors Licensed under the Apache License, Version 2.0. - */ - -package com.fr.third.bitmap.roaringbitmap.buffer; - -import java.io.DataOutput; -import java.io.IOException; - -/** - * Generic interface for the array underlying roaring bitmap classes. - */ -public interface PointableRoaringArray extends Cloneable { - /** - * Find the smallest integer index larger than pos such that getKeyAtIndex(index)>=x. If none - * can be found, return size. - * - * @param x minimal value - * @param pos index to exceed - * @return the smallest index greater than pos such that getKeyAtIndex(index) is at least as large - * as min, or size if it is not possible. - */ - int advanceUntil(short x, int pos); - - /** - * Create an independent copy of the underlying array - * - * @return a copy - */ - PointableRoaringArray clone(); - - /** - * Returns the cardinality of the container at the given index. This method is expected to be - * fast. - * - * @param i index - * @return the cardinality - */ - public int getCardinality(int i); - - /** - * @param x 16-bit key - * @return matching container - */ - MappeableContainer getContainer(short x); - - /** - * @param i index - * @return matching container - */ - MappeableContainer getContainerAtIndex(int i); - - /** - * @return a ContainerPointer to iterator over the array - */ - MappeableContainerPointer getContainerPointer(); - - /** - * @param startIndex starting index - * @return a ContainerPointer to iterator over the array initially positioned at startIndex - */ - MappeableContainerPointer getContainerPointer(int startIndex); - - /** - * @param x 16-bit key - * @return corresponding index - */ - int getIndex(short x); - - /** - * @param i the index - * @return 16-bit key at the index - */ - short getKeyAtIndex(int i); - - /** - * Check whether this bitmap has had its runs compressed. - * - * @return whether this bitmap has run compression - */ - public boolean hasRunCompression(); - - /** - * Serialize. - *

- * The current bitmap is not modified. - * - * @param out the DataOutput stream - * @throws IOException Signals that an I/O exception has occurred. - */ - public void serialize(DataOutput out) throws IOException; - - /** - * @return the size that the data structure occupies on disk - */ - public int serializedSizeInBytes(); - - - /** - * @return number of keys - */ - int size(); -} diff --git a/fine-socketio/pom.xml b/fine-socketio/pom.xml index 785a9fd41..cbc6deae1 100644 --- a/fine-socketio/pom.xml +++ b/fine-socketio/pom.xml @@ -35,6 +35,11 @@ fine-spring ${revision} + + com.fr.essential + fine-common + ${essentialVersion} + 以下是lib的本地jar包ä¾èµ–<--> com.fr.third diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/Configuration.java b/fine-socketio/src/main/java/com/fr/third/socketio/Configuration.java index 84c8383ed..8948b005e 100644 --- a/fine-socketio/src/main/java/com/fr/third/socketio/Configuration.java +++ b/fine-socketio/src/main/java/com/fr/third/socketio/Configuration.java @@ -98,6 +98,10 @@ public class Configuration { private List disconnectInterceptors = Collections.emptyList(); private List eventInterceptors = Collections.emptyList(); + private String[] nettyProtocols = new String[]{}; + + private String[] nettyCiphers = new String[]{}; + public Configuration() { } @@ -169,6 +173,9 @@ public class Configuration { setConnectInterceptors(conf.getConnectInterceptors().toArray(new Interceptor[0])); setDisconnectInterceptors(conf.getDisconnectInterceptors().toArray(new Interceptor[0])); setEventInterceptors(conf.getEventInterceptors().toArray(new EventInterceptor[0])); + + setNettyProtocols(conf.getNettyProtocols()); + setNettyCiphers(conf.getNettyCiphers()); } public JsonSupport getJsonSupport() { @@ -630,4 +637,20 @@ public class Configuration { public void setEventInterceptors(EventInterceptor[] eventInterceptors) { this.eventInterceptors = Arrays.asList(eventInterceptors); } + + public String[] getNettyProtocols() { + return nettyProtocols; + } + + public void setNettyProtocols(String[] nettyProtocols) { + this.nettyProtocols = nettyProtocols; + } + + public String[] getNettyCiphers() { + return nettyCiphers; + } + + public void setNettyCiphers(String[] nettyCiphers) { + this.nettyCiphers = nettyCiphers; + } } diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java b/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java index 645767565..ae8133599 100644 --- a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java +++ b/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java @@ -23,6 +23,7 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; +import com.fr.stable.ArrayUtils; import com.fr.third.socketio.scheduler.HashedWheelTimeoutScheduler; import com.fr.third.socketio.transport.PollingTransport; import com.fr.third.socketio.transport.WebSocketTransport; @@ -155,6 +156,15 @@ public class SocketIOChannelInitializer extends ChannelInitializer impl if (sslContext != null) { SSLEngine engine = sslContext.createSSLEngine(); engine.setUseClientMode(false); + + if (ArrayUtils.isNotEmpty(configuration.getNettyProtocols())) { + engine.setEnabledProtocols(configuration.getNettyProtocols()); + } + + if (ArrayUtils.isNotEmpty(configuration.getNettyCiphers())) { + engine.setEnabledCipherSuites(configuration.getNettyCiphers()); + } + pipeline.addLast(SSL_HANDLER, new SslHandler(engine)); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/README.md b/fine-xmlgraphics/xmlgraphics-batik/README.md index df4d31ab8..e96552704 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/README.md +++ b/fine-xmlgraphics/xmlgraphics-batik/README.md @@ -1,2 +1,2 @@ æºç åœ°å€:https://github.com/apache/xmlgraphics-batik
-版本:1.9 \ No newline at end of file +版本:1.14 \ No newline at end of file diff --git a/fine-xmlgraphics/xmlgraphics-batik/lib/xercesImpl-2.12.0.jar b/fine-xmlgraphics/xmlgraphics-batik/lib/xercesImpl-2.12.0.jar new file mode 100644 index 000000000..b69d01dac Binary files /dev/null and b/fine-xmlgraphics/xmlgraphics-batik/lib/xercesImpl-2.12.0.jar differ diff --git a/fine-xmlgraphics/xmlgraphics-batik/lib/xercesImpl-2.9.1.jar b/fine-xmlgraphics/xmlgraphics-batik/lib/xercesImpl-2.9.1.jar deleted file mode 100644 index 78abfddd2..000000000 Binary files a/fine-xmlgraphics/xmlgraphics-batik/lib/xercesImpl-2.9.1.jar and /dev/null differ diff --git a/fine-xmlgraphics/xmlgraphics-batik/pom.xml b/fine-xmlgraphics/xmlgraphics-batik/pom.xml index 1ac49ac62..ba2335c6d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/pom.xml +++ b/fine-xmlgraphics/xmlgraphics-batik/pom.xml @@ -66,7 +66,7 @@ xercesImpl local system - ${basedir}/lib/xercesImpl-2.9.1.jar + ${basedir}/lib/xercesImpl-2.12.0.jar
\ No newline at end of file diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/Version.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/Version.java index cd77a3505..ffbbf6476 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/Version.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/Version.java @@ -37,7 +37,7 @@ public final class Version { * branch. The format of the returned string will be one of the * following: *

- * + *
* * * @@ -72,7 +72,8 @@ public final class Version { if (pkg != null) { version = pkg.getImplementationVersion(); } - String headURL = "$HeadURL: https://svn.apache.org/repos/asf/xmlgraphics/batik/branches/maven/batik-util/src/main/java/org/apache/batik/Version.java $"; + String headURL = "$HeadURL: https://svn.apache.org/repos/asf/xmlgraphics/batik/branches/maven/batik-util" + + "/src/main/java/org/apache/batik/Version.java $"; String prefix = "$HeadURL: "; String suffix = "/sources/org/apache/batik/Version.java $"; if (headURL.startsWith(prefix) && headURL.endsWith(suffix)) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/AnimationEngine.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/AnimationEngine.java index 4f4f755ff..e6ccbb5d9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/AnimationEngine.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/AnimationEngine.java @@ -18,11 +18,6 @@ */ package org.apache.batik.anim; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - import org.apache.batik.anim.dom.AnimationTarget; import org.apache.batik.anim.dom.AnimationTargetListener; import org.apache.batik.anim.timing.TimedDocumentRoot; @@ -30,9 +25,13 @@ import org.apache.batik.anim.timing.TimedElement; import org.apache.batik.anim.timing.TimegraphListener; import org.apache.batik.anim.values.AnimatableValue; import org.apache.batik.util.DoublyIndexedTable; - import org.w3c.dom.Document; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + /** * An abstract base class for managing animation in a document. * @@ -90,22 +89,21 @@ public abstract class AnimationEngine { */ public void dispose() { // Remove any target listeners that are registered. - Iterator i = targets.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); + for (Object o : targets.entrySet()) { + Map.Entry e = (Map.Entry) o; AnimationTarget target = (AnimationTarget) e.getKey(); TargetInfo info = (TargetInfo) e.getValue(); Iterator j = info.xmlAnimations.iterator(); while (j.hasNext()) { DoublyIndexedTable.Entry e2 = - (DoublyIndexedTable.Entry) j.next(); + (DoublyIndexedTable.Entry) j.next(); String namespaceURI = (String) e2.getKey1(); String localName = (String) e2.getKey2(); Sandwich sandwich = (Sandwich) e2.getValue(); if (sandwich.listenerRegistered) { target.removeTargetListener(namespaceURI, localName, false, - targetListener); + targetListener); } } @@ -116,7 +114,7 @@ public abstract class AnimationEngine { Sandwich sandwich = (Sandwich) e2.getValue(); if (sandwich.listenerRegistered) { target.removeTargetListener(null, propertyName, true, - targetListener); + targetListener); } } } @@ -304,8 +302,7 @@ public abstract class AnimationEngine { float waitTime = timedDocumentRoot.seekTo(time, hyperlinking); Map.Entry[] targetEntries = (Map.Entry[]) targets.entrySet().toArray(MAP_ENTRY_ARRAY); - for (int i = 0; i < targetEntries.length; i++) { - Map.Entry e = targetEntries[i]; + for (Map.Entry e : targetEntries) { AnimationTarget target = (AnimationTarget) e.getKey(); TargetInfo info = (TargetInfo) e.getValue(); @@ -313,29 +310,29 @@ public abstract class AnimationEngine { Iterator j = info.xmlAnimations.iterator(); while (j.hasNext()) { DoublyIndexedTable.Entry e2 = - (DoublyIndexedTable.Entry) j.next(); + (DoublyIndexedTable.Entry) j.next(); String namespaceURI = (String) e2.getKey1(); String localName = (String) e2.getKey2(); Sandwich sandwich = (Sandwich) e2.getValue(); if (sandwich.shouldUpdate || sandwich.animation != null - && sandwich.animation.isDirty) { + && sandwich.animation.isDirty) { AnimatableValue av = null; boolean usesUnderlying = false; AbstractAnimation anim = sandwich.animation; if (anim != null) { av = anim.getComposedValue(); usesUnderlying = - sandwich.lowestAnimation.usesUnderlyingValue(); + sandwich.lowestAnimation.usesUnderlyingValue(); anim.isDirty = false; } if (usesUnderlying && !sandwich.listenerRegistered) { target.addTargetListener(namespaceURI, localName, false, - targetListener); + targetListener); sandwich.listenerRegistered = true; } else if (!usesUnderlying && sandwich.listenerRegistered) { target.removeTargetListener(namespaceURI, localName, - false, targetListener); + false, targetListener); sandwich.listenerRegistered = false; } target.updateAttributeValue(namespaceURI, localName, av); @@ -351,23 +348,23 @@ public abstract class AnimationEngine { Sandwich sandwich = (Sandwich) e2.getValue(); if (sandwich.shouldUpdate || sandwich.animation != null - && sandwich.animation.isDirty) { + && sandwich.animation.isDirty) { AnimatableValue av = null; boolean usesUnderlying = false; AbstractAnimation anim = sandwich.animation; if (anim != null) { av = anim.getComposedValue(); usesUnderlying = - sandwich.lowestAnimation.usesUnderlyingValue(); + sandwich.lowestAnimation.usesUnderlyingValue(); anim.isDirty = false; } if (usesUnderlying && !sandwich.listenerRegistered) { target.addTargetListener(null, propertyName, true, - targetListener); + targetListener); sandwich.listenerRegistered = true; } else if (!usesUnderlying && sandwich.listenerRegistered) { target.removeTargetListener(null, propertyName, true, - targetListener); + targetListener); sandwich.listenerRegistered = false; } if (usesUnderlying) { @@ -388,7 +385,7 @@ public abstract class AnimationEngine { Sandwich sandwich = (Sandwich) e2.getValue(); if (sandwich.shouldUpdate || sandwich.animation != null - && sandwich.animation.isDirty) { + && sandwich.animation.isDirty) { AnimatableValue av = null; AbstractAnimation anim = sandwich.animation; if (anim != null) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/AbstractSVGAnimatedValue.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/AbstractSVGAnimatedValue.java index 84b809bfd..56cad492e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/AbstractSVGAnimatedValue.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/AbstractSVGAnimatedValue.java @@ -18,11 +18,10 @@ */ package org.apache.batik.anim.dom; -import java.util.Iterator; -import java.util.LinkedList; - import org.apache.batik.anim.values.AnimatableValue; +import java.util.LinkedList; + /** * An abstract base class for the SVGAnimated* classes, that * implements an {@link AnimatedAttributeListener} list. @@ -125,10 +124,9 @@ public abstract class AbstractSVGAnimatedValue * Fires the listeners for the animated value. */ protected void fireAnimatedAttributeListeners() { - Iterator i = listeners.iterator(); - while (i.hasNext()) { + for (Object listener1 : listeners) { AnimatedAttributeListener listener = - (AnimatedAttributeListener) i.next(); + (AnimatedAttributeListener) listener1; listener.animatedAttributeChanged(element, this); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SAXSVGDocumentFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SAXSVGDocumentFactory.java index c21cc8f33..d19267735 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SAXSVGDocumentFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SAXSVGDocumentFactory.java @@ -18,26 +18,24 @@ */ package org.apache.batik.anim.dom; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.net.MalformedURLException; -import java.util.MissingResourceException; -import java.util.Properties; - import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.svg.SVGDocumentFactory; import org.apache.batik.dom.util.SAXDocumentFactory; import org.apache.batik.util.MimeTypeConstants; import org.apache.batik.util.ParsedURL; - -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.svg.SVGDocument; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.net.MalformedURLException; +import java.util.MissingResourceException; +import java.util.Properties; /** * This class contains methods for creating SVGDocument instances @@ -76,7 +74,7 @@ public class SAXSVGDocumentFactory * The dtd public IDs resource bundle class name. */ protected static final String DTDIDS = - "org.apache.batik.dom.svg.resources.dtdids"; + "org.apache.batik.anim.dom.resources.dtdids"; /** * Constant for HTTP content type header charset field. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12DOMImplementation.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12DOMImplementation.java index db8492603..50d09532e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12DOMImplementation.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12DOMImplementation.java @@ -18,8 +18,6 @@ */ package org.apache.batik.anim.dom; -import java.net.URL; - import org.apache.batik.css.engine.CSSContext; import org.apache.batik.css.engine.CSSEngine; import org.apache.batik.css.engine.SVG12CSSEngine; @@ -34,20 +32,21 @@ import org.apache.batik.dom.events.DocumentEventSupport; import org.apache.batik.dom.events.EventSupport; import org.apache.batik.dom.svg12.SVGOMWheelEvent; import org.apache.batik.dom.svg12.XBLOMShadowTreeEvent; -import org.apache.batik.dom.util.HashTable; import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVG12Constants; import org.apache.batik.util.XBLConstants; - import org.w3c.css.sac.InputSource; +import org.w3c.dom.DOMException; +import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.DOMException; import org.w3c.dom.Element; import org.w3c.dom.events.Event; +import java.net.URL; +import java.util.HashMap; + /** * This class implements the {@link DOMImplementation} interface. * It provides support the SVG 1.2 documents. @@ -118,12 +117,12 @@ public class SVG12DOMImplementation String name = DOMUtilities.getLocalName(qualifiedName); String prefix = DOMUtilities.getPrefix(qualifiedName); if (SVG12Constants.SVG_NAMESPACE_URI.equals(namespaceURI)) { - ElementFactory ef = (ElementFactory)factories.get(name); + ElementFactory ef = factories.get(name); if (ef != null) { return ef.create(prefix, document); } } else if (XBLConstants.XBL_NAMESPACE_URI.equals(namespaceURI)) { - ElementFactory ef = (ElementFactory)xblFactories.get(name); + ElementFactory ef = xblFactories.get(name); if (ef != null) { return ef.create(prefix, document); } @@ -173,7 +172,7 @@ public class SVG12DOMImplementation /** * The SVG element factories. */ - protected static HashTable svg12Factories = new HashTable(svg11Factories); + protected static HashMap svg12Factories = new HashMap(svg11Factories); static { svg12Factories.put(SVG12Constants.SVG_FLOW_DIV_TAG, @@ -413,7 +412,7 @@ public class SVG12DOMImplementation /** * The XBL element factories. */ - protected static HashTable xblFactories = new HashTable(); + protected static HashMap xblFactories = new HashMap(); static { xblFactories.put(XBLConstants.XBL_XBL_TAG, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12OMDocument.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12OMDocument.java index 9f3218edd..4e50a3e6e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12OMDocument.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVG12OMDocument.java @@ -19,7 +19,7 @@ package org.apache.batik.anim.dom; import org.apache.batik.css.engine.CSSNavigableDocumentListener; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.DOMImplementation; import org.w3c.dom.DocumentType; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGAnimationTargetContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGAnimationTargetContext.java index 2c62c2654..551a4251e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGAnimationTargetContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGAnimationTargetContext.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.anim.dom; import org.apache.batik.dom.svg.SVGContext; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGDOMImplementation.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGDOMImplementation.java index 61efc1c4d..c683a5b26 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGDOMImplementation.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGDOMImplementation.java @@ -19,6 +19,7 @@ package org.apache.batik.anim.dom; import java.net.URL; +import java.util.HashMap; import org.apache.batik.css.dom.CSSOMSVGViewCSS; import org.apache.batik.css.engine.CSSContext; @@ -35,7 +36,7 @@ import org.apache.batik.dom.events.DocumentEventSupport; import org.apache.batik.dom.svg.SVGOMEvent; import org.apache.batik.dom.util.CSSStyleDeclarationFactory; import org.apache.batik.dom.util.DOMUtilities; -import org.apache.batik.dom.util.HashTable; + import org.apache.batik.i18n.LocalizableSupport; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVGConstants; @@ -76,7 +77,7 @@ public class SVGDOMImplementation protected static final String RESOURCES = "org.apache.batik.dom.svg.resources.Messages"; - protected HashTable factories; + protected HashMap factories; /** * Returns the default instance of this class. @@ -172,7 +173,7 @@ public class SVGDOMImplementation * Creates a stylesheet from the data of an xml-stylesheet * processing instruction or return null. */ - public StyleSheet createStyleSheet(Node n, HashTable attrs) { + public StyleSheet createStyleSheet(Node n, HashMap attrs) { throw new UnsupportedOperationException ("StyleSheetFactory.createStyleSheet is not implemented"); // XXX } @@ -194,7 +195,7 @@ public class SVGDOMImplementation String qualifiedName) { if (SVGConstants.SVG_NAMESPACE_URI.equals(namespaceURI)) { String name = DOMUtilities.getLocalName(qualifiedName); - ElementFactory ef = (ElementFactory)factories.get(name); + ElementFactory ef = factories.get(name); if (ef != null) return ef.create(DOMUtilities.getPrefix(qualifiedName), document); @@ -232,7 +233,7 @@ public class SVGDOMImplementation /** * The SVG element factories. */ - protected static HashTable svg11Factories = new HashTable(); + protected static HashMap svg11Factories = new HashMap(); static { svg11Factories.put(SVGConstants.SVG_A_TAG, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedNumberList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedNumberList.java index a2343d965..20ddfa320 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedNumberList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedNumberList.java @@ -23,7 +23,6 @@ import java.util.Iterator; import org.apache.batik.anim.values.AnimatableNumberListValue; import org.apache.batik.anim.values.AnimatableValue; -import org.apache.batik.dom.svg.AbstractSVGList; import org.apache.batik.dom.svg.AbstractSVGNumberList; import org.apache.batik.dom.svg.ListBuilder; import org.apache.batik.dom.svg.LiveAttributeException; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPathData.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPathData.java index 55d653983..4c9d87920 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPathData.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPathData.java @@ -23,7 +23,6 @@ import java.util.Iterator; import org.apache.batik.anim.values.AnimatablePathDataValue; import org.apache.batik.anim.values.AnimatableValue; -import org.apache.batik.dom.svg.AbstractSVGList; import org.apache.batik.dom.svg.AbstractSVGNormPathSegList; import org.apache.batik.dom.svg.AbstractSVGPathSegList; import org.apache.batik.dom.svg.ListBuilder; @@ -618,68 +617,60 @@ public class SVGOMAnimatedPathData switch (command) { case SVGPathSeg.PATHSEG_ARC_ABS: case SVGPathSeg.PATHSEG_ARC_REL: - return new SVGPathSegArcItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++] != 0, - parameters[j[0]++] != 0, - parameters[j[0]++], - parameters[j[0]++]); + return new SVGPathSegArcItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++] != 0, + parameters[j[0]++] != 0, + parameters[j[0]++], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_CLOSEPATH: return new SVGPathSegItem (command, PATHSEG_LETTERS[command]); case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL: - return new SVGPathSegCurvetoCubicItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++]); + return new SVGPathSegCurvetoCubicItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL: - return new SVGPathSegCurvetoCubicSmoothItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++]); + return new SVGPathSegCurvetoCubicSmoothItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL: - return new SVGPathSegCurvetoQuadraticItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++], - parameters[j[0]++]); + return new SVGPathSegCurvetoQuadraticItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: - return new SVGPathSegCurvetoQuadraticSmoothItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++], - parameters[j[0]++]); + return new SVGPathSegCurvetoQuadraticSmoothItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_LINETO_ABS: case SVGPathSeg.PATHSEG_LINETO_REL: case SVGPathSeg.PATHSEG_MOVETO_ABS: case SVGPathSeg.PATHSEG_MOVETO_REL: - return new SVGPathSegMovetoLinetoItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++], - parameters[j[0]++]); + return new SVGPathSegMovetoLinetoItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS: - return new SVGPathSegLinetoHorizontalItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++]); + return new SVGPathSegLinetoHorizontalItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++]); case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS: - return new SVGPathSegLinetoVerticalItem - (command, PATHSEG_LETTERS[command], - parameters[j[0]++]); + return new SVGPathSegLinetoVerticalItem(command, PATHSEG_LETTERS[command], + parameters[j[0]++]); } return null; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPoints.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPoints.java index a658e9a72..dfa82c56c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPoints.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMAnimatedPoints.java @@ -23,7 +23,6 @@ import java.util.Iterator; import org.apache.batik.anim.values.AnimatablePointListValue; import org.apache.batik.anim.values.AnimatableValue; -import org.apache.batik.dom.svg.AbstractSVGList; import org.apache.batik.dom.svg.AbstractSVGPointList; import org.apache.batik.dom.svg.ListBuilder; import org.apache.batik.dom.svg.LiveAttributeException; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMDocument.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMDocument.java index 62f0a9cd1..3a7449100 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMDocument.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMDocument.java @@ -18,16 +18,7 @@ */ package org.apache.batik.anim.dom; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Locale; -import java.util.MissingResourceException; - +import org.apache.batik.constants.XMLConstants; import org.apache.batik.css.engine.CSSNavigableDocument; import org.apache.batik.css.engine.CSSNavigableDocumentListener; import org.apache.batik.css.engine.CSSStylableElement; @@ -50,8 +41,6 @@ import org.apache.batik.i18n.Localizable; import org.apache.batik.i18n.LocalizableSupport; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; - import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; @@ -74,6 +63,15 @@ import org.w3c.dom.svg.SVGDocument; import org.w3c.dom.svg.SVGLangSpace; import org.w3c.dom.svg.SVGSVGElement; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Locale; +import java.util.MissingResourceException; + /** * This class implements {@link SVGDocument}. * @@ -496,10 +494,9 @@ public class SVGOMDocument * modified. */ protected void overrideStyleTextChanged(CSSStylableElement e, String text) { - Iterator i = cssNavigableDocumentListeners.keySet().iterator(); - while (i.hasNext()) { + for (Object o : cssNavigableDocumentListeners.keySet()) { CSSNavigableDocumentListener l = - (CSSNavigableDocumentListener) i.next(); + (CSSNavigableDocumentListener) o; l.overrideStyleTextChanged(e, text); } } @@ -509,10 +506,9 @@ public class SVGOMDocument */ protected void overrideStylePropertyRemoved(CSSStylableElement e, String name) { - Iterator i = cssNavigableDocumentListeners.keySet().iterator(); - while (i.hasNext()) { + for (Object o : cssNavigableDocumentListeners.keySet()) { CSSNavigableDocumentListener l = - (CSSNavigableDocumentListener) i.next(); + (CSSNavigableDocumentListener) o; l.overrideStylePropertyRemoved(e, name); } } @@ -522,10 +518,9 @@ public class SVGOMDocument */ protected void overrideStylePropertyChanged (CSSStylableElement e, String name, String value, String prio) { - Iterator i = cssNavigableDocumentListeners.keySet().iterator(); - while (i.hasNext()) { + for (Object o : cssNavigableDocumentListeners.keySet()) { CSSNavigableDocumentListener l = - (CSSNavigableDocumentListener) i.next(); + (CSSNavigableDocumentListener) o; l.overrideStylePropertyChanged(e, name, value, prio); } } @@ -553,7 +548,7 @@ public class SVGOMDocument /** * DOM node inserted listener wrapper. */ - protected class DOMNodeInsertedListenerWrapper implements EventListener { + protected static class DOMNodeInsertedListenerWrapper implements EventListener { /** * The CSSNavigableDocumentListener. @@ -579,7 +574,7 @@ public class SVGOMDocument /** * DOM node removed listener wrapper. */ - protected class DOMNodeRemovedListenerWrapper implements EventListener { + protected static class DOMNodeRemovedListenerWrapper implements EventListener { /** * The CSSNavigableDocumentListener. @@ -605,7 +600,7 @@ public class SVGOMDocument /** * DOM subtree modified listener wrapper. */ - protected class DOMSubtreeModifiedListenerWrapper implements EventListener { + protected static class DOMSubtreeModifiedListenerWrapper implements EventListener { /** * The CSSNavigableDocumentListener. @@ -632,7 +627,7 @@ public class SVGOMDocument /** * DOM character data modified listener wrapper. */ - protected class DOMCharacterDataModifiedListenerWrapper + protected static class DOMCharacterDataModifiedListenerWrapper implements EventListener { /** @@ -660,7 +655,7 @@ public class SVGOMDocument /** * DOM attribute modified listener wrapper. */ - protected class DOMAttrModifiedListenerWrapper implements EventListener { + protected static class DOMAttrModifiedListenerWrapper implements EventListener { /** * The CSSNavigableDocumentListener. @@ -701,10 +696,9 @@ public class SVGOMDocument */ public void animatedAttributeChanged(Element e, AnimatedLiveAttributeValue alav) { - Iterator i = animatedAttributeListeners.iterator(); - while (i.hasNext()) { + for (Object animatedAttributeListener : animatedAttributeListeners) { AnimatedAttributeListener aal = - (AnimatedAttributeListener) i.next(); + (AnimatedAttributeListener) animatedAttributeListener; aal.animatedAttributeChanged(e, alav); } } @@ -716,10 +710,9 @@ public class SVGOMDocument * @param type the type of animation whose value changed */ public void otherAnimationChanged(Element e, String type) { - Iterator i = animatedAttributeListeners.iterator(); - while (i.hasNext()) { + for (Object animatedAttributeListener : animatedAttributeListeners) { AnimatedAttributeListener aal = - (AnimatedAttributeListener) i.next(); + (AnimatedAttributeListener) animatedAttributeListener; aal.otherAnimationChanged(e, type); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMElement.java index b66231c40..f3553f5a5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMElement.java @@ -18,7 +18,6 @@ */ package org.apache.batik.anim.dom; -import java.util.Iterator; import java.util.LinkedList; import org.apache.batik.anim.values.AnimatableNumberOptionalNumberValue; @@ -236,7 +235,7 @@ public abstract class SVGOMElement if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } if (prefix != null && @@ -244,7 +243,7 @@ public abstract class SVGOMElement !DOMUtilities.isValidName(prefix)) { throw createDOMException(DOMException.INVALID_CHARACTER_ERR, "prefix", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), prefix }); } @@ -841,9 +840,8 @@ public abstract class SVGOMElement void fireBaseAttributeListeners(String ns, String ln) { if (targetListeners != null) { LinkedList ll = (LinkedList) targetListeners.get(ns, ln); - Iterator it = ll.iterator(); - while (it.hasNext()) { - AnimationTargetListener l = (AnimationTargetListener) it.next(); + for (Object aLl : ll) { + AnimationTargetListener l = (AnimationTargetListener) aLl; l.baseValueChanged(this, ns, ln, false); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMFEConvolveMatrixElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMFEConvolveMatrixElement.java index bc9f42995..1eb7ef28b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMFEConvolveMatrixElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMFEConvolveMatrixElement.java @@ -148,7 +148,7 @@ public class SVGOMFEConvolveMatrixElement } /** - * DOM: Implements {@link SVGFEConvolveMatrixElement#getIn1()}. + * DOM: Implements SVGFEConvolveMatrixElement#getIn1(). */ public SVGAnimatedString getIn1() { return in; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMSVGElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMSVGElement.java index b3d15253f..89bfc85f9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMSVGElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMSVGElement.java @@ -453,7 +453,7 @@ public class SVGOMSVGElement if (!ctx.unsuspendRedraw(suspend_handle_id)) { throw createDOMException (DOMException.NOT_FOUND_ERR, "invalid.suspend.handle", - new Object[] { new Integer(suspend_handle_id) }); + new Object[] {suspend_handle_id}); } } @@ -723,8 +723,8 @@ public class SVGOMSVGElement } /** - * DOM: Implements {@link - * org.w3c.dom.events.DocumentEvent#canDispatch(String,String)}. + * DOM: Implements + * org.w3c.dom.events.DocumentEvent#canDispatch(String,String). */ public boolean canDispatch(String namespaceURI, String type) throws DOMException { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMStyleElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMStyleElement.java index 99c8bc4c1..336f27aaf 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMStyleElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGOMStyleElement.java @@ -25,7 +25,7 @@ import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.util.XMLSupport; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.DOMException; import org.w3c.dom.Node; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGPathSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGPathSupport.java index 2c074df9d..567b3cb8c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGPathSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGPathSupport.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.anim.dom; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGStyleSheetProcessingInstruction.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGStyleSheetProcessingInstruction.java index 4f88ac169..15a05a326 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGStyleSheetProcessingInstruction.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/SVGStyleSheetProcessingInstruction.java @@ -24,11 +24,13 @@ import org.apache.batik.css.engine.StyleSheet; import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.StyleSheetFactory; import org.apache.batik.dom.StyleSheetProcessingInstruction; -import org.apache.batik.dom.util.HashTable; + import org.apache.batik.util.ParsedURL; import org.w3c.dom.DOMException; import org.w3c.dom.Node; +import java.util.HashMap; + /** * This class provides an implementation of the 'xml-stylesheet' processing * instructions. @@ -66,7 +68,7 @@ public class SVGStyleSheetProcessingInstruction public String getStyleSheetURI() { SVGOMDocument svgDoc = (SVGOMDocument) getOwnerDocument(); ParsedURL url = svgDoc.getParsedURL(); - String href = (String)getPseudoAttributes().get("href"); + String href = getPseudoAttributes().get("href"); if (url != null) { return new ParsedURL(url, href).toString(); } @@ -78,14 +80,14 @@ public class SVGStyleSheetProcessingInstruction */ public StyleSheet getCSSStyleSheet() { if (styleSheet == null) { - HashTable attrs = getPseudoAttributes(); - String type = (String)attrs.get("type"); + HashMap attrs = getPseudoAttributes(); + String type = attrs.get("type"); if ("text/css".equals(type)) { - String title = (String)attrs.get("title"); - String media = (String)attrs.get("media"); - String href = (String)attrs.get("href"); - String alternate = (String)attrs.get("alternate"); + String title = attrs.get("title"); + String media = attrs.get("media"); + String href = attrs.get("href"); + String alternate = attrs.get("alternate"); SVGOMDocument doc = (SVGOMDocument)getOwnerDocument(); ParsedURL durl = doc.getParsedURL(); ParsedURL burl = new ParsedURL(durl, href); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLEventSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLEventSupport.java index 1a8138593..835dff371 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLEventSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLEventSupport.java @@ -18,6 +18,7 @@ */ package org.apache.batik.anim.dom; +import java.util.HashMap; import java.util.HashSet; import org.apache.batik.dom.AbstractNode; @@ -25,10 +26,10 @@ import org.apache.batik.dom.events.AbstractEvent; import org.apache.batik.dom.events.EventListenerList; import org.apache.batik.dom.events.EventSupport; import org.apache.batik.dom.events.NodeEventTarget; -import org.apache.batik.dom.util.HashTable; + import org.apache.batik.dom.xbl.NodeXBL; import org.apache.batik.dom.xbl.ShadowTreeEvent; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.DOMException; import org.w3c.dom.Node; @@ -49,17 +50,17 @@ public class XBLEventSupport extends EventSupport { /** * The unstoppable capturing listeners table. */ - protected HashTable capturingImplementationListeners; + protected HashMap capturingImplementationListeners; /** * The unstoppable bubbling listeners table. */ - protected HashTable bubblingImplementationListeners; + protected HashMap bubblingImplementationListeners; /** * Map of event types to their aliases. */ - protected static HashTable eventTypeAliases = new HashTable(); + protected static HashMap eventTypeAliases = new HashMap(); static { eventTypeAliases.put("SVGLoad", "load"); eventTypeAliases.put("SVGUnoad", "unload"); @@ -90,7 +91,7 @@ public class XBLEventSupport extends EventSupport { (namespaceURI, type, listener, useCapture, group); if (namespaceURI == null || namespaceURI.equals(XMLConstants.XML_EVENTS_NAMESPACE_URI)) { - String alias = (String) eventTypeAliases.get(type); + String alias = eventTypeAliases.get(type); if (alias != null) { super.addEventListenerNS (namespaceURI, alias, listener, useCapture, group); @@ -108,7 +109,7 @@ public class XBLEventSupport extends EventSupport { super.removeEventListenerNS(namespaceURI, type, listener, useCapture); if (namespaceURI == null || namespaceURI.equals(XMLConstants.XML_EVENTS_NAMESPACE_URI)) { - String alias = (String) eventTypeAliases.get(type); + String alias = eventTypeAliases.get(type); if (alias != null) { super.removeEventListenerNS (namespaceURI, alias, listener, useCapture); @@ -124,19 +125,19 @@ public class XBLEventSupport extends EventSupport { String type, EventListener listener, boolean useCapture) { - HashTable listeners; + HashMap listeners; if (useCapture) { if (capturingImplementationListeners == null) { - capturingImplementationListeners = new HashTable(); + capturingImplementationListeners = new HashMap(); } listeners = capturingImplementationListeners; } else { if (bubblingImplementationListeners == null) { - bubblingImplementationListeners = new HashTable(); + bubblingImplementationListeners = new HashMap(); } listeners = bubblingImplementationListeners; } - EventListenerList list = (EventListenerList) listeners.get(type); + EventListenerList list = listeners.get(type); if (list == null) { list = new EventListenerList(); listeners.put(type, list); @@ -151,12 +152,12 @@ public class XBLEventSupport extends EventSupport { String type, EventListener listener, boolean useCapture) { - HashTable listeners = useCapture ? capturingImplementationListeners - : bubblingImplementationListeners; + HashMap listeners = useCapture + ? capturingImplementationListeners : bubblingImplementationListeners; if (listeners == null) { return; } - EventListenerList list = (EventListenerList) listeners.get(type); + EventListenerList list = listeners.get(type); if (list == null) { return; } @@ -438,12 +439,9 @@ public class XBLEventSupport extends EventSupport { */ public EventListenerList getImplementationEventListeners (String type, boolean useCapture) { - HashTable listeners = useCapture ? capturingImplementationListeners - : bubblingImplementationListeners; - if (listeners == null) { - return null; - } - return (EventListenerList) listeners.get(type); + HashMap listeners = useCapture + ? capturingImplementationListeners : bubblingImplementationListeners; + return listeners != null ? listeners.get(type) : null; } /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMDefinitionElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMDefinitionElement.java index 1f07fe3e9..66bd52e4d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMDefinitionElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMDefinitionElement.java @@ -72,7 +72,7 @@ public class XBLOMDefinitionElement extends XBLOMElement { throw createDOMException (DOMException.NAMESPACE_ERR, "prefix", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), prefix }); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMElement.java index a0eaadcec..17fd578e8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/dom/XBLOMElement.java @@ -80,7 +80,7 @@ public abstract class XBLOMElement extends SVGOMElement if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } if (prefix != null && @@ -88,7 +88,7 @@ public abstract class XBLOMElement extends SVGOMElement !DOMUtilities.isValidName(prefix)) { throw createDOMException(DOMException.INVALID_CHARACTER_ERR, "prefix", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), prefix }); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/AccesskeyTimingSpecifier.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/AccesskeyTimingSpecifier.java index 35c5aa382..67c8ed993 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/AccesskeyTimingSpecifier.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/AccesskeyTimingSpecifier.java @@ -20,7 +20,7 @@ package org.apache.batik.anim.timing; import org.apache.batik.dom.events.DOMKeyEvent; import org.apache.batik.dom.events.NodeEventTarget; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/InstanceTime.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/InstanceTime.java index 7c4589e28..0e1cfc7c6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/InstanceTime.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/InstanceTime.java @@ -53,7 +53,7 @@ public class InstanceTime implements Comparable { public InstanceTime(TimingSpecifier creator, float time, boolean clearOnReset) { - // Trace.enter(this, null, new Object[] { creator, new Float(time), timebase, new Boolean(clearOnReset) } ); try { + // Trace.enter(this, null, new Object[] { creator, Float.valueOf(time), timebase, new Boolean(clearOnReset) } ); try { this.creator = creator; // XXX Convert time from the creator's syncbase's // time system into this time system. Not @@ -84,7 +84,7 @@ public class InstanceTime implements Comparable { * @param newTime the new time, in parent simple time */ float dependentUpdate(float newTime) { - // Trace.enter(this, "dependentUpdate", new Object[] { new Float(newTime) } ); try { + // Trace.enter(this, "dependentUpdate", new Object[] { Float.valueOf(newTime) } ); try { // XXX Convert time from the creator's syncbase's // time system into this time system. Not // strictly necessary in SVG. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/Interval.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/Interval.java index c181efb97..2622ef096 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/Interval.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/Interval.java @@ -18,7 +18,6 @@ */ package org.apache.batik.anim.timing; -import java.util.Iterator; import java.util.LinkedList; /** @@ -72,7 +71,7 @@ public class Interval { */ public Interval(float begin, float end, InstanceTime beginInstanceTime, InstanceTime endInstanceTime) { - // Trace.enter(this, null, new Object[] { new Float(begin), new Float(end), beginInstanceTime, endInstanceTime } ); try { + // Trace.enter(this, null, new Object[] { Float.valueOf(begin), Float.valueOf(end), beginInstanceTime, endInstanceTime } ); try { this.begin = begin; this.end = end; this.beginInstanceTime = beginInstanceTime; @@ -147,12 +146,11 @@ public class Interval { * Updates the begin time for this interval. */ float setBegin(float begin) { - // Trace.enter(this, "setBegin", new Object[] { new Float(begin) } ); try { + // Trace.enter(this, "setBegin", new Object[] { Float.valueOf(begin) } ); try { float minTime = Float.POSITIVE_INFINITY; this.begin = begin; - Iterator i = beginDependents.iterator(); - while (i.hasNext()) { - InstanceTime it = (InstanceTime) i.next(); + for (Object beginDependent : beginDependents) { + InstanceTime it = (InstanceTime) beginDependent; float t = it.dependentUpdate(begin); if (t < minTime) { minTime = t; @@ -166,13 +164,12 @@ public class Interval { * Updates the end time for this interval. */ float setEnd(float end, InstanceTime endInstanceTime) { - // Trace.enter(this, "setEnd", new Object[] { new Float(end) } ); try { + // Trace.enter(this, "setEnd", new Object[] { Float.valueOf(end) } ); try { float minTime = Float.POSITIVE_INFINITY; this.end = end; this.endInstanceTime = endInstanceTime; - Iterator i = endDependents.iterator(); - while (i.hasNext()) { - InstanceTime it = (InstanceTime) i.next(); + for (Object endDependent : endDependents) { + InstanceTime it = (InstanceTime) endDependent; float t = it.dependentUpdate(end); if (t < minTime) { minTime = t; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/SyncbaseTimingSpecifier.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/SyncbaseTimingSpecifier.java index 823bb7cc9..dc5a05909 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/SyncbaseTimingSpecifier.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/SyncbaseTimingSpecifier.java @@ -58,7 +58,7 @@ public class SyncbaseTimingSpecifier extends OffsetTimingSpecifier { float offset, String syncbaseID, boolean syncBegin) { super(owner, isBegin, offset); - // Trace.enter(this, null, new Object[] { owner, new Boolean(isBegin), new Float(offset), syncbaseID, new Boolean(syncBegin) } ); try { + // Trace.enter(this, null, new Object[] { owner, new Boolean(isBegin), Float.valueOf(offset), syncbaseID, new Boolean(syncBegin) } ); try { this.syncbaseID = syncbaseID; this.syncBegin = syncBegin; this.syncbaseElement = owner.getTimedElementById(syncbaseID); @@ -126,7 +126,7 @@ public class SyncbaseTimingSpecifier extends OffsetTimingSpecifier { * to indicate that its value has changed. */ float handleTimebaseUpdate(InstanceTime instanceTime, float newTime) { - // Trace.enter(this, "handleTimebaseUpdate", new Object[] { instanceTime, new Float(newTime) } ); try { + // Trace.enter(this, "handleTimebaseUpdate", new Object[] { instanceTime, Float.valueOf(newTime) } ); try { if (owner.hasPropagated) { return Float.POSITIVE_INFINITY; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimeContainer.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimeContainer.java index cbbf52bca..6d5bc3246 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimeContainer.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimeContainer.java @@ -18,7 +18,6 @@ */ package org.apache.batik.anim.timing; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -57,9 +56,8 @@ public abstract class TimeContainer extends TimedElement { e.root = root; if (e instanceof TimeContainer) { TimeContainer c = (TimeContainer) e; - Iterator it = c.children.iterator(); - while (it.hasNext()) { - TimedElement te = (TimedElement)it.next(); + for (Object aChildren : c.children) { + TimedElement te = (TimedElement) aChildren; setRoot(te, root); } } @@ -108,9 +106,8 @@ public abstract class TimeContainer extends TimedElement { protected float sampleChildren(float parentSimpleTime, boolean hyperlinking) { float mint = Float.POSITIVE_INFINITY; - Iterator i = children.iterator(); - while (i.hasNext()) { - TimedElement e = (TimedElement) i.next(); + for (Object aChildren : children) { + TimedElement e = (TimedElement) aChildren; float t = e.sampleAt(parentSimpleTime, hyperlinking); if (t < mint) { mint = t; @@ -124,9 +121,8 @@ public abstract class TimeContainer extends TimedElement { */ protected void reset(boolean clearCurrentBegin) { super.reset(clearCurrentBegin); - Iterator i = children.iterator(); - while (i.hasNext()) { - TimedElement e = (TimedElement) i.next(); + for (Object aChildren : children) { + TimedElement e = (TimedElement) aChildren; e.reset(clearCurrentBegin); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedDocumentRoot.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedDocumentRoot.java index d02b79ac9..e80400f05 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedDocumentRoot.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedDocumentRoot.java @@ -19,7 +19,6 @@ package org.apache.batik.anim.timing; import java.util.Calendar; -import java.util.Iterator; import java.util.LinkedList; import org.apache.batik.util.DoublyIndexedSet; @@ -129,7 +128,7 @@ public abstract class TimedDocumentRoot extends TimeContainer { * Samples the entire timegraph at the given time. */ public float seekTo(float time, boolean hyperlinking) { - // Trace.enter(this, "seekTo", new Object[] { new Float(time) } ); try { + // Trace.enter(this, "seekTo", new Object[] { Float.valueOf(time) } ); try { isSampling = true; lastSampleTime = time; isHyperlinking = hyperlinking; @@ -138,8 +137,8 @@ public abstract class TimedDocumentRoot extends TimeContainer { // about a partial ordering of timed elements to sample. float mint = Float.POSITIVE_INFINITY; TimedElement[] es = getChildren(); - for (int i = 0; i < es.length; i++) { - float t = es[i].sampleAt(time, hyperlinking); + for (TimedElement e1 : es) { + float t = e1.sampleAt(time, hyperlinking); if (t < mint) { mint = t; } @@ -147,11 +146,11 @@ public abstract class TimedDocumentRoot extends TimeContainer { boolean needsUpdates; do { needsUpdates = false; - for (int i = 0; i < es.length; i++) { - if (es[i].shouldUpdateCurrentInterval) { + for (TimedElement e : es) { + if (e.shouldUpdateCurrentInterval) { needsUpdates = true; // System.err.print("{" + ((Test.AnimateElement) es[i]).id + "} "); - float t = es[i].sampleAt(time, hyperlinking); + float t = e.sampleAt(time, hyperlinking); if (t < mint) { mint = t; } @@ -221,9 +220,8 @@ public abstract class TimedDocumentRoot extends TimeContainer { * timegraph listeners. */ void fireElementAdded(TimedElement e) { - Iterator i = listeners.iterator(); - while (i.hasNext()) { - ((TimegraphListener) i.next()).elementAdded(e); + for (Object listener : listeners) { + ((TimegraphListener) listener).elementAdded(e); } } @@ -232,9 +230,8 @@ public abstract class TimedDocumentRoot extends TimeContainer { * timegraph listeners. */ void fireElementRemoved(TimedElement e) { - Iterator i = listeners.iterator(); - while (i.hasNext()) { - ((TimegraphListener) i.next()).elementRemoved(e); + for (Object listener : listeners) { + ((TimegraphListener) listener).elementRemoved(e); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedElement.java index 2e83b8739..601cca219 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/timing/TimedElement.java @@ -599,23 +599,22 @@ public abstract class TimedElement implements SMILConstants { * element is currently active. */ protected float sampleAt(float parentSimpleTime, boolean hyperlinking) { - // Trace.enter(this, "sampleAt", new Object[] { new Float(parentSimpleTime) } ); try { + // Trace.enter(this, "sampleAt", new Object[] { Float.valueOf(parentSimpleTime) } ); try { isSampling = true; float time = parentSimpleTime; // No time containers in SVG. // First, process any events that occurred since the last sampling, // taking into account event sensitivity. - Iterator i = handledEvents.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); + for (Object o : handledEvents.entrySet()) { + Map.Entry e = (Map.Entry) o; Event evt = (Event) e.getKey(); Set ts = (Set) e.getValue(); Iterator j = ts.iterator(); boolean hasBegin = false, hasEnd = false; while (j.hasNext() && !(hasBegin && hasEnd)) { EventLikeTimingSpecifier t = - (EventLikeTimingSpecifier) j.next(); + (EventLikeTimingSpecifier) j.next(); if (t.isBegin()) { hasBegin = true; } else { @@ -627,7 +626,7 @@ public abstract class TimedElement implements SMILConstants { useBegin = !isActive || restartMode == RESTART_ALWAYS; useEnd = !useBegin; } else if (hasBegin && (!isActive || - restartMode == RESTART_ALWAYS)) { + restartMode == RESTART_ALWAYS)) { useBegin = true; useEnd = false; } else if (hasEnd && isActive) { @@ -639,7 +638,7 @@ public abstract class TimedElement implements SMILConstants { j = ts.iterator(); while (j.hasNext()) { EventLikeTimingSpecifier t = - (EventLikeTimingSpecifier) j.next(); + (EventLikeTimingSpecifier) j.next(); boolean isBegin = t.isBegin(); if (isBegin && useBegin || !isBegin && useEnd) { t.resolve(evt); @@ -838,8 +837,8 @@ public abstract class TimedElement implements SMILConstants { * accesskey or repeat timing specifiers. */ protected boolean endHasEventConditions() { - for (int i = 0; i < endTimes.length; i++) { - if (endTimes[i].isEventCondition()) { + for (TimingSpecifier endTime : endTimes) { + if (endTime.isEventCondition()) { return true; } } @@ -897,7 +896,7 @@ public abstract class TimedElement implements SMILConstants { */ protected Interval computeInterval(boolean first, boolean fixedBegin, float beginAfter, boolean incl) { - // Trace.enter(this, "computeInterval", new Object[] { new Boolean(first), new Boolean(fixedBegin), new Float(beginAfter)} ); try { + // Trace.enter(this, "computeInterval", new Object[] { new Boolean(first), new Boolean(fixedBegin), Float.valueOf(beginAfter)} ); try { // Trace.print("computing interval from begins=" + beginInstanceTimes + ", ends=" + endInstanceTimes); Iterator beginIterator = beginInstanceTimes.iterator(); Iterator endIterator = endInstanceTimes.iterator(); @@ -1179,7 +1178,7 @@ public abstract class TimedElement implements SMILConstants { try { this.min = parseClockValue(min, false); } catch (ParseException ex) { - this.min = 0; + this.min = 0; } if (this.min < 0) { this.min = 0; @@ -1203,7 +1202,7 @@ public abstract class TimedElement implements SMILConstants { try { this.max = parseClockValue(max, false); } catch (ParseException ex) { - this.max = INDEFINITE; + this.max = INDEFINITE; } if (this.max < 0) { this.max = 0; @@ -1289,11 +1288,11 @@ public abstract class TimedElement implements SMILConstants { * Initializes this timed element. */ public void initialize() { - for (int i = 0; i < beginTimes.length; i++) { - beginTimes[i].initialize(); + for (TimingSpecifier beginTime : beginTimes) { + beginTime.initialize(); } - for (int i = 0; i < endTimes.length; i++) { - endTimes[i].initialize(); + for (TimingSpecifier endTime : endTimes) { + endTime.initialize(); } } @@ -1301,11 +1300,11 @@ public abstract class TimedElement implements SMILConstants { * Deinitializes this timed element. */ public void deinitialize() { - for (int i = 0; i < beginTimes.length; i++) { - beginTimes[i].deinitialize(); + for (TimingSpecifier beginTime : beginTimes) { + beginTime.deinitialize(); } - for (int i = 0; i < endTimes.length; i++) { - endTimes[i].deinitialize(); + for (TimingSpecifier endTime : endTimes) { + endTime.deinitialize(); } } @@ -1404,7 +1403,7 @@ public abstract class TimedElement implements SMILConstants { * exposing animation information from the document. */ public TimingSpecifier[] getBeginTimingSpecifiers() { - return (TimingSpecifier[]) beginTimes.clone(); + return beginTimes.clone(); } /** @@ -1414,7 +1413,7 @@ public abstract class TimedElement implements SMILConstants { * exposing animation information from the document. */ public TimingSpecifier[] getEndTimingSpecifiers() { - return (TimingSpecifier[]) endTimes.clone(); + return endTimes.clone(); } /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/values/AnimatablePathDataValue.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/values/AnimatablePathDataValue.java index 6eaf40a21..236b1559d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/values/AnimatablePathDataValue.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/anim/values/AnimatablePathDataValue.java @@ -186,9 +186,9 @@ public class AnimatablePathDataValue extends AnimatableValue { public String toStringRep() { StringBuffer sb = new StringBuffer(); int k = 0; - for (int i = 0; i < commands.length; i++) { - sb.append(PATH_COMMANDS[commands[i]]); - for (int j = 0; j < PATH_PARAMS[commands[i]]; j++) { + for (short command : commands) { + sb.append(PATH_COMMANDS[command]); + for (int j = 0; j < PATH_PARAMS[command]; j++) { sb.append(' '); sb.append(parameters[k++]); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DefaultSVGConverterController.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DefaultSVGConverterController.java index b60bccb71..f6ccf67ab 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DefaultSVGConverterController.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DefaultSVGConverterController.java @@ -56,9 +56,7 @@ public class DefaultSVGConverterController implements SVGConverterController { * The controller should return true if the source should be * transcoded and false otherwise. */ - public boolean proceedWithSourceTranscoding(SVGConverterSource source, - File dest) { - System.out.println("About to transcoder source of type: " + source.getClass().getName()); + public boolean proceedWithSourceTranscoding(SVGConverterSource source, File dest) { return true; } @@ -84,4 +82,4 @@ public class DefaultSVGConverterController implements SVGConverterController { public void onSourceTranscodingSuccess(SVGConverterSource source, File dest){ } -} \ No newline at end of file +} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DestinationType.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DestinationType.java index 037f165cc..cfcb0ce7b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DestinationType.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/DestinationType.java @@ -94,7 +94,7 @@ public final class DestinationType { case PDF_CODE: try { Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder"); - return (Transcoder)pdfClass.newInstance(); + return (Transcoder)pdfClass.getDeclaredConstructor().newInstance(); } catch(Exception e) { return null; } @@ -124,7 +124,7 @@ public final class DestinationType { case PDF_CODE: return PDF; default: - throw new Error("unknown code:" + code ); + throw new RuntimeException("unknown code:" + code ); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/Main.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/Main.java index 01679160f..a4248b527 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/Main.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/Main.java @@ -21,7 +21,6 @@ package org.apache.batik.apps.rasterizer; import java.awt.Color; import java.awt.geom.Rectangle2D; import java.io.File; -import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; import java.util.List; @@ -36,7 +35,7 @@ import org.apache.batik.util.ApplicationSecurityEnforcer; /** * Handles command line parameters to configure the SVGConverter - * and rasterizer images.
+ * and rasterizer images.
* * Each command line option is handled by an OptionHandler which * is responsible for converting the option into a configuration of the @@ -55,7 +54,7 @@ public class Main implements SVGConverterController { /** * Interface for handling one command line option */ - public static interface OptionHandler { + public interface OptionHandler { /** * The OptionHandler should configure the SVGConverter * according to the value of the option. @@ -502,6 +501,12 @@ public class Main implements SVGConverterController { public static String CL_OPTION_CONSTRAIN_SCRIPT_ORIGIN_DESCRIPTION = Messages.get("Main.cl.option.constrain.script.origin.description", "No description"); + public static String CL_OPTION_BLOCK_EXTERNAL_RESOURCES + = Messages.get("Main.cl.option.block.external.resources", "-blockExternalResources"); + + public static String CL_OPTION_BLOCK_EXTERNAL_RESOURCES_DESCRIPTION + = Messages.get("Main.cl.option.block.external.resources.description", "No description"); + /** * Option to turn off secure execution of scripts */ @@ -830,6 +835,17 @@ public class Main implements SVGConverterController { return CL_OPTION_SECURITY_OFF_DESCRIPTION; } }); + + optionMap.put(CL_OPTION_BLOCK_EXTERNAL_RESOURCES, + new NoValueOptionHandler(){ + public void handleOption(SVGConverter c){ + c.allowExternalResources = false; + } + + public String getOptionDescription(){ + return CL_OPTION_BLOCK_EXTERNAL_RESOURCES_DESCRIPTION; + } + }); } /** @@ -840,8 +856,8 @@ public class Main implements SVGConverterController { public Main(String[] args){ this.args = new ArrayList(); - for (int i=0; i + *
* Possible result raster image formats are PNG, JPEG, TIFF, and PDF. * The Batik Transcoder API is used to execute the conversion. FOP is - * needed to be able to transcode to the PDF format
+ * needed to be able to transcode to the PDF format
* * The source has to be list of files or URL (set by the setSources - * method).
+ * method).
* - * The destination can be:
    + * The destination can be:
      *
    • unspecified. In that case, only file sources can be converted and * a file in the same directory as the source will be created.
    • *
    • a directory, set by the setDst method. In that case, * the output files are created in that destination directory
    • *
    • a file. In case there is a single * source, the destination can be a single named file - * (set with the setDst method.
    • )
      + * (set with the setDst method.) *
    * - *
    + *
    * * There are a number of options which control the way the image is - * converted to the destination format:
      + * converted to the destination format:
        *
      • destinationType: controls the type of conversion which should be done. * see the {@link DestinationType} documentation.
      • *
      • width/height: they control the desired width and height, in user space, @@ -253,6 +253,8 @@ public class SVGConverter { the document which references them. */ protected boolean constrainScriptOrigin = true; + protected boolean allowExternalResources = true; + /** Controls whether scripts should be run securely or not */ protected boolean securityOff = false; @@ -470,9 +472,9 @@ public class SVGConverter { } else{ this.sources = new ArrayList(); - for (int i=0; i 0) { - map.put(JPEGTranscoder.KEY_QUALITY, new Float(this.quality)); + map.put(JPEGTranscoder.KEY_QUALITY, this.quality); } // Set image indexed. ------------------------------------------------ if (indexed != -1) { - map.put(PNGTranscoder.KEY_INDEXED, new Integer(indexed)); + map.put(PNGTranscoder.KEY_INDEXED, indexed); } // Set image background color ----------------------------------------- @@ -848,18 +850,18 @@ public class SVGConverter { // Set image height and width. ---------------------------------------- if (height > 0) { - map.put(ImageTranscoder.KEY_HEIGHT, new Float(this.height)); + map.put(ImageTranscoder.KEY_HEIGHT, this.height); } if (width > 0){ - map.put(ImageTranscoder.KEY_WIDTH, new Float(this.width)); + map.put(ImageTranscoder.KEY_WIDTH, this.width); } // Set maximum height and width --------------------------------------- if (maxHeight > 0) { - map.put(ImageTranscoder.KEY_MAX_HEIGHT, new Float(this.maxHeight)); + map.put(ImageTranscoder.KEY_MAX_HEIGHT, this.maxHeight); } if (maxWidth > 0){ - map.put(ImageTranscoder.KEY_MAX_WIDTH, new Float(this.maxWidth)); + map.put(ImageTranscoder.KEY_MAX_WIDTH, this.maxWidth); } // Set CSS Media @@ -897,7 +899,7 @@ public class SVGConverter { // Sets the millimeters per pixel if (pixelUnitToMillimeter > 0){ map.put(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, - new Float(pixelUnitToMillimeter)); + pixelUnitToMillimeter); } // Set validation @@ -912,7 +914,7 @@ public class SVGConverter { // Set snapshot time if (!Float.isNaN(snapshotTime)) { - map.put(ImageTranscoder.KEY_SNAPSHOT_TIME, new Float(snapshotTime)); + map.put(ImageTranscoder.KEY_SNAPSHOT_TIME, snapshotTime); } // Set allowed scripts @@ -925,6 +927,10 @@ public class SVGConverter { map.put(ImageTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, Boolean.FALSE); } + if (!allowExternalResources) { + map.put(ImageTranscoder.KEY_ALLOW_EXTERNAL_RESOURCES, Boolean.FALSE); + } + return map; } @@ -989,6 +995,7 @@ public class SVGConverter { boolean proceed = controller.proceedOnSourceTranscodingFailure (inputFile, outputFile, e.getErrorCode()); if (proceed){ + e.printStackTrace(); return; } else { throw e; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterFileSource.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterFileSource.java index dceb5534d..b463a5107 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterFileSource.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterFileSource.java @@ -67,7 +67,7 @@ public class SVGConverterFileSource implements SVGConverterSource { } return uri; } catch(MalformedURLException e){ - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterURLSource.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterURLSource.java index aaa937a2b..35157a0a3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterURLSource.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/rasterizer/SVGConverterURLSource.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.apps.rasterizer; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/slideshow/Main.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/slideshow/Main.java index b1598f5f7..4a5191f93 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/slideshow/Main.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/slideshow/Main.java @@ -124,33 +124,33 @@ public class Main extends JComponent { public void run() { renderer.setDoubleBuffered(true); - for (int i=0; i 1) { DefaultMutableTreeNode node = - (DefaultMutableTreeNode) path.getLastPathComponent(); + (DefaultMutableTreeNode) path.getLastPathComponent(); Node associatedNode = getDomNodeFromTreeNode(node); if (associatedNode != null) { nodeList.add(associatedNode); @@ -324,10 +322,10 @@ public class DOMDocumentTree extends JTree implements Autoscroll { .getTransferable(); // Transferable transferable = dtde.getTransferable(); DataFlavor[] flavors = transferable.getTransferDataFlavors(); - for (int i = 0; i < flavors.length; i++) { - if (transferable.isDataFlavorSupported(flavors[i])) { + for (DataFlavor flavor : flavors) { + if (transferable.isDataFlavorSupported(flavor)) { transferData = (TransferData) transferable - .getTransferData(flavors[i]); + .getTransferData(flavor); return; } } @@ -691,8 +689,8 @@ public class DOMDocumentTree extends JTree implements Autoscroll { * @return boolean */ public boolean isDataFlavorSupported(DataFlavor flavor) { - for (int i = 0; i < FLAVORS.length; i++) { - if (flavor.equals(FLAVORS[i])) { + for (DataFlavor FLAVOR : FLAVORS) { + if (flavor.equals(FLAVOR)) { return true; } } @@ -755,9 +753,8 @@ public class DOMDocumentTree extends JTree implements Autoscroll { */ public String getNodesAsXML() { String toReturn = ""; - Iterator iterator = nodeList.iterator(); - while (iterator.hasNext()) { - Node node = (Node) iterator.next(); + for (Object aNodeList : nodeList) { + Node node = (Node) aNodeList; toReturn += DOMUtilities.getXML(node); } return toReturn; @@ -832,7 +829,7 @@ public class DOMDocumentTree extends JTree implements Autoscroll { /** * The DOMDocumentTreeListener. */ - public static interface DOMDocumentTreeListener extends EventListener { + public interface DOMDocumentTreeListener extends EventListener { /** * Fired after successfully completed drop. @@ -1002,8 +999,8 @@ public class DOMDocumentTree extends JTree implements Autoscroll { Node parentNode) { ArrayList children = new ArrayList(); int n = potentialChildren.size(); - for (int i = 0; i < n; i++) { - Node node = (Node) potentialChildren.get(i); + for (Object aPotentialChildren : potentialChildren) { + Node node = (Node) aPotentialChildren; if (DOMUtilities.canAppend(node, parentNode)) { children.add(node); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DOMViewer.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DOMViewer.java index 75960f64d..ce553b549 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DOMViewer.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DOMViewer.java @@ -38,7 +38,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -434,11 +433,11 @@ public class DOMViewer extends JFrame implements ActionMap { } public boolean canEdit(Element el) { - if (panel == null || panel.document == null || true - /*|| panel.document.getDocumentElement() != el*/) { +// if (panel == null || panel.document == null || true +// /*|| panel.document.getDocumentElement() != el*/) { return true; - } - return false; +// } +// return false; } } @@ -649,7 +648,7 @@ public class DOMViewer extends JFrame implements ActionMap { domViewerController.performUpdate(new Runnable() { public void run() { selectNode(elem); - }; + } }); } }); @@ -1692,8 +1691,8 @@ public class DOMViewer extends JFrame implements ActionMap { HashMap menuMap = new HashMap(); ArrayList categoriesList = templates.getCategories(); int n = categoriesList.size(); - for (int i = 0; i < n; i++) { - String category = categoriesList.get(i).toString(); + for (Object aCategoriesList : categoriesList) { + String category = aCategoriesList.toString(); JMenu currentMenu = new JMenu(category); submenu.add(currentMenu); // Add submenus to the map @@ -1710,17 +1709,16 @@ public class DOMViewer extends JFrame implements ActionMap { return n1.getName().compareTo(n2.getName()); } }); - Iterator iter = values.iterator(); - while (iter.hasNext()) { + for (Object value : values) { NodeTemplateDescriptor desc = - (NodeTemplateDescriptor) iter .next(); + (NodeTemplateDescriptor) value; String toParse = desc.getXmlValue(); short nodeType = desc.getType(); String nodeCategory = desc.getCategory(); JMenuItem currentItem = new JMenuItem(desc.getName()); currentItem.addActionListener - (new NodeTemplateParser(toParse, nodeType)); - JMenu currentSubmenu = (JMenu)menuMap.get(nodeCategory); + (new NodeTemplateParser(toParse, nodeType)); + JMenu currentSubmenu = (JMenu) menuMap.get(nodeCategory); currentSubmenu.add(currentItem); } return submenu; @@ -1834,20 +1832,19 @@ public class DOMViewer extends JFrame implements ActionMap { */ protected void handleElementSelection(TreeSelectionEvent ev) { TreePath[] paths = ev.getPaths(); - for (int i = 0; i < paths.length; i++) { - TreePath path = paths[i]; + for (TreePath path : paths) { DefaultMutableTreeNode mtn = - (DefaultMutableTreeNode) path.getLastPathComponent(); + (DefaultMutableTreeNode) path.getLastPathComponent(); Object nodeInfo = mtn.getUserObject(); if (nodeInfo instanceof NodeInfo) { Node node = ((NodeInfo) nodeInfo).getNode(); if (node.getNodeType() == Node.ELEMENT_NODE) { if (ev.isAddedPath(path)) { elementOverlayManager.addElement - ((Element) node); + ((Element) node); } else { elementOverlayManager.removeElement - ((Element) node); + ((Element) node); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DropDownHistoryModel.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DropDownHistoryModel.java index 4a907c595..35dec3d7e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DropDownHistoryModel.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/DropDownHistoryModel.java @@ -185,9 +185,9 @@ public class DropDownHistoryModel implements ScrollablePopupMenuModel { * @return True if item was successfully removed */ protected boolean removeFirstScrollablePopupMenuItem(String details) { - for (int i = 0; i < items.size(); i++) { + for (Object item1 : items) { ScrollablePopupMenuItem item = - (ScrollablePopupMenuItem) items.get(i); + (ScrollablePopupMenuItem) item1; removeItem(item, details); return true; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/ElementOverlayManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/ElementOverlayManager.java index 411063b76..5b97305bc 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/ElementOverlayManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/ElementOverlayManager.java @@ -137,8 +137,8 @@ public class ElementOverlayManager { protected Rectangle getAllElementsBounds() { Rectangle resultBound = null; int n = elements.size(); - for (int i = 0; i < n; i++) { - Element currentElement = (Element) elements.get(i); + for (Object element : elements) { + Element currentElement = (Element) element; Rectangle currentBound = getElementBounds(currentElement); if (resultBound == null) { resultBound = currentBound; @@ -213,13 +213,13 @@ public class ElementOverlayManager { public void paint(Graphics g) { if (controller.isOverlayEnabled() && isOverlayEnabled()) { int n = elements.size(); - for (int i = 0; i < n; i++) { - Element currentElement = (Element) elements.get(i); + for (Object element : elements) { + Element currentElement = (Element) element; GraphicsNode nodeToPaint = canvas.getUpdateManager() .getBridgeContext().getGraphicsNode(currentElement); if (nodeToPaint != null) { AffineTransform elementsAt = - nodeToPaint.getGlobalTransform(); + nodeToPaint.getGlobalTransform(); Shape selectionHighlight = nodeToPaint.getOutline(); AffineTransform at = canvas.getRenderingTransform(); at.concatenate(elementsAt); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/HistoryBrowser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/HistoryBrowser.java index 40fdc6be5..47a1de625 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/HistoryBrowser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/HistoryBrowser.java @@ -293,7 +293,7 @@ public class HistoryBrowser { /** * The HistoryBrowserListener. */ - public static interface HistoryBrowserListener extends EventListener { + public interface HistoryBrowserListener extends EventListener { /** * The command has been executed. @@ -535,7 +535,7 @@ public class HistoryBrowser { /** * Wrapps the command's execute, undo and redo methods. */ - public static interface CommandController { + public interface CommandController { /** * Wrapps the execute method. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JPEGOptionPanel.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JPEGOptionPanel.java index c4460f258..4a9f7cbe7 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JPEGOptionPanel.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JPEGOptionPanel.java @@ -72,9 +72,9 @@ public class JPEGOptionPanel extends OptionPanel { quality.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); Hashtable labels = new Hashtable(); for (int i=0; i < 100; i+=10) { - labels.put(new Integer(i), new JLabel("0."+i/10)); + labels.put(i, new JLabel("0."+i/10)); } - labels.put(new Integer(100), new JLabel("1")); + labels.put(100, new JLabel("1")); quality.setLabelTable(labels); Dimension dim = quality.getPreferredSize(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java index 164ad4c24..f9657ec55 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java @@ -22,7 +22,6 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; -import java.awt.Event; import java.awt.EventQueue; import java.awt.FileDialog; import java.awt.Font; @@ -32,6 +31,7 @@ import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -101,7 +101,7 @@ import org.apache.batik.bridge.UpdateManager; import org.apache.batik.bridge.UpdateManagerEvent; import org.apache.batik.bridge.UpdateManagerListener; import org.apache.batik.dom.StyleSheetProcessingInstruction; -import org.apache.batik.dom.util.HashTable; + import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.ext.swing.JAffineTransformChooser; import org.apache.batik.swing.JSVGCanvas; @@ -130,7 +130,7 @@ import org.apache.batik.util.ParsedURL; import org.apache.batik.util.Platform; import org.apache.batik.util.Service; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.util.gui.JErrorPane; import org.apache.batik.util.gui.LocationBar; import org.apache.batik.util.gui.MemoryMonitor; @@ -620,11 +620,11 @@ public class JSVGViewerFrame cMap.get(JSVGCanvas.ZOOM_OUT_ACTION)); listeners.put(PREVIOUS_TRANSFORM_ACTION, previousTransformAction); - key = KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.CTRL_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.CTRL_DOWN_MASK); imap.put(key, previousTransformAction); listeners.put(NEXT_TRANSFORM_ACTION, nextTransformAction); - key = KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK); imap.put(key, nextTransformAction); listeners.put(USE_STYLESHEET_ACTION, useStylesheetAction); @@ -650,9 +650,9 @@ public class JSVGViewerFrame localHistory = new LocalHistory(mb, this); String[] uri = application.getVisitedURIs(); - for (int i=0; i "Close" menu.getItem(3).setAccelerator - (KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK)); + (KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK)); debugGui.setSize(600, 460); debugGui.pack(); @@ -1199,10 +1199,9 @@ public class JSVGViewerFrame Resources.getString(OPEN_TITLE)); fileDialog.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { - Iterator iter = getHandlers().iterator(); - while (iter.hasNext()) { + for (Object o : getHandlers()) { SquiggleInputHandler handler - = (SquiggleInputHandler)iter.next(); + = (SquiggleInputHandler) o; if (handler.accept(new File(dir, name))) { return true; } @@ -1238,12 +1237,11 @@ public class JSVGViewerFrame // // Add file filters from the handlers map // - Iterator iter = getHandlers().iterator(); - while (iter.hasNext()) { + for (Object o : getHandlers()) { SquiggleInputHandler handler - = (SquiggleInputHandler)iter.next(); + = (SquiggleInputHandler) o; fileChooser.addChoosableFileFilter - (new SquiggleInputHandlerFilter(handler)); + (new SquiggleInputHandlerFilter(handler)); } int choice = fileChooser.showOpenDialog(JSVGViewerFrame.this); @@ -1476,9 +1474,8 @@ public class JSVGViewerFrame protected void update() { boolean b = localHistory.canGoBack(); - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(b); + for (Object component : components) { + ((JComponent) component).setEnabled(b); } } } @@ -1503,9 +1500,8 @@ public class JSVGViewerFrame protected void update() { boolean b = localHistory.canGoForward(); - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(b); + for (Object component : components) { + ((JComponent) component).setEnabled(b); } } } @@ -1721,7 +1717,7 @@ public class JSVGViewerFrame application.getXMLParserClassName()); } trans.addTranscodingHint - (JPEGTranscoder.KEY_QUALITY, new Float(quality)); + (JPEGTranscoder.KEY_QUALITY, quality); final BufferedImage img = trans.createImage(w, h); @@ -1785,7 +1781,7 @@ public class JSVGViewerFrame Boolean.TRUE ); if(isIndexed){ - trans.addTranscodingHint(PNGTranscoder.KEY_INDEXED, new Integer(8)); + trans.addTranscodingHint(PNGTranscoder.KEY_INDEXED, 8); } final BufferedImage img = trans.createImage(w, h); @@ -1976,9 +1972,8 @@ public class JSVGViewerFrame protected void update() { boolean b = transformHistory.canGoBack(); - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(b); + for (Object component : components) { + ((JComponent) component).setEnabled(b); } } } @@ -2006,9 +2001,8 @@ public class JSVGViewerFrame protected void update() { boolean b = transformHistory.canGoForward(); - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(b); + for (Object component : components) { + ((JComponent) component).setEnabled(b); } } } @@ -2048,9 +2042,9 @@ public class JSVGViewerFrame if (n instanceof StyleSheetProcessingInstruction) { StyleSheetProcessingInstruction sspi; sspi = (StyleSheetProcessingInstruction)n; - HashTable attrs = sspi.getPseudoAttributes(); - final String title = (String)attrs.get("title"); - String alt = (String)attrs.get("alternate"); + HashMap attrs = sspi.getPseudoAttributes(); + final String title = attrs.get("title"); + String alt = attrs.get("alternate"); if (title != null && "yes".equals(alt)) { JRadioButtonMenuItem button; button = new JRadioButtonMenuItem(title); @@ -2093,9 +2087,8 @@ public class JSVGViewerFrame } public void update(boolean enabled) { - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(enabled); + for (Object component : components) { + ((JComponent) component).setEnabled(enabled); } } } @@ -2117,9 +2110,8 @@ public class JSVGViewerFrame } public void update(boolean enabled) { - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(enabled); + for (Object component : components) { + ((JComponent) component).setEnabled(enabled); } } } @@ -2141,9 +2133,8 @@ public class JSVGViewerFrame } public void update(boolean enabled) { - Iterator it = components.iterator(); - while (it.hasNext()) { - ((JComponent)it.next()).setEnabled(enabled); + for (Object component : components) { + ((JComponent) component).setEnabled(enabled); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/Main.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/Main.java index 5f7d2e5e7..f1b2d05fa 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/Main.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/Main.java @@ -35,7 +35,6 @@ import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.Charset; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -377,19 +376,19 @@ public class Main implements Application { defaults.put(PreferenceDialog.PREFERENCE_KEY_LOAD_ECMASCRIPT, Boolean.TRUE); defaults.put(PreferenceDialog.PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN, - new Integer(ResourceOrigin.DOCUMENT)); + ResourceOrigin.DOCUMENT); defaults.put(PreferenceDialog.PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN, - new Integer(ResourceOrigin.ANY)); + ResourceOrigin.ANY); defaults.put(PREFERENCE_KEY_VISITED_URI_LIST, ""); defaults.put(PREFERENCE_KEY_VISITED_URI_LIST_LENGTH, - new Integer(MAX_VISITED_URIS)); + MAX_VISITED_URIS); defaults.put(PreferenceDialog.PREFERENCE_KEY_ANIMATION_RATE_LIMITING_MODE, - new Integer(1)); + 1); defaults.put(PreferenceDialog.PREFERENCE_KEY_ANIMATION_RATE_LIMITING_CPU, - new Float(0.75f)); + 0.75f); defaults.put(PreferenceDialog.PREFERENCE_KEY_ANIMATION_RATE_LIMITING_FPS, - new Float(10)); + (float) 10); defaults.put(PreferenceDialog.PREFERENCE_KEY_USER_STYLESHEET_ENABLED, Boolean.TRUE); @@ -604,10 +603,9 @@ public class Main implements Application { System.out.println(resources.getString("Command.syntax")); System.out.println(); System.out.println(resources.getString("Command.options")); - Iterator it = handlers.keySet().iterator(); - while (it.hasNext()) { - String s = (String)it.next(); - System.out.println(((OptionHandler)handlers.get(s)).getDescription()); + for (Object o : handlers.keySet()) { + String s = (String) o; + System.out.println(((OptionHandler) handlers.get(s)).getDescription()); } } @@ -757,9 +755,8 @@ public class Main implements Application { } private void setPreferences() throws IOException { - Iterator it = viewerFrames.iterator(); - while (it.hasNext()) { - setPreferences((JSVGViewerFrame)it.next()); + for (Object viewerFrame : viewerFrames) { + setPreferences((JSVGViewerFrame) viewerFrame); } System.setProperty("proxyHost", preferenceManager.getString @@ -960,11 +957,11 @@ public class Main implements Application { // Now, save the list of visited URL into the preferences StringBuffer lastVisitedBuffer = new StringBuffer( lastVisited.size() * 8 ); - for (int i=0; i"; + public static String animateElementValue = + ""; public static short animateElementType = Node.ELEMENT_NODE; @@ -1163,7 +1164,8 @@ public class NodeTemplates { public static String animateColorElementName = SVGConstants.SVG_ANIMATE_COLOR_TAG; - public static String animateColorElementValue = ""; + public static String animateColorElementValue = + ""; public static short animateColorElementType = Node.ELEMENT_NODE; @@ -1189,7 +1191,8 @@ public class NodeTemplates { public static String animateTransformElementName = SVGConstants.SVG_ANIMATE_TRANSFORM_TAG; - public static String animateTransformElementValue = ""; + public static String animateTransformElementValue = + ""; public static short animateTransformElementType = Node.ELEMENT_NODE; @@ -1229,8 +1232,7 @@ public class NodeTemplates { */ private void initializeTemplates() { Field[] fields = getClass().getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - Field currentField = fields[i]; + for (Field currentField : fields) { try { if (currentField.getType() == String.class && currentField.getName().endsWith("MemberName")) { @@ -1241,8 +1243,8 @@ public class NodeTemplates { baseFieldName + VALUE).get(this).toString(); String nodeName = getClass().getField(baseFieldName + NAME) .get(this).toString(); - short nodeType = ((Short) getClass().getField( - baseFieldName + TYPE).get(this)).shortValue(); + short nodeType = (Short) getClass().getField( + baseFieldName + TYPE).get(this); String nodeDescription = getClass().getField( baseFieldName + DESCRIPTION).get(this).toString(); String nodeCategory = getClass().getField( diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/PreferenceDialog.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/PreferenceDialog.java index 423b06604..dd8e6f0ef 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/PreferenceDialog.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/PreferenceDialog.java @@ -1196,7 +1196,7 @@ public class PreferenceDialog extends JDialog // button.setIconTextGap(0); AbstractButton.class.getMethod ("setIconTextGap", new Class[] { Integer.TYPE }) - .invoke(button, new Object[] { new Integer(0) }); + .invoke(button, new Object[] {0}); } catch (Exception ex) { } button.setPressedIcon(icon2); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SVGInputHandler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SVGInputHandler.java index 0d614b333..3f03f6b7a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SVGInputHandler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SVGInputHandler.java @@ -26,7 +26,7 @@ import org.apache.batik.util.ParsedURL; * This implementation of the SquiggleInputHandler class * simply displays an SVG file into the JSVGCanvas. * - * @author Vincent Hardy + * @author Vincent Hardy * @version $Id$ */ public class SVGInputHandler implements SquiggleInputHandler { @@ -93,8 +93,8 @@ public class SVGInputHandler implements SquiggleInputHandler { */ public boolean accept(String path) { if (path == null) return false; - for (int i=0; iVincent Hardy + * @author Vincent Hardy * @version $Id$ */ public interface SquiggleInputHandler { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SquiggleInputHandlerFilter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SquiggleInputHandlerFilter.java index 5c60d8ebc..57b0e9782 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SquiggleInputHandlerFilter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/SquiggleInputHandlerFilter.java @@ -25,7 +25,7 @@ import javax.swing.filechooser.FileFilter; /** * This class filters file for a given SquiggleInputHandler * - * @author Vincent Hardy + * @author Vincent Hardy * @version $Id$ */ public class SquiggleInputHandlerFilter extends FileFilter { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/WindowsAltFileSystemView.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/WindowsAltFileSystemView.java index c51605eb0..458038660 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/WindowsAltFileSystemView.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/WindowsAltFileSystemView.java @@ -128,7 +128,7 @@ class WindowsAltFileSystemView extends FileSystemView { // Create the A: drive whether it is mounted or not FileSystemRoot floppy = new FileSystemRoot(Resources.getString(FLOPPY_DRIVE) - + "\\"); + + "\\"); rootsVector.add(floppy); // Run through all possible mount points and check @@ -146,7 +146,7 @@ class WindowsAltFileSystemView extends FileSystemView { return roots; } - class FileSystemRoot extends File { + static class FileSystemRoot extends File { public FileSystemRoot(File f) { super(f, ""); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLInputHandler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLInputHandler.java index 05cbd5e88..350416cca 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLInputHandler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLInputHandler.java @@ -21,6 +21,7 @@ package org.apache.batik.apps.svgbrowser; import java.io.File; import java.io.StringReader; import java.io.StringWriter; +import java.util.HashMap; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -35,7 +36,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.batik.anim.dom.SAXSVGDocumentFactory; import org.apache.batik.anim.dom.SVGDOMImplementation; import org.apache.batik.dom.util.DOMUtilities; -import org.apache.batik.dom.util.HashTable; + import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVGConstants; import org.apache.batik.util.XMLResourceDescriptor; @@ -57,7 +58,7 @@ import org.w3c.dom.svg.SVGDocument; * input XML file and the handler checks that the result is an * SVG document with an SVG root. * - * @author Vincent Hardy + * @author Vincent Hardy * @version $Id$ */ public class XMLInputHandler implements SquiggleInputHandler { @@ -144,8 +145,8 @@ public class XMLInputHandler implements SquiggleInputHandler { return false; } - for (int i=0; i table = new HashMap(); DOMUtilities.parseStyleSheetPIData(pi.getData(), table); @@ -316,7 +317,7 @@ public class XMLInputHandler implements SquiggleInputHandler { * Implements the URIResolver interface so that relative urls used in * transformations are resolved properly. */ - public class DocumentURIResolver implements URIResolver { + public static class DocumentURIResolver implements URIResolver { String documentURI; public DocumentURIResolver(String documentURI) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLPreferenceManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLPreferenceManager.java index 912860a42..c070e0cdc 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLPreferenceManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgbrowser/XMLPreferenceManager.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.apps.svgbrowser; @@ -27,7 +27,6 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -163,11 +162,10 @@ public class XMLPreferenceManager extends PreferenceManager { w.write("\n"); - Iterator it = m.keySet().iterator(); - while (it.hasNext()) { - String n = (String)it.next(); - String v = (String)m.get(n); - + for (Object o : m.keySet()) { + String n = (String) o; + String v = (String) m.get(n); + w.write(""); try { w.write(DOMUtilities.contentToString(v, false)); @@ -187,15 +185,11 @@ public class XMLPreferenceManager extends PreferenceManager { */ private synchronized void enumerate(Map m) { if (defaults != null) { - Iterator it = m.keySet().iterator(); - while (it.hasNext()) { - Object k = it.next(); + for (Object k : m.keySet()) { m.put(k, defaults.get(k)); } } - Iterator it = keySet().iterator(); - while (it.hasNext()) { - Object k = it.next(); + for (Object k : keySet()) { m.put(k, get(k)); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgpp/Main.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgpp/Main.java index 485bcec9e..1a6623b8b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgpp/Main.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/svgpp/Main.java @@ -15,12 +15,11 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.apps.svgpp; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.apache.batik.i18n.LocalizableSupport; @@ -136,10 +135,9 @@ public class Main { System.out.println(localizableSupport.formatMessage("syntax", null)); System.out.println(); System.out.println(localizableSupport.formatMessage("options", null)); - Iterator it = handlers.keySet().iterator(); - while (it.hasNext()) { - String s = (String)it.next(); - System.out.println(((OptionHandler)handlers.get(s)).getDescription()); + for (Object o : handlers.keySet()) { + String s = (String) o; + System.out.println(((OptionHandler) handlers.get(s)).getDescription()); } } @@ -296,7 +294,7 @@ public class Main { throw new IllegalArgumentException(); } transcoder.addTranscodingHint(SVGTranscoder.KEY_TABULATION_WIDTH, - new Integer(arguments[index++])); + Integer.valueOf(arguments[index++])); } public String getDescription() { @@ -314,7 +312,7 @@ public class Main { throw new IllegalArgumentException(); } transcoder.addTranscodingHint(SVGTranscoder.KEY_DOCUMENT_WIDTH, - new Integer(arguments[index++])); + Integer.valueOf(arguments[index++])); } public String getDescription() { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/ttf2svg/Main.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/ttf2svg/Main.java index fccb177cb..193c3dcbb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/ttf2svg/Main.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/apps/ttf2svg/Main.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.apps.ttf2svg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java index 24dce1552..84e0673c0 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java @@ -18,11 +18,6 @@ */ package org.apache.batik.bridge; -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.lang.ref.SoftReference; - import org.apache.batik.anim.dom.AnimatedLiveAttributeValue; import org.apache.batik.anim.dom.SVGOMAnimatedTransformList; import org.apache.batik.anim.dom.SVGOMElement; @@ -37,7 +32,6 @@ import org.apache.batik.ext.awt.geom.SegmentList; import org.apache.batik.gvt.CanvasGraphicsNode; import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.gvt.GraphicsNode; - import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.events.DocumentEvent; @@ -46,6 +40,11 @@ import org.w3c.dom.events.MutationEvent; import org.w3c.dom.svg.SVGFitToViewBox; import org.w3c.dom.svg.SVGTransformable; +import java.lang.ref.SoftReference; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + /** * The base bridge class for SVG graphics node. By default, the namespace URI is * the SVG namespace. Override the getNamespaceURI if you want to add @@ -356,8 +355,7 @@ public abstract class AbstractGraphicsNodeBridge extends AnimatableSVGBridge try { SVGCSSEngine eng = (SVGCSSEngine) evt.getSource(); int[] properties = evt.getProperties(); - for (int i = 0; i < properties.length; i++) { - int idx = properties[i]; + for (int idx : properties) { handleCSSPropertyChanged(idx); String pn = eng.getPropertyName(idx); fireBaseAttributeListeners(pn); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java index 608ab7fb4..0d1fd1606 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java @@ -25,7 +25,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.ext.awt.MultipleGradientPaint; import org.apache.batik.gvt.GraphicsNode; @@ -195,7 +194,7 @@ public abstract class AbstractSVGGradientElementBridge return null; // no xlink:href found, exit } // check if there is circular dependencies - String baseURI = ((AbstractNode) paintElement).getBaseURI(); + String baseURI = paintElement.getBaseURI(); ParsedURL purl = new ParsedURL(baseURI, uri); if (contains(refs, purl)) { @@ -257,16 +256,15 @@ public abstract class AbstractSVGGradientElementBridge * @param key the url to search for */ private static boolean contains(List urls, ParsedURL key) { - Iterator iter = urls.iterator(); - while (iter.hasNext()) { - if (key.equals(iter.next())) + for (Object url : urls) { + if (key.equals(url)) return true; } return false; } /** - * This class represents a gradient <stop> element. + * This class represents a gradient <stop> element. */ public static class Stop { @@ -288,7 +286,7 @@ public abstract class AbstractSVGGradientElementBridge } /** - * Bridge class for the gradient <stop> element. + * Bridge class for the gradient <stop> element. */ public static class SVGStopElementBridge extends AnimatableGenericSVGBridge implements Bridge { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGLightingElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGLightingElementBridge.java index 7d64cc597..1ab025136 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGLightingElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AbstractSVGLightingElementBridge.java @@ -29,7 +29,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <feDiffuseLighting> element. + * Bridge class for the <feDiffuseLighting> element. * * @author Thierry Kormann * @version $Id$ @@ -132,7 +132,7 @@ public abstract class AbstractSVGLightingElementBridge } /** - * Bridge class for the <feSpotLight> element. + * Bridge class for the <feSpotLight> element. */ public static class SVGFeSpotLightElementBridge extends AbstractSVGLightElementBridge { @@ -200,7 +200,7 @@ public abstract class AbstractSVGLightingElementBridge } /** - * Bridge class for the <feDistantLight> element. + * Bridge class for the <feDistantLight> element. */ public static class SVGFeDistantLightElementBridge extends AbstractSVGLightElementBridge { @@ -243,7 +243,7 @@ public abstract class AbstractSVGLightingElementBridge } /** - * Bridge class for the <fePointLight> element. + * Bridge class for the <fePointLight> element. */ public static class SVGFePointLightElementBridge extends AbstractSVGLightElementBridge { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimatableSVGBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimatableSVGBridge.java index f4a28df31..7e2bbf9b0 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimatableSVGBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimatableSVGBridge.java @@ -19,7 +19,6 @@ package org.apache.batik.bridge; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import org.apache.batik.anim.dom.AnimationTarget; @@ -87,10 +86,9 @@ public abstract class AnimatableSVGBridge if (targetListeners != null) { LinkedList ll = (LinkedList) targetListeners.get(pn); if (ll != null) { - Iterator it = ll.iterator(); - while (it.hasNext()) { + for (Object aLl : ll) { AnimationTargetListener l = - (AnimationTargetListener) it.next(); + (AnimationTargetListener) aLl; l.baseValueChanged((AnimationTarget) e, null, pn, true); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimationSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimationSupport.java index 4435ed572..6cbac6bab 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimationSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/AnimationSupport.java @@ -25,7 +25,7 @@ import org.apache.batik.anim.timing.TimedElement; import org.apache.batik.dom.events.DOMTimeEvent; import org.apache.batik.dom.svg.IdContainer; import org.apache.batik.dom.svg.SVGOMUseShadowRoot; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.Node; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BaseScriptingEnvironment.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BaseScriptingEnvironment.java index 02579219c..72eb7ac94 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BaseScriptingEnvironment.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BaseScriptingEnvironment.java @@ -29,7 +29,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -45,8 +44,9 @@ import org.apache.batik.script.InterpreterException; import org.apache.batik.script.ScriptEventWrapper; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; +import org.apache.batik.w3c.dom.Location; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -134,9 +134,8 @@ public class BaseScriptingEnvironment { */ public static boolean isDynamicElement (Element elt, BridgeContext ctx, List bridgeExtensions) { - Iterator i = bridgeExtensions.iterator(); - while (i.hasNext()) { - BridgeExtension bridgeExtension = (BridgeExtension) i.next(); + for (Object bridgeExtension1 : bridgeExtensions) { + BridgeExtension bridgeExtension = (BridgeExtension) bridgeExtension1; if (bridgeExtension.isDynamicElement(elt)) { return true; } @@ -256,7 +255,7 @@ public class BaseScriptingEnvironment { protected Map windowObjects = new HashMap(); /** - * Set of <script> elements that have already been executed. + * Set of <script> elements that have already been executed. */ protected WeakHashMap executedScripts = new WeakHashMap(); @@ -343,7 +342,7 @@ public class BaseScriptingEnvironment { } /** - * Loads the scripts contained in the <script> elements. + * Loads the scripts contained in the <script> elements. */ public void loadScripts() { NodeList scripts = document.getElementsByTagNameNS @@ -357,7 +356,7 @@ public class BaseScriptingEnvironment { } /** - * Executes the specified <script> element, if it hasn't been + * Executes the specified <script> element, if it hasn't been * executed already. */ protected void loadScript(AbstractElement script) { @@ -420,7 +419,7 @@ public class BaseScriptingEnvironment { if (sh != null) { // Run the script handler. ScriptHandler h; - h = (ScriptHandler)cll.loadClass(sh).newInstance(); + h = (ScriptHandler)cll.loadClass(sh).getDeclaredConstructor().newInstance(); h.run(document, getWindow()); } @@ -430,7 +429,7 @@ public class BaseScriptingEnvironment { // Run the initializer EventListenerInitializer initializer; initializer = - (EventListenerInitializer)cll.loadClass(sh).newInstance(); + (EventListenerInitializer)cll.loadClass(sh).getDeclaredConstructor().newInstance(); getWindow(); @@ -541,7 +540,7 @@ public class BaseScriptingEnvironment { (INLINE_SCRIPT_DESCRIPTION, new Object [] {d.getURL(), "<"+script.getNodeName()+">", - new Integer(line)}); + line}); // Inline script. Node n = script.getFirstChild(); if (n != null) { @@ -656,7 +655,7 @@ public class BaseScriptingEnvironment { (EVENT_SCRIPT_DESCRIPTION, new Object [] {d.getURL(), SVGConstants.SVG_ONLOAD_ATTRIBUTE, - new Integer(line)}); + line}); EventListener l = new EventListener() { public void handleEvent(Event evt) { @@ -922,7 +921,7 @@ public class BaseScriptingEnvironment { /** * Returns the Location. */ - public org.apache.batik.w3c.dom.Location getLocation() { + public Location getLocation() { return null; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeContext.java index ea06204aa..169121dea 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeContext.java @@ -18,23 +18,6 @@ */ package org.apache.batik.bridge; -import java.awt.Cursor; -import java.awt.geom.Dimension2D; -import java.io.IOException; -import java.io.InterruptedIOException; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; -import java.net.MalformedURLException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; - import org.apache.batik.anim.dom.AnimatedAttributeListener; import org.apache.batik.anim.dom.AnimatedLiveAttributeValue; import org.apache.batik.anim.dom.SVGDOMImplementation; @@ -43,6 +26,7 @@ import org.apache.batik.anim.dom.SVGOMElement; import org.apache.batik.anim.dom.SVGStylableElement; import org.apache.batik.bridge.svg12.SVG12BridgeContext; import org.apache.batik.bridge.svg12.SVG12BridgeExtension; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.css.engine.CSSContext; import org.apache.batik.css.engine.CSSEngine; import org.apache.batik.css.engine.CSSEngineEvent; @@ -64,8 +48,6 @@ import org.apache.batik.util.CleanerThread; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.SVGConstants; import org.apache.batik.util.Service; -import org.apache.batik.util.XMLConstants; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -76,6 +58,23 @@ import org.w3c.dom.events.MouseEvent; import org.w3c.dom.events.MutationEvent; import org.w3c.dom.svg.SVGDocument; +import java.io.IOException; +import java.io.InterruptedIOException; +import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; +import java.awt.Cursor; +import java.awt.geom.Dimension2D; + /** * This class represents a context used by the various bridges and the * builder. A bridge context is associated to a particular document @@ -567,8 +566,8 @@ public class BridgeContext implements ErrorConstants, CSSContext { language, null); String[] mimeTypes = interpreter.getMimeTypes(); - for (int i = 0; i < mimeTypes.length; i++) { - interpreterMap.put(mimeTypes[i], interpreter); + for (String mimeType : mimeTypes) { + interpreterMap.put(mimeType, interpreter); } } catch (Exception e) { if (userAgent != null) { @@ -1023,7 +1022,7 @@ public class BridgeContext implements ErrorConstants, CSSContext { // start assert if (!(namespaceURI.equals(bridge.getNamespaceURI()) && localName.equals(bridge.getLocalName()))) { - throw new Error("Invalid Bridge: "+ + throw new RuntimeException("Invalid Bridge: "+ namespaceURI+"/"+bridge.getNamespaceURI()+" "+ localName+"/"+bridge.getLocalName()+" "+ bridge.getClass()); @@ -1205,15 +1204,14 @@ public class BridgeContext implements ErrorConstants, CSSContext { public void removeUIEventListeners(Document doc) { EventTarget evtTarget = (EventTarget)doc.getDocumentElement(); synchronized (eventListenerSet) { - Iterator i = eventListenerSet.iterator(); - while (i.hasNext()) { - EventListenerMememto elm = (EventListenerMememto)i.next(); + for (Object anEventListenerSet : eventListenerSet) { + EventListenerMememto elm = (EventListenerMememto) anEventListenerSet; NodeEventTarget et = elm.getTarget(); if (et == evtTarget) { EventListener el = elm.getListener(); - boolean uc = elm.getUseCapture(); - String t = elm.getEventType(); - boolean n = elm.getNamespaced(); + boolean uc = elm.getUseCapture(); + String t = elm.getEventType(); + boolean n = elm.getNamespaced(); if (et == null || el == null || t == null) { continue; } @@ -1428,14 +1426,13 @@ public class BridgeContext implements ErrorConstants, CSSContext { synchronized (eventListenerSet) { // remove all listeners added by Bridges - Iterator iter = eventListenerSet.iterator(); - while (iter.hasNext()) { - EventListenerMememto m = (EventListenerMememto)iter.next(); + for (Object anEventListenerSet : eventListenerSet) { + EventListenerMememto m = (EventListenerMememto) anEventListenerSet; NodeEventTarget et = m.getTarget(); - EventListener el = m.getListener(); - boolean uc = m.getUseCapture(); - String t = m.getEventType(); - boolean n = m.getNamespaced(); + EventListener el = m.getListener(); + boolean uc = m.getUseCapture(); + String t = m.getEventType(); + boolean n = m.getNamespaced(); if (et == null || el == null || t == null) { continue; } @@ -1458,9 +1455,8 @@ public class BridgeContext implements ErrorConstants, CSSContext { animationEngine = null; } - Iterator iter = interpreterMap.values().iterator(); - while (iter.hasNext()) { - Interpreter interpreter = (Interpreter)iter.next(); + for (Object o : interpreterMap.values()) { + Interpreter interpreter = (Interpreter) o; if (interpreter != null) interpreter.dispose(); } @@ -1705,8 +1701,8 @@ public class BridgeContext implements ErrorConstants, CSSContext { // Check if 'display' changed on this element. int [] properties = evt.getProperties(); - for (int i=0; i < properties.length; ++i) { - if (properties[i] == SVGCSSEngine.DISPLAY_INDEX) { + for (int property : properties) { + if (property == SVGCSSEngine.DISPLAY_INDEX) { if (!CSSUtilities.convertDisplay(elem)) { // (Still) Not displayed break; @@ -1714,17 +1710,17 @@ public class BridgeContext implements ErrorConstants, CSSContext { // build the graphics node GVTBuilder builder = getGVTBuilder(); GraphicsNode childNode = builder.build - (BridgeContext.this, elem); + (BridgeContext.this, elem); if (childNode == null) { // the added element is not a graphic element? break; } int idx = -1; - for(Node ps = elem.getPreviousSibling(); ps != null; - ps = ps.getPreviousSibling()) { + for (Node ps = elem.getPreviousSibling(); ps != null; + ps = ps.getPreviousSibling()) { if (ps.getNodeType() != Node.ELEMENT_NODE) continue; - Element pse = (Element)ps; + Element pse = (Element) ps; GraphicsNode gn = getGraphicsNode(pse); if (gn == null) continue; @@ -1904,7 +1900,7 @@ public class BridgeContext implements ErrorConstants, CSSContext { /** * Tells whether the given SVG document is Interactive. - * We say it is, if it has any <title>, <desc>, or <a> elements, + * We say it is, if it has any <title>, <desc>, or <a> elements, * of if the 'cursor' property is anything but Auto on any element. */ public boolean isInteractiveDocument(Document doc) { @@ -2045,10 +2041,9 @@ public class BridgeContext implements ErrorConstants, CSSContext { public void registerSVGBridges() { UserAgent ua = getUserAgent(); List ext = getBridgeExtensions(document); - Iterator iter = ext.iterator(); - while(iter.hasNext()) { - BridgeExtension be = (BridgeExtension)iter.next(); + for (Object anExt : ext) { + BridgeExtension be = (BridgeExtension) anExt; be.registerTags(this); ua.registerExtension(be); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeEventSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeEventSupport.java index 111e74b18..2953a43a5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeEventSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeEventSupport.java @@ -20,7 +20,6 @@ package org.apache.batik.bridge; import java.awt.Point; import java.awt.event.KeyEvent; -import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.lang.ref.SoftReference; @@ -39,7 +38,7 @@ import org.apache.batik.gvt.event.GraphicsNodeMouseEvent; import org.apache.batik.gvt.event.GraphicsNodeMouseListener; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -423,7 +422,7 @@ public abstract class BridgeEventSupport implements SVGConstants { * event or null if any. * * @param node the graphics node that received the event - * @param coords the mouse coordinates in the GVT tree space + * @param pt the mouse coordinates in the GVT tree space */ protected Element getEventTarget(GraphicsNode node, Point2D pt) { Element target = context.getElement(node); @@ -435,21 +434,21 @@ public abstract class BridgeEventSupport implements SVGConstants { if (list != null){ float x = (float)pt.getX(); float y = (float)pt.getY(); - for (int i = 0 ; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run = - (StrokingTextPainter.TextRun)list.get(i); + (StrokingTextPainter.TextRun) aList; AttributedCharacterIterator aci = run.getACI(); TextSpanLayout layout = run.getLayout(); TextHit textHit = layout.hitTestChar(x, y); Rectangle2D bounds = layout.getBounds2D(); if ((textHit != null) && - (bounds != null) && bounds.contains(x, y)) { + (bounds != null) && bounds.contains(x, y)) { SoftReference sr; - sr =(SoftReference)aci.getAttribute - (TEXT_COMPOUND_ID); + sr = (SoftReference) aci.getAttribute + (TEXT_COMPOUND_ID); Object delimiter = sr.get(); if (delimiter instanceof Element) { - return (Element)delimiter; + return (Element) delimiter; } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeException.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeException.java index aae2254cb..baeb8d078 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeException.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/BridgeException.java @@ -185,7 +185,7 @@ public class BridgeException extends RuntimeException { else uri = doc.getURL(); Object [] fullparams = new Object[params.length+3]; fullparams[0] = uri; - fullparams[1] = new Integer(line); + fullparams[1] = line; fullparams[2] = lname; System.arraycopy( params, 0, fullparams, 3, params.length ); return Messages.formatMessage(code, fullparams); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSFontFace.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSFontFace.java index 1bbacc22e..c84f6f61f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSFontFace.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSFontFace.java @@ -34,7 +34,7 @@ import org.w3c.dom.css.CSSValue; import org.w3c.dom.css.CSSPrimitiveValue; /** - * This class represents a <font-face> element or @font-face rule + * This class represents a <font-face> element or @font-face rule * * @author Bella Robinson * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSUtilities.java index eb8b5d577..fede60f75 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CSSUtilities.java @@ -39,7 +39,7 @@ import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.filter.Mask; import org.apache.batik.util.CSSConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; @@ -823,7 +823,7 @@ public abstract class CSSUtilities ///////////////////////////////////////////////////////////////////////// /** - * Converts the color defined on the specified <feFlood> + * Converts the color defined on the specified <feFlood> * element to a Color. * * @param e the feFlood element @@ -846,7 +846,7 @@ public abstract class CSSUtilities ///////////////////////////////////////////////////////////////////////// /** - * Converts the color defined on the specified <stop> element + * Converts the color defined on the specified <stop> element * to a Color. * * @param e the stop element diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ConcreteTextSelector.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ConcreteTextSelector.java index 849f8935f..246f4f927 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ConcreteTextSelector.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ConcreteTextSelector.java @@ -19,8 +19,6 @@ package org.apache.batik.bridge; import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Iterator; @@ -109,7 +107,7 @@ public class ConcreteTextSelector implements Selector { public void setSelection(Mark begin, Mark end) { TextNode node = begin.getTextNode(); if (node != end.getTextNode()) { - throw new Error("Markers not from same TextNode"); + throw new RuntimeException("Markers not from same TextNode"); } node.setSelection(begin, end); selectionNode = node; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CursorManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CursorManager.java index 36f6a257e..775dfa98d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CursorManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/CursorManager.java @@ -32,7 +32,7 @@ import java.awt.image.Raster; import java.awt.image.RenderedImage; import java.awt.image.SampleModel; import java.awt.image.WritableRaster; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Map; import org.apache.batik.css.engine.SVGCSSEngine; @@ -100,7 +100,7 @@ public class CursorManager implements SVGConstants, ErrorConstants { */ static { Toolkit toolkit = Toolkit.getDefaultToolkit(); - cursorMap = new Hashtable(); + cursorMap = new HashMap(); cursorMap.put(SVG_CROSSHAIR_VALUE, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); cursorMap.put(SVG_DEFAULT_VALUE, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DefaultFontFamilyResolver.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DefaultFontFamilyResolver.java index a8e4c1ddd..6c4923104 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DefaultFontFamilyResolver.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DefaultFontFamilyResolver.java @@ -24,7 +24,6 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -109,8 +108,7 @@ public final class DefaultFontFamilyResolver implements FontFamilyResolver { //Example: Font Family: "Univers", but Font Name: "Univers 45 Light" //Without this, matching "Univers 45 Light" is not possible. Font[] allFonts = env.getAllFonts(); - for (int i = 0; i < allFonts.length; i++) { - Font f = allFonts[i]; + for (Font f : allFonts) { fonts.put(f.getFontName().toLowerCase(), f.getFontName()); } @@ -119,9 +117,8 @@ public final class DefaultFontFamilyResolver implements FontFamilyResolver { awtFonts.add(new AWTGVTFont(DEFAULT_FONT_FAMILY.getFamilyName(), 0, 12)); Collection fontValues = fonts.values(); - Iterator iter = fontValues.iterator(); - while(iter.hasNext()) { - String fontFamily = (String)iter.next(); + for (Object fontValue : fontValues) { + String fontFamily = (String) fontValue; AWTFontFamily awtFontFamily = new AWTFontFamily(fontFamily); awtFontFamilies.add(awtFontFamily); AWTGVTFont font = new AWTGVTFont(fontFamily, 0, 12); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DocumentJarClassLoader.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DocumentJarClassLoader.java index 6ea3d7dcb..a15cb56ad 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DocumentJarClassLoader.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/DocumentJarClassLoader.java @@ -36,7 +36,7 @@ import java.util.Enumeration; * allows linked jar files to come from a different origin than * the document referencing them. * - * @author Vincent Hardy + * @author Vincent Hardy * @version $Id$ */ public class DocumentJarClassLoader extends URLClassLoader { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/EventTargetWrapper.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/EventTargetWrapper.java index 711bc86ca..452935bd8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/EventTargetWrapper.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/EventTargetWrapper.java @@ -215,7 +215,7 @@ class EventTargetWrapper extends NativeJavaObject { args[i] = Context.jsToJava(args[i], paramTypes[i]); ((EventTarget)njo.unwrap()).addEventListener ((String)args[0], evtListener, - ((Boolean)args[2]).booleanValue()); + (Boolean) args[2]); return Undefined.instance; } if (args[1] instanceof NativeObject) { @@ -236,7 +236,7 @@ class EventTargetWrapper extends NativeJavaObject { args[i] = Context.jsToJava(args[i], paramTypes[i]); ((EventTarget)njo.unwrap()).addEventListener ((String)args[0], evtListener, - ((Boolean)args[2]).booleanValue()); + (Boolean) args[2]); return Undefined.instance; } return delegate.call(ctx, scope, thisObj, args); @@ -268,7 +268,7 @@ class EventTargetWrapper extends NativeJavaObject { for (int i = 0; i < args.length; i++) args[i] = Context.jsToJava(args[i], paramTypes[i]); ((EventTarget)njo.unwrap()).removeEventListener - ((String)args[0], el, ((Boolean)args[2]).booleanValue()); + ((String)args[0], el, (Boolean) args[2]); return Undefined.instance; } if (args[1] instanceof NativeObject) { @@ -284,7 +284,7 @@ class EventTargetWrapper extends NativeJavaObject { for (int i = 0; i < args.length; i++) args[i] = Context.jsToJava(args[i], paramTypes[i]); ((EventTarget)njo.unwrap()).removeEventListener - ((String)args[0], el, ((Boolean)args[2]).booleanValue()); + ((String)args[0], el, (Boolean) args[2]); return Undefined.instance; } return delegate.call(ctx, scope, thisObj, args); @@ -320,7 +320,7 @@ class EventTargetWrapper extends NativeJavaObject { ((String)args[0], (String)args[1], evtListener, - ((Boolean)args[3]).booleanValue(), + (Boolean) args[3], args[4]); return Undefined.instance; } @@ -339,7 +339,7 @@ class EventTargetWrapper extends NativeJavaObject { ((String)args[0], (String)args[1], evtListener, - ((Boolean)args[3]).booleanValue(), + (Boolean) args[3], args[4]); return Undefined.instance; } @@ -375,7 +375,7 @@ class EventTargetWrapper extends NativeJavaObject { ((String)args[0], (String)args[1], el, - ((Boolean)args[3]).booleanValue()); + (Boolean) args[3]); return Undefined.instance; } if (args[2] instanceof NativeObject) { @@ -396,7 +396,7 @@ class EventTargetWrapper extends NativeJavaObject { ((String)args[0], (String)args[1], el, - ((Boolean)args[3]).booleanValue()); + (Boolean) args[3]); return Undefined.instance; } return delegate.call(ctx, scope, thisObj, args); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowGlyphLayout.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowGlyphLayout.java index 877b06a9a..ffbcc8058 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowGlyphLayout.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowGlyphLayout.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextNode.java index 287fe0534..cd9ea7f38 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextNode.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextPainter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextPainter.java index 5c36aca53..2843e23a0 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextPainter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FlowTextPainter.java @@ -15,21 +15,10 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; -import java.awt.font.FontRenderContext; -import java.awt.font.TextAttribute; -import java.text.AttributedCharacterIterator; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.Arrays; - import org.apache.batik.gvt.flow.BlockInfo; import org.apache.batik.gvt.flow.FlowRegions; import org.apache.batik.gvt.flow.GlyphGroupInfo; @@ -43,6 +32,17 @@ import org.apache.batik.gvt.font.GVTLineMetrics; import org.apache.batik.gvt.font.MultiGlyphVector; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; +import java.text.AttributedCharacterIterator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.awt.font.FontRenderContext; +import java.awt.font.TextAttribute; + /** * One line Class Desc * @@ -151,9 +151,8 @@ public class FlowTextPainter extends StrokingTextPainter { AttributedCharacterIterator aci = acis[chunk]; List gvl = new LinkedList(); List layouts = (List)clIter.next(); - Iterator iter = layouts.iterator(); - while (iter.hasNext()) { - GlyphLayout gl = (GlyphLayout)iter.next(); + for (Object layout : layouts) { + GlyphLayout gl = (GlyphLayout) layout; gvl.add(gl.getGlyphVector()); } GVTGlyphVector gv = new MultiGlyphVector(gvl); @@ -310,7 +309,7 @@ public class FlowTextPainter extends StrokingTextPainter { int cnt = gv.getCharacterCount(i,i); aci.setIndex(aciIdx); Integer integer = (Integer)aci.getAttribute(WORD_LIMIT); - int minWord = integer.intValue()-numWords; + int minWord = integer -numWords; if (minWord > maxWord) { maxWord = minWord; wordMap = allocWordMap(wordMap, maxWord+1); @@ -319,7 +318,7 @@ public class FlowTextPainter extends StrokingTextPainter { for (int c=1; c maxWord) { maxWord = cWord; wordMap = allocWordMap(wordMap, maxWord+1); @@ -370,7 +369,7 @@ public class FlowTextPainter extends StrokingTextPainter { float lineHeight = 1.0f; Float lineHeightFloat = (Float)aci.getAttribute(LINE_HEIGHT); if (lineHeightFloat != null) - lineHeight = lineHeightFloat.floatValue(); + lineHeight = lineHeightFloat; int runLimit = aci.getRunLimit(szAtts); WordInfo prevWI = null; float [] lastAdvAdj = new float [numGlyphs]; @@ -383,7 +382,7 @@ public class FlowTextPainter extends StrokingTextPainter { char pch = ch; ch = aci.setIndex(aciIdx); Integer integer = (Integer)aci.getAttribute(WORD_LIMIT); - WordInfo theWI = cWordMap[integer.intValue()-numWords]; + WordInfo theWI = cWordMap[integer -numWords]; if (theWI.getFlowLine() == null) theWI.setFlowLine(aci.getAttribute(FLOW_LINE_BREAK)); @@ -437,7 +436,7 @@ public class FlowTextPainter extends StrokingTextPainter { aci.setIndex(aciIdx); gvtFont = (GVTFont)aci.getAttribute(GVT_FONT); Float f = (Float)aci.getAttribute(LINE_HEIGHT); - lineHeight = f.floatValue(); + lineHeight = f; runLimit = aci.getRunLimit(szAtts); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FocusManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FocusManager.java index c9693fc44..47dfe55cc 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FocusManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FocusManager.java @@ -20,7 +20,7 @@ package org.apache.batik.bridge; import org.apache.batik.dom.events.DOMUIEvent; import org.apache.batik.dom.events.NodeEventTarget; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFace.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFace.java index 330f5380c..2de6c3750 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFace.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFace.java @@ -18,7 +18,6 @@ */ package org.apache.batik.bridge; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -30,10 +29,10 @@ import org.apache.batik.dom.AbstractNode; import org.apache.batik.gvt.font.GVTFontFace; import org.apache.batik.gvt.font.GVTFontFamily; import org.apache.batik.util.ParsedURL; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; /** - * This class represents a <font-face> element or @font-face rule + * This class represents a <font-face> element or @font-face rule * * @author Bella Robinson * @version $Id$ @@ -96,9 +95,7 @@ public abstract class FontFace extends GVTFontFace return family; } - Iterator iter = srcs.iterator(); - while (iter.hasNext()) { - Object o = iter.next(); + for (Object o : srcs) { if (o instanceof String) { family = fontFamilyResolver.resolve((String) o, this); if (family != null) { @@ -106,7 +103,7 @@ public abstract class FontFace extends GVTFontFace } } else if (o instanceof ParsedURL) { try { - GVTFontFamily ff = getFontFamily(ctx, (ParsedURL)o); + GVTFontFamily ff = getFontFamily(ctx, (ParsedURL) o); if (ff != null) return ff; } catch (SecurityException ex) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFamilyResolver.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFamilyResolver.java index 7793e0b7a..e6e429098 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFamilyResolver.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/FontFamilyResolver.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ /* $Id$ */ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlobalWrapper.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlobalWrapper.java index fe9ec0121..47702013d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlobalWrapper.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlobalWrapper.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; import org.apache.batik.dom.svg12.SVGGlobal; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlyphLayout.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlyphLayout.java index b7a8852ab..89e49cc4b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlyphLayout.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/GlyphLayout.java @@ -349,9 +349,8 @@ public class GlyphLayout implements TextSpanLayout { public boolean isLeftToRight() { aci.first(); int bidiLevel = - ((Integer)aci.getAttribute - (GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL)) - .intValue(); + (Integer) aci.getAttribute + (GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL); // Check if low bit is set if not then we are left to right // (even bidi level). @@ -987,7 +986,7 @@ public class GlyphLayout implements TextSpanLayout { aci.first(); Float dy = (Float) aci.getAttribute(DY); if (dy != null) - y += dy.floatValue(); + y += dy; Stroke overlineStroke = new BasicStroke(overlineThickness); @@ -1018,7 +1017,7 @@ public class GlyphLayout implements TextSpanLayout { aci.first(); Float dy = (Float) aci.getAttribute(DY); if (dy != null) - y += dy.floatValue(); + y += dy; Rectangle2D logicalBounds = gv.getLogicalBounds(); @@ -1042,7 +1041,7 @@ public class GlyphLayout implements TextSpanLayout { aci.first(); Float dy = (Float) aci.getAttribute(DY); if (dy != null) - y += dy.floatValue(); + y += dy; Rectangle2D logicalBounds = gv.getLogicalBounds(); return strikethroughStroke.createStrokedShape( @@ -1186,26 +1185,26 @@ public class GlyphLayout implements TextSpanLayout { if (rotation == null || rotation.isNaN()) { glyphRotation = glyphOrientationRotation; } else { - glyphRotation = (rotation.floatValue() + + glyphRotation = (rotation + glyphOrientationRotation); } if ((x != null) && !x.isNaN()) { if (i == 0) - shift_x_pos = (float)(x.floatValue()-offset.getX()); - curr_x_pos = x.floatValue()-shift_x_pos; + shift_x_pos = (float)(x -offset.getX()); + curr_x_pos = x -shift_x_pos; } if (dx != null && !dx.isNaN()) { - curr_x_pos += dx.floatValue(); + curr_x_pos += dx; } if ((y != null) && !y.isNaN()) { if (i == 0) - shift_y_pos = (float)(y.floatValue()-offset.getY()); - curr_y_pos = y.floatValue()-shift_y_pos; + shift_y_pos = (float)(y -offset.getY()); + curr_y_pos = y -shift_y_pos; } if (dy != null && !dy.isNaN()) { - curr_y_pos += dy.floatValue(); + curr_y_pos += dy; } else if (i > 0) { curr_y_pos += gp[i*2 + 1]-gp[i*2 - 1]; } @@ -1219,7 +1218,7 @@ public class GlyphLayout implements TextSpanLayout { baselineAdjust = -baselineAscent*0.5f; } } else if (baseline instanceof Float) { - baselineAdjust = ((Float) baseline).floatValue(); + baselineAdjust = (Float) baseline; } if (vertical) { ox = baselineAdjust; @@ -1468,7 +1467,7 @@ public class GlyphLayout implements TextSpanLayout { aci.first(); Boolean customSpacing = (Boolean) aci.getAttribute( GVTAttributedCharacterIterator.TextAttribute.CUSTOM_SPACING); - if ((customSpacing != null) && customSpacing.booleanValue()) { + if ((customSpacing != null) && customSpacing) { advance = doSpacing ((Float) aci.getAttribute (GVTAttributedCharacterIterator.TextAttribute.KERNING), @@ -1506,11 +1505,11 @@ public class GlyphLayout implements TextSpanLayout { float letterSpacingVal = 0f; if ((kern != null) && (!kern.isNaN())) { - kernVal = kern.floatValue(); + kernVal = kern; autoKern = false; } if ((letterSpacing != null) && (!letterSpacing.isNaN())) { - letterSpacingVal = letterSpacing.floatValue(); + letterSpacingVal = letterSpacing; doLetterSpacing = true; } if ((wordSpacing != null) && (!wordSpacing.isNaN())) { @@ -1622,9 +1621,9 @@ public class GlyphLayout implements TextSpanLayout { dx = (float) (gpos.getX() - px)/(nWS+1); dy = (float) (gpos.getY() - py)/(nWS+1); if (vertical) { - dy += wordSpacing.floatValue()/(nWS+1); + dy += wordSpacing /(nWS+1); } else { - dx += wordSpacing.floatValue()/(nWS+1); + dx += wordSpacing /(nWS+1); } for (int j=beginWS; j<=endWS; ++j) { x += dx; @@ -2019,8 +2018,8 @@ public class GlyphLayout implements TextSpanLayout { */ public boolean hasCharacterIndex(int index){ - for (int n=0; n FIX ME: Move to Bridge + * FIX ME: Move to Bridge */ Bridge getInstance(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Location.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Location.java index f290674bc..f0c67d6e4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Location.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Location.java @@ -18,19 +18,14 @@ */ package org.apache.batik.bridge; -import java.net.URL; - -import org.apache.batik.anim.dom.SVGOMDocument; -import org.apache.batik.bridge.BridgeContext; -import org.apache.batik.dom.AbstractDocument; - /** - * This class implements the org.w3c.dom.Location interface for Batik + * This class implements the org.apache.batik.w3c.dom.Location interface for Batik * * @author G. Wade Johnson * @version $Id: Location.java$ */ -public class Location implements org.apache.batik.w3c.dom.Location { +public class Location implements org.apache.batik.w3c.dom.Location +{ private BridgeContext bridgeContext; /** @@ -50,23 +45,23 @@ public class Location implements org.apache.batik.w3c.dom.Location { * navigate to. */ public void assign(String url) { - ((UserAgent)bridgeContext.getUserAgent()).loadDocument(url); + bridgeContext.getUserAgent().loadDocument(url); } /** * The user agent reloads the current document. */ public void reload() { - String url = ((AbstractDocument) bridgeContext.getDocument()) + String url = bridgeContext.getDocument() .getDocumentURI(); - ((UserAgent)bridgeContext.getUserAgent()).loadDocument(url); + bridgeContext.getUserAgent().loadDocument(url); } /** * Returns the URL of this location as a String. */ public String toString() { - return ((AbstractDocument) bridgeContext.getDocument()) + return bridgeContext.getDocument() .getDocumentURI(); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/PaintServer.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/PaintServer.java index ce7f688c4..4caa51a62 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/PaintServer.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/PaintServer.java @@ -630,8 +630,8 @@ public abstract class PaintServer // negative values if ( dashoffset < 0 ) { float dashpatternlength = 0; - for ( int i=0; i element. + * Bridge class for the <a> element. * * @author Thierry Kormann * @version $Id$ @@ -50,7 +47,7 @@ public class SVGAElementBridge extends SVGGElementBridge { protected CursorMouseOutListener cl; /** - * Constructs a new bridge for the <a> element. + * Constructs a new bridge for the <a> element. */ public SVGAElementBridge() {} @@ -139,7 +136,7 @@ public class SVGAElementBridge extends SVGGElementBridge { } /** - * Returns true as the <a> element is a container. + * Returns true as the <a> element is a container. */ public boolean isComposite() { return true; @@ -178,9 +175,7 @@ public class SVGAElementBridge extends SVGGElementBridge { List l = ae.getDefaultActions(); if (l != null) { - Iterator i = l.iterator(); - while (i.hasNext()) { - Object o = i.next(); + for (Object o : l) { if (o instanceof AnchorDefaultActionable) return; // only one anchor in default list... } @@ -254,9 +249,7 @@ public class SVGAElementBridge extends SVGGElementBridge { List l = ae.getDefaultActions(); if (l != null) { - Iterator i = l.iterator(); - while (i.hasNext()) { - Object o = i.next(); + for (Object o : l) { if (o instanceof MouseOverDefaultActionable) return; // only one anchor in default list... } @@ -340,9 +333,7 @@ public class SVGAElementBridge extends SVGGElementBridge { List l = ae.getDefaultActions(); if (l != null) { - Iterator i = l.iterator(); - while (i.hasNext()) { - Object o = i.next(); + for (Object o : l) { if (o instanceof MouseOutDefaultActionable) return; // only one anchor in default list... } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAltGlyphElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAltGlyphElementBridge.java index 6d045a4fe..44f77207c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAltGlyphElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAltGlyphElementBridge.java @@ -26,13 +26,13 @@ import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.gvt.font.Glyph; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.gvt.text.TextPaintInfo; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * Bridge class for the <altGlyph> element. + * Bridge class for the <altGlyph> element. * * @author Bella Robinson * @version $Id$ @@ -44,7 +44,7 @@ public class SVGAltGlyphElementBridge extends AbstractSVGBridge = GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO; /** - * Constructs a new bridge for the <altGlyph> element. + * Constructs a new bridge for the <altGlyph> element. */ public SVGAltGlyphElementBridge() { } @@ -58,7 +58,7 @@ public class SVGAltGlyphElementBridge extends AbstractSVGBridge /** * Constructs an array of Glyphs that represents the specified - * <altGlyph> element at the requested size. + * <altGlyph> element at the requested size. * * @param ctx The current bridge context. * @param altGlyphElement The altGlyph element to base the SVGGVTGlyphVector diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateElementBridge.java index 92bf3ae93..1130a414c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateElementBridge.java @@ -218,7 +218,7 @@ outer: while (i < len) { try { float keyTime = Float.parseFloat(keyTimesString.substring(start, end)); - keyTimes.add(new Float(keyTime)); + keyTimes.add(keyTime); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -228,7 +228,7 @@ outer: while (i < len) { len = keyTimes.size(); float[] ret = new float[len]; for (int j = 0; j < len; j++) { - ret[j] = ((Float) keyTimes.get(j)).floatValue(); + ret[j] = (Float) keyTimes.get(j); } return ret; } @@ -294,7 +294,7 @@ outer: while (i < len) { try { float keySplineValue = Float.parseFloat(keySplinesString.substring(start, end)); - keySplines.add(new Float(keySplineValue)); + keySplines.add(keySplineValue); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -304,7 +304,7 @@ outer: while (i < len) { len = keySplines.size(); float[] ret = new float[len]; for (int j = 0; j < len; j++) { - ret[j] = ((Float) keySplines.get(j)).floatValue(); + ret[j] = (Float) keySplines.get(j); } return ret; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateMotionElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateMotionElementBridge.java index 009457217..5e931c380 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateMotionElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimateMotionElementBridge.java @@ -221,7 +221,7 @@ outer: while (i < len) { try { float keyPointCoord = Float.parseFloat(keyPointsString.substring(start, end)); - keyPoints.add(new Float(keyPointCoord)); + keyPoints.add(keyPointCoord); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -231,7 +231,7 @@ outer: while (i < len) { len = keyPoints.size(); float[] ret = new float[len]; for (int j = 0; j < len; j++) { - ret[j] = ((Float) keyPoints.get(j)).floatValue(); + ret[j] = (Float) keyPoints.get(j); } return ret; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationElementBridge.java index 81e83871c..89bdea873 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationElementBridge.java @@ -36,7 +36,6 @@ import org.apache.batik.css.engine.CSSEngineEvent; import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.svg.SVGAnimationContext; import org.apache.batik.dom.util.XLinkSupport; -import org.apache.batik.util.SVGTypes; import org.w3c.dom.DOMException; import org.w3c.dom.Element; @@ -241,7 +240,7 @@ public abstract class SVGAnimationElementBridge extends AbstractSVGBridge /** * Returns whether the animation element being handled by this bridge can * animate attributes of the specified type. - * @param type one of the TYPE_ constants defined in {@link SVGTypes}. + * @param type one of the TYPE_ constants defined in {@link org.apache.batik.util.SVGTypes}. */ protected abstract boolean canAnimateType(int type); @@ -626,8 +625,8 @@ public abstract class SVGAnimationElementBridge extends AbstractSVGBridge * element in document order. */ public boolean isBefore(TimedElement other) { - Element e = ((SVGTimedElement) other).getElement(); - int pos = ((AbstractNode) element).compareDocumentPosition(e); + Element e = other.getElement(); + int pos = element.compareDocumentPosition(e); return (pos & AbstractNode.DOCUMENT_POSITION_PRECEDING) != 0; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationEngine.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationEngine.java index f3e07325d..1828b84a1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationEngine.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGAnimationEngine.java @@ -78,7 +78,7 @@ import org.apache.batik.parser.PreserveAspectRatioHandler; import org.apache.batik.parser.PreserveAspectRatioParser; import org.apache.batik.util.RunnableQueue; import org.apache.batik.util.SMILConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -151,9 +151,9 @@ public class SVGAnimationEngine extends AnimationEngine { */ protected Factory[] factories = { null, // TYPE_UNKNOWN - new AnimatableIntegerValueFactory(), // TYPE_INTEGER - new AnimatableNumberValueFactory(), // TYPE_NUMBER - new AnimatableLengthValueFactory(), // TYPE_LENGTH + new AnimatableIntegerValueFactory(), // TYPE_INTEGER + new AnimatableNumberValueFactory(), // TYPE_NUMBER + new AnimatableLengthValueFactory(), // TYPE_LENGTH null, // TYPE_NUMBER_OPTIONAL_NUMBER new AnimatableAngleValueFactory(), // TYPE_ANGLE new AnimatableColorValueFactory(), // TYPE_COLOR @@ -163,8 +163,8 @@ public class SVGAnimationEngine extends AnimationEngine { uncomputedAnimatableStringValueFactory, // TYPE_URI null, // TYPE_FREQUENCY null, // TYPE_TIME - new AnimatableNumberListValueFactory(), // TYPE_NUMBER_LIST - new AnimatableLengthListValueFactory(), // TYPE_LENGTH_LIST + new AnimatableNumberListValueFactory(), // TYPE_NUMBER_LIST + new AnimatableLengthListValueFactory(), // TYPE_LENGTH_LIST uncomputedAnimatableStringValueFactory, // TYPE_IDENT uncomputedAnimatableStringValueFactory, // TYPE_CDATA animatableLengthOrIdentFactory, // TYPE_LENGTH_OR_INHERIT @@ -172,7 +172,7 @@ public class SVGAnimationEngine extends AnimationEngine { uncomputedAnimatableStringValueFactory, // TYPE_CLIP_VALUE uncomputedAnimatableStringValueFactory, // TYPE_URI_OR_IDENT uncomputedAnimatableStringValueFactory, // TYPE_CURSOR_VALUE - new AnimatablePathDataFactory(), // TYPE_PATH_DATA + new AnimatablePathDataFactory(), // TYPE_PATH_DATA uncomputedAnimatableStringValueFactory, // TYPE_ENABLE_BACKGROUND_VALUE null, // TYPE_TIME_VALUE_LIST animatableNumberOrIdentFactory, // TYPE_NUMBER_OR_INHERIT @@ -181,8 +181,8 @@ public class SVGAnimationEngine extends AnimationEngine { new AnimatableNumberOrIdentFactory(true), // TYPE_FONT_WEIGHT_VALUE new AnimatableAngleOrIdentFactory(), // TYPE_ANGLE_OR_IDENT null, // TYPE_KEY_SPLINES_VALUE - new AnimatablePointListValueFactory(), // TYPE_POINTS_VALUE - new AnimatablePreserveAspectRatioValueFactory(), // TYPE_PRESERVE_ASPECT_RATIO_VALUE + new AnimatablePointListValueFactory(), // TYPE_POINTS_VALUE + new AnimatablePreserveAspectRatioValueFactory(), // TYPE_PRESERVE_ASPECT_RATIO_VALUE null, // TYPE_URI_LIST uncomputedAnimatableStringValueFactory, // TYPE_LENGTH_LIST_OR_IDENT null, // TYPE_CHARACTER_OR_UNICODE_RANGE_LIST @@ -197,10 +197,10 @@ public class SVGAnimationEngine extends AnimationEngine { animatableNumberOrIdentFactory, // TYPE_FONT_SIZE_ADJUST_VALUE null, // TYPE_LANG_VALUE null, // TYPE_LANG_LIST_VALUE - new AnimatableNumberOrPercentageValueFactory(), // TYPE_NUMBER_OR_PERCENTAGE + new AnimatableNumberOrPercentageValueFactory(), // TYPE_NUMBER_OR_PERCENTAGE null, // TYPE_TIMING_SPECIFIER_LIST - new AnimatableBooleanValueFactory(), // TYPE_BOOLEAN - new AnimatableRectValueFactory() // TYPE_RECT + new AnimatableBooleanValueFactory(), // TYPE_BOOLEAN + new AnimatableRectValueFactory() // TYPE_RECT }; /** @@ -258,15 +258,15 @@ public class SVGAnimationEngine extends AnimationEngine { String[] eventNamesSVG12 = { "load", "resize", "scroll", "zoom" }; - for (int i = 0; i < eventNamesCommon.length; i++) { - animationEventNames11.add(eventNamesCommon[i]); - animationEventNames12.add(eventNamesCommon[i]); + for (String anEventNamesCommon : eventNamesCommon) { + animationEventNames11.add(anEventNamesCommon); + animationEventNames12.add(anEventNamesCommon); } - for (int i = 0; i < eventNamesSVG11.length; i++) { - animationEventNames11.add(eventNamesSVG11[i]); + for (String anEventNamesSVG11 : eventNamesSVG11) { + animationEventNames11.add(anEventNamesSVG11); } - for (int i = 0; i < eventNamesSVG12.length; i++) { - animationEventNames12.add(eventNamesSVG12[i]); + for (String anEventNamesSVG12 : eventNamesSVG12) { + animationEventNames12.add(anEventNamesSVG12); } } @@ -439,14 +439,14 @@ public class SVGAnimationEngine extends AnimationEngine { timedDocumentRoot.resetDocument(cal); Object[] bridges = initialBridges.toArray(); initialBridges = null; - for (int i = 0; i < bridges.length; i++) { + for (Object bridge2 : bridges) { SVGAnimationElementBridge bridge = - (SVGAnimationElementBridge) bridges[i]; + (SVGAnimationElementBridge) bridge2; bridge.initializeAnimation(); } - for (int i = 0; i < bridges.length; i++) { + for (Object bridge1 : bridges) { SVGAnimationElementBridge bridge = - (SVGAnimationElementBridge) bridges[i]; + (SVGAnimationElementBridge) bridge1; bridge.initializeTimedElement(); } @@ -1091,7 +1091,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableBooleanValue}s. */ - protected class AnimatableBooleanValueFactory implements Factory { + protected static class AnimatableBooleanValueFactory implements Factory { /** * Creates a new AnimatableValue from a string. @@ -1114,7 +1114,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableIntegerValue}s. */ - protected class AnimatableIntegerValueFactory implements Factory { + protected static class AnimatableIntegerValueFactory implements Factory { /** * Creates a new AnimatableValue from a string. @@ -1137,7 +1137,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableNumberValue}s. */ - protected class AnimatableNumberValueFactory implements Factory { + protected static class AnimatableNumberValueFactory implements Factory { /** * Creates a new AnimatableValue from a string. @@ -1159,7 +1159,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableNumberOrPercentageValue}s. */ - protected class AnimatableNumberOrPercentageValueFactory + protected static class AnimatableNumberOrPercentageValueFactory implements Factory { /** @@ -1200,7 +1200,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatablePreserveAspectRatioValue}s. */ - protected class AnimatablePreserveAspectRatioValueFactory implements Factory { + protected static class AnimatablePreserveAspectRatioValueFactory implements Factory { /** * The parsed 'align' value. @@ -1353,7 +1353,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableLengthValue}s. */ - protected class AnimatableLengthValueFactory implements Factory { + protected static class AnimatableLengthValueFactory implements Factory { /** * The parsed length unit type. @@ -1447,7 +1447,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableLengthListValue}s. */ - protected class AnimatableLengthListValueFactory implements Factory { + protected static class AnimatableLengthListValueFactory implements Factory { /** * Parser for length lists. @@ -1498,7 +1498,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableNumberListValue}s. */ - protected class AnimatableNumberListValueFactory implements Factory { + protected static class AnimatableNumberListValueFactory implements Factory { /** * Parser for number lists. @@ -1545,7 +1545,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableNumberListValue}s. */ - protected class AnimatableRectValueFactory implements Factory { + protected static class AnimatableRectValueFactory implements Factory { /** * Parser for number lists. @@ -1596,7 +1596,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatablePointListValue}s. */ - protected class AnimatablePointListValueFactory implements Factory { + protected static class AnimatablePointListValueFactory implements Factory { /** * Parser for point lists. @@ -1643,7 +1643,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatablePathDataValue}s. */ - protected class AnimatablePathDataFactory implements Factory { + protected static class AnimatablePathDataFactory implements Factory { /** * Parser for path data. @@ -1691,7 +1691,7 @@ public class SVGAnimationEngine extends AnimationEngine { /** * Factory class for {@link AnimatableStringValue}s. */ - protected class UncomputedAnimatableStringValueFactory implements Factory { + protected static class UncomputedAnimatableStringValueFactory implements Factory { public AnimatableValue createValue(AnimationTarget target, String ns, String ln, boolean isCSS, String s) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGCircleElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGCircleElementBridge.java index 0a1eeb018..483450820 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGCircleElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGCircleElementBridge.java @@ -31,7 +31,7 @@ import org.apache.batik.gvt.ShapePainter; import org.w3c.dom.Element; /** - * Bridge class for the <circle> element. + * Bridge class for the <circle> element. * * @author Thierry Kormann * @version $Id$ @@ -39,7 +39,7 @@ import org.w3c.dom.Element; public class SVGCircleElementBridge extends SVGShapeElementBridge { /** - * Constructs a new bridge for the <circle> element. + * Constructs a new bridge for the <circle> element. */ public SVGCircleElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGClipPathElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGClipPathElementBridge.java index 6d99c4605..1aabcd70c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGClipPathElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGClipPathElementBridge.java @@ -34,7 +34,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <clipPath> element. + * Bridge class for the <clipPath> element. * * @author Thierry Kormann * @version $Id$ @@ -43,7 +43,7 @@ public class SVGClipPathElementBridge extends AnimatableGenericSVGBridge implements ClipBridge { /** - * Constructs a new bridge for the <clipPath> element. + * Constructs a new bridge for the <clipPath> element. */ public SVGClipPathElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGColorProfileElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGColorProfileElementBridge.java index b6c09c04f..e96393910 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGColorProfileElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGColorProfileElementBridge.java @@ -21,7 +21,6 @@ package org.apache.batik.bridge; import java.awt.color.ICC_Profile; import java.io.IOException; -import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.ext.awt.color.NamedProfileCache; import org.apache.batik.util.ParsedURL; @@ -106,7 +105,7 @@ public class SVGColorProfileElementBridge extends AbstractSVGBridge String href = XLinkSupport.getXLinkHref(profile); ICC_Profile p = null; if (href != null) { - String baseURI = ((AbstractNode) profile).getBaseURI(); + String baseURI = profile.getBaseURI(); ParsedURL pDocURL = null; if (baseURI != null) { pDocURL = new ParsedURL(baseURI); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGDescriptiveElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGDescriptiveElementBridge.java index 09f201acf..b0813826e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGDescriptiveElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGDescriptiveElementBridge.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGEllipseElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGEllipseElementBridge.java index 39995d686..fbfa0aca1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGEllipseElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGEllipseElementBridge.java @@ -31,7 +31,7 @@ import org.apache.batik.gvt.ShapePainter; import org.w3c.dom.Element; /** - * Bridge class for the <ellipse> element. + * Bridge class for the <ellipse> element. * * @author Thierry Kormann * @version $Id$ @@ -39,7 +39,7 @@ import org.w3c.dom.Element; public class SVGEllipseElementBridge extends SVGShapeElementBridge { /** - * Constructs a new bridge for the <ellipse> element. + * Constructs a new bridge for the <ellipse> element. */ public SVGEllipseElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeBlendElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeBlendElementBridge.java index 78126accd..a8ed9f0f4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeBlendElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeBlendElementBridge.java @@ -32,7 +32,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feBlend> element. + * Bridge class for the <feBlend> element. * * @author Thierry Kormann * @version $Id$ @@ -42,7 +42,7 @@ public class SVGFeBlendElementBridge /** - * Constructs a new bridge for the <feBlend> element. + * Constructs a new bridge for the <feBlend> element. */ public SVGFeBlendElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeColorMatrixElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeColorMatrixElementBridge.java index f2ce7250c..d2ba324fb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeColorMatrixElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeColorMatrixElementBridge.java @@ -31,7 +31,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feColorMatrix> element. + * Bridge class for the <feColorMatrix> element. * * @author Thierry Kormann * @version $Id$ @@ -40,7 +40,7 @@ public class SVGFeColorMatrixElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feColorMatrix> element. + * Constructs a new bridge for the <feColorMatrix> element. */ public SVGFeColorMatrixElementBridge() {} @@ -119,7 +119,7 @@ public class SVGFeColorMatrixElementBridge colorMatrix = ColorMatrixRable8Bit.buildSaturate(s); break; default: - throw new Error("invalid convertType:" + type ); // can't be reached + throw new RuntimeException("invalid convertType:" + type ); // can't be reached } colorMatrix.setSource(in); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeComponentTransferElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeComponentTransferElementBridge.java index 4a481f427..dd4c8980a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeComponentTransferElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeComponentTransferElementBridge.java @@ -33,7 +33,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <feComponentTransfer> element. + * Bridge class for the <feComponentTransfer> element. * * @author Thierry Kormann * @version $Id$ @@ -42,7 +42,7 @@ public class SVGFeComponentTransferElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feComponentTransfer> element. + * Constructs a new bridge for the <feComponentTransfer> element. */ public SVGFeComponentTransferElementBridge() {} @@ -153,7 +153,7 @@ public class SVGFeComponentTransferElementBridge } /** - * Bridge class for the <feFuncA> element. + * Bridge class for the <feFuncA> element. */ public static class SVGFeFuncAElementBridge extends SVGFeFuncElementBridge { @@ -171,7 +171,7 @@ public class SVGFeComponentTransferElementBridge } /** - * Bridge class for the <feFuncR> element. + * Bridge class for the <feFuncR> element. */ public static class SVGFeFuncRElementBridge extends SVGFeFuncElementBridge { @@ -189,7 +189,7 @@ public class SVGFeComponentTransferElementBridge } /** - * Bridge class for the <feFuncG> element. + * Bridge class for the <feFuncG> element. */ public static class SVGFeFuncGElementBridge extends SVGFeFuncElementBridge { @@ -207,7 +207,7 @@ public class SVGFeComponentTransferElementBridge } /** - * Bridge class for the <feFuncB> element. + * Bridge class for the <feFuncB> element. */ public static class SVGFeFuncBElementBridge extends SVGFeFuncElementBridge { @@ -292,7 +292,7 @@ public class SVGFeComponentTransferElementBridge } } default: - throw new Error("invalid convertType:" + type ); // can't be reached + throw new RuntimeException("invalid convertType:" + type ); // can't be reached } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeCompositeElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeCompositeElementBridge.java index 3937c581f..f666ab3b4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeCompositeElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeCompositeElementBridge.java @@ -32,7 +32,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feComposite> element. + * Bridge class for the <feComposite> element. * * @author Thierry Kormann * @version $Id$ @@ -42,7 +42,7 @@ public class SVGFeCompositeElementBridge /** - * Constructs a new bridge for the <feComposite> element. + * Constructs a new bridge for the <feComposite> element. */ public SVGFeCompositeElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeConvolveMatrixElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeConvolveMatrixElementBridge.java index 59ffa3deb..b4069fa40 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeConvolveMatrixElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeConvolveMatrixElementBridge.java @@ -34,7 +34,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feConvolveMatrix> element. + * Bridge class for the <feConvolveMatrix> element. * * @author Thierry Kormann * @version $Id$ @@ -44,7 +44,7 @@ public class SVGFeConvolveMatrixElementBridge /** - * Constructs a new bridge for the <feConvolveMatrix> element. + * Constructs a new bridge for the <feConvolveMatrix> element. */ public SVGFeConvolveMatrixElementBridge() {} @@ -246,8 +246,8 @@ public class SVGFeConvolveMatrixElementBridge if (s.length() == 0) { // default is sum of kernel values (if sum is zero then 1.0) float sum = 0; - for (int i=0; i < kernelMatrix.length; ++i) { - sum += kernelMatrix[i]; + for (float aKernelMatrix : kernelMatrix) { + sum += aKernelMatrix; } return (sum == 0) ? 1.0f : sum; } else { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDiffuseLightingElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDiffuseLightingElementBridge.java index 0b5651a9f..5a28ca4fa 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDiffuseLightingElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDiffuseLightingElementBridge.java @@ -28,7 +28,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feDiffuseLighting> element. + * Bridge class for the <feDiffuseLighting> element. * * @author Thierry Kormann * @version $Id$ @@ -38,7 +38,7 @@ public class SVGFeDiffuseLightingElementBridge /** - * Constructs a new bridge for the <feDiffuseLighting> element. + * Constructs a new bridge for the <feDiffuseLighting> element. */ public SVGFeDiffuseLightingElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDisplacementMapElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDisplacementMapElementBridge.java index 2588ad480..ad17a9b5c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDisplacementMapElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeDisplacementMapElementBridge.java @@ -33,7 +33,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feDisplacementMap> element. + * Bridge class for the <feDisplacementMap> element. * * @author Thierry Kormann * @version $Id$ @@ -43,7 +43,7 @@ public class SVGFeDisplacementMapElementBridge /** - * Constructs a new bridge for the <feDisplacementMap> element. + * Constructs a new bridge for the <feDisplacementMap> element. */ public SVGFeDisplacementMapElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeFloodElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeFloodElementBridge.java index 14b695182..d6320ab02 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeFloodElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeFloodElementBridge.java @@ -28,7 +28,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feFlood> element. + * Bridge class for the <feFlood> element. * * @author Thierry Kormann * @version $Id$ @@ -37,7 +37,7 @@ public class SVGFeFloodElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feFlood> element. + * Constructs a new bridge for the <feFlood> element. */ public SVGFeFloodElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeGaussianBlurElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeGaussianBlurElementBridge.java index 76fb2be04..67d00ee40 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeGaussianBlurElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeGaussianBlurElementBridge.java @@ -31,7 +31,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feGaussianBlur> element. + * Bridge class for the <feGaussianBlur> element. * * @author Thierry Kormann * @version $Id$ @@ -41,7 +41,7 @@ public class SVGFeGaussianBlurElementBridge /** - * Constructs a new bridge for the <feGaussianBlur> element. + * Constructs a new bridge for the <feGaussianBlur> element. */ public SVGFeGaussianBlurElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeImageElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeImageElementBridge.java index fc3cd83b8..3bfc293c6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeImageElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeImageElementBridge.java @@ -34,7 +34,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * Bridge class for the <feImage> element. + * Bridge class for the <feImage> element. * * @author Thierry Kormann * @version $Id$ @@ -43,7 +43,7 @@ public class SVGFeImageElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feImage> element. + * Constructs a new bridge for the <feImage> element. */ public SVGFeImageElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMergeElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMergeElementBridge.java index 7ab08a29a..6de1b4b5d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMergeElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMergeElementBridge.java @@ -34,7 +34,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <feMerge> element. + * Bridge class for the <feMerge> element. * * @author Thierry Kormann * @version $Id$ @@ -43,7 +43,7 @@ public class SVGFeMergeElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feMerge> element. + * Constructs a new bridge for the <feMerge> element. */ public SVGFeMergeElementBridge() {} @@ -178,13 +178,13 @@ public class SVGFeMergeElementBridge } /** - * Bridge class for the <feMergeNode> element. + * Bridge class for the <feMergeNode> element. */ public static class SVGFeMergeNodeElementBridge extends AnimatableGenericSVGBridge { /** - * Constructs a new bridge for the <feMergeNode> element. + * Constructs a new bridge for the <feMergeNode> element. */ public SVGFeMergeNodeElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMorphologyElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMorphologyElementBridge.java index f630f15b5..a24cba126 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMorphologyElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeMorphologyElementBridge.java @@ -31,7 +31,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feMorphology> element. + * Bridge class for the <feMorphology> element. * * @author Thierry Kormann * @version $Id$ @@ -41,7 +41,7 @@ public class SVGFeMorphologyElementBridge /** - * Constructs a new bridge for the <feMorphology> element. + * Constructs a new bridge for the <feMorphology> element. */ public SVGFeMorphologyElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeOffsetElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeOffsetElementBridge.java index 3856ca946..ec2af1677 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeOffsetElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeOffsetElementBridge.java @@ -31,7 +31,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feOffset> element. + * Bridge class for the <feOffset> element. * * @author Thierry Kormann * @version $Id$ @@ -40,7 +40,7 @@ public class SVGFeOffsetElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feOffset> element. + * Constructs a new bridge for the <feOffset> element. */ public SVGFeOffsetElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeSpecularLightingElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeSpecularLightingElementBridge.java index f0297ef79..e648ad465 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeSpecularLightingElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeSpecularLightingElementBridge.java @@ -28,7 +28,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feSpecularLighting> element. + * Bridge class for the <feSpecularLighting> element. * * @author Thierry Kormann * @version $Id$ @@ -38,7 +38,7 @@ public class SVGFeSpecularLightingElementBridge /** - * Constructs a new bridge for the <feSpecularLighting> element. + * Constructs a new bridge for the <feSpecularLighting> element. */ public SVGFeSpecularLightingElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTileElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTileElementBridge.java index 3d5ded2af..fafdbfc41 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTileElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTileElementBridge.java @@ -27,7 +27,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feTile> element. + * Bridge class for the <feTile> element. * * @author Thierry Kormann * @version $Id$ @@ -37,7 +37,7 @@ public class SVGFeTileElementBridge /** - * Constructs a new bridge for the <feTile> element. + * Constructs a new bridge for the <feTile> element. */ public SVGFeTileElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTurbulenceElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTurbulenceElementBridge.java index 33d504f33..5aa0f6b7e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTurbulenceElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFeTurbulenceElementBridge.java @@ -29,7 +29,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <feTurbulence> element. + * Bridge class for the <feTurbulence> element. * * @author Thierry Kormann * @version $Id$ @@ -38,7 +38,7 @@ public class SVGFeTurbulenceElementBridge extends AbstractSVGFilterPrimitiveElementBridge { /** - * Constructs a new bridge for the <feTurbulence> element. + * Constructs a new bridge for the <feTurbulence> element. */ public SVGFeTurbulenceElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFilterElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFilterElementBridge.java index 0ca31238c..0ae85a391 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFilterElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFilterElementBridge.java @@ -39,7 +39,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <filter> element. + * Bridge class for the <filter> element. * * @author Thierry Kormann * @version $Id$ @@ -53,7 +53,7 @@ public class SVGFilterElementBridge extends AnimatableGenericSVGBridge protected static final Color TRANSPARENT_BLACK = new Color(0, true); /** - * Constructs a new bridge for the <filter> element. + * Constructs a new bridge for the <filter> element. */ public SVGFilterElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontElementBridge.java index 5ea0cc87a..320298b61 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontElementBridge.java @@ -24,7 +24,7 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** - * Bridge class for the <font> element. + * Bridge class for the <font> element. * * @author Bella Robinson * @version $Id$ @@ -32,7 +32,7 @@ import org.w3c.dom.NodeList; public class SVGFontElementBridge extends AbstractSVGBridge { /** - * Constructs a new bridge for the <font> element. + * Constructs a new bridge for the <font> element. */ public SVGFontElementBridge() { } @@ -45,7 +45,7 @@ public class SVGFontElementBridge extends AbstractSVGBridge { } /** - * Constructs a new SVGGVTFont that represents the specified <font> element + * Constructs a new SVGGVTFont that represents the specified <font> element * at the requested size. * * @param ctx The current bridge context. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFace.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFace.java index 8c8bf73e2..151e3dfd1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFace.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFace.java @@ -18,13 +18,13 @@ */ package org.apache.batik.bridge; -import java.util.List; - import org.apache.batik.gvt.font.GVTFontFamily; import org.w3c.dom.Element; +import java.util.List; + /** - * This class represents a <font-face> element or @font-face rule + * This class represents a <font-face> element or @font-face rule * * @author Bella Robinson * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFaceElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFaceElementBridge.java index 473c2e578..732510a50 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFaceElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFaceElementBridge.java @@ -29,7 +29,7 @@ import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.util.ParsedURL; /** - * Bridge class for the <font-face> element. + * Bridge class for the <font-face> element. * * @author Bella Robinson * @version $Id$ @@ -38,7 +38,7 @@ public class SVGFontFaceElementBridge extends AbstractSVGBridge implements ErrorConstants { /** - * Constructs a new bridge for the <font-face> element. + * Constructs a new bridge for the <font-face> element. */ public SVGFontFaceElementBridge() { } @@ -52,10 +52,10 @@ public class SVGFontFaceElementBridge extends AbstractSVGBridge /** * Creates an SVGFontFace that repesents the specified - * <font-face> element. + * <font-face> element. * * @param ctx The current bridge context. - * @param fontFaceElement The <font-face> element. + * @param fontFaceElement The <font-face> element. * * @return A new SVGFontFace. */ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFamily.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFamily.java index e20c8b9d3..3116c0477 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFamily.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontFamily.java @@ -18,20 +18,19 @@ */ package org.apache.batik.bridge; -import java.lang.ref.SoftReference; -import java.text.AttributedCharacterIterator; -import java.util.Map; - import org.apache.batik.gvt.font.GVTFont; import org.apache.batik.gvt.font.GVTFontFace; import org.apache.batik.gvt.font.GVTFontFamily; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.util.SVGConstants; - import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.lang.ref.SoftReference; +import java.text.AttributedCharacterIterator; +import java.util.Map; + /** * A font family class for SVG fonts. * @@ -120,7 +119,7 @@ public class SVGFontFamily implements GVTFontFamily { * it does not need CSS treatment. */ public boolean isComplex() { - if (complex != null) return complex.booleanValue(); + if (complex != null) return complex; boolean ret = isComplex(fontElement, ctx); complex = ret ? Boolean.TRUE : Boolean.FALSE; return ret; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontUtilities.java index dafc16179..9ffde05d5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGFontUtilities.java @@ -72,9 +72,8 @@ public abstract class SVGFontUtilities implements SVGConstants { CSSEngine engine = ((SVGOMDocument)doc).getCSSEngine(); List sms = engine.getFontFaces(); - Iterator iter = sms.iterator(); - while (iter.hasNext()) { - FontFaceRule ffr = (FontFaceRule)iter.next(); + for (Object sm : sms) { + FontFaceRule ffr = (FontFaceRule) sm; ret.add(CSSFontFace.createCSSFontFace(engine, ffr)); } return ret; @@ -159,10 +158,9 @@ public abstract class SVGFontUtilities implements SVGConstants { // create lists of font weight numbers for each font family List fontFamilyWeights = new ArrayList(svgFontFamilies.size()); - Iterator ffiter = svgFontFamilies.iterator(); - while(ffiter.hasNext()) { + for (Object svgFontFamily : svgFontFamilies) { GVTFontFace fontFace; - fontFace = ((GVTFontFamily)ffiter.next()).getFontFace(); + fontFace = ((GVTFontFamily) svgFontFamily).getFontFace(); String fontFaceWeight = fontFace.getFontWeight(); fontFaceWeight = getFontWeightNumberString(fontFaceWeight); fontFamilyWeights.add(fontFaceWeight); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGElementBridge.java index 7edc795c0..80a2fc9b8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGElementBridge.java @@ -28,7 +28,7 @@ import org.w3c.dom.Node; import org.w3c.dom.events.MutationEvent; /** - * Bridge class for the <g> element. + * Bridge class for the <g> element. * * @author Thierry Kormann * @version $Id$ @@ -36,7 +36,7 @@ import org.w3c.dom.events.MutationEvent; public class SVGGElementBridge extends AbstractGraphicsNodeBridge { /** - * Constructs a new bridge for the <g> element. + * Constructs a new bridge for the <g> element. */ public SVGGElementBridge() {} @@ -91,7 +91,7 @@ public class SVGGElementBridge extends AbstractGraphicsNodeBridge { } /** - * Returns true as the <g> element is a container. + * Returns true as the <g> element is a container. */ public boolean isComposite() { return true; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGVTFont.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGVTFont.java index f0a621835..7997492f7 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGVTFont.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGVTFont.java @@ -224,12 +224,12 @@ public final class SVGGVTFont implements GVTFont, SVGConstants { List glyphCodes = new ArrayList(); for (int i = 0; i < glyphNames.length; i++) { if (glyphNames[i] != null && glyphNames[i].equals(name)) { - glyphCodes.add(new Integer(i)); + glyphCodes.add(i); } } int[] glyphCodeArray = new int[glyphCodes.size()]; for (int i = 0; i < glyphCodes.size(); i++) { - glyphCodeArray[i] = ((Integer)glyphCodes.get(i)).intValue(); + glyphCodeArray[i] = (Integer) glyphCodes.get(i); } return glyphCodeArray; } @@ -246,12 +246,12 @@ public final class SVGGVTFont implements GVTFont, SVGConstants { List glyphCodes = new ArrayList(); for (int i = 0; i < glyphUnicodes.length; i++) { if (glyphUnicodes[i] != null && glyphUnicodes[i].equals(unicode)) { - glyphCodes.add(new Integer(i)); + glyphCodes.add(i); } } int[] glyphCodeArray = new int[glyphCodes.size()]; for (int i = 0; i < glyphCodes.size(); i++) { - glyphCodeArray[i] = ((Integer)glyphCodes.get(i)).intValue(); + glyphCodeArray[i] = (Integer) glyphCodes.get(i); } return glyphCodeArray; } @@ -682,8 +682,8 @@ public final class SVGGVTFont implements GVTFont, SVGConstants { // construct a string from the glyphCodes int nGlyphs = glyphCodes.length; StringBuffer workBuff = new StringBuffer( nGlyphs ); - for (int i = 0; i < nGlyphs; i++) { - workBuff.append( glyphUnicodes[glyphCodes[i]] ); + for (int glyphCode : glyphCodes) { + workBuff.append(glyphUnicodes[glyphCode]); } StringCharacterIterator sci = new StringCharacterIterator( workBuff.toString() ); return createGlyphVector(frc, sci); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGlyphElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGlyphElementBridge.java index 39e965d1f..0fcf1bbee 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGlyphElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGGlyphElementBridge.java @@ -41,7 +41,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * Bridge class for the <glyph> element. + * Bridge class for the <glyph> element. * * @author Bella Robinson * @version $Id$ @@ -50,7 +50,7 @@ public class SVGGlyphElementBridge extends AbstractSVGBridge implements ErrorConstants { /** - * Constructs a new bridge for the <glyph> element. + * Constructs a new bridge for the <glyph> element. */ protected SVGGlyphElementBridge() {} @@ -62,7 +62,7 @@ public class SVGGlyphElementBridge extends AbstractSVGBridge } /** - * Constructs a new Glyph that represents the specified <glyph> element + * Constructs a new Glyph that represents the specified <glyph> element * at the requested size. * * @param ctx The current bridge context. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGHKernElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGHKernElementBridge.java index 60171c667..ac789638c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGHKernElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGHKernElementBridge.java @@ -19,7 +19,7 @@ package org.apache.batik.bridge; /** - * Bridge class for the <hkern> element. + * Bridge class for the <hkern> element. * * @author Dean Jackson * @version $Id$ @@ -27,7 +27,7 @@ package org.apache.batik.bridge; public class SVGHKernElementBridge extends SVGKernElementBridge { /** - * Constructs a new bridge for the <hkern> element. + * Constructs a new bridge for the <hkern> element. */ public SVGHKernElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGImageElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGImageElementBridge.java index 8eea9aac4..a4f76534e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGImageElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGImageElementBridge.java @@ -42,7 +42,6 @@ import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.events.DOMMouseEvent; import org.apache.batik.dom.events.NodeEventTarget; import org.apache.batik.dom.svg.LiveAttributeException; -import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit; import org.apache.batik.ext.awt.image.renderable.Filter; import org.apache.batik.ext.awt.image.spi.BrokenLinkProvider; @@ -56,7 +55,7 @@ import org.apache.batik.gvt.ShapeNode; import org.apache.batik.util.HaltingThread; import org.apache.batik.util.MimeTypeConstants; import org.apache.batik.util.ParsedURL; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.xmlgraphics.java2d.color.ICCColorSpaceWithIntent; import org.apache.xmlgraphics.java2d.color.RenderingIntent; @@ -72,7 +71,7 @@ import org.w3c.dom.svg.SVGImageElement; import org.w3c.dom.svg.SVGSVGElement; /** - * Bridge class for the <image> element. + * Bridge class for the <image> element. * * @author Thierry Kormann * @version $Id$ @@ -84,7 +83,7 @@ public class SVGImageElementBridge extends AbstractGraphicsNodeBridge { protected BridgeContext subCtx = null; protected boolean hitCheckChildren = false; /** - * Constructs a new bridge for the <image> element. + * Constructs a new bridge for the <image> element. */ public SVGImageElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGKernElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGKernElementBridge.java index 640c71380..e9986fa13 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGKernElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGKernElementBridge.java @@ -38,8 +38,8 @@ public abstract class SVGKernElementBridge extends AbstractSVGBridge { * Creates a Kern object that repesents the specified kerning element. * * @param ctx The bridge context. - * @param kernElement The kerning element. Should be either a <hkern> - * or <vkern> element. + * @param kernElement The kerning element. Should be either a <hkern> + * or <vkern> element. * @param font The font the kerning is related to. * * @return kern The new Kern object @@ -89,8 +89,7 @@ public abstract class SVGKernElementBridge extends AbstractSVGBridge { System.arraycopy( firstGlyphSet, 0, tmp, 0, firstGlyphLen ); firstGlyphSet = tmp; } - for (int i = 0; i < glyphCodes.length; i++) - firstGlyphSet[firstGlyphLen++] = glyphCodes[i]; + for (int glyphCode : glyphCodes) firstGlyphSet[firstGlyphLen++] = glyphCode; } } } @@ -116,8 +115,7 @@ public abstract class SVGKernElementBridge extends AbstractSVGBridge { System.arraycopy( secondGlyphSet, 0, tmp, 0, secondGlyphLen ); secondGlyphSet = tmp; } - for (int i = 0; i < glyphCodes.length; i++) - secondGlyphSet[secondGlyphLen++] = glyphCodes[i]; + for (int glyphCode : glyphCodes) secondGlyphSet[secondGlyphLen++] = glyphCode; } } } @@ -140,8 +138,7 @@ public abstract class SVGKernElementBridge extends AbstractSVGBridge { System.arraycopy( firstGlyphSet, 0, tmp, 0, firstGlyphLen ); firstGlyphSet = tmp; } - for (int i = 0; i < glyphCodes.length; i++) - firstGlyphSet[firstGlyphLen++] = glyphCodes[i]; + for (int glyphCode : glyphCodes) firstGlyphSet[firstGlyphLen++] = glyphCode; } } @@ -163,8 +160,7 @@ public abstract class SVGKernElementBridge extends AbstractSVGBridge { System.arraycopy( secondGlyphSet, 0, tmp, 0, secondGlyphLen ); secondGlyphSet = tmp; } - for (int i = 0; i < glyphCodes.length; i++) - secondGlyphSet[secondGlyphLen++] = glyphCodes[i]; + for (int glyphCode : glyphCodes) secondGlyphSet[secondGlyphLen++] = glyphCode; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLineElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLineElementBridge.java index 9dde8d6bd..b16b1c4a2 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLineElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLineElementBridge.java @@ -30,7 +30,7 @@ import org.apache.batik.gvt.ShapePainter; import org.w3c.dom.Element; /** - * Bridge class for the <line> element. + * Bridge class for the <line> element. * * @author Thierry Kormann * @version $Id$ @@ -38,7 +38,7 @@ import org.w3c.dom.Element; public class SVGLineElementBridge extends SVGDecoratedShapeElementBridge { /** - * Constructs a new bridge for the <line> element. + * Constructs a new bridge for the <line> element. */ public SVGLineElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLinearGradientElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLinearGradientElementBridge.java index ff0a17008..8c9dfb508 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLinearGradientElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGLinearGradientElementBridge.java @@ -32,7 +32,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <linearGradient> element. + * Bridge class for the <linearGradient> element. * * @author Thierry Kormann * @version $Id$ @@ -123,7 +123,7 @@ public class SVGLinearGradientElementBridge && bridge instanceof AbstractGraphicsNodeBridge) { // XXX Make this work for non-AbstractGraphicsNodeBridges, like // the various text child bridges. - Rectangle2D bbox = ((AbstractGraphicsNodeBridge) bridge).getBBox(); + Rectangle2D bbox = bridge.getBBox(); if (bbox != null && (bbox.getWidth() == 0 || bbox.getHeight() == 0)) { return null; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMarkerElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMarkerElementBridge.java index c46823323..5e116d981 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMarkerElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMarkerElementBridge.java @@ -33,7 +33,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <marker> element. + * Bridge class for the <marker> element. * * @author Thierry Kormann * @version $Id$ @@ -42,7 +42,7 @@ public class SVGMarkerElementBridge extends AnimatableGenericSVGBridge implements MarkerBridge, ErrorConstants { /** - * Constructs a new bridge for the <marker> element. + * Constructs a new bridge for the <marker> element. */ protected SVGMarkerElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMaskElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMaskElementBridge.java index dcbf6009f..8bddbbcf0 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMaskElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMaskElementBridge.java @@ -30,7 +30,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <mask> element. + * Bridge class for the <mask> element. * * @author Thierry Kormann * @version $Id$ @@ -39,7 +39,7 @@ public class SVGMaskElementBridge extends AnimatableGenericSVGBridge implements MaskBridge { /** - * Constructs a new bridge for the <mask> element. + * Constructs a new bridge for the <mask> element. */ public SVGMaskElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMissingGlyphElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMissingGlyphElementBridge.java index 549184401..fd58db4e8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMissingGlyphElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGMissingGlyphElementBridge.java @@ -19,7 +19,7 @@ package org.apache.batik.bridge; /** - * Bridge class for the <missing-glyph> element. + * Bridge class for the <missing-glyph> element. * * @author Thierry Kormann * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPathElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPathElementBridge.java index bb07a0f2f..30f67cd0a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPathElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPathElementBridge.java @@ -37,7 +37,7 @@ import org.w3c.dom.Element; import org.w3c.dom.svg.SVGPathSegList; /** - * Bridge class for the <path> element. + * Bridge class for the <path> element. * * @author Thierry Kormann * @version $Id$ @@ -52,7 +52,7 @@ public class SVGPathElementBridge extends SVGDecoratedShapeElementBridge protected static final Shape DEFAULT_SHAPE = new GeneralPath(); /** - * Constructs a new bridge for the <path> element. + * Constructs a new bridge for the <path> element. */ public SVGPathElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPatternElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPatternElementBridge.java index 13cb4c4d2..40b2864c3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPatternElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPatternElementBridge.java @@ -23,7 +23,6 @@ import java.awt.Paint; import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -41,7 +40,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <pattern> element. + * Bridge class for the <pattern> element. * * @author Thierry Kormann * @version $Id$ @@ -309,9 +308,8 @@ public class SVGPatternElementBridge extends AnimatableGenericSVGBridge * @param urls the list of ParsedURLs * @param key the url to search for */ private static boolean contains(List urls, ParsedURL key) { - Iterator iter = urls.iterator(); - while (iter.hasNext()) { - if (key.equals(iter.next())) + for (Object url : urls) { + if (key.equals(url)) return true; } return false; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolygonElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolygonElementBridge.java index 51f37d531..1e017775f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolygonElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolygonElementBridge.java @@ -34,7 +34,7 @@ import org.w3c.dom.svg.SVGPoint; import org.w3c.dom.svg.SVGPointList; /** - * Bridge class for the <polygon> element. + * Bridge class for the <polygon> element. * * @author Thierry Kormann * @version $Id$ @@ -48,7 +48,7 @@ public class SVGPolygonElementBridge extends SVGDecoratedShapeElementBridge { protected static final Shape DEFAULT_SHAPE = new GeneralPath(); /** - * Constructs a new bridge for the <polygon> element. + * Constructs a new bridge for the <polygon> element. */ public SVGPolygonElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolylineElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolylineElementBridge.java index a985cb8b5..6ba975db6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolylineElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGPolylineElementBridge.java @@ -34,7 +34,7 @@ import org.w3c.dom.svg.SVGPoint; import org.w3c.dom.svg.SVGPointList; /** - * Bridge class for the <polyline> element. + * Bridge class for the <polyline> element. * * @author Thierry Kormann * @version $Id$ @@ -48,7 +48,7 @@ public class SVGPolylineElementBridge extends SVGDecoratedShapeElementBridge { protected static final Shape DEFAULT_SHAPE = new GeneralPath(); /** - * Constructs a new bridge for the <polyline> element. + * Constructs a new bridge for the <polyline> element. */ public SVGPolylineElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRadialGradientElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRadialGradientElementBridge.java index ff3f0a26e..2cd95e28a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRadialGradientElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRadialGradientElementBridge.java @@ -32,7 +32,7 @@ import org.apache.batik.gvt.GraphicsNode; import org.w3c.dom.Element; /** - * Bridge class for the <radialGradient> element. + * Bridge class for the <radialGradient> element. * * @author Thierry Kormann * @version $Id$ @@ -131,7 +131,7 @@ public class SVGRadialGradientElementBridge && bridge instanceof AbstractGraphicsNodeBridge) { // XXX Make this work for non-AbstractGraphicsNodeBridges, like // the various text child bridges. - Rectangle2D bbox = ((AbstractGraphicsNodeBridge) bridge).getBBox(); + Rectangle2D bbox = bridge.getBBox(); if (bbox != null && (bbox.getWidth() == 0 || bbox.getHeight() == 0)) { return null; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRectElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRectElementBridge.java index 2942afc9f..2a397caa2 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRectElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGRectElementBridge.java @@ -32,7 +32,7 @@ import org.apache.batik.gvt.ShapePainter; import org.w3c.dom.Element; /** - * Bridge class for the <rect> element. + * Bridge class for the <rect> element. * * @author Thierry Kormann * @version $Id$ @@ -40,7 +40,7 @@ import org.w3c.dom.Element; public class SVGRectElementBridge extends SVGShapeElementBridge { /** - * Constructs a new bridge for the <rect> element. + * Constructs a new bridge for the <rect> element. */ public SVGRectElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSVGElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSVGElementBridge.java index ebfe5c1a8..d4d0b267b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSVGElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSVGElementBridge.java @@ -51,7 +51,7 @@ import org.w3c.dom.svg.SVGDocument; import org.w3c.dom.svg.SVGRect; /** - * Bridge class for the <svg> element. + * Bridge class for the <svg> element. * * @author Thierry Kormann * @version $Id$ @@ -61,7 +61,7 @@ public class SVGSVGElementBridge implements SVGSVGContext { /** - * Constructs a new bridge for the <svg> element. + * Constructs a new bridge for the <svg> element. */ public SVGSVGElementBridge() {} @@ -407,7 +407,7 @@ public class SVGSVGElementBridge } /** - * A viewport defined an <svg> element. + * A viewport defined an <svg> element. */ public static class SVGSVGElementViewport implements Viewport { private float width; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSwitchElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSwitchElementBridge.java index 4e4d31d4f..3fb732765 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSwitchElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGSwitchElementBridge.java @@ -26,7 +26,7 @@ import org.w3c.dom.Node; import org.w3c.dom.svg.SVGTests; /** - * Bridge class for the <switch> element. + * Bridge class for the <switch> element. * * @author Thierry Kormann * @version $Id$ @@ -40,7 +40,7 @@ public class SVGSwitchElementBridge extends SVGGElementBridge { protected Element selectedChild; /** - * Constructs a new bridge for the <switch> element. + * Constructs a new bridge for the <switch> element. */ public SVGSwitchElementBridge() {} @@ -97,7 +97,7 @@ public class SVGSwitchElementBridge extends SVGGElementBridge { } /** - * Returns true as the <switch> element is not a container. + * Returns true as the <switch> element is not a container. */ public boolean isComposite() { return false; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextElementBridge.java index 46a2083c3..e3bbe440a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextElementBridge.java @@ -68,7 +68,7 @@ import org.apache.batik.gvt.font.UnresolvedFontFamily; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.gvt.text.TextPaintInfo; import org.apache.batik.gvt.text.TextPath; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -83,7 +83,7 @@ import org.w3c.dom.svg.SVGTextContentElement; import org.w3c.dom.svg.SVGTextPositioningElement; /** - * Bridge class for the <text> element. + * Bridge class for the <text> element. * * @author Stephane Hillion * @author Bill Haneman @@ -92,7 +92,7 @@ import org.w3c.dom.svg.SVGTextPositioningElement; public class SVGTextElementBridge extends AbstractGraphicsNodeBridge implements SVGTextContent { - protected static final Integer ZERO = new Integer(0); + protected static final Integer ZERO = 0; public static final AttributedCharacterIterator.Attribute TEXT_COMPOUND_DELIMITER = @@ -144,7 +144,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge protected boolean usingComplexSVGFont = false; /** - * Constructs a new bridge for the <text> element. + * Constructs a new bridge for the <text> element. */ public SVGTextElementBridge() {} @@ -707,30 +707,30 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge hasNewACI = false; int [] properties = evt.getProperties(); // first try to find CSS properties that change the layout - for (int i=0; i < properties.length; ++i) { - switch(properties[i]) { // fall-through is intended - case SVGCSSEngine.BASELINE_SHIFT_INDEX: - case SVGCSSEngine.DIRECTION_INDEX: - case SVGCSSEngine.DISPLAY_INDEX: - case SVGCSSEngine.FONT_FAMILY_INDEX: - case SVGCSSEngine.FONT_SIZE_INDEX: - case SVGCSSEngine.FONT_STRETCH_INDEX: - case SVGCSSEngine.FONT_STYLE_INDEX: - case SVGCSSEngine.FONT_WEIGHT_INDEX: - case SVGCSSEngine.GLYPH_ORIENTATION_HORIZONTAL_INDEX: - case SVGCSSEngine.GLYPH_ORIENTATION_VERTICAL_INDEX: - case SVGCSSEngine.KERNING_INDEX: - case SVGCSSEngine.LETTER_SPACING_INDEX: - case SVGCSSEngine.TEXT_ANCHOR_INDEX: - case SVGCSSEngine.UNICODE_BIDI_INDEX: - case SVGCSSEngine.WORD_SPACING_INDEX: - case SVGCSSEngine.WRITING_MODE_INDEX: { - if (!hasNewACI) { - hasNewACI = true; - computeLaidoutText(ctx, e, getTextNode()); + for (int property : properties) { + switch (property) { // fall-through is intended + case SVGCSSEngine.BASELINE_SHIFT_INDEX: + case SVGCSSEngine.DIRECTION_INDEX: + case SVGCSSEngine.DISPLAY_INDEX: + case SVGCSSEngine.FONT_FAMILY_INDEX: + case SVGCSSEngine.FONT_SIZE_INDEX: + case SVGCSSEngine.FONT_STRETCH_INDEX: + case SVGCSSEngine.FONT_STYLE_INDEX: + case SVGCSSEngine.FONT_WEIGHT_INDEX: + case SVGCSSEngine.GLYPH_ORIENTATION_HORIZONTAL_INDEX: + case SVGCSSEngine.GLYPH_ORIENTATION_VERTICAL_INDEX: + case SVGCSSEngine.KERNING_INDEX: + case SVGCSSEngine.LETTER_SPACING_INDEX: + case SVGCSSEngine.TEXT_ANCHOR_INDEX: + case SVGCSSEngine.UNICODE_BIDI_INDEX: + case SVGCSSEngine.WORD_SPACING_INDEX: + case SVGCSSEngine.WRITING_MODE_INDEX: { + if (!hasNewACI) { + hasNewACI = true; + computeLaidoutText(ctx, e, getTextNode()); + } + break; } - break; - } } } //optimize the calculation of @@ -1024,11 +1024,10 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge strippedSome = true; } if (strippedSome) { - Iterator iter = elemTPI.values().iterator(); - while (iter.hasNext()) { - TextPaintInfo tpi = (TextPaintInfo)iter.next(); + for (Object o1 : elemTPI.values()) { + TextPaintInfo tpi = (TextPaintInfo) o1; if (tpi.endChar >= asb.length()) { - tpi.endChar = asb.length()-1; + tpi.endChar = asb.length() - 1; if (tpi.startChar > tpi.endChar) tpi.startChar = tpi.endChar; } @@ -1226,9 +1225,8 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge } StringBuffer sb = new StringBuffer( strings.size() * 5 ); - Iterator it = strings.iterator(); - while (it.hasNext()) { - sb.append((String)it.next()); + for (Object string : strings) { + sb.append((String) string); } AttributedString result = new AttributedString(sb.toString()); @@ -1264,9 +1262,8 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge } StringBuffer sb = new StringBuffer( strings.size() * 5 ); - Iterator it = strings.iterator(); - while (it.hasNext()) { - sb.append((String)it.next()); + for (Object string : strings) { + sb.append((String) string); } return sb.toString(); } @@ -1352,7 +1349,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge for (int i = 0; i < len && firstChar + i <= lastChar; i++) { as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.X, - new Float(xs.getItem(i).getValue()), firstChar + i, + xs.getItem(i).getValue(), firstChar + i, firstChar + i + 1); } @@ -1361,7 +1358,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge for (int i = 0; i < len && firstChar + i <= lastChar; i++) { as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.Y, - new Float(ys.getItem(i).getValue()), firstChar + i, + ys.getItem(i).getValue(), firstChar + i, firstChar + i + 1); } @@ -1370,7 +1367,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge for (int i = 0; i < len && firstChar + i <= lastChar; i++) { as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.DX, - new Float(dxs.getItem(i).getValue()), firstChar + i, + dxs.getItem(i).getValue(), firstChar + i, firstChar + i + 1); } @@ -1379,7 +1376,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge for (int i = 0; i < len && firstChar + i <= lastChar; i++) { as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.DY, - new Float(dys.getItem(i).getValue()), firstChar + i, + dys.getItem(i).getValue(), firstChar + i, firstChar + i + 1); } @@ -1387,7 +1384,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge len = rs.getNumberOfItems(); if (len == 1) { // not a list // each char will have the same rotate value - Float rad = new Float(Math.toRadians(rs.getItem(0).getValue())); + Float rad = (float) Math.toRadians(rs.getItem(0).getValue()); as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.ROTATION, rad, firstChar, lastChar + 1); @@ -1395,7 +1392,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge } else if (len > 1) { // it's a list // set each rotate value from the list for (int i = 0; i < len && firstChar + i <= lastChar; i++) { - Float rad = new Float(Math.toRadians(rs.getItem(i).getValue())); + Float rad = (float) Math.toRadians(rs.getItem(i).getValue()); as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.ROTATION, rad, firstChar + i, firstChar + i + 1); @@ -1477,7 +1474,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge result.put(TEXT_COMPOUND_ID, new SoftReference(element)); Float fsFloat = TextUtilities.convertFontSize(element); - float fontSize = fsFloat.floatValue(); + float fontSize = fsFloat; // Font size. result.put(TextAttribute.SIZE, fsFloat); @@ -1630,7 +1627,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge (element, SVGCSSEngine.DIRECTION_INDEX); String rs = val.getStringValue(); int cbidi = 0; - if (bidiLevel != null) cbidi = bidiLevel.intValue(); + if (bidiLevel != null) cbidi = bidiLevel; // We don't care if it was embed or override we just want // it's level here. So map override to positive value. @@ -1657,7 +1654,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge break; } - result.put(TextAttribute.BIDI_EMBEDDING, new Integer(cbidi)); + result.put(TextAttribute.BIDI_EMBEDDING, cbidi); } // Writing mode @@ -1705,7 +1702,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge TextAttribute.ORIENTATION_ANGLE); result.put(GVTAttributedCharacterIterator. TextAttribute.VERTICAL_ORIENTATION_ANGLE, - new Float(val.getFloatValue())); + val.getFloatValue()); break; case CSSPrimitiveValue.CSS_RAD: result.put(GVTAttributedCharacterIterator. @@ -1714,7 +1711,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge TextAttribute.ORIENTATION_ANGLE); result.put(GVTAttributedCharacterIterator. TextAttribute.VERTICAL_ORIENTATION_ANGLE, - new Float( Math.toDegrees( val.getFloatValue() ) )); + (float) Math.toDegrees(val.getFloatValue())); break; case CSSPrimitiveValue.CSS_GRAD: result.put(GVTAttributedCharacterIterator. @@ -1723,7 +1720,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge TextAttribute.ORIENTATION_ANGLE); result.put(GVTAttributedCharacterIterator. TextAttribute.VERTICAL_ORIENTATION_ANGLE, - new Float(val.getFloatValue() * 9 / 5)); + val.getFloatValue() * 9 / 5); break; default: // Cannot happen @@ -1739,17 +1736,17 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge case CSSPrimitiveValue.CSS_DEG: result.put(GVTAttributedCharacterIterator. TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, - new Float(val.getFloatValue())); + val.getFloatValue()); break; case CSSPrimitiveValue.CSS_RAD: result.put(GVTAttributedCharacterIterator. TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, - new Float( Math.toDegrees( val.getFloatValue() ) )); + (float) Math.toDegrees(val.getFloatValue())); break; case CSSPrimitiveValue.CSS_GRAD: result.put(GVTAttributedCharacterIterator. TextAttribute.HORIZONTAL_ORIENTATION_ANGLE, - new Float(val.getFloatValue() * 9 / 5)); + val.getFloatValue() * 9 / 5); break; default: // Cannot happen @@ -1803,7 +1800,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge inheritMap = new HashMap(); } - Object value = new Float(textLength.getCheckedValue()); + Object value = textLength.getCheckedValue(); result.put (GVTAttributedCharacterIterator.TextAttribute.BBOX_WIDTH, value); @@ -1984,7 +1981,7 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge * Implementation of SVGContext for * the children of <text> */ - public abstract class AbstractTextChildSVGContext + public abstract static class AbstractTextChildSVGContext extends AnimatableSVGBridge { /** Text bridge parent */ @@ -2901,11 +2898,11 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge CharacterInformation info = new CharacterInformation(); info.characterIndex = startIndex+charnum; - for (int i = 0; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run; - run = (StrokingTextPainter.TextRun)list.get(i); + run = (StrokingTextPainter.TextRun) aList; - if (!run.getLayout().hasCharacterIndex(info.characterIndex) ) + if (!run.getLayout().hasCharacterIndex(info.characterIndex)) continue; info.layout = run.getLayout(); @@ -2913,20 +2910,19 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge aci.setIndex(info.characterIndex); //check is it is a altGlyph - if (aci.getAttribute(ALT_GLYPH_HANDLER) != null){ + if (aci.getAttribute(ALT_GLYPH_HANDLER) != null) { info.glyphIndexStart = 0; - info.glyphIndexEnd = info.layout.getGlyphCount()-1; + info.glyphIndexEnd = info.layout.getGlyphCount() - 1; } else { info.glyphIndexStart = info.layout.getGlyphIndex - (info.characterIndex); + (info.characterIndex); //special case when the glyph does not have a unicode //associated to it, it will return -1 - if ( info.glyphIndexStart == -1 ){ + if (info.glyphIndexStart == -1) { info.glyphIndexStart = 0; - info.glyphIndexEnd = info.layout.getGlyphCount()-1; - } - else{ + info.glyphIndexEnd = info.layout.getGlyphCount() - 1; + } else { info.glyphIndexEnd = info.glyphIndexStart; } } @@ -2971,19 +2967,19 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge if (list == null) return elems; - for (int i = 0 ; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run; - run = (StrokingTextPainter.TextRun)list.get(i); + run = (StrokingTextPainter.TextRun) aList; TextSpanLayout layout = run.getLayout(); AttributedCharacterIterator aci = run.getACI(); aci.first(); SoftReference sr; - sr =(SoftReference)aci.getAttribute(TEXT_COMPOUND_ID); - Element elem = (Element)sr.get(); + sr = (SoftReference) aci.getAttribute(TEXT_COMPOUND_ID); + Element elem = (Element) sr.get(); if (elem == null) continue; if (elems.contains(elem)) continue; - if (!isTextSensitive(elem)) continue; + if (!isTextSensitive(elem)) continue; Rectangle2D glBounds = layout.getBounds2D(); if (glBounds != null) { @@ -2993,13 +2989,13 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge continue; } } - + GVTGlyphVector gv = layout.getGlyphVector(); for (int g = 0; g < gv.getNumGlyphs(); g++) { Shape gBounds = gv.getGlyphLogicalBounds(g); if (gBounds != null) { gBounds = at.createTransformedShape - (gBounds).getBounds2D(); + (gBounds).getBounds2D(); if (gBounds.intersects(rect)) { elems.add(elem); @@ -3021,15 +3017,15 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge return elems; Set reject = new HashSet(); - for (int i = 0 ; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run; - run = (StrokingTextPainter.TextRun)list.get(i); + run = (StrokingTextPainter.TextRun) aList; TextSpanLayout layout = run.getLayout(); AttributedCharacterIterator aci = run.getACI(); aci.first(); SoftReference sr; - sr =(SoftReference)aci.getAttribute(TEXT_COMPOUND_ID); - Element elem = (Element)sr.get(); + sr = (SoftReference) aci.getAttribute(TEXT_COMPOUND_ID); + Element elem = (Element) sr.get(); if (elem == null) continue; if (reject.contains(elem)) continue; @@ -3039,11 +3035,11 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge } Rectangle2D glBounds = layout.getBounds2D(); - if ( glBounds == null ){ + if (glBounds == null) { continue; } - glBounds = at.createTransformedShape( glBounds ).getBounds2D(); + glBounds = at.createTransformedShape(glBounds).getBounds2D(); if (rect.contains(glBounds)) { elems.add(elem); @@ -3091,15 +3087,15 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge tnRect = at.createTransformedShape(tnRect).getBounds2D(); if (!rect.intersects(tnRect)) return false; - for (int i = 0 ; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run; - run = (StrokingTextPainter.TextRun)list.get(i); + run = (StrokingTextPainter.TextRun) aList; TextSpanLayout layout = run.getLayout(); AttributedCharacterIterator aci = run.getACI(); aci.first(); SoftReference sr; - sr =(SoftReference)aci.getAttribute(TEXT_COMPOUND_ID); - Element runElem = (Element)sr.get(); + sr = (SoftReference) aci.getAttribute(TEXT_COMPOUND_ID); + Element runElem = (Element) sr.get(); if (runElem == null) continue; // Only consider runElem if it is sensitive. @@ -3122,9 +3118,9 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge Shape gBounds = gv.getGlyphLogicalBounds(g); if (gBounds != null) { gBounds = at.createTransformedShape - (gBounds).getBounds2D(); + (gBounds).getBounds2D(); - if (gBounds.intersects(rect)){ + if (gBounds.intersects(rect)) { return true; } } @@ -3158,15 +3154,15 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge Element txtElem = txtBridge.e; Rectangle2D ret = null; - for (int i = 0 ; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run; - run = (StrokingTextPainter.TextRun)list.get(i); + run = (StrokingTextPainter.TextRun) aList; TextSpanLayout layout = run.getLayout(); AttributedCharacterIterator aci = run.getACI(); aci.first(); SoftReference sr; - sr =(SoftReference)aci.getAttribute(TEXT_COMPOUND_ID); - Element runElem = (Element)sr.get(); + sr = (SoftReference) aci.getAttribute(TEXT_COMPOUND_ID); + Element runElem = (Element) sr.get(); if (runElem == null) continue; // Only consider runElem if it is sensitive. @@ -3181,8 +3177,8 @@ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge // runElem is a child of elem so include it's bounds. Rectangle2D glBounds = layout.getBounds2D(); if (glBounds != null) { - if (ret == null) ret = (Rectangle2D)glBounds.clone(); - else ret.add(glBounds); + if (ret == null) ret = (Rectangle2D) glBounds.clone(); + else ret.add(glBounds); } } return ret; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextPathElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextPathElementBridge.java index dabc7250c..2836389fb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextPathElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGTextPathElementBridge.java @@ -30,7 +30,7 @@ import org.apache.batik.parser.PathParser; import org.w3c.dom.Element; /** - * Bridge class for the <textPath> element. + * Bridge class for the <textPath> element. * * @author Bella Robinson * @version $Id$ @@ -39,7 +39,7 @@ public class SVGTextPathElementBridge extends AnimatableGenericSVGBridge implements ErrorConstants { /** - * Constructs a new bridge for the <textPath> element. + * Constructs a new bridge for the <textPath> element. */ public SVGTextPathElementBridge() {} @@ -59,7 +59,7 @@ public class SVGTextPathElementBridge extends AnimatableGenericSVGBridge * is to be rendered. * * @param ctx The bridge context. - * @param textPathElement The <textPath> element. + * @param textPathElement The <textPath> element. * * @return The new TextPath. */ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUseElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUseElementBridge.java index 9f6871b90..62cc23eb1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUseElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUseElementBridge.java @@ -18,23 +18,17 @@ */ package org.apache.batik.bridge; -import java.awt.Cursor; -import java.awt.RenderingHints; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; - import org.apache.batik.anim.dom.AbstractSVGAnimatedLength; import org.apache.batik.anim.dom.AnimatedLiveAttributeValue; import org.apache.batik.anim.dom.SVGOMAnimatedLength; import org.apache.batik.anim.dom.SVGOMDocument; import org.apache.batik.anim.dom.SVGOMUseElement; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.dom.events.NodeEventTarget; import org.apache.batik.dom.svg.LiveAttributeException; import org.apache.batik.dom.svg.SVGOMUseShadowRoot; import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.gvt.GraphicsNode; -import org.apache.batik.util.XMLConstants; - import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -44,8 +38,13 @@ import org.w3c.dom.events.EventListener; import org.w3c.dom.svg.SVGTransformable; import org.w3c.dom.svg.SVGUseElement; +import java.awt.Cursor; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + /** - * Bridge class for the <use> element. + * Bridge class for the <use> element. * * @author Thierry Kormann * @version $Id$ @@ -65,7 +64,7 @@ public class SVGUseElementBridge extends AbstractGraphicsNodeBridge { protected BridgeContext subCtx; /** - * Constructs a new bridge for the <use> element. + * Constructs a new bridge for the <use> element. */ public SVGUseElementBridge() {} @@ -362,7 +361,7 @@ public class SVGUseElementBridge extends AbstractGraphicsNodeBridge { } /** - * Returns false as the <use> element is a not container. + * Returns false as the <use> element is a not container. */ public boolean isComposite() { return false; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUtilities.java index 899367fc2..9e4a9f93c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGUtilities.java @@ -18,17 +18,7 @@ */ package org.apache.batik.bridge; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - import org.apache.batik.css.engine.CSSEngine; -import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.dom.util.XMLSupport; import org.apache.batik.gvt.GraphicsNode; @@ -46,6 +36,14 @@ import org.w3c.dom.svg.SVGElement; import org.w3c.dom.svg.SVGLangSpace; import org.w3c.dom.svg.SVGNumberList; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.StringTokenizer; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + /** * A collection of utility methods for SVG. * @@ -66,7 +64,7 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { /** * Returns the logical parent element of the given element. - * The parent element of a used element is the <use> element + * The parent element of a used element is the <use> element * which reference it. */ public static Element getParentElement(Element elt) { @@ -260,15 +258,14 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { if (uriStr.length() == 0) { // exit if no more xlink:href return ""; } - String baseURI = ((AbstractNode) e).getBaseURI(); + String baseURI = e.getBaseURI(); ParsedURL purl = new ParsedURL(baseURI, uriStr); - Iterator iter = refs.iterator(); - while (iter.hasNext()) { - if (purl.equals(iter.next())) + for (Object ref : refs) { + if (purl.equals(ref)) throw new BridgeException - (ctx, e, ERR_XLINK_HREF_CIRCULAR_DEPENDENCIES, - new Object[] {uriStr}); + (ctx, e, ERR_XLINK_HREF_CIRCULAR_DEPENDENCIES, + new Object[]{uriStr}); } try { @@ -512,7 +509,7 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { if (vals[0] == null) filterRes[0] = -1; else { - filterRes[0] = vals[0].floatValue(); + filterRes[0] = vals[0]; if (filterRes[0] < 0) throw new BridgeException (ctx, filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -522,7 +519,7 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { if (vals[1] == null) filterRes[1] = filterRes[0]; else { - filterRes[1] = vals[1].floatValue(); + filterRes[1] = vals[1]; if (filterRes[1] < 0) throw new BridgeException (ctx, filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -547,9 +544,9 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { try { StringTokenizer tokens = new StringTokenizer(attrValue, " "); - ret[0] = new Float(Float.parseFloat(tokens.nextToken())); + ret[0] = Float.parseFloat(tokens.nextToken()); if (tokens.hasMoreTokens()) { - ret[1] = new Float(Float.parseFloat(tokens.nextToken())); + ret[1] = Float.parseFloat(tokens.nextToken()); } if (tokens.hasMoreTokens()) { @@ -920,7 +917,7 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { } break; default: - throw new Error("invalid unitsType:" + unitsType); // can't be reached + throw new RuntimeException("invalid unitsType:" + unitsType); // can't be reached } Rectangle2D region = new Rectangle2D.Double(x, y, w, h); @@ -1141,7 +1138,7 @@ public abstract class SVGUtilities implements SVGConstants, ErrorConstants { (hStr, SVG_HEIGHT_ATTRIBUTE, uctx); break; default: - throw new Error("invalid unitsType:" + unitsType ); // can't be reached + throw new RuntimeException("invalid unitsType:" + unitsType ); // can't be reached } return new Rectangle2D.Double(x, y, w, h); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGVKernElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGVKernElementBridge.java index acbf80c8d..a55c5c6ec 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGVKernElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/SVGVKernElementBridge.java @@ -19,7 +19,7 @@ package org.apache.batik.bridge; /** - * Bridge class for the <vkern> element. + * Bridge class for the <vkern> element. * * @author Dean Jackson * @version $Id$ @@ -27,7 +27,7 @@ package org.apache.batik.bridge; public class SVGVKernElementBridge extends SVGKernElementBridge { /** - * Constructs a new bridge for the <vkern> element. + * Constructs a new bridge for the <vkern> element. */ public SVGVKernElementBridge() {} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ScriptingEnvironment.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ScriptingEnvironment.java index a556aa1b6..2ed30ea72 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ScriptingEnvironment.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/ScriptingEnvironment.java @@ -33,7 +33,6 @@ import java.net.URL; import java.net.URLConnection; import java.util.HashMap; import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; @@ -49,7 +48,6 @@ import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.anim.dom.SAXSVGDocumentFactory; import org.apache.batik.anim.dom.SVGOMDocument; import org.apache.batik.anim.dom.SVGOMScriptElement; -import org.apache.batik.bridge.Location; import org.apache.batik.script.Interpreter; import org.apache.batik.script.InterpreterException; import org.apache.batik.script.ScriptEventWrapper; @@ -57,7 +55,7 @@ import org.apache.batik.util.EncodingUtilities; import org.apache.batik.util.ParsedURL; import org.apache.batik.util.RunnableQueue; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.util.XMLResourceDescriptor; import org.w3c.dom.Document; @@ -1164,7 +1162,7 @@ public class ScriptingEnvironment extends BaseScriptingEnvironment { public void run() { try { String base = - ((SVGOMDocument)document).getDocumentURI(); + document.getDocumentURI(); URL url; if (base == null) { url = new URL(uri); @@ -1421,7 +1419,7 @@ public class ScriptingEnvironment extends BaseScriptingEnvironment { int line = dl.getLineNumber(elt); final String desc = Messages.formatMessage (EVENT_SCRIPT_DESCRIPTION, - new Object [] {d.getURL(), attribute, new Integer(line)}); + new Object [] {d.getURL(), attribute, line}); // Find the scripting language Element e = elt; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/StrokingTextPainter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/StrokingTextPainter.java index baea3e1ee..8f21a220a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/StrokingTextPainter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/StrokingTextPainter.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; @@ -38,7 +38,6 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.apache.batik.bridge.BasicTextPainter.BasicMark; import org.apache.batik.gvt.font.GVTFont; import org.apache.batik.gvt.font.GVTFontFamily; import org.apache.batik.gvt.font.GVTGlyphMetrics; @@ -441,7 +440,7 @@ public class StrokingTextPainter extends BasicTextPainter { float fontSize = 12; Float fsFloat = (Float)aci.getAttribute(TextAttribute.SIZE); if (fsFloat != null) - fontSize = fsFloat.floatValue(); + fontSize = fsFloat; // if could not resolve at least one of the fontFamilies // then use the default font @@ -461,24 +460,24 @@ public class StrokingTextPainter extends BasicTextPainter { int numSet=0; int firstUnset=start; boolean firstUnsetSet; - for (int i = 0; i < fonts.size(); i++) { + for (Object font1 : fonts) { // assign this font to all characters it can display if it has // not already been assigned int currentIndex = firstUnset; firstUnsetSet = false; aci.setIndex(currentIndex); - GVTFont font = (GVTFont)fonts.get(i); + GVTFont font = (GVTFont) font1; if (defaultFont == null) defaultFont = font; while (currentIndex < end) { int displayUpToIndex = font.canDisplayUpTo - (aci, currentIndex, end); + (aci, currentIndex, end); Object altGlyphElement; altGlyphElement = aci.getAttribute(ALT_GLYPH_HANDLER); - if ( altGlyphElement != null ){ + if (altGlyphElement != null) { //found all the glyph to be displayed //consider the font matching done displayUpToIndex = -1; @@ -505,8 +504,8 @@ public class StrokingTextPainter extends BasicTextPainter { if (fontAssigned[j - start]) { if (runStart != -1) { as.addAttribute(GVT_FONT, font, - runStart-begin, j-begin); - runStart=-1; + runStart - begin, j - begin); + runStart = -1; } } else { if (runStart == -1) @@ -517,13 +516,13 @@ public class StrokingTextPainter extends BasicTextPainter { } if (runStart != -1) { as.addAttribute(GVT_FONT, font, - runStart-begin, - displayUpToIndex-begin); + runStart - begin, + displayUpToIndex - begin); } // set currentIndex to be one after the char // that couldn't display - currentIndex = displayUpToIndex+1; + currentIndex = displayUpToIndex + 1; } } @@ -723,25 +722,25 @@ public class StrokingTextPainter extends BasicTextPainter { if (layout.isVertical()) { if (lengthAdj == ADJUST_SPACING) { yScale = (float) - ((length.floatValue() - lastH) / + ((length - lastH) / (advance.getY() - lastMetrics.getVerticalAdvance())); } else { double adv =(advance.getY() + lastH - lastMetrics.getVerticalAdvance()); - yScale = (float)(length.floatValue()/adv); + yScale = (float)(length /adv); } - visualAdvance = new Point2D.Float(0, length.floatValue()); + visualAdvance = new Point2D.Float(0, length); } else { if (lengthAdj == ADJUST_SPACING) { xScale = (float) - ((length.floatValue() - lastW) / + ((length - lastW) / (advance.getX() - lastMetrics.getHorizontalAdvance())); } else { double adv = (advance.getX() + lastW - lastMetrics.getHorizontalAdvance()); - xScale = (float)(length.floatValue()/adv); + xScale = (float)(length /adv); } - visualAdvance = new Point2D.Float(length.floatValue(), 0); + visualAdvance = new Point2D.Float(length, 0); } Point2D.Float adv = new Point2D.Float(0,0); @@ -791,12 +790,12 @@ public class StrokingTextPainter extends BasicTextPainter { // Of course X and Y override that, but they don't apply for // text on a path. if ((runX != null) && (!runX.isNaN())) { - absX = runX.floatValue(); + absX = runX; tpShiftX = absX; } if ((runY != null) && (!runY.isNaN())) { - absY = runY.floatValue(); + absY = runY; tpShiftY = absY; } @@ -821,12 +820,12 @@ public class StrokingTextPainter extends BasicTextPainter { if (vertical) { runX = (Float) runaci.getAttribute(XPOS); if ((runX != null) && (!runX.isNaN())) { - absX = runX.floatValue(); + absX = runX; } } else { runY = (Float) runaci.getAttribute(YPOS); if ((runY != null) && (!runY.isNaN())) { - absY = runY.floatValue(); + absY = runY; } } @@ -864,55 +863,55 @@ public class StrokingTextPainter extends BasicTextPainter { Rectangle2D decorationRect = null; double yLoc = 0, height = 0; - for (int i = 0; i < textRuns.size(); i++) { - TextRun textRun = (TextRun)textRuns.get(i); + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; AttributedCharacterIterator runaci = textRun.getACI(); runaci.first(); - Paint paint = null; - Stroke stroke = null; - Paint strokePaint = null; - boolean visible = true; - TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO); + Paint paint = null; + Stroke stroke = null; + Paint strokePaint = null; + boolean visible = true; + TextPaintInfo tpi = (TextPaintInfo) runaci.getAttribute(PAINT_INFO); if (tpi != null) { visible = tpi.visible; if (tpi.composite != null) { g2d.setComposite(tpi.composite); } switch (decorationType) { - case TextSpanLayout.DECORATION_UNDERLINE : - paint = tpi.underlinePaint; - stroke = tpi.underlineStroke; - strokePaint = tpi.underlineStrokePaint; - break; - case TextSpanLayout.DECORATION_OVERLINE : - paint = tpi.overlinePaint; - stroke = tpi.overlineStroke; - strokePaint = tpi.overlineStrokePaint; - break; - case TextSpanLayout.DECORATION_STRIKETHROUGH : - paint = tpi.strikethroughPaint; - stroke = tpi.strikethroughStroke; - strokePaint = tpi.strikethroughStrokePaint; - break; - default: // should never get here - return; + case TextSpanLayout.DECORATION_UNDERLINE: + paint = tpi.underlinePaint; + stroke = tpi.underlineStroke; + strokePaint = tpi.underlineStrokePaint; + break; + case TextSpanLayout.DECORATION_OVERLINE: + paint = tpi.overlinePaint; + stroke = tpi.overlineStroke; + strokePaint = tpi.overlineStrokePaint; + break; + case TextSpanLayout.DECORATION_STRIKETHROUGH: + paint = tpi.strikethroughPaint; + stroke = tpi.strikethroughStroke; + strokePaint = tpi.strikethroughStrokePaint; + break; + default: // should never get here + return; } } if (textRun.isFirstRunInChunk()) { Shape s = textRun.getLayout().getDecorationOutline - (decorationType); + (decorationType); Rectangle2D r2d = s.getBounds2D(); - yLoc = r2d.getY(); + yLoc = r2d.getY(); height = r2d.getHeight(); } if (textRun.isFirstRunInChunk() || - (paint != prevPaint) || - (stroke != prevStroke) || - (strokePaint != prevStrokePaint) || - (visible != prevVisible)) { + (paint != prevPaint) || + (stroke != prevStroke) || + (strokePaint != prevStrokePaint) || + (visible != prevVisible)) { // if there is a current visible decoration, draw it now if (prevVisible && (decorationRect != null)) { if (prevPaint != null) { @@ -931,8 +930,8 @@ public class StrokingTextPainter extends BasicTextPainter { } if ((paint != null || strokePaint != null) - && !textRun.getLayout().isVertical() - && !textRun.getLayout().isOnATextPath()) { + && !textRun.getLayout().isVertical() + && !textRun.getLayout().isOnATextPath()) { // this text run should be decorated with the // specified decoration type @@ -940,20 +939,20 @@ public class StrokingTextPainter extends BasicTextPainter { // horizontal layouts Shape decorationShape = - textRun.getLayout().getDecorationOutline(decorationType); + textRun.getLayout().getDecorationOutline(decorationType); if (decorationRect == null) { // create a new one Rectangle2D r2d = decorationShape.getBounds2D(); decorationRect = new Rectangle2D.Double - (r2d.getX(), yLoc, r2d.getWidth(), height); + (r2d.getX(), yLoc, r2d.getWidth(), height); } else { // extend the current one Rectangle2D bounds = decorationShape.getBounds2D(); double minX = Math.min(decorationRect.getX(), - bounds.getX()); + bounds.getX()); double maxX = Math.max(decorationRect.getMaxX(), - bounds.getMaxX()); - decorationRect.setRect(minX, yLoc, maxX-minX, height); + bounds.getMaxX()); + decorationRect.setRect(minX, yLoc, maxX - minX, height); } } prevPaint = paint; @@ -985,12 +984,12 @@ public class StrokingTextPainter extends BasicTextPainter { */ protected void paintTextRuns(List textRuns, Graphics2D g2d) { - for (int i = 0; i < textRuns.size(); i++) { - TextRun textRun = (TextRun)textRuns.get(i); + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; AttributedCharacterIterator runaci = textRun.getACI(); runaci.first(); - TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO); + TextPaintInfo tpi = (TextPaintInfo) runaci.getAttribute(PAINT_INFO); if ((tpi != null) && (tpi.composite != null)) { g2d.setComposite(tpi.composite); } @@ -1016,14 +1015,14 @@ public class StrokingTextPainter extends BasicTextPainter { // for each text run, get its outline and append it to the overall // outline - for (int i = 0; i < textRuns.size(); ++i) { - TextRun textRun = (TextRun)textRuns.get(i); + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; TextSpanLayout textRunLayout = textRun.getLayout(); GeneralPath textRunOutline = - new GeneralPath(textRunLayout.getOutline()); + new GeneralPath(textRunLayout.getOutline()); if (outline == null) { - outline = textRunOutline; + outline = textRunOutline; } else { outline.setWindingRule(GeneralPath.WIND_NON_ZERO); outline.append(textRunOutline, false); @@ -1085,17 +1084,17 @@ public class StrokingTextPainter extends BasicTextPainter { Rectangle2D bounds = null; // for each text run, get its stroke outline and append it to // the overall outline - for (int i = 0; i < textRuns.size(); ++i) { - TextRun textRun = (TextRun)textRuns.get(i); - TextSpanLayout textRunLayout = textRun.getLayout(); - Rectangle2D runBounds = textRunLayout.getBounds2D(); - if (runBounds != null) { - if (bounds == null) - bounds = runBounds; - else - bounds.add( runBounds ); - } - } + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; + TextSpanLayout textRunLayout = textRun.getLayout(); + Rectangle2D runBounds = textRunLayout.getBounds2D(); + if (runBounds != null) { + if (bounds == null) + bounds = runBounds; + else + bounds.add(runBounds); + } + } // append any stroked decoration outlines @@ -1149,50 +1148,50 @@ public class StrokingTextPainter extends BasicTextPainter { Rectangle2D decorationRect = null; double yLoc = 0, height = 0; - for (int i = 0; i < textRuns.size(); i++) { - TextRun textRun = (TextRun)textRuns.get(i); + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; AttributedCharacterIterator runaci = textRun.getACI(); runaci.first(); Paint paint = null; Stroke stroke = null; Paint strokePaint = null; - TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO); + TextPaintInfo tpi = (TextPaintInfo) runaci.getAttribute(PAINT_INFO); if (tpi != null) { switch (decorationType) { - case TextSpanLayout.DECORATION_UNDERLINE : - paint = tpi.underlinePaint; - stroke = tpi.underlineStroke; - strokePaint = tpi.underlineStrokePaint; - break; - case TextSpanLayout.DECORATION_OVERLINE : - paint = tpi.overlinePaint; - stroke = tpi.overlineStroke; - strokePaint = tpi.overlineStrokePaint; - break; - case TextSpanLayout.DECORATION_STRIKETHROUGH : - paint = tpi.strikethroughPaint; - stroke = tpi.strikethroughStroke; - strokePaint = tpi.strikethroughStrokePaint; - break; - default: - // should never get here - return null; + case TextSpanLayout.DECORATION_UNDERLINE: + paint = tpi.underlinePaint; + stroke = tpi.underlineStroke; + strokePaint = tpi.underlineStrokePaint; + break; + case TextSpanLayout.DECORATION_OVERLINE: + paint = tpi.overlinePaint; + stroke = tpi.overlineStroke; + strokePaint = tpi.overlineStrokePaint; + break; + case TextSpanLayout.DECORATION_STRIKETHROUGH: + paint = tpi.strikethroughPaint; + stroke = tpi.strikethroughStroke; + strokePaint = tpi.strikethroughStrokePaint; + break; + default: + // should never get here + return null; } } if (textRun.isFirstRunInChunk()) { Shape s = textRun.getLayout().getDecorationOutline - (decorationType); + (decorationType); Rectangle2D r2d = s.getBounds2D(); - yLoc = r2d.getY(); + yLoc = r2d.getY(); height = r2d.getHeight(); } if (textRun.isFirstRunInChunk() || - paint != prevPaint || - stroke != prevStroke || - strokePaint != prevStrokePaint) { + paint != prevPaint || + stroke != prevStroke || + strokePaint != prevStrokePaint) { // if there is a current decoration, added it to the overall // outline @@ -1207,28 +1206,28 @@ public class StrokingTextPainter extends BasicTextPainter { } if ((paint != null || strokePaint != null) - && !textRun.getLayout().isVertical() - && !textRun.getLayout().isOnATextPath()) { + && !textRun.getLayout().isVertical() + && !textRun.getLayout().isOnATextPath()) { // this text run should be decorated with the specified // decoration type note: decorations are only supported for // plain horizontal layouts Shape decorationShape = - textRun.getLayout().getDecorationOutline(decorationType); + textRun.getLayout().getDecorationOutline(decorationType); if (decorationRect == null) { // create a new one Rectangle2D r2d = decorationShape.getBounds2D(); decorationRect = new Rectangle2D.Double - (r2d.getX(), yLoc, r2d.getWidth(), height); + (r2d.getX(), yLoc, r2d.getWidth(), height); } else { // extend the current one Rectangle2D bounds = decorationShape.getBounds2D(); double minX = Math.min(decorationRect.getX(), - bounds.getX()); + bounds.getX()); double maxX = Math.max(decorationRect.getMaxX(), - bounds.getMaxX()); - decorationRect.setRect(minX, yLoc, maxX-minX, height); + bounds.getMaxX()); + decorationRect.setRect(minX, yLoc, maxX - minX, height); } } @@ -1270,50 +1269,50 @@ public class StrokingTextPainter extends BasicTextPainter { Rectangle2D decorationRect = null; double yLoc = 0, height = 0; - for (int i = 0; i < textRuns.size(); i++) { + for (Object textRun1 : textRuns) { - TextRun textRun = (TextRun)textRuns.get(i); + TextRun textRun = (TextRun) textRun1; AttributedCharacterIterator runaci = textRun.getACI(); runaci.first(); Paint paint = null; Stroke stroke = null; Paint strokePaint = null; - TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO); + TextPaintInfo tpi = (TextPaintInfo) runaci.getAttribute(PAINT_INFO); if (tpi != null) { switch (decorationType) { - case TextSpanLayout.DECORATION_UNDERLINE : - paint = tpi.underlinePaint; - stroke = tpi.underlineStroke; - strokePaint = tpi.underlineStrokePaint; - break; - case TextSpanLayout.DECORATION_OVERLINE : - paint = tpi.overlinePaint; - stroke = tpi.overlineStroke; - strokePaint = tpi.overlineStrokePaint; - break; - case TextSpanLayout.DECORATION_STRIKETHROUGH : - paint = tpi.strikethroughPaint; - stroke = tpi.strikethroughStroke; - strokePaint = tpi.strikethroughStrokePaint; - break; - default: // should never get here - return null; + case TextSpanLayout.DECORATION_UNDERLINE: + paint = tpi.underlinePaint; + stroke = tpi.underlineStroke; + strokePaint = tpi.underlineStrokePaint; + break; + case TextSpanLayout.DECORATION_OVERLINE: + paint = tpi.overlinePaint; + stroke = tpi.overlineStroke; + strokePaint = tpi.overlineStrokePaint; + break; + case TextSpanLayout.DECORATION_STRIKETHROUGH: + paint = tpi.strikethroughPaint; + stroke = tpi.strikethroughStroke; + strokePaint = tpi.strikethroughStrokePaint; + break; + default: // should never get here + return null; } } if (textRun.isFirstRunInChunk()) { Shape s = textRun.getLayout().getDecorationOutline - (decorationType); + (decorationType); Rectangle2D r2d = s.getBounds2D(); - yLoc = r2d.getY(); + yLoc = r2d.getY(); height = r2d.getHeight(); } if (textRun.isFirstRunInChunk() || - paint != prevPaint || - stroke != prevStroke || - strokePaint != prevStrokePaint) { + paint != prevPaint || + stroke != prevStroke || + strokePaint != prevStrokePaint) { // if there is a current decoration, added it to the overall // outline @@ -1321,7 +1320,7 @@ public class StrokingTextPainter extends BasicTextPainter { Shape s = null; if (prevStroke != null && - prevStrokePaint != null) + prevStrokePaint != null) s = prevStroke.createStrokedShape(decorationRect); else if (prevPaint != null) s = decorationRect; @@ -1336,29 +1335,29 @@ public class StrokingTextPainter extends BasicTextPainter { } if ((paint != null || strokePaint != null) - && !textRun.getLayout().isVertical() - && !textRun.getLayout().isOnATextPath()) { + && !textRun.getLayout().isVertical() + && !textRun.getLayout().isOnATextPath()) { // this text run should be decorated with the specified // decoration type note: decorations are only supported for // plain horizontal layouts Shape decorationShape = - textRun.getLayout().getDecorationOutline(decorationType); + textRun.getLayout().getDecorationOutline(decorationType); if (decorationRect == null) { // create a new one Rectangle2D r2d = decorationShape.getBounds2D(); decorationRect = new Rectangle2D.Double - (r2d.getX(), yLoc, r2d.getWidth(), height); + (r2d.getX(), yLoc, r2d.getWidth(), height); } else { // extend the current one Rectangle2D bounds = decorationShape.getBounds2D(); double minX = Math.min(decorationRect.getX(), - bounds.getX()); + bounds.getX()); double maxX = Math.max(decorationRect.getMaxX(), - bounds.getMaxX()); - decorationRect.setRect(minX, yLoc, maxX-minX, height); + bounds.getMaxX()); + decorationRect.setRect(minX, yLoc, maxX - minX, height); } } @@ -1412,14 +1411,14 @@ public class StrokingTextPainter extends BasicTextPainter { List textRuns = getTextRuns(node, aci); if (textRuns != null) { // for each text run, see if its been hit - for (int i = 0; i < textRuns.size(); ++i) { - TextRun textRun = (TextRun)textRuns.get(i); + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; TextSpanLayout layout = textRun.getLayout(); TextHit textHit = layout.hitTestChar((float) x, (float) y); Rectangle2D bounds = layout.getBounds2D(); - if ((textHit != null) && - (bounds != null) && bounds.contains(x,y)) - return new BasicTextPainter.BasicMark(node, textHit); + if ((textHit != null) && + (bounds != null) && bounds.contains(x, y)) + return new BasicMark(node, textHit); } } @@ -1471,7 +1470,7 @@ public class StrokingTextPainter extends BasicTextPainter { start = (BasicTextPainter.BasicMark) startMark; finish = (BasicTextPainter.BasicMark) finishMark; } catch (ClassCastException cce) { - throw new Error + throw new RuntimeException ("This Mark was not instantiated by this TextPainter class!"); } @@ -1479,7 +1478,7 @@ public class StrokingTextPainter extends BasicTextPainter { if (textNode == null) return null; if (textNode != finish.getTextNode()) - throw new Error("Markers are from different TextNodes!"); + throw new RuntimeException("Markers are from different TextNodes!"); AttributedCharacterIterator aci; aci = textNode.getAttributedCharacterIterator(); @@ -1556,7 +1555,7 @@ public class StrokingTextPainter extends BasicTextPainter { begin = (BasicTextPainter.BasicMark) beginMark; end = (BasicTextPainter.BasicMark) endMark; } catch (ClassCastException cce) { - throw new Error + throw new RuntimeException ("This Mark was not instantiated by this TextPainter class!"); } @@ -1564,7 +1563,7 @@ public class StrokingTextPainter extends BasicTextPainter { if (textNode == null) return null; if (textNode != end.getTextNode()) - throw new Error("Markers are from different TextNodes!"); + throw new RuntimeException("Markers are from different TextNodes!"); AttributedCharacterIterator aci; aci = textNode.getAttributedCharacterIterator(); @@ -1589,17 +1588,17 @@ public class StrokingTextPainter extends BasicTextPainter { // for each text run, append any highlight it may contain for // the current selection - for (int i = 0; i < textRuns.size(); ++i) { - TextRun textRun = (TextRun)textRuns.get(i); + for (Object textRun1 : textRuns) { + TextRun textRun = (TextRun) textRun1; TextSpanLayout layout = textRun.getLayout(); Shape layoutHighlightedShape = layout.getHighlightShape - (beginIndex, endIndex); + (beginIndex, endIndex); // append the highlighted shape of this layout to the // overall hightlighted shape - if (( layoutHighlightedShape != null) && - (!layoutHighlightedShape.getBounds().isEmpty())) { + if ((layoutHighlightedShape != null) && + (!layoutHighlightedShape.getBounds().isEmpty())) { highlightedShape.append(layoutHighlightedShape, false); } } @@ -1608,7 +1607,7 @@ public class StrokingTextPainter extends BasicTextPainter { // inner classes - public class TextChunk { + public static class TextChunk { // the following denote indices of text runs over all chunks of text node, // where index 0 is first run of first chunk of text node; the begin index @@ -1632,7 +1631,7 @@ public class StrokingTextPainter extends BasicTextPainter { * Inner convenience class for associating a TextLayout for * sub-spans, and the ACI which iterates over that subspan. */ - public class TextRun { + public static class TextRun { protected AttributedCharacterIterator aci; // source aci protected TextSpanLayout layout; // layout object @@ -1677,7 +1676,7 @@ public class StrokingTextPainter extends BasicTextPainter { Integer level = (Integer) aci.getAttribute(BIDI_LEVEL); if (level != null) { - this.level = level.intValue(); + this.level = level; } else { this.level = -1; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextNode.java index e70106171..d6938ca6a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextNode.java @@ -297,7 +297,7 @@ public class TextNode extends AbstractGraphicsNode implements Selectable { public void setSelection(Mark begin, Mark end) { if ((begin.getTextNode() != this) || (end.getTextNode() != this)) - throw new Error("Markers not from this TextNode"); + throw new RuntimeException("Markers not from this TextNode"); beginMark = begin; endMark = end; @@ -421,12 +421,12 @@ public class TextNode extends AbstractGraphicsNode implements Selectable { } List list = getTextRuns(); // place coords in text node coordinate system - for (int i = 0 ; i < list.size(); i++) { + for (Object aList : list) { StrokingTextPainter.TextRun run = - (StrokingTextPainter.TextRun)list.get(i); + (StrokingTextPainter.TextRun) aList; TextSpanLayout layout = run.getLayout(); - float x = (float)p.getX(); - float y = (float)p.getY(); + float x = (float) p.getX(); + float y = (float) p.getY(); TextHit textHit = layout.hitTestChar(x, y); if (textHit != null && contains(p, layout.getBounds2D())) { return true; @@ -534,7 +534,7 @@ public class TextNode extends AbstractGraphicsNode implements Selectable { case ANCHOR_END: return END; default: - throw new Error("Unknown Anchor type"); + throw new RuntimeException("Unknown Anchor type"); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextSpanLayout.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextSpanLayout.java index 9123882c6..ddf26a512 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextSpanLayout.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextSpanLayout.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextUtilities.java index 5456f5113..bb05ec35c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/TextUtilities.java @@ -78,8 +78,8 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { StringTokenizer st = new StringTokenizer(valueStr, ", ", false); while (st.hasMoreTokens()) { values.add - (new Float(UnitProcessor.svgHorizontalCoordinateToUserSpace - (st.nextToken(), attrName, uctx))); + (UnitProcessor.svgHorizontalCoordinateToUserSpace + (st.nextToken(), attrName, uctx)); } return values; } @@ -104,8 +104,8 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { StringTokenizer st = new StringTokenizer(valueStr, ", ", false); while (st.hasMoreTokens()) { values.add - (new Float(UnitProcessor.svgVerticalCoordinateToUserSpace - (st.nextToken(), attrName, uctx))); + (UnitProcessor.svgVerticalCoordinateToUserSpace + (st.nextToken(), attrName, uctx)); } return values; } @@ -123,8 +123,8 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { try { s = st.nextToken(); values.add - (new Float(Math.toRadians - (SVGUtilities.convertSVGNumber(s)))); + ((float) Math.toRadians + (SVGUtilities.convertSVGNumber(s))); } catch (NumberFormatException nfEx ) { throw new BridgeException (ctx, element, nfEx, ERR_ATTRIBUTE_VALUE_MALFORMED, @@ -141,7 +141,7 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { public static Float convertFontSize(Element e) { Value v = CSSUtilities.getComputedStyle (e, SVGCSSEngine.FONT_SIZE_INDEX); - return new Float(v.getFloatValue()); + return v.getFloatValue(); } /** @@ -282,7 +282,7 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { return null; } } else { - return new Float(v.getFloatValue()); + return v.getFloatValue(); } } @@ -297,7 +297,7 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { return null; } - return new Float(v.getFloatValue()); + return v.getFloatValue(); } /** @@ -311,7 +311,7 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { return null; } - return new Float(v.getFloatValue()); + return v.getFloatValue(); } /** @@ -325,6 +325,6 @@ public abstract class TextUtilities implements CSSConstants, ErrorConstants { if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { return null; } - return new Float(v.getFloatValue()); + return v.getFloatValue(); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/URIResolver.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/URIResolver.java index eaed0f3cf..60b48e5be 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/URIResolver.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/URIResolver.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.net.MalformedURLException; import org.apache.batik.anim.dom.SVGOMDocument; -import org.apache.batik.dom.AbstractNode; import org.apache.batik.util.ParsedURL; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -143,7 +142,7 @@ public class URIResolver { * Returns the base URI of the referer element. */ protected String getRefererBaseURI(Element ref) { - return ((AbstractNode) ref).getBaseURI(); + return ref.getBaseURI(); } /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UpdateManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UpdateManager.java index c5e6d7767..8fb95d39b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UpdateManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UpdateManager.java @@ -39,7 +39,7 @@ import org.apache.batik.gvt.RootGraphicsNode; import org.apache.batik.gvt.UpdateTracker; import org.apache.batik.gvt.renderer.ImageRenderer; import org.apache.batik.util.EventDispatcher; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.util.EventDispatcher.Dispatcher; import org.apache.batik.util.RunnableQueue; import org.w3c.dom.Document; @@ -171,7 +171,7 @@ public class UpdateManager { // primary document also need to have their scripting // environments initialized. secondaryBridgeContexts = - (BridgeContext[]) ctx.getChildContexts().clone(); + ctx.getChildContexts().clone(); secondaryScriptingEnvironments = new ScriptingEnvironment[secondaryBridgeContexts.length]; for (int i = 0; i < secondaryBridgeContexts.length; i++) { @@ -602,7 +602,7 @@ public class UpdateManager { outOfDateTime = 0; } - protected class SuspensionInfo { + protected static class SuspensionInfo { /** * The index of this redraw suspension */ @@ -621,7 +621,7 @@ public class UpdateManager { public long getResumeMilli() { return resumeMilli; } } - protected class RepaintTimerTask extends TimerTask { + protected static class RepaintTimerTask extends TimerTask { UpdateManager um; RepaintTimerTask(UpdateManager um) { this.um = um; @@ -675,7 +675,7 @@ public class UpdateManager { int addRedrawSuspension(int max_wait_milliseconds) { long resumeTime = System.currentTimeMillis() + max_wait_milliseconds; SuspensionInfo si = new SuspensionInfo(nextSuspensionIndex++, - resumeTime); + resumeTime); if (resumeTime > allResumeTime) { allResumeTime = resumeTime; // System.err.println("Added AllRes Time: " + allResumeTime); @@ -729,9 +729,8 @@ public class UpdateManager { long findNewAllResumeTime() { long ret = -1; - Iterator i = suspensionList.iterator(); - while (i.hasNext()) { - SuspensionInfo si = (SuspensionInfo)i.next(); + for (Object aSuspensionList : suspensionList) { + SuspensionInfo si = (SuspensionInfo) aSuspensionList; long t = si.getResumeMilli(); if (t > ret) ret = t; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgent.java index 25aaba0ee..c4d9f5766 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgent.java @@ -18,18 +18,17 @@ */ package org.apache.batik.bridge; -import java.awt.Cursor; -import java.awt.Point; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; - import org.apache.batik.gvt.event.EventDispatcher; import org.apache.batik.util.ParsedURL; - import org.w3c.dom.Element; import org.w3c.dom.svg.SVGAElement; import org.w3c.dom.svg.SVGDocument; +import java.awt.Cursor; +import java.awt.Point; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; + /** * An interface that provides access to the User Agent informations * needed by the bridge. @@ -293,7 +292,7 @@ public interface UserAgent { * can't be loaded. If it returns 'null' then a BridgeException will * be thrown. * - * @param e The <image> element that can't be loaded. + * @param e The <image> element that can't be loaded. * @param url The resolved url that can't be loaded. * @param message As best as can be determined the reason it can't be * loaded (not available, corrupt, unknown format, ...). @@ -308,5 +307,5 @@ public interface UserAgent { void loadDocument(String url); /** Returns the Font Family Resolver */ - public FontFamilyResolver getFontFamilyResolver(); + FontFamilyResolver getFontFamilyResolver(); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgentAdapter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgentAdapter.java index e31330d07..d163acf3e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgentAdapter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/UserAgentAdapter.java @@ -437,7 +437,7 @@ public class UserAgentAdapter implements UserAgent { /** * This Implementation simply throws a BridgeException. * - * @param e The <image> element that can't be loaded. + * @param e The <image> element that can't be loaded. * @param url The resolved url that can't be loaded. * @param message As best as can be determined the reason it can't be * loaded (not available, corrupt, unknown format,...). diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Viewport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Viewport.java index c0c02578f..cb5b9c34f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Viewport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Viewport.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Window.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Window.java index 3bcd98036..02edc1c73 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Window.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/Window.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; @@ -31,7 +31,8 @@ import org.w3c.dom.Node; * @author Stephane Hillion * @version $Id$ */ -public interface Window extends org.apache.batik.w3c.dom.Window { +public interface Window extends org.apache.batik.w3c.dom.Window +{ /** * Evaluates the given string repeatedly after the given amount of * time. This method does not stall the script: the evaluation is diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/WindowWrapper.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/WindowWrapper.java index 0a35adfc7..0fbe4083d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/WindowWrapper.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/WindowWrapper.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge; @@ -93,7 +93,7 @@ public class WindowWrapper extends ImporterTopLevel { if (len < 2) { throw Context.reportRuntimeError("invalid argument count"); } - long to = ((Long)Context.jsToJava(args[1], Long.TYPE)).longValue(); + long to = (Long) Context.jsToJava(args[1], Long.TYPE); if (args[0] instanceof Function) { RhinoInterpreter interp = (RhinoInterpreter)window.getInterpreter(); @@ -120,7 +120,7 @@ public class WindowWrapper extends ImporterTopLevel { if (len < 2) { throw Context.reportRuntimeError("invalid argument count"); } - long to = ((Long)Context.jsToJava(args[1], Long.TYPE)).longValue(); + long to = (Long) Context.jsToJava(args[1], Long.TYPE); if (args[0] instanceof Function) { RhinoInterpreter interp = (RhinoInterpreter)window.getInterpreter(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/AbstractContentSelector.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/AbstractContentSelector.java index f1bc6c569..cbaf6df12 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/AbstractContentSelector.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/AbstractContentSelector.java @@ -122,7 +122,7 @@ public abstract class AbstractContentSelector { /** * An interface for content selector factories. */ - protected static interface ContentSelectorFactory { + protected interface ContentSelectorFactory { /** * Creates a new selector object. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/ContentManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/ContentManager.java index 90e027a58..1b0c65588 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/ContentManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/ContentManager.java @@ -32,7 +32,7 @@ import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.events.NodeEventTarget; import org.apache.batik.dom.xbl.XBLManager; import org.apache.batik.util.XBLConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Attr; import org.w3c.dom.Element; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/DefaultXBLManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/DefaultXBLManager.java index a4033121a..eb5ac45fb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/DefaultXBLManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/DefaultXBLManager.java @@ -50,7 +50,7 @@ import org.apache.batik.dom.xbl.XBLManagerData; import org.apache.batik.dom.xbl.XBLShadowTreeElement; import org.apache.batik.util.DoublyIndexedTable; import org.apache.batik.util.XBLConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Attr; import org.w3c.dom.Document; @@ -200,19 +200,19 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { docSubtreeListener, true); // Add definitions. - for (int i = 0; i < defs.length; i++) { - if (defs[i].getAttributeNS(null, XBL_REF_ATTRIBUTE).length() != 0) { - addDefinitionRef(defs[i]); + for (XBLOMDefinitionElement def : defs) { + if (def.getAttributeNS(null, XBL_REF_ATTRIBUTE).length() != 0) { + addDefinitionRef(def); } else { - String ns = defs[i].getElementNamespaceURI(); - String ln = defs[i].getElementLocalName(); - addDefinition(ns, ln, defs[i], null); + String ns = def.getElementNamespaceURI(); + String ln = def.getElementLocalName(); + addDefinition(ns, ln, def, null); } } // Add imports. - for (int i = 0; i < imports.length; i++) { - addImport(imports[i]); + for (Element anImport : imports) { + addImport(anImport); } // Bind all of the bindable elements in the document that have a @@ -250,8 +250,7 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { int nSlots = imports.values().size(); ImportRecord[] irs = new ImportRecord[ nSlots ]; imports.values().toArray( irs ); - for (int i = 0; i < irs.length; i++) { - ImportRecord ir = irs[i]; + for (ImportRecord ir : irs) { if (ir.importElement.getLocalName().equals(XBL_DEFINITION_TAG)) { removeDefinitionRef(ir.importElement); } else { @@ -262,10 +261,10 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { // Remove all bindings. Object[] defRecs = definitions.getValuesArray(); definitions.clear(); - for (int i = 0; i < defRecs.length; i++) { - DefinitionRecord defRec = (DefinitionRecord) defRecs[i]; + for (Object defRec1 : defRecs) { + DefinitionRecord defRec = (DefinitionRecord) defRec1; TreeSet defs = (TreeSet) definitionLists.get(defRec.namespaceURI, - defRec.localName); + defRec.localName); if (defs != null) { while (!defs.isEmpty()) { defRec = (DefinitionRecord) defs.first(); @@ -403,8 +402,8 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { importAttrListener, false); Object[] defRecs = definitions.getValuesArray(); - for (int i = 0; i < defRecs.length; i++) { - DefinitionRecord defRec = (DefinitionRecord) defRecs[i]; + for (Object defRec1 : defRecs) { + DefinitionRecord defRec = (DefinitionRecord) defRec1; if (defRec.importElement == imp) { removeDefinition(defRec); } @@ -448,7 +447,7 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { } } defRec = new DefinitionRecord(namespaceURI, localName, def, - template, imp); + template, imp); defs.add(defRec); definitions.put(def, imp, defRec); addDefinitionElementListeners(def, ir); @@ -1187,7 +1186,7 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { /** * Record class for storing information about an XBL definition. */ - protected class DefinitionRecord implements Comparable { + protected static class DefinitionRecord implements Comparable { /** * The namespace URI. @@ -1377,7 +1376,7 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { /** * DOM node removed listener for imported XBL trees. */ - protected class ImportRemovedListener implements EventListener { + protected static class ImportRemovedListener implements EventListener { /** * List of definition elements to be removed from the document. @@ -1422,10 +1421,10 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { public void handleEvent(Event evt) { Object[] defs = importRemovedListener.toBeRemoved.toArray(); importRemovedListener.toBeRemoved.clear(); - for (int i = 0; i < defs.length; i++) { - XBLOMDefinitionElement def = (XBLOMDefinitionElement) defs[i]; + for (Object def1 : defs) { + XBLOMDefinitionElement def = (XBLOMDefinitionElement) def1; DefinitionRecord defRec - = (DefinitionRecord) definitions.get(def, importElement); + = (DefinitionRecord) definitions.get(def, importElement); removeDefinition(defRec); } } @@ -1542,11 +1541,11 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { public void handleEvent(Event evt) { Object[] defs = docRemovedListener.defsToBeRemoved.toArray(); docRemovedListener.defsToBeRemoved.clear(); - for (int i = 0; i < defs.length; i++) { - XBLOMDefinitionElement def = (XBLOMDefinitionElement) defs[i]; + for (Object def1 : defs) { + XBLOMDefinitionElement def = (XBLOMDefinitionElement) def1; if (def.getAttributeNS(null, XBL_REF_ATTRIBUTE).length() == 0) { DefinitionRecord defRec - = (DefinitionRecord) definitions.get(def, null); + = (DefinitionRecord) definitions.get(def, null); removeDefinition(defRec); } else { removeDefinitionRef(def); @@ -1555,14 +1554,14 @@ public class DefaultXBLManager implements XBLManager, XBLConstants { Object[] imps = docRemovedListener.importsToBeRemoved.toArray(); docRemovedListener.importsToBeRemoved.clear(); - for (int i = 0; i < imps.length; i++) { - removeImport((Element) imps[i]); + for (Object imp : imps) { + removeImport((Element) imp); } Object[] nodes = docRemovedListener.nodesToBeInvalidated.toArray(); docRemovedListener.nodesToBeInvalidated.clear(); - for (int i = 0; i < nodes.length; i++) { - invalidateChildNodes((Node) nodes[i]); + for (Object node : nodes) { + invalidateChildNodes((Node) node); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeContext.java index 3bf735ffd..e5cf1f050 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeContext.java @@ -18,8 +18,6 @@ */ package org.apache.batik.bridge.svg12; -import java.util.Iterator; - import org.apache.batik.anim.dom.SVGOMDocument; import org.apache.batik.anim.dom.XBLEventSupport; import org.apache.batik.anim.dom.XBLOMShadowTreeElement; @@ -39,7 +37,7 @@ import org.apache.batik.dom.xbl.XBLManager; import org.apache.batik.script.Interpreter; import org.apache.batik.script.InterpreterPool; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -136,21 +134,20 @@ public class SVG12BridgeContext extends BridgeContext { synchronized (eventListenerSet) { // remove all listeners added by Bridges - Iterator iter = eventListenerSet.iterator(); - while (iter.hasNext()) { - EventListenerMememto m = (EventListenerMememto)iter.next(); + for (Object anEventListenerSet : eventListenerSet) { + EventListenerMememto m = (EventListenerMememto) anEventListenerSet; NodeEventTarget et = m.getTarget(); - EventListener el = m.getListener(); - boolean uc = m.getUseCapture(); - String t = m.getEventType(); - boolean in = m.getNamespaced(); + EventListener el = m.getListener(); + boolean uc = m.getUseCapture(); + String t = m.getEventType(); + boolean in = m.getNamespaced(); if (et == null || el == null || t == null) { continue; } if (m instanceof ImplementationEventListenerMememto) { String ns = m.getNamespaceURI(); - Node nde = (Node)et; - AbstractNode n = (AbstractNode)nde.getOwnerDocument(); + Node nde = (Node) et; + AbstractNode n = (AbstractNode) nde.getOwnerDocument(); if (n != null) { XBLEventSupport es; es = (XBLEventSupport) n.initializeEventSupport(); @@ -175,9 +172,8 @@ public class SVG12BridgeContext extends BridgeContext { animationEngine = null; } - Iterator iter = interpreterMap.values().iterator(); - while (iter.hasNext()) { - Interpreter interpreter = (Interpreter)iter.next(); + for (Object o : interpreterMap.values()) { + Interpreter interpreter = (Interpreter) o; if (interpreter != null) interpreter.dispose(); } @@ -249,8 +245,8 @@ public class SVG12BridgeContext extends BridgeContext { "DOMNodeRemoved", domNodeRemovedEventListener, true); - domCharacterDataModifiedEventListener = - new EventListenerWrapper(new DOMCharacterDataModifiedEventListener()); + domCharacterDataModifiedEventListener = + new EventListenerWrapper(new DOMCharacterDataModifiedEventListener()); evtSupport.addImplementationEventListenerNS (XMLConstants.XML_EVENTS_NAMESPACE_URI, "DOMCharacterDataModified", @@ -315,15 +311,14 @@ public class SVG12BridgeContext extends BridgeContext { XBLEventSupport es = (XBLEventSupport) n.initializeEventSupport(); synchronized (eventListenerSet) { - Iterator i = eventListenerSet.iterator(); - while (i.hasNext()) { - EventListenerMememto elm = (EventListenerMememto)i.next(); + for (Object anEventListenerSet : eventListenerSet) { + EventListenerMememto elm = (EventListenerMememto) anEventListenerSet; NodeEventTarget et = elm.getTarget(); if (et == evtTarget) { EventListener el = elm.getListener(); - boolean uc = elm.getUseCapture(); - String t = elm.getEventType(); - boolean in = elm.getNamespaced(); + boolean uc = elm.getUseCapture(); + String t = elm.getEventType(); + boolean in = elm.getNamespaced(); if (et == null || el == null || t == null) { continue; } @@ -472,7 +467,7 @@ public class SVG12BridgeContext extends BridgeContext { * Wrapper for DOM event listeners so that they will see only * original events (i.e., not retargetted). */ - protected class EventListenerWrapper implements EventListener { + protected static class EventListenerWrapper implements EventListener { /** * The wrapped listener. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeEventSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeEventSupport.java index 9b8911ae4..5854c9581 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeEventSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12BridgeEventSupport.java @@ -20,13 +20,11 @@ package org.apache.batik.bridge.svg12; import java.awt.Point; import java.awt.event.KeyEvent; -import java.awt.geom.Point2D; import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.BridgeEventSupport; import org.apache.batik.bridge.FocusManager; import org.apache.batik.bridge.UserAgent; -import org.apache.batik.dom.events.AbstractEvent; import org.apache.batik.dom.events.DOMKeyboardEvent; import org.apache.batik.dom.events.DOMMouseEvent; import org.apache.batik.dom.events.DOMTextEvent; @@ -39,7 +37,7 @@ import org.apache.batik.gvt.event.GraphicsNodeKeyEvent; import org.apache.batik.gvt.event.GraphicsNodeMouseEvent; import org.apache.batik.gvt.event.GraphicsNodeMouseWheelEvent; import org.apache.batik.gvt.event.GraphicsNodeMouseWheelListener; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -811,7 +809,7 @@ public abstract class SVG12BridgeEventSupport extends BridgeEventSupport { (EventTarget) relatedElement, modifiers); - ((AbstractEvent) mouseEvt).setBubbleLimit(bubbleLimit); + mouseEvt.setBubbleLimit(bubbleLimit); try { ((EventTarget) targetElement).dispatchEvent(mouseEvt); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12FocusManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12FocusManager.java index 78c6faa73..ea7742cc4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12FocusManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12FocusManager.java @@ -21,10 +21,9 @@ package org.apache.batik.bridge.svg12; import org.apache.batik.anim.dom.XBLEventSupport; import org.apache.batik.bridge.FocusManager; import org.apache.batik.dom.AbstractNode; -import org.apache.batik.dom.events.AbstractEvent; import org.apache.batik.dom.events.DOMUIEvent; import org.apache.batik.dom.events.EventSupport; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -173,7 +172,7 @@ public class SVG12FocusManager extends FocusManager { 0); // detailArg int limit = DefaultXBLManager.computeBubbleLimit((Node) relatedTarget, (Node) target); - ((AbstractEvent) uiEvt).setBubbleLimit(limit); + uiEvt.setBubbleLimit(limit); target.dispatchEvent(uiEvt); } @@ -196,7 +195,7 @@ public class SVG12FocusManager extends FocusManager { 0); // detailArg int limit = DefaultXBLManager.computeBubbleLimit((Node) target, (Node) relatedTarget); - ((AbstractEvent) uiEvt).setBubbleLimit(limit); + uiEvt.setBubbleLimit(limit); target.dispatchEvent(uiEvt); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12ScriptingEnvironment.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12ScriptingEnvironment.java index 8a42d0231..44ec69f6d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12ScriptingEnvironment.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12ScriptingEnvironment.java @@ -33,7 +33,7 @@ import org.apache.batik.dom.util.TriplyIndexedTable; import org.apache.batik.script.Interpreter; import org.apache.batik.util.SVGConstants; import org.apache.batik.util.SVG12Constants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.events.Event; @@ -161,7 +161,7 @@ public class SVG12ScriptingEnvironment extends ScriptingEnvironment { String prefix = DOMUtilities.getPrefix(eventType); eventType = DOMUtilities.getLocalName(eventType); eventNamespaceURI - = ((AbstractElement) elt).lookupNamespaceURI(prefix); + = elt.lookupNamespaceURI(prefix); } EventListener listener = new HandlerScriptingEventListener @@ -197,7 +197,7 @@ public class SVG12ScriptingEnvironment extends ScriptingEnvironment { String prefix = DOMUtilities.getPrefix(eventType); eventType = DOMUtilities.getLocalName(eventType); eventNamespaceURI - = ((AbstractElement) elt).lookupNamespaceURI(prefix); + = elt.lookupNamespaceURI(prefix); } EventListener listener = @@ -263,7 +263,7 @@ public class SVG12ScriptingEnvironment extends ScriptingEnvironment { new Object [] {d.getDocumentURI(), eventNamespaceURI, eventType, - new Integer(line)}); + line}); // Find the scripting language String lang = handlerElement.getAttributeNS diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12TextElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12TextElementBridge.java index 4fdaf0131..ca49b9333 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12TextElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVG12TextElementBridge.java @@ -26,7 +26,7 @@ import org.apache.batik.dom.AbstractNode; import org.apache.batik.dom.events.EventSupport; import org.apache.batik.dom.events.NodeEventTarget; import org.apache.batik.dom.xbl.NodeXBL; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.Node; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java index 47ce1f4fd..bdee7bc03 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.bridge.svg12; @@ -29,7 +29,6 @@ import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.LinkedList; import java.util.Map; @@ -73,13 +72,13 @@ import org.apache.batik.gvt.text.TextPaintInfo; import org.apache.batik.gvt.text.TextPath; import org.apache.batik.util.SVG12Constants; import org.apache.batik.util.SVG12CSSConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; /** - * Bridge class for the <flowRoot> element. + * Bridge class for the <flowRoot> element. * * @author Thomas DeWeese * @version $Id$ @@ -141,7 +140,7 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { protected RegionChangeListener regionChangeListener; /** - * Constructs a new bridge for the <flowRoot> element. + * Constructs a new bridge for the <flowRoot> element. */ public SVGFlowRootElementBridge() {} @@ -439,7 +438,7 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { ch = aci.next()) { chars.append( ch ).append( ' ' ).append( ' ' ); - int w = ((Integer)aci.getAttribute(WORD_LIMIT)).intValue(); + int w = (Integer) aci.getAttribute(WORD_LIMIT); brkStr.append( w ).append( ' ' ); if (w < 10) { // for small values append another ' ' @@ -509,13 +508,13 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { (ctx, e, true, null, null, asb, lnLocs); paraElems.add(e); - paraEnds.add(new Integer(asb.length())); + paraEnds.add(asb.length()); } else if (ln.equals(SVG12Constants.SVG_FLOW_REGION_BREAK_TAG)) { fillAttributedStringBuffer (ctx, e, true, null, null, asb, lnLocs); paraElems.add(e); - paraEnds.add(new Integer(asb.length())); + paraEnds.add(asb.length()); } } divTPI.startChar = 0; @@ -530,16 +529,15 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { // Note: The Working Group (in conjunction with XHTML working // group) has decided that multiple line elements collapse. int prevLN = 0; - Iterator lnIter = lnLocs.iterator(); - while (lnIter.hasNext()) { - int nextLN = ((Integer)lnIter.next()).intValue(); + for (Object lnLoc : lnLocs) { + int nextLN = (Integer) lnLoc; if (nextLN == prevLN) continue; // System.out.println("Attr: [" + prevLN + "," + nextLN + "]"); ret.addAttribute(FLOW_LINE_BREAK, - new Object(), - prevLN, nextLN); - prevLN = nextLN; + new Object(), + prevLN, nextLN); + prevLN = nextLN; } int start=0; @@ -547,7 +545,7 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { List emptyPara = null; for (int i=0; i= 0)) { Integer i = (Integer)lnLocs.get(idx); - if (i.intValue() == len) { + if (i == len) { prevEndsWithSpace = true; } } @@ -706,7 +704,7 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { // System.out.println("Line: " + asb.length() + // " - '" + asb + "'"); lineBreak = asb.length(); - lnLocs.add(new Integer(lineBreak)); + lnLocs.add(lineBreak); if (before != lineBreak) { initialAttributes = null; } @@ -791,13 +789,13 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { int len = asb.length(); if (idx >= 0) { Integer i = (Integer)lnLocs.get(idx); - if (i.intValue() >= len) { - i = new Integer(len-1); + if (i >= len) { + i = len - 1; lnLocs.set(idx, i); idx--; while (idx >= 0) { i = (Integer)lnLocs.get(idx); - if (i.intValue() < len-1) + if (i < len-1) break; lnLocs.remove(idx); idx--; @@ -808,11 +806,10 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { strippedSome = true; } if (strippedSome) { - Iterator iter = elemTPI.values().iterator(); - while (iter.hasNext()) { - TextPaintInfo tpi = (TextPaintInfo)iter.next(); + for (Object o1 : elemTPI.values()) { + TextPaintInfo tpi = (TextPaintInfo) o1; if (tpi.endChar >= asb.length()) { - tpi.endChar = asb.length()-1; + tpi.endChar = asb.length() - 1; if (tpi.startChar > tpi.endChar) tpi.startChar = tpi.endChar; } @@ -834,9 +831,9 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { Map inheritingMap = super.getAttributeMap(ctx, element, textPath, bidiLevel, result); - float fontSize = TextUtilities.convertFontSize(element).floatValue(); + float fontSize = TextUtilities.convertFontSize(element); float lineHeight = getLineHeight(ctx, element, fontSize); - result.put(LINE_HEIGHT, new Float(lineHeight)); + result.put(LINE_HEIGHT, lineHeight); return inheritingMap; } @@ -923,7 +920,7 @@ public class SVGFlowRootElementBridge extends SVG12TextElementBridge { Map fontAttrs = new HashMap(20); List fontList = getFontList(ctx, element, fontAttrs); Float fs = (Float)fontAttrs.get(TextAttribute.SIZE); - float fontSize = fs.floatValue(); + float fontSize = fs; float lineHeight = getLineHeight(ctx, element, fontSize); String ln = element.getLocalName(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGMultiImageElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGMultiImageElementBridge.java index 54aa69e6c..6d9921ec7 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGMultiImageElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGMultiImageElementBridge.java @@ -52,7 +52,7 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** - * Bridge class for the <multiImage> element. + * Bridge class for the <multiImage> element. * * The 'multiImage' element is similar to the 'image' element (supports * all the same attributes and properties) except. @@ -392,17 +392,17 @@ public class SVGMultiImageElementBridge extends SVGImageElementBridge { if (vals[0] == null) return null; - float xPixSz = vals[0].floatValue(); + float xPixSz = vals[0]; float yPixSz = xPixSz; if (vals[1] != null) - yPixSz = vals[1].floatValue(); + yPixSz = vals[1]; return new Dimension((int)(bounds.getWidth()/xPixSz+0.5), (int)(bounds.getHeight()/yPixSz+0.5)); } /** - * A viewport defined an <svg> element. + * A viewport defined an <svg> element. */ public static class MultiImageElementViewport implements Viewport { private float width; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java index a8cd7a76b..6c9b86779 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java @@ -53,7 +53,7 @@ public class SVGSolidColorElementBridge extends AnimatableGenericSVGBridge implements PaintBridge { /** - * Constructs a new bridge for the <rect> element. + * Constructs a new bridge for the <rect> element. */ public SVGSolidColorElementBridge() { /* nothing */ } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLConstants.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/constants/XMLConstants.java similarity index 96% rename from fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLConstants.java rename to fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/constants/XMLConstants.java index bc1efc372..25c43b0df 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLConstants.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/constants/XMLConstants.java @@ -16,13 +16,13 @@ limitations under the License. */ -package org.apache.batik.util; +package org.apache.batik.constants; /** * Contains common XML constants. * * @author Vincent Hardy - * @version $Id$ + * @version $Id: XMLConstants.java 1733416 2016-03-03 07:07:13Z gadams $ */ public interface XMLConstants { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMValue.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMValue.java index 72725a30f..656e86503 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMValue.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMValue.java @@ -726,7 +726,7 @@ public class CSSOMValue /** * This class provides an abstract implementation of a ModificationHandler. */ - public abstract class AbstractModificationHandler + public abstract static class AbstractModificationHandler implements ModificationHandler { /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMViewCSS.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMViewCSS.java index f9e4772aa..370c3f7ec 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMViewCSS.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/dom/CSSOMViewCSS.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.dom; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/CSSEngine.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/CSSEngine.java index a8a1cca33..8483a408e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/CSSEngine.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/CSSEngine.java @@ -679,8 +679,7 @@ public abstract class CSSEngine { if (pseudoElementNames != null) { int len = pseudoElementNames.length; - for (int i = 0; i < len; i++) { - String pe = pseudoElementNames[i]; + for (String pe : pseudoElementNames) { sm = srceng.getCascadedStyleMap(csrc, pe); cdest.setComputedStyleMap(pe, sm); } @@ -787,14 +786,14 @@ public abstract class CSSEngine { int slen = snodes.size(); if (slen > 0) { ArrayList rules = new ArrayList(); - for (int i = 0; i < slen; i++) { - CSSStyleSheetNode ssn = (CSSStyleSheetNode)snodes.get(i); + for (Object snode : snodes) { + CSSStyleSheetNode ssn = (CSSStyleSheetNode) snode; StyleSheet ss = ssn.getCSSStyleSheet(); if (ss != null && - (!ss.isAlternate() || - ss.getTitle() == null || - ss.getTitle().equals(alternateStyleSheet)) && - mediaMatch(ss.getMedia())) { + (!ss.isAlternate() || + ss.getTitle() == null || + ss.getTitle().equals(alternateStyleSheet)) && + mediaMatch(ss.getMedia())) { addMatchingRules(rules, ss, elt, pseudo); } } @@ -918,9 +917,9 @@ public abstract class CSSEngine { // Find all the style-sheets in the document. findStyleSheetNodes(document); int len = styleSheetNodes.size(); - for (int i = 0; i < len; i++) { + for (Object styleSheetNode : styleSheetNodes) { CSSStyleSheetNode ssn; - ssn = (CSSStyleSheetNode)styleSheetNodes.get(i); + ssn = (CSSStyleSheetNode) styleSheetNode; StyleSheet ss = ssn.getCSSStyleSheet(); if (ss != null) { findSelectorAttributes(selectorAttributes, ss); @@ -1345,21 +1344,21 @@ public abstract class CSSEngine { int rlen = rules.size(); if (origin == StyleMap.AUTHOR_ORIGIN) { - for (int r = 0; r < rlen; r++) { - StyleRule sr = (StyleRule)rules.get(r); + for (Object rule : rules) { + StyleRule sr = (StyleRule) rule; StyleDeclaration sd = sr.getStyleDeclaration(); int len = sd.size(); for (int i = 0; i < len; i++) { putAuthorProperty(sm, - sd.getIndex(i), - sd.getValue(i), - sd.getPriority(i), - origin); + sd.getIndex(i), + sd.getValue(i), + sd.getPriority(i), + origin); } } } else { - for (int r = 0; r < rlen; r++) { - StyleRule sr = (StyleRule)rules.get(r); + for (Object rule : rules) { + StyleRule sr = (StyleRule) rule; StyleDeclaration sd = sr.getStyleDeclaration(); int len = sd.size(); for (int i = 0; i < len; i++) { @@ -1827,8 +1826,8 @@ public abstract class CSSEngine { int len = ll.length; if (len > 0) { CSSEngineEvent evt = new CSSEngineEvent(this, target, props); - for (int i = 0; i < len; i++) { - ll[i].propertiesChanged(evt); + for (CSSEngineListener aLl : ll) { + aLl.propertiesChanged(evt); } } } @@ -1977,14 +1976,14 @@ public abstract class CSSEngine { System.arraycopy( updated, 0, diffs, 0, updated.length ); } if (properties != null) { - for (int i=0; i || || ]? - * [ / ]? ] | + * [ [ <font-style> || <font-variant> || <font-weight> ]? + * <font-size> [ / <line-height> ]? <font-family> ] | * caption | icon | menu | message-box | small-caption | * status-bar | inherit * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/css2/VisibilityManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/css2/VisibilityManager.java index ff05229bd..e7f75ab92 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/css2/VisibilityManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/css2/VisibilityManager.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.engine.value.css2; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg/WritingModeManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg/WritingModeManager.java index 1815a568a..3e13c6059 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg/WritingModeManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg/WritingModeManager.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.engine.value.svg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/LineHeightManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/LineHeightManager.java index eec33ee82..60e8b49fa 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/LineHeightManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/LineHeightManager.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.engine.value.svg12; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/MarginLengthManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/MarginLengthManager.java index 3b6939987..84135fbfb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/MarginLengthManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/MarginLengthManager.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.engine.value.svg12; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/SVG12ValueConstants.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/SVG12ValueConstants.java index 1b2d41394..9c1bec70f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/SVG12ValueConstants.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/SVG12ValueConstants.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.engine.value.svg12; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/TextAlignManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/TextAlignManager.java index baeab63d1..1b99b917a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/TextAlignManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/engine/value/svg12/TextAlignManager.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.engine.value.svg12; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/Parser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/Parser.java index f8a5d79cc..c660a9604 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/Parser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/Parser.java @@ -383,7 +383,7 @@ public class Parser implements ExtendedParser, Localizable { case LexicalUnits.IMPORT_SYMBOL: return true; default: - reportError("token", new Object[] { new Integer(current) }); + reportError("token", new Object[] {current}); return false; } } @@ -920,7 +920,7 @@ public class Parser implements ExtendedParser, Localizable { if (current == LexicalUnits.RIGHT_BRACE) { if (op) { throw createCSSParseException - ("token", new Object[] { new Integer(current) }); + ("token", new Object[] {current}); } return result; } @@ -933,7 +933,7 @@ public class Parser implements ExtendedParser, Localizable { case LexicalUnits.EOF: if (op) { throw createCSSParseException - ("token", new Object[] { new Integer(current) }); + ("token", new Object[] {current}); } return result; default: @@ -1031,7 +1031,7 @@ public class Parser implements ExtendedParser, Localizable { if (sgn) { throw createCSSParseException ("token", - new Object[] { new Integer(current) }); + new Object[] {current}); } } switch (current) { @@ -1060,7 +1060,7 @@ public class Parser implements ExtendedParser, Localizable { default: throw createCSSParseException ("token", - new Object[] { new Integer(current) }); + new Object[] {current}); } } @@ -1076,7 +1076,7 @@ public class Parser implements ExtendedParser, Localizable { if (current != LexicalUnits.RIGHT_BRACE) { throw createCSSParseException ("token", - new Object[] { new Integer(current) }); + new Object[] {current}); } nextIgnoreSpaces(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/ScannerUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/ScannerUtilities.java index 38292101f..a6d70a528 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/ScannerUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/css/parser/ScannerUtilities.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.css.parser; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttr.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttr.java index 88e880c56..6d9d2ab8f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttr.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttr.java @@ -134,7 +134,7 @@ public abstract class AbstractAttr extends AbstractParentNode implements Attr { if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -314,9 +314,9 @@ public abstract class AbstractAttr extends AbstractParentNode implements Attr { throw createDOMException (DOMException.HIERARCHY_REQUEST_ERR, "child.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), - new Integer(n.getNodeType()), + (int) n.getNodeType(), n.getNodeName() }); } } @@ -338,7 +338,7 @@ public abstract class AbstractAttr extends AbstractParentNode implements Attr { /** * Inner class to hold type information about this attribute. */ - public class AttrTypeInfo implements TypeInfo { + public static class AttrTypeInfo implements TypeInfo { /** * Type namespace. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttrNS.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttrNS.java index 1680a58b3..c5d6de58d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttrNS.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractAttrNS.java @@ -85,7 +85,7 @@ public abstract class AbstractAttrNS extends AbstractAttr { throw createDOMException (DOMException.NAMESPACE_ERR, "namespace.uri", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), nsURI }); } @@ -93,7 +93,7 @@ public abstract class AbstractAttrNS extends AbstractAttr { !XMLSupport.XMLNS_NAMESPACE_URI.equals(nsURI)) { throw createDOMException(DOMException.NAMESPACE_ERR, "namespace.uri", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), nsURI }); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractCharacterData.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractCharacterData.java index b2c413a1f..484bc822e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractCharacterData.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractCharacterData.java @@ -52,7 +52,7 @@ public abstract class AbstractCharacterData if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } // Node modification @@ -110,7 +110,7 @@ public abstract class AbstractCharacterData if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } setNodeValue(getNodeValue() + ((arg == null) ? "" : arg)); @@ -124,13 +124,13 @@ public abstract class AbstractCharacterData if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } if (offset < 0 || offset > getLength()) { throw createDOMException(DOMException.INDEX_SIZE_ERR, "offset", - new Object[] { new Integer(offset) }); + new Object[] {offset}); } String v = getNodeValue(); setNodeValue(v.substring(0, offset) + @@ -145,7 +145,7 @@ public abstract class AbstractCharacterData if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } checkOffsetCount(offset, count); @@ -165,7 +165,7 @@ public abstract class AbstractCharacterData if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } checkOffsetCount(offset, count); @@ -185,12 +185,12 @@ public abstract class AbstractCharacterData if (offset < 0 || offset >= getLength()) { throw createDOMException(DOMException.INDEX_SIZE_ERR, "offset", - new Object[] { new Integer(offset) }); + new Object[] {offset}); } if (count < 0) { throw createDOMException(DOMException.INDEX_SIZE_ERR, "negative.count", - new Object[] { new Integer(count) }); + new Object[] {count}); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDOMImplementation.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDOMImplementation.java index ba0bfc5e4..84a531cf9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDOMImplementation.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDOMImplementation.java @@ -19,6 +19,7 @@ package org.apache.batik.dom; import java.io.Serializable; +import java.util.HashMap; import java.util.Locale; import java.util.MissingResourceException; @@ -26,7 +27,6 @@ import org.apache.batik.dom.events.DocumentEventSupport; import org.apache.batik.dom.events.EventSupport; import org.apache.batik.i18n.Localizable; import org.apache.batik.i18n.LocalizableSupport; -import org.apache.batik.dom.util.HashTable; import org.w3c.dom.DOMImplementation; @@ -58,7 +58,7 @@ public abstract class AbstractDOMImplementation /** * The supported features. */ - protected final HashTable features = new HashTable(); + protected final HashMap features = new HashMap(); { // registerFeature("BasicEvents", "3.0"); registerFeature("Core", new String[] { "2.0", "3.0" }); @@ -111,8 +111,8 @@ public abstract class AbstractDOMImplementation return version.equals(v); } else { String[] va = (String[])v; - for (int i = 0; i < va.length; i++) { - if (version.equals(va[i])) { + for (String aVa : va) { + if (version.equals(aVa)) { return true; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocument.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocument.java index 7d255e9d9..35d586836 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocument.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocument.java @@ -43,7 +43,7 @@ import org.apache.batik.i18n.LocalizableSupport; import org.apache.batik.util.CleanerThread; import org.apache.batik.util.DOMConstants; import org.apache.batik.util.SoftDoublyIndexedTable; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.xml.utils.PrefixResolver; @@ -702,8 +702,8 @@ public abstract class AbstractDocument } /** - * DOM: Implements {@link - * org.apache.batik.w3c.dom.events.DocumentEvent#canDispatch(String,String)}. + * DOM: Implements + * org.w3c.dom.events.DocumentEvent#canDispatch(String,String). */ public boolean canDispatch(String ns, String eventType) { if (eventType == null) { @@ -852,9 +852,9 @@ public abstract class AbstractDocument default: throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "child.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), - new Integer(t), + (int) t, n.getNodeName() }); } if (!replace && @@ -862,7 +862,7 @@ public abstract class AbstractDocument (t == DOCUMENT_TYPE_NODE && getDoctype() != null)) { throw createDOMException(DOMException.NOT_SUPPORTED_ERR, "document.child.already.exists", - new Object[] { new Integer(t), + new Object[] {(int) t, n.getNodeName() }); } } @@ -979,7 +979,7 @@ public abstract class AbstractDocument throw createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(an.getNodeType()), + new Object[] {(int) an.getNodeType(), an.getNodeName() }); } Node parent = n.getParentNode(); @@ -1045,7 +1045,7 @@ public abstract class AbstractDocument if (nt != Node.ELEMENT_NODE && nt != Node.ATTRIBUTE_NODE) { throw createDOMException(DOMException.NOT_SUPPORTED_ERR, "rename.node", - new Object[] { new Integer(nt), + new Object[] {nt, n.getNodeName() }); } if (xmlVersion.equals(XMLConstants.XML_VERSION_11) @@ -1058,14 +1058,14 @@ public abstract class AbstractDocument if (n.getOwnerDocument() != this) { throw createDOMException(DOMException.NOT_SUPPORTED_ERR, "node.from.wrong.document", - new Object[] { new Integer(nt), + new Object[] {nt, n.getNodeName() }); } int i = qn.indexOf(':'); if (i == 0 || i == qn.length() - 1) { throw createDOMException(DOMException.NAMESPACE_ERR, "qname", - new Object[] { new Integer(nt), + new Object[] {nt, n.getNodeName(), qn }); } @@ -1076,7 +1076,7 @@ public abstract class AbstractDocument if (prefix != null && ns == null) { throw createDOMException(DOMException.NAMESPACE_ERR, "prefix", - new Object[] { new Integer(nt), + new Object[] {nt, n.getNodeName(), prefix }); } @@ -1087,7 +1087,7 @@ public abstract class AbstractDocument && !XMLConstants.XMLNS_NAMESPACE_URI.equals(ns)) { throw createDOMException(DOMException.NAMESPACE_ERR, "namespace", - new Object[] { new Integer(nt), + new Object[] {nt, n.getNodeName(), ns }); } @@ -1386,9 +1386,8 @@ public abstract class AbstractDocument if (!namespaceDeclarations) { // remove namespace declarations - Iterator i = toRemove.iterator(); - while (i.hasNext()) { - e.removeAttributeNode((Attr) i.next()); + for (Object aToRemove : toRemove) { + e.removeAttributeNode((Attr) aToRemove); } } else { if (namespaces) { @@ -1489,7 +1488,7 @@ public abstract class AbstractDocument DOMConstants.DOM_INVALID_CHARACTER_ERROR, DOMError.SEVERITY_ERROR, "wf.invalid.character", - new Object[] { new Integer(Node.ATTRIBUTE_NODE), + new Object[] {(int) Node.ATTRIBUTE_NODE, a.getNodeName(), a.getNodeValue() }, a, @@ -1511,7 +1510,7 @@ public abstract class AbstractDocument DOMConstants.DOM_INVALID_CHARACTER_ERROR, DOMError.SEVERITY_ERROR, "wf.invalid.character", - new Object[] { new Integer(m.getNodeType()), + new Object[] {(int) m.getNodeType(), m.getNodeName(), s }, m, @@ -1531,7 +1530,7 @@ public abstract class AbstractDocument DOMConstants.DOM_INVALID_CHARACTER_ERROR, DOMError.SEVERITY_ERROR, "wf.invalid.character", - new Object[] { new Integer(m.getNodeType()), + new Object[] {(int) m.getNodeType(), m.getNodeName(), s }, m, @@ -1550,7 +1549,7 @@ public abstract class AbstractDocument DOMConstants.DOM_INVALID_CHARACTER_ERROR, DOMError.SEVERITY_ERROR, "wf.invalid.character", - new Object[] { new Integer(m.getNodeType()), + new Object[] {(int) m.getNodeType(), m.getNodeName(), s }, m, @@ -1584,7 +1583,7 @@ public abstract class AbstractDocument DOMConstants.DOM_INVALID_CHARACTER_ERROR, DOMError.SEVERITY_ERROR, "wf.invalid.character", - new Object[] { new Integer(m.getNodeType()), + new Object[] {(int) m.getNodeType(), m.getNodeName(), s }, m, @@ -1703,16 +1702,16 @@ public abstract class AbstractDocument Exception e) { try { return new DocumentError(type, - severity, - getCurrentDocument().formatMessage(key, args), - related, - e); + severity, + getCurrentDocument().formatMessage(key, args), + related, + e); } catch (Exception ex) { return new DocumentError(type, - severity, - key, - related, - e); + severity, + key, + related, + e); } } @@ -1747,7 +1746,7 @@ public abstract class AbstractDocument /** * DOMError implementation. */ - protected class DocumentError implements DOMError { + protected static class DocumentError implements DOMError { /** * The error type. @@ -1824,7 +1823,7 @@ public abstract class AbstractDocument /** * The DOMLocator implementation. */ - protected class ErrorLocation implements DOMLocator { + protected static class ErrorLocation implements DOMLocator { /** * The node that caused the error. @@ -1958,7 +1957,7 @@ public abstract class AbstractDocument protected Map booleanParamIndexes = new HashMap(); { for (int i = 0; i < booleanParamNames.length; i++) { - booleanParamIndexes.put(booleanParamNames[i], new Integer(i)); + booleanParamIndexes.put(booleanParamNames[i], i); } } @@ -2005,8 +2004,8 @@ public abstract class AbstractDocument "domconfig.param.type", new Object[] { name }); } - int index = i.intValue(); - boolean val = ((Boolean) value).booleanValue(); + int index = i; + boolean val = (Boolean) value; if (booleanParamReadOnly[index] && booleanParamValues[index] != val) { throw createDOMException @@ -2041,7 +2040,7 @@ public abstract class AbstractDocument "domconfig.param.not.found", new Object[] { name }); } - return booleanParamValues[index.intValue()] ? Boolean.TRUE + return booleanParamValues[index] ? Boolean.TRUE : Boolean.FALSE; } @@ -2050,7 +2049,7 @@ public abstract class AbstractDocument */ public boolean getBooleanParameter(String name) { Boolean b = (Boolean) getParameter(name); - return b.booleanValue(); + return b; } /** @@ -2064,8 +2063,8 @@ public abstract class AbstractDocument if (i == null || value == null || !(value instanceof Boolean)) { return false; } - int index = i.intValue(); - boolean val = ((Boolean) value).booleanValue(); + int index = i; + boolean val = (Boolean) value; return !booleanParamReadOnly[index] || booleanParamValues[index] == val; } @@ -2115,8 +2114,8 @@ public abstract class AbstractDocument if (DOMConstants.DOM_ERROR_HANDLER_PARAM.equals(s)) { return true; } - for (int i = 0; i < booleanParamNames.length; i++) { - if (booleanParamNames[i].equals(s)) { + for (String booleanParamName : booleanParamNames) { + if (booleanParamName.equals(s)) { return true; } } @@ -2226,13 +2225,13 @@ public abstract class AbstractDocument throw createDOMException (DOMException.WRONG_DOCUMENT_ERR, "node.from.wrong.document", - new Object[] { new Integer(contextNode.getNodeType()), + new Object[] {(int) contextNode.getNodeType(), contextNode.getNodeName() }); } if (type < 0 || type > 9) { throw createDOMException(DOMException.NOT_SUPPORTED_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(type) }); + new Object[] {(int) type}); } switch (contextNode.getNodeType()) { case ENTITY_REFERENCE_NODE: @@ -2243,7 +2242,7 @@ public abstract class AbstractDocument throw createDOMException (DOMException.NOT_SUPPORTED_ERR, "xpath.invalid.context.node", - new Object[] { new Integer(contextNode.getNodeType()), + new Object[] {(int) contextNode.getNodeType(), contextNode.getNodeName() }); } context.reset(); @@ -2291,7 +2290,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.cannot.convert.result", - new Object[] { new Integer(type), + new Object[] {(int) type, te.getMessage() }); } return null; @@ -2438,7 +2437,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return booleanValue; } @@ -2451,7 +2450,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return numberValue; } @@ -2464,7 +2463,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return stringValue; } @@ -2478,7 +2477,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return singleNodeValue; } @@ -2500,7 +2499,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return iterator.getLength(); } @@ -2515,7 +2514,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return iterator.item(iteratorPosition++); } @@ -2529,7 +2528,7 @@ public abstract class AbstractDocument throw createXPathException (XPathException.TYPE_ERR, "xpath.invalid.result.type", - new Object[] { new Integer(resultType) }); + new Object[] {(int) resultType}); } return iterator.item(i); } @@ -2581,7 +2580,7 @@ public abstract class AbstractDocument /** * An XPathNSResolver that uses Node.lookupNamespaceURI. */ - protected class XPathNodeNSResolver implements XPathNSResolver { + protected static class XPathNodeNSResolver implements XPathNSResolver { /** * The context node for namespace prefix resolution. @@ -2600,7 +2599,7 @@ public abstract class AbstractDocument * {@link org.w3c.dom.xpath.XPathNSResolver#lookupNamespaceURI(String)}. */ public String lookupNamespaceURI(String prefix) { - return ((AbstractNode) contextNode).lookupNamespaceURI(prefix); + return contextNode.lookupNamespaceURI(prefix); } } @@ -2730,9 +2729,13 @@ public abstract class AbstractDocument Method m = c.getMethod("getDOMImplementation", (Class[])null); implementation = (DOMImplementation)m.invoke(null, (Object[])null); } catch (Exception e) { - try { - implementation = (DOMImplementation)c.newInstance(); - } catch (Exception ex) { + if (DOMImplementation.class.isAssignableFrom(c)) { + try { + implementation = (DOMImplementation)c.getDeclaredConstructor().newInstance(); + } catch (Exception ex) { + } + } else { + throw new SecurityException("Trying to create object that is not a DOMImplementation."); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocumentFragment.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocumentFragment.java index 6472bd8b2..aa646ac1a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocumentFragment.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractDocumentFragment.java @@ -66,9 +66,9 @@ public abstract class AbstractDocumentFragment throw createDOMException (DOMException.HIERARCHY_REQUEST_ERR, "child.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), - new Integer(n.getNodeType()), + (int) n.getNodeType(), n.getNodeName() }); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElement.java index 2bb225f14..07e1146c2 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElement.java @@ -22,12 +22,12 @@ import java.io.Serializable; import org.apache.batik.dom.events.DOMMutationEvent; import org.apache.batik.dom.util.DOMUtilities; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; import org.w3c.dom.Element; -import org.w3c.dom.ElementTraversal; +import org.apache.batik.w3c.dom.ElementTraversal; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.TypeInfo; @@ -607,9 +607,9 @@ public abstract class AbstractElement throw createDOMException (DOMException.HIERARCHY_REQUEST_ERR, "child.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), - new Integer(n.getNodeType()), + (int) n.getNodeType(), n.getNodeName() }); } } @@ -629,19 +629,19 @@ public abstract class AbstractElement String newv, short change) { switch (change) { case MutationEvent.ADDITION: - if (((AbstractAttr)node).isId()) + if (node.isId()) ownerDocument.addIdEntry(this, newv); attrAdded(node, newv); break; case MutationEvent.MODIFICATION: - if (((AbstractAttr)node).isId()) + if (node.isId()) ownerDocument.updateIdEntry(this, oldv, newv); attrModified(node, oldv, newv); break; default: // MutationEvent.REMOVAL: - if (((AbstractAttr)node).isId()) + if (node.isId()) ownerDocument.removeIdEntry(this, oldv); attrRemoved(node, oldv); } @@ -813,17 +813,17 @@ public abstract class AbstractElement return null; } int j = 0; - for ( int i = 0; i < table.length; i++ ) { - Entry e = table[ i ]; - if ( e == null ) { + for (Entry aTable : table) { + Entry e = aTable; + if (e == null) { continue; } do { - if ( j++ == index ) { + if (j++ == index) { return e.value; } e = e.next; - } while ( e != null ); + } while (e != null); } return null; } @@ -934,7 +934,7 @@ public abstract class AbstractElement if ( getOwnerDocument() != arg.getOwnerDocument() ) { throw createDOMException( DOMException.WRONG_DOCUMENT_ERR, "node.from.wrong.document", - new Object[]{new Integer( arg.getNodeType() ), + new Object[]{(int) arg.getNodeType(), arg.getNodeName()} ); } if ( arg.getNodeType() == ATTRIBUTE_NODE && @@ -1107,7 +1107,7 @@ public abstract class AbstractElement /** * Inner class to hold type information about this element. */ - public class ElementTypeInfo implements TypeInfo { + public static class ElementTypeInfo implements TypeInfo { /** * Type namespace. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElementNS.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElementNS.java index 26fb815e9..01ea1d99b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElementNS.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractElementNS.java @@ -73,7 +73,7 @@ public abstract class AbstractElementNS extends AbstractElement { throw createDOMException (DOMException.NAMESPACE_ERR, "namespace.uri", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), nsURI }); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntity.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntity.java index 80aceeda0..01ec0aff1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntity.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntity.java @@ -203,9 +203,9 @@ public abstract class AbstractEntity throw createDOMException (DOMException.HIERARCHY_REQUEST_ERR, "child.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), - new Integer(n.getNodeType()), + (int) n.getNodeType(), n.getNodeName() }); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntityReference.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntityReference.java index 4e16a3857..a5930a090 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntityReference.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractEntityReference.java @@ -146,9 +146,9 @@ public abstract class AbstractEntityReference throw createDOMException (DOMException.HIERARCHY_REQUEST_ERR, "child.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), - new Integer(n.getNodeType()), + (int) n.getNodeType(), n.getNodeName() }); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractNode.java index cebbcddbc..ff9d80833 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractNode.java @@ -21,7 +21,6 @@ package org.apache.batik.dom; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.apache.batik.dom.events.DOMMutationEvent; @@ -32,7 +31,7 @@ import org.apache.batik.dom.util.XMLSupport; import org.apache.batik.dom.xbl.NodeXBL; import org.apache.batik.dom.xbl.XBLManagerData; import org.apache.batik.util.ParsedURL; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; @@ -114,7 +113,7 @@ public abstract class AbstractNode public void setSpecified(boolean v) { throw createDOMException(DOMException.INVALID_STATE_ERR, "node.type", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName()}); } @@ -148,7 +147,7 @@ public abstract class AbstractNode public void setParentNode(Node v) { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "parent.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -183,7 +182,7 @@ public abstract class AbstractNode public void setPreviousSibling(Node n) { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "sibling.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -202,7 +201,7 @@ public abstract class AbstractNode public void setNextSibling(Node n) { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "sibling.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -255,7 +254,7 @@ public abstract class AbstractNode throws DOMException { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "children.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -268,7 +267,7 @@ public abstract class AbstractNode throws DOMException { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "children.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName()}); } @@ -279,7 +278,7 @@ public abstract class AbstractNode public Node removeChild(Node oldChild) throws DOMException { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "children.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -290,7 +289,7 @@ public abstract class AbstractNode public Node appendChild(Node newChild) throws DOMException { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "children.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -343,14 +342,14 @@ public abstract class AbstractNode if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } String uri = getNamespaceURI(); if (uri == null) { throw createDOMException(DOMException.NAMESPACE_ERR, "namespace", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -365,14 +364,14 @@ public abstract class AbstractNode if (!prefix.equals("") && !DOMUtilities.isValidName(prefix)) { throw createDOMException(DOMException.INVALID_CHARACTER_ERR, "prefix", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), prefix }); } if (!DOMUtilities.isValidPrefix(prefix)) { throw createDOMException(DOMException.NAMESPACE_ERR, "prefix", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), prefix }); } @@ -382,7 +381,7 @@ public abstract class AbstractNode !XMLSupport.XMLNS_NAMESPACE_URI.equals(uri))) { throw createDOMException(DOMException.NAMESPACE_ERR, "namespace.uri", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), uri }); } @@ -462,7 +461,7 @@ public abstract class AbstractNode } public static String getBaseURI(Node n) { - return ((AbstractNode) n).getBaseURI(); + return n.getBaseURI(); } // DocumentPosition constants from DOM Level 3 Core org.w3c.dom.Node @@ -496,7 +495,7 @@ public abstract class AbstractNode if (other.getNodeType() == ATTRIBUTE_NODE) { Attr otherAttr = (Attr) other; if (n == otherAttr.getOwnerElement()) { - if (hashCode() < ((Attr) other).hashCode()) { + if (hashCode() < other.hashCode()) { return DOCUMENT_POSITION_PRECEDING | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; } else { @@ -577,7 +576,7 @@ public abstract class AbstractNode if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } if (getNodeType() != DOCUMENT_TYPE_NODE) { @@ -627,7 +626,7 @@ public abstract class AbstractNode n != null; n = n.getParentNode()) { if (n.getNodeType() == ELEMENT_NODE) { - return ((AbstractNode) n).lookupPrefix(namespaceURI); + return n.lookupPrefix(namespaceURI); } } return null; @@ -645,7 +644,7 @@ public abstract class AbstractNode && ns.equals(namespaceURI) && prefix != null) { String pns = - ((AbstractNode) originalElement).lookupNamespaceURI(prefix); + originalElement.lookupNamespaceURI(prefix); if (pns != null && pns.equals(namespaceURI)) { return prefix; } @@ -819,7 +818,7 @@ public abstract class AbstractNode Node n = getFirstChild(); Node m = other.getFirstChild(); if (n != null && m != null) { - if (!((AbstractNode) n).isEqualNode(m)) { + if (!n.isEqualNode(m)) { return false; } } @@ -856,7 +855,7 @@ public abstract class AbstractNode } else { n2 = nnm2.getNamedItem(n1.getNodeName()); } - if (!((AbstractNode) n1).isEqualNode(n2)) { + if (!n1.isEqualNode(n2)) { return false; } } @@ -907,17 +906,16 @@ public abstract class AbstractNode Node newNode) { AbstractNode an = (AbstractNode) oldNode; if (an.userData != null) { - Iterator i = an.userData.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); + for (Object o : an.userData.entrySet()) { + Map.Entry e = (Map.Entry) o; UserDataHandler h - = (UserDataHandler) an.userDataHandlers.get(e.getKey()); + = (UserDataHandler) an.userDataHandlers.get(e.getKey()); if (h != null) { h.handle(type, - (String) e.getKey(), - e.getValue(), - oldNode, - newNode); + (String) e.getKey(), + e.getValue(), + oldNode, + newNode); } } } @@ -1182,7 +1180,7 @@ public abstract class AbstractNode protected void checkChildType(Node n, boolean replace) { throw createDOMException(DOMException.HIERARCHY_REQUEST_ERR, "children.not.allowed", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractParentNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractParentNode.java index af0aa2749..3fe1e06aa 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractParentNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractParentNode.java @@ -21,7 +21,7 @@ package org.apache.batik.dom; import java.io.Serializable; import org.apache.batik.dom.events.DOMMutationEvent; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.DOMException; import org.w3c.dom.Node; @@ -78,7 +78,7 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", - new Object[] { new Integer(refChild.getNodeType()), + new Object[] {(int) refChild.getNodeType(), refChild.getNodeName() }); checkAndRemove(newChild, false); @@ -119,7 +119,7 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", - new Object[] { new Integer(oldChild.getNodeType()), + new Object[] {(int) oldChild.getNodeType(), oldChild.getNodeName() }); checkAndRemove(newChild, true); @@ -171,13 +171,13 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", - new Object[] { new Integer(oldChild.getNodeType()), + new Object[] {(int) oldChild.getNodeType(), oldChild.getNodeName() }); } if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -457,13 +457,13 @@ public abstract class AbstractParentNode extends AbstractNode { if (isReadonly()) throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); if (n.getOwnerDocument() != getCurrentDocument()) throw createDOMException(DOMException.WRONG_DOCUMENT_ERR, "node.from.wrong.document", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); if (this == n) throw createDOMException @@ -479,7 +479,7 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.HIERARCHY_REQUEST_ERR, "add.ancestor", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } @@ -835,7 +835,7 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", - new Object[] { new Integer(r.getNodeType()), + new Object[] {(int) r.getNodeType(), r.getNodeName() }); } @@ -901,7 +901,7 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", - new Object[] { new Integer(o.getNodeType()), + new Object[] {(int) o.getNodeType(), o.getNodeName() }); } @@ -959,7 +959,7 @@ public abstract class AbstractParentNode extends AbstractNode { throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", - new Object[] { new Integer(n.getNodeType()), + new Object[] {(int) n.getNodeType(), n.getNodeName() }); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractProcessingInstruction.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractProcessingInstruction.java index 38cee2c44..6a2fde75a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractProcessingInstruction.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractProcessingInstruction.java @@ -86,7 +86,7 @@ public abstract class AbstractProcessingInstruction if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } String val = this.data; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractStylableDocument.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractStylableDocument.java index 8099c4528..2ebe385ae 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractStylableDocument.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractStylableDocument.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractText.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractText.java index 32db1e1aa..603b9856d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractText.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/AbstractText.java @@ -19,7 +19,7 @@ package org.apache.batik.dom; import org.apache.batik.dom.util.XMLSupport; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.xml.XMLUtilities; import org.w3c.dom.DOMException; @@ -45,14 +45,14 @@ public abstract class AbstractText if (isReadonly()) { throw createDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName() }); } String v = getNodeValue(); if (offset < 0 || offset >= v.length()) { throw createDOMException(DOMException.INDEX_SIZE_ERR, "offset", - new Object[] { new Integer(offset) }); + new Object[] {offset}); } Node n = getParentNode(); if (n == null) { @@ -175,7 +175,7 @@ public abstract class AbstractText throw createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(n.getNodeType()), + new Object[] {(int) n.getNodeType(), n.getNodeName() }); } } @@ -187,7 +187,7 @@ public abstract class AbstractText throw createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(n.getNodeType()), + new Object[] {(int) n.getNodeType(), n.getNodeName() }); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/ExtensibleDOMImplementation.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/ExtensibleDOMImplementation.java index 86c03915b..d544a1912 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/ExtensibleDOMImplementation.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/ExtensibleDOMImplementation.java @@ -18,6 +18,7 @@ */ package org.apache.batik.dom; +import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -76,10 +77,9 @@ public abstract class ExtensibleDOMImplementation * Creates a new DOMImplementation. */ public ExtensibleDOMImplementation() { - Iterator iter = getDomExtensions().iterator(); - while(iter.hasNext()) { - DomExtension de = (DomExtension)iter.next(); + for (Object o : getDomExtensions()) { + DomExtension de = (DomExtension) o; de.registerTags(this); } } @@ -124,7 +124,7 @@ public abstract class ExtensibleDOMImplementation String pn = XMLResourceDescriptor.getCSSParserClassName(); Parser p; try { - p = (Parser)Class.forName(pn).newInstance(); + p = (Parser)Class.forName(pn).getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException e) { throw new DOMException(DOMException.INVALID_ACCESS_ERR, formatMessage("css.parser.class", @@ -137,6 +137,14 @@ public abstract class ExtensibleDOMImplementation throw new DOMException(DOMException.INVALID_ACCESS_ERR, formatMessage("css.parser.access", new Object[] { pn })); + } catch (NoSuchMethodException e) { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, + formatMessage("css.parser.access", + new Object[] { pn })); + } catch (InvocationTargetException e) { + throw new DOMException(DOMException.INVALID_ACCESS_ERR, + formatMessage("css.parser.access", + new Object[] { pn })); } ExtendedParser ep = ExtendedParserWrapper.wrap(p); @@ -208,8 +216,7 @@ public abstract class ExtensibleDOMImplementation } /** - * DOM: Implements {@link - * DOMImplementation#createDocumentType(String,String,String)}. + * DOM: Implements DOMImplementation#createDocumentType(String,String,String). */ public DocumentType createDocumentType(String qualifiedName, String publicId, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocument.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocument.java index f1cde7776..9dedbec1a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocument.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocument.java @@ -18,7 +18,7 @@ */ package org.apache.batik.dom; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocumentType.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocumentType.java index a19aca552..00d497d45 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocumentType.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/GenericDocumentType.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetFactory.java index 9ecafe223..1f49d2018 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetFactory.java @@ -18,10 +18,12 @@ */ package org.apache.batik.dom; -import org.apache.batik.dom.util.HashTable; + import org.w3c.dom.Node; import org.w3c.dom.stylesheets.StyleSheet; +import java.util.HashMap; + /** * This interface represents a StyleSheet factory. * @@ -34,5 +36,5 @@ public interface StyleSheetFactory { * processing instruction or return null when it is not possible * to create the given stylesheet. */ - StyleSheet createStyleSheet(Node node, HashTable pseudoAttrs); + StyleSheet createStyleSheet(Node node, HashMap pseudoAttrs); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetProcessingInstruction.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetProcessingInstruction.java index 5b403560e..996417068 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetProcessingInstruction.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/StyleSheetProcessingInstruction.java @@ -15,17 +15,19 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom; import org.apache.batik.dom.util.DOMUtilities; -import org.apache.batik.dom.util.HashTable; + import org.w3c.dom.DOMException; import org.w3c.dom.Node; import org.w3c.dom.stylesheets.LinkStyle; import org.w3c.dom.stylesheets.StyleSheet; +import java.util.HashMap; + /** * This class provides an implementation of the 'xml-stylesheet' processing * instructions. @@ -55,7 +57,7 @@ public class StyleSheetProcessingInstruction /** * The pseudo attributes. */ - protected transient HashTable pseudoAttributes; + protected transient HashMap pseudoAttributes; /** * Creates a new ProcessingInstruction object. @@ -116,9 +118,9 @@ public class StyleSheetProcessingInstruction /** * Returns the pseudo attributes in a table. */ - public HashTable getPseudoAttributes() { + public HashMap getPseudoAttributes() { if (pseudoAttributes == null) { - pseudoAttributes = new HashTable(); + pseudoAttributes = new HashMap(); pseudoAttributes.put("alternate", "no"); pseudoAttributes.put("media", "all"); DOMUtilities.parseStyleSheetPIData(data, pseudoAttributes); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/AbstractEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/AbstractEvent.java index 63212b1ec..d719144f3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/AbstractEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/AbstractEvent.java @@ -25,6 +25,7 @@ import org.w3c.dom.events.EventTarget; import java.util.ArrayList; import java.util.List; + /** * The abstract Event root class. * @@ -278,7 +279,7 @@ public abstract class AbstractEvent /** * DOM: Implements - * {@link org.w3c.dom.events.Event#initEventNS(String,String,boolean,boolean)}. + * org.w3c.dom.events.Event#initEventNS(String,String,boolean,boolean). */ public void initEventNS(String namespaceURIArg, String eventTypeArg, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMKeyboardEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMKeyboardEvent.java index 35868e43a..9010eef83 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMKeyboardEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMKeyboardEvent.java @@ -324,13 +324,13 @@ public class DOMKeyboardEvent extends DOMUIEvent implements KeyboardEvent { keyLocation = keyLocationArg; modifierKeys.clear(); String[] modifiers = split(modifiersList); - for (int i = 0; i < modifiers.length; i++) { - modifierKeys.add(modifiers[i]); + for (String modifier : modifiers) { + modifierKeys.add(modifier); } } /** - * DOMDOM: Initializes this KeyboardEvent object. * @param namespaceURIArg Specifies the event namespace URI. * @param typeArg Specifies the event type. * @param canBubbleArg Specifies whether or not the event can bubble. @@ -363,8 +363,8 @@ public class DOMKeyboardEvent extends DOMUIEvent implements KeyboardEvent { keyLocation = keyLocationArg; modifierKeys.clear(); String[] modifiers = split(modifiersList); - for (int i = 0; i < modifiers.length; i++) { - modifierKeys.add(modifiers[i]); + for (String modifier : modifiers) { + modifierKeys.add(modifier); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMMouseEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMMouseEvent.java index 84b685779..a717b662f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMMouseEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DOMMouseEvent.java @@ -267,8 +267,8 @@ public class DOMMouseEvent extends DOMUIEvent implements MouseEvent { relatedTarget = relatedTargetArg; modifierKeys.clear(); String[] modifiers = split(modifiersList); - for (int i = 0; i < modifiers.length; i++) { - modifierKeys.add(modifiers[i]); + for (String modifier : modifiers) { + modifierKeys.add(modifier); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DocumentEventSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DocumentEventSupport.java index 6adddb7ac..5c6580de2 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DocumentEventSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/DocumentEventSupport.java @@ -18,10 +18,12 @@ */ package org.apache.batik.dom.events; -import org.apache.batik.dom.util.HashTable; + import org.w3c.dom.DOMException; import org.w3c.dom.events.Event; +import java.util.HashMap; + /** * This class implements the behavior of DocumentEvent. * @@ -98,7 +100,7 @@ public class DocumentEventSupport { /** * The event factories table. */ - protected HashTable eventFactories = new HashTable(); + protected HashMap eventFactories = new HashMap(); { // DOM 3 event names: eventFactories.put(EVENT_TYPE.toLowerCase(), @@ -161,7 +163,7 @@ public class DocumentEventSupport { */ public Event createEvent(String eventType) throws DOMException { - EventFactory ef = (EventFactory)eventFactories.get(eventType.toLowerCase()); + EventFactory ef = eventFactories.get(eventType.toLowerCase()); if (ef == null) { throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Bad event type: " + eventType); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventListenerList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventListenerList.java index f6e14bd7b..c2de62dd4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventListenerList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventListenerList.java @@ -19,10 +19,12 @@ package org.apache.batik.dom.events; import org.apache.batik.dom.util.IntTable; -import org.apache.batik.dom.util.HashTable; + import org.w3c.dom.events.EventListener; +import java.util.HashMap; + /** * Class to manager event listeners for one event type. * @@ -55,7 +57,7 @@ public class EventListenerList { /** * Caches of listeners with a given namespace URI. */ - protected HashTable listenersNS = new HashTable(); + protected HashMap listenersNS = new HashMap(); /** * Adds a listener. @@ -174,7 +176,7 @@ public class EventListenerList { /** * EventListenerTable entry class. */ - public class Entry { + public static class Entry { /** * The event listener. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventSupport.java index 914c11dc8..f9a799b86 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/EventSupport.java @@ -18,16 +18,14 @@ */ package org.apache.batik.dom.events; +import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Iterator; import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.AbstractNode; -import org.apache.batik.dom.util.HashTable; import org.w3c.dom.DOMException; -import org.w3c.dom.Node; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventException; import org.w3c.dom.events.EventListener; @@ -46,12 +44,12 @@ public class EventSupport { /** * The capturing listeners table. */ - protected HashTable capturingListeners; + protected HashMap capturingListeners; /** * The bubbling listeners table. */ - protected HashTable bubblingListeners; + protected HashMap bubblingListeners; /** * The node for which events are being handled. @@ -107,19 +105,19 @@ public class EventSupport { EventListener listener, boolean useCapture, Object group) { - HashTable listeners; + HashMap listeners; if (useCapture) { if (capturingListeners == null) { - capturingListeners = new HashTable(); + capturingListeners = new HashMap(); } listeners = capturingListeners; } else { if (bubblingListeners == null) { - bubblingListeners = new HashTable(); + bubblingListeners = new HashMap(); } listeners = bubblingListeners; } - EventListenerList list = (EventListenerList) listeners.get(type); + EventListenerList list = listeners.get(type); if (list == null) { list = new EventListenerList(); listeners.put(type, list); @@ -166,7 +164,7 @@ public class EventSupport { String type, EventListener listener, boolean useCapture) { - HashTable listeners; + HashMap listeners; if (useCapture) { listeners = capturingListeners; } else { @@ -175,7 +173,7 @@ public class EventSupport { if (listeners == null) { return; } - EventListenerList list = (EventListenerList) listeners.get(type); + EventListenerList list = listeners.get(type); if (list != null) { list.removeListener(namespaceURI, listener); if (list.size() == 0) { @@ -188,7 +186,7 @@ public class EventSupport { * Moves all of the event listeners from this EventSupport object * to the given EventSupport object. * Used by {@link - * org.apache.batik.dom.AbstractDocument#renameNode(Node,String,String)}. + * org.apache.batik.dom.AbstractDocument#renameNode(org.w3c.dom.Node,String,String)}. */ public void moveEventListeners(EventSupport other) { other.capturingListeners = capturingListeners; @@ -252,11 +250,10 @@ public class EventSupport { e.setEventPhase(Event.CAPTURING_PHASE); HashSet stoppedGroups = new HashSet(); HashSet toBeStoppedGroups = new HashSet(); - for (int i = 0; i < ancestors.length; i++) { - NodeEventTarget node = ancestors[i]; + for (NodeEventTarget node : ancestors) { e.setCurrentTarget(node); fireEventListeners(node, e, true, stoppedGroups, - toBeStoppedGroups); + toBeStoppedGroups); stoppedGroups.addAll(toBeStoppedGroups); toBeStoppedGroups.clear(); } @@ -291,9 +288,8 @@ public class EventSupport { protected void runDefaultActions(AbstractEvent e) { List runables = e.getDefaultActions(); if (runables != null) { - Iterator i = runables.iterator(); - while (i.hasNext()) { - Runnable r = (Runnable)i.next(); + for (Object runable : runables) { + Runnable r = (Runnable) runable; r.run(); } } @@ -312,16 +308,16 @@ public class EventSupport { } // fire event listeners String eventNS = e.getNamespaceURI(); - for (int i = 0; i < listeners.length; i++) { + for (EventListenerList.Entry listener : listeners) { try { - String listenerNS = listeners[i].getNamespaceURI(); + String listenerNS = listener.getNamespaceURI(); if (listenerNS != null && eventNS != null && !listenerNS.equals(eventNS)) { continue; } - Object group = listeners[i].getGroup(); + Object group = listener.getGroup(); if (stoppedGroups == null || !stoppedGroups.contains(group)) { - listeners[i].getListener().handleEvent(e); + listener.getListener().handleEvent(e); if (e.getStopImmediatePropagation()) { if (stoppedGroups != null) { stoppedGroups.add(group); @@ -392,8 +388,7 @@ public class EventSupport { */ public boolean hasEventListenerNS(String namespaceURI, String type) { if (capturingListeners != null) { - EventListenerList ell - = (EventListenerList) capturingListeners.get(type); + EventListenerList ell = capturingListeners.get(type); if (ell != null) { if (ell.hasEventListener(namespaceURI)) { return true; @@ -401,8 +396,7 @@ public class EventSupport { } } if (bubblingListeners != null) { - EventListenerList ell - = (EventListenerList) capturingListeners.get(type); + EventListenerList ell = capturingListeners.get(type); if (ell != null) { return ell.hasEventListener(namespaceURI); } @@ -418,12 +412,12 @@ public class EventSupport { */ public EventListenerList getEventListeners(String type, boolean useCapture) { - HashTable listeners + HashMap listeners = useCapture ? capturingListeners : bubblingListeners; if (listeners == null) { return null; } - return (EventListenerList) listeners.get(type); + return listeners.get(type); } /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/NodeEventTarget.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/NodeEventTarget.java index d8d14cf67..b62e79d59 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/NodeEventTarget.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/events/NodeEventTarget.java @@ -69,7 +69,8 @@ public interface NodeEventTarget extends EventTarget { * NOT_SUPPORTED_ERR: Raised if the Event object has not * been created using DocumentEvent.createEvent(). *
        INVALID_CHARACTER_ERR: Raised if Event.type is not - * an NCName as defined in [XML Namespaces 1.1] + * an NCName as defined in + * [XML Namespaces 1.1] * . * @version DOM Level 3 */ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGList.java index d2a6b4ec7..043ed4962 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGList.java @@ -189,7 +189,7 @@ public abstract class AbstractSVGList { if (index < 0 || itemList == null || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", - new Object[] { new Integer(index) } ); + new Object[] {index} ); } return (SVGItem)itemList.get(index); @@ -228,7 +228,7 @@ public abstract class AbstractSVGList { if (index < 0) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", - new Object[] { new Integer(index) } ); + new Object[] {index} ); } if (index > itemList.size()) { @@ -279,7 +279,7 @@ public abstract class AbstractSVGList { if (index < 0 || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", - new Object[] { new Integer(index) } ); + new Object[] {index} ); } SVGItem item = removeIfNeeded(newItem); @@ -314,7 +314,7 @@ public abstract class AbstractSVGList { if (index < 0 || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", - new Object[] { new Integer(index) } ); + new Object[] {index} ); } SVGItem item = (SVGItem)itemList.remove(index); @@ -491,9 +491,8 @@ public abstract class AbstractSVGList { if (list == null) { return; } - Iterator it = list.iterator(); - while (it.hasNext()) { - SVGItem item = (SVGItem)it.next(); + for (Object aList : list) { + SVGItem item = (SVGItem) aList; item.setParent(null); } list.clear(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNormPathSegList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNormPathSegList.java index fed4e04df..e5a09a482 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNormPathSegList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNormPathSegList.java @@ -60,7 +60,7 @@ public abstract class AbstractSVGNormPathSegList extends AbstractSVGPathSegList pathParser.parse(value); } - protected class NormalizedPathSegListBuilder extends DefaultPathHandler { + protected static class NormalizedPathSegListBuilder extends DefaultPathHandler { protected ListHandler listHandler; protected SVGPathSegGenericItem lastAbs; @@ -74,7 +74,7 @@ public abstract class AbstractSVGNormPathSegList extends AbstractSVGPathSegList public void startPath() throws ParseException { listHandler.startList(); lastAbs = new SVGPathSegGenericItem(SVGPathSeg.PATHSEG_MOVETO_ABS, - PATHSEG_MOVETO_ABS_LETTER, 0,0,0,0,0,0); + PATHSEG_MOVETO_ABS_LETTER, 0, 0, 0, 0, 0, 0); } /** @@ -95,9 +95,8 @@ public abstract class AbstractSVGNormPathSegList extends AbstractSVGPathSegList * Implements {@link org.apache.batik.parser.PathHandler#movetoAbs(float,float)}. */ public void movetoAbs(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegMovetoLinetoItem - (SVGPathSeg.PATHSEG_MOVETO_ABS,PATHSEG_MOVETO_ABS_LETTER, - x,y)); + listHandler.item(new SVGPathSegMovetoLinetoItem(SVGPathSeg.PATHSEG_MOVETO_ABS, PATHSEG_MOVETO_ABS_LETTER, + x, y)); lastAbs.setX(x); lastAbs.setY(y); lastAbs.setPathSegType(SVGPathSeg.PATHSEG_MOVETO_ABS); @@ -122,9 +121,8 @@ public abstract class AbstractSVGNormPathSegList extends AbstractSVGPathSegList * Implements {@link org.apache.batik.parser.PathHandler#linetoAbs(float,float)}. */ public void linetoAbs(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegMovetoLinetoItem - (SVGPathSeg.PATHSEG_LINETO_ABS,PATHSEG_LINETO_ABS_LETTER, - x,y)); + listHandler.item(new SVGPathSegMovetoLinetoItem(SVGPathSeg.PATHSEG_LINETO_ABS, PATHSEG_LINETO_ABS_LETTER, + x, y)); lastAbs.setX(x); lastAbs.setY(y); lastAbs.setPathSegType(SVGPathSeg.PATHSEG_LINETO_ABS); @@ -177,9 +175,8 @@ public abstract class AbstractSVGNormPathSegList extends AbstractSVGPathSegList public void curvetoCubicAbs(float x1, float y1, float x2, float y2, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoCubicItem - (SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS,PATHSEG_CURVETO_CUBIC_ABS_LETTER, - x1,y1,x2,y2,x,y)); + listHandler.item(new SVGPathSegCurvetoCubicItem(SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS, PATHSEG_CURVETO_CUBIC_ABS_LETTER, + x1, y1, x2, y2, x, y)); lastAbs.setValue(x1,y1,x2,y2,x,y); lastAbs.setPathSegType(SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS); } @@ -321,7 +318,7 @@ public abstract class AbstractSVGNormPathSegList extends AbstractSVGPathSegList } - protected class SVGPathSegGenericItem extends SVGPathSegItem { + protected static class SVGPathSegGenericItem extends SVGPathSegItem { public SVGPathSegGenericItem(short type, String letter, float x1, float y1, float x2, float y2, float x, float y){ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNumberList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNumberList.java index 7b5b69a4c..f0570fb83 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNumberList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGNumberList.java @@ -160,7 +160,7 @@ public abstract class AbstractSVGNumberList * Helper class to interface the {@link NumberListParser} and the * {@link NumberListHandler}. */ - protected class NumberListBuilder implements NumberListHandler { + protected static class NumberListBuilder implements NumberListHandler { /** * The ListHandler to notify of parsed numbers. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPathSegList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPathSegList.java index fdf2277ab..4c82f72c5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPathSegList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPathSegList.java @@ -224,7 +224,7 @@ public abstract class AbstractSVGPathSegList return pathSegItem; } - public class SVGPathSegMovetoLinetoItem extends SVGPathSegItem + public static class SVGPathSegMovetoLinetoItem extends SVGPathSegItem implements SVGPathSegMovetoAbs, SVGPathSegMovetoRel, SVGPathSegLinetoAbs, @@ -282,7 +282,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegCurvetoCubicItem extends SVGPathSegItem + public static class SVGPathSegCurvetoCubicItem extends SVGPathSegItem implements SVGPathSegCurvetoCubicAbs, SVGPathSegCurvetoCubicRel { @@ -367,7 +367,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegCurvetoQuadraticItem extends SVGPathSegItem + public static class SVGPathSegCurvetoQuadraticItem extends SVGPathSegItem implements SVGPathSegCurvetoQuadraticAbs, SVGPathSegCurvetoQuadraticRel { @@ -434,7 +434,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegArcItem extends SVGPathSegItem + public static class SVGPathSegArcItem extends SVGPathSegItem implements SVGPathSegArcAbs, SVGPathSegArcRel { @@ -539,7 +539,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegLinetoHorizontalItem + public static class SVGPathSegLinetoHorizontalItem extends SVGPathSegItem implements SVGPathSegLinetoHorizontalAbs, SVGPathSegLinetoHorizontalRel { @@ -576,7 +576,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegLinetoVerticalItem + public static class SVGPathSegLinetoVerticalItem extends SVGPathSegItem implements SVGPathSegLinetoVerticalAbs, SVGPathSegLinetoVerticalRel { @@ -614,7 +614,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegCurvetoCubicSmoothItem extends SVGPathSegItem + public static class SVGPathSegCurvetoCubicSmoothItem extends SVGPathSegItem implements SVGPathSegCurvetoCubicSmoothAbs, SVGPathSegCurvetoCubicSmoothRel { @@ -679,7 +679,7 @@ public abstract class AbstractSVGPathSegList } } - public class SVGPathSegCurvetoQuadraticSmoothItem extends SVGPathSegItem + public static class SVGPathSegCurvetoQuadraticSmoothItem extends SVGPathSegItem implements SVGPathSegCurvetoQuadraticSmoothAbs , SVGPathSegCurvetoQuadraticSmoothRel { @@ -725,7 +725,7 @@ public abstract class AbstractSVGPathSegList } } - protected class PathSegListBuilder extends DefaultPathHandler { + protected static class PathSegListBuilder extends DefaultPathHandler { protected ListHandler listHandler; @@ -750,18 +750,16 @@ public abstract class AbstractSVGPathSegList * Implements {@link org.apache.batik.parser.PathHandler#movetoRel(float,float)}. */ public void movetoRel(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegMovetoLinetoItem - (SVGPathSeg.PATHSEG_MOVETO_REL,PATHSEG_MOVETO_REL_LETTER, - x,y)); + listHandler.item(new SVGPathSegMovetoLinetoItem(SVGPathSeg.PATHSEG_MOVETO_REL, PATHSEG_MOVETO_REL_LETTER, + x, y)); } /** * Implements {@link org.apache.batik.parser.PathHandler#movetoAbs(float,float)}. */ public void movetoAbs(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegMovetoLinetoItem - (SVGPathSeg.PATHSEG_MOVETO_ABS,PATHSEG_MOVETO_ABS_LETTER, - x,y)); + listHandler.item(new SVGPathSegMovetoLinetoItem(SVGPathSeg.PATHSEG_MOVETO_ABS, PATHSEG_MOVETO_ABS_LETTER, + x, y)); } /** @@ -777,54 +775,48 @@ public abstract class AbstractSVGPathSegList * Implements {@link org.apache.batik.parser.PathHandler#linetoRel(float,float)}. */ public void linetoRel(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegMovetoLinetoItem - (SVGPathSeg.PATHSEG_LINETO_REL,PATHSEG_LINETO_REL_LETTER, - x,y)); + listHandler.item(new SVGPathSegMovetoLinetoItem(SVGPathSeg.PATHSEG_LINETO_REL, PATHSEG_LINETO_REL_LETTER, + x, y)); } /** * Implements {@link org.apache.batik.parser.PathHandler#linetoAbs(float,float)}. */ public void linetoAbs(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegMovetoLinetoItem - (SVGPathSeg.PATHSEG_LINETO_ABS,PATHSEG_LINETO_ABS_LETTER, - x,y)); + listHandler.item(new SVGPathSegMovetoLinetoItem(SVGPathSeg.PATHSEG_LINETO_ABS, PATHSEG_LINETO_ABS_LETTER, + x, y)); } /** * Implements {@link org.apache.batik.parser.PathHandler#linetoHorizontalRel(float)}. */ public void linetoHorizontalRel(float x) throws ParseException { - listHandler.item(new SVGPathSegLinetoHorizontalItem - (SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL,PATHSEG_LINETO_HORIZONTAL_REL_LETTER, - x)); + listHandler.item(new SVGPathSegLinetoHorizontalItem(SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL, PATHSEG_LINETO_HORIZONTAL_REL_LETTER, + x)); } /** * Implements {@link org.apache.batik.parser.PathHandler#linetoHorizontalAbs(float)}. */ public void linetoHorizontalAbs(float x) throws ParseException { - listHandler.item(new SVGPathSegLinetoHorizontalItem - (SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS,PATHSEG_LINETO_HORIZONTAL_ABS_LETTER, - x)); + listHandler.item(new SVGPathSegLinetoHorizontalItem(SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS, PATHSEG_LINETO_HORIZONTAL_ABS_LETTER, + x)); } /** * Implements {@link org.apache.batik.parser.PathHandler#linetoVerticalRel(float)}. */ public void linetoVerticalRel(float y) throws ParseException { - listHandler.item(new SVGPathSegLinetoVerticalItem - (SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL,PATHSEG_LINETO_VERTICAL_REL_LETTER, - y)); + listHandler.item(new SVGPathSegLinetoVerticalItem(SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL, PATHSEG_LINETO_VERTICAL_REL_LETTER, + y)); } /** * Implements {@link org.apache.batik.parser.PathHandler#linetoVerticalAbs(float)}. */ public void linetoVerticalAbs(float y) throws ParseException { - listHandler.item(new SVGPathSegLinetoVerticalItem - (SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS,PATHSEG_LINETO_VERTICAL_ABS_LETTER, - y)); + listHandler.item(new SVGPathSegLinetoVerticalItem(SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS, PATHSEG_LINETO_VERTICAL_ABS_LETTER, + y)); } /** @@ -834,9 +826,8 @@ public abstract class AbstractSVGPathSegList public void curvetoCubicRel(float x1, float y1, float x2, float y2, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoCubicItem - (SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL,PATHSEG_CURVETO_CUBIC_REL_LETTER, - x1,y1,x2,y2,x,y)); + listHandler.item(new SVGPathSegCurvetoCubicItem(SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL, PATHSEG_CURVETO_CUBIC_REL_LETTER, + x1, y1, x2, y2, x, y)); } /** @@ -846,9 +837,8 @@ public abstract class AbstractSVGPathSegList public void curvetoCubicAbs(float x1, float y1, float x2, float y2, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoCubicItem - (SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS,PATHSEG_CURVETO_CUBIC_ABS_LETTER, - x1,y1,x2,y2,x,y)); + listHandler.item(new SVGPathSegCurvetoCubicItem(SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS, PATHSEG_CURVETO_CUBIC_ABS_LETTER, + x1, y1, x2, y2, x, y)); } /** @@ -857,9 +847,9 @@ public abstract class AbstractSVGPathSegList */ public void curvetoCubicSmoothRel(float x2, float y2, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoCubicSmoothItem - (SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL,PATHSEG_CURVETO_CUBIC_SMOOTH_REL_LETTER, - x2,y2,x,y)); + listHandler.item(new SVGPathSegCurvetoCubicSmoothItem(SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL, + PATHSEG_CURVETO_CUBIC_SMOOTH_REL_LETTER, + x2, y2, x, y)); } /** @@ -868,9 +858,9 @@ public abstract class AbstractSVGPathSegList */ public void curvetoCubicSmoothAbs(float x2, float y2, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoCubicSmoothItem - (SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS,PATHSEG_CURVETO_CUBIC_SMOOTH_ABS_LETTER, - x2,y2,x,y)); + listHandler.item(new SVGPathSegCurvetoCubicSmoothItem(SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS, + PATHSEG_CURVETO_CUBIC_SMOOTH_ABS_LETTER, + x2, y2, x, y)); } /** @@ -879,9 +869,9 @@ public abstract class AbstractSVGPathSegList */ public void curvetoQuadraticRel(float x1, float y1, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoQuadraticItem - (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL,PATHSEG_CURVETO_QUADRATIC_REL_LETTER, - x1,y1,x,y)); + listHandler.item(new SVGPathSegCurvetoQuadraticItem(SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL, + PATHSEG_CURVETO_QUADRATIC_REL_LETTER, + x1, y1, x, y)); } /** @@ -890,9 +880,9 @@ public abstract class AbstractSVGPathSegList */ public void curvetoQuadraticAbs(float x1, float y1, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoQuadraticItem - (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS,PATHSEG_CURVETO_QUADRATIC_ABS_LETTER, - x1,y1,x,y)); + listHandler.item(new SVGPathSegCurvetoQuadraticItem(SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS, + PATHSEG_CURVETO_QUADRATIC_ABS_LETTER, + x1, y1, x, y)); } /** @@ -900,9 +890,9 @@ public abstract class AbstractSVGPathSegList */ public void curvetoQuadraticSmoothRel(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem - (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL,PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL_LETTER, - x,y)); + listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem(SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL, + PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL_LETTER, + x, y)); } /** @@ -910,9 +900,9 @@ public abstract class AbstractSVGPathSegList */ public void curvetoQuadraticSmoothAbs(float x, float y) throws ParseException { - listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem - (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS,PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS_LETTER, - x,y)); + listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem(SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS, + PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS_LETTER, + x, y)); } /** @@ -923,9 +913,8 @@ public abstract class AbstractSVGPathSegList float xAxisRotation, boolean largeArcFlag, boolean sweepFlag, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegArcItem - (SVGPathSeg.PATHSEG_ARC_REL,PATHSEG_ARC_REL_LETTER, - rx,ry,xAxisRotation,largeArcFlag,sweepFlag,x,y)); + listHandler.item(new SVGPathSegArcItem(SVGPathSeg.PATHSEG_ARC_REL, PATHSEG_ARC_REL_LETTER, + rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y)); } /** @@ -936,9 +925,8 @@ public abstract class AbstractSVGPathSegList float xAxisRotation, boolean largeArcFlag, boolean sweepFlag, float x, float y) throws ParseException { - listHandler.item(new SVGPathSegArcItem - (SVGPathSeg.PATHSEG_ARC_ABS,PATHSEG_ARC_ABS_LETTER, - rx,ry,xAxisRotation,largeArcFlag,sweepFlag,x,y)); + listHandler.item(new SVGPathSegArcItem(SVGPathSeg.PATHSEG_ARC_ABS, PATHSEG_ARC_ABS_LETTER, + rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y)); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPointList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPointList.java index 21f575437..dc1226ab3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPointList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPointList.java @@ -141,7 +141,7 @@ public abstract class AbstractSVGPointList * Helper class to interface the {@link PointsParser} and the * {@link PointsHandler}. */ - protected class PointsListBuilder implements PointsHandler { + protected static class PointsListBuilder implements PointsHandler { /** * The {@link ListHandler} to pass newly created {@link SVGPointItem} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPreserveAspectRatio.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPreserveAspectRatio.java index 9e2e08f32..c0c8eeb2b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPreserveAspectRatio.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGPreserveAspectRatio.java @@ -157,7 +157,7 @@ public abstract class AbstractSVGPreserveAspectRatio throw createDOMException (DOMException.INVALID_MODIFICATION_ERR, "preserve.aspect.ratio.align", - new Object[] { new Integer(align) }); + new Object[] {(int) align}); } String value = ALIGN_VALUES[align]; if (align == SVG_PRESERVEASPECTRATIO_NONE) { @@ -168,12 +168,12 @@ public abstract class AbstractSVGPreserveAspectRatio throw createDOMException (DOMException.INVALID_MODIFICATION_ERR, "preserve.aspect.ratio.meet.or.slice", - new Object[] { new Integer(meetOrSlice) }); + new Object[] {(int) meetOrSlice}); } return value + ' ' + MEET_OR_SLICE_VALUES[meetOrSlice]; } - protected class PreserveAspectRatioParserHandler + protected static class PreserveAspectRatioParserHandler extends DefaultPreserveAspectRatioHandler { public short align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGTransformList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGTransformList.java index 62d1d66ec..162ae5fc8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGTransformList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/AbstractSVGTransformList.java @@ -192,7 +192,7 @@ public abstract class AbstractSVGTransformList /** * An {@link SVGTransform} in the list. */ - public class SVGTransformItem + public static class SVGTransformItem extends AbstractSVGTransform implements SVGItem { @@ -502,7 +502,7 @@ public abstract class AbstractSVGTransformList * Helper class to interface the {@link TransformListParser} and the * {@link ListHandler}. */ - protected class TransformListBuilder implements TransformListHandler { + protected static class TransformListBuilder implements TransformListHandler { /** * The {@link ListHandler} to pass newly created diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/ListBuilder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/ListBuilder.java index 7a8a57521..8f39a6a19 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/ListBuilder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/ListBuilder.java @@ -1,3 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ package org.apache.batik.dom.svg; import java.util.ArrayList; @@ -52,4 +70,4 @@ public class ListBuilder implements ListHandler { */ public void endList() { } -} \ No newline at end of file +} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGAnimationContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGAnimationContext.java index 0b08f6488..aac501cea 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGAnimationContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGAnimationContext.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.svg; import org.w3c.dom.smil.ElementTimeControl; @@ -51,7 +51,7 @@ public interface SVGAnimationContext extends SVGContext, ElementTimeControl { * DOM: Implements {@link * org.w3c.dom.svg.SVGAnimationElement#getSimpleDuration()}. With the * difference that an indefinite simple duration is returned as - * {@link org.apache.batik.anim.timing.TimedElement#INDEFINITE}, rather than + * org.apache.batik.anim.timing.TimedElement#INDEFINITE, rather than * throwing an exception. */ float getSimpleDuration(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGNumberItem.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGNumberItem.java index 502d07cf6..d5d4ae010 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGNumberItem.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGNumberItem.java @@ -1,3 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ package org.apache.batik.dom.svg; import org.w3c.dom.svg.SVGNumberList; @@ -49,4 +67,4 @@ public class SVGNumberItem extends AbstractSVGNumber implements SVGItem { parentList.itemChanged(); } } -} \ No newline at end of file +} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathContext.java index 75901be5d..79d84ce3a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathContext.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.svg; import java.awt.geom.Point2D; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathSegItem.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathSegItem.java index 6b4c7cd8a..e0c00eae7 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathSegItem.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPathSegItem.java @@ -1,3 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ package org.apache.batik.dom.svg; import org.w3c.dom.svg.SVGPathSeg; @@ -141,4 +159,4 @@ public class SVGPathSegItem extends AbstractSVGItem implements SVGPathSeg, SVGPa this.y2 = y2; } -} \ No newline at end of file +} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPointItem.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPointItem.java index 13a98bbd7..4b13539a2 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPointItem.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGPointItem.java @@ -1,3 +1,21 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ package org.apache.batik.dom.svg; import org.w3c.dom.svg.SVGMatrix; @@ -71,4 +89,4 @@ public class SVGPointItem extends AbstractSVGItem implements SVGPoint { public SVGPoint matrixTransform(SVGMatrix matrix) { return SVGOMPoint.matrixTransform(this, matrix); } -} \ No newline at end of file +} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGSVGContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGSVGContext.java index 6706a4f12..0755547c3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGSVGContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGSVGContext.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.svg; import java.util.List; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGZoomAndPanSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGZoomAndPanSupport.java index 32f171226..8c6317a57 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGZoomAndPanSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/svg/SVGZoomAndPanSupport.java @@ -56,7 +56,7 @@ public class SVGZoomAndPanSupport implements SVGConstants { throw ((AbstractNode)elt).createDOMException (DOMException.INVALID_MODIFICATION_ERR, "zoom.and.pan", - new Object[] { new Integer(val) }); + new Object[] {(int) val}); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/traversal/TraversalSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/traversal/TraversalSupport.java index 251824d88..3672f29f3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/traversal/TraversalSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/traversal/TraversalSupport.java @@ -15,11 +15,10 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.traversal; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -94,9 +93,8 @@ public class TraversalSupport { */ public void nodeToBeRemoved(Node removedNode) { if (iterators != null) { - Iterator it = iterators.iterator(); - while (it.hasNext()) { - ((DOMNodeIterator)it.next()).nodeToBeRemoved(removedNode); + for (Object iterator : iterators) { + ((DOMNodeIterator) iterator).nodeToBeRemoved(removedNode); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/DOMUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/DOMUtilities.java index 0498d9040..66ac53887 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/DOMUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/DOMUtilities.java @@ -23,13 +23,11 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; +import java.util.HashMap; import java.util.Map; -import java.util.Set; import org.apache.batik.dom.AbstractDocument; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.apache.batik.xml.XMLUtilities; import org.w3c.dom.Attr; @@ -59,7 +57,7 @@ public class DOMUtilities extends XMLUtilities implements XMLConstants { /** * A node in a linked list of prefix to namespace name mappings. */ - private static class NSMap { + private static final class NSMap { /** * The prefix to map. @@ -526,8 +524,8 @@ public class DOMUtilities extends XMLUtilities implements XMLConstants { */ public static boolean isAnyNodeAncestorOf(ArrayList ancestorNodes, Node node) { int n = ancestorNodes.size(); - for (int i = 0; i < n; i++) { - Node ancestor = (Node) ancestorNodes.get(i); + for (Object ancestorNode : ancestorNodes) { + Node ancestor = (Node) ancestorNode; if (isAncestorOf(ancestor, node)) { return true; } @@ -606,8 +604,8 @@ public class DOMUtilities extends XMLUtilities implements XMLConstants { return false; } int n = children.size(); - for (int i = 0; i < n; i++) { - Node child = (Node) children.get(i); + for (Object aChildren : children) { + Node child = (Node) aChildren; if (canAppend(child, parentNode)) { return true; } @@ -672,9 +670,8 @@ public class DOMUtilities extends XMLUtilities implements XMLConstants { // Copy the prefixes from the prefixes map to the wrapper element if (prefixes != null) { wrapperElementPrefix += " "; - Iterator iter = prefixes.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry e = (Map.Entry) iter.next(); + for (Object o : prefixes.entrySet()) { + Map.Entry e = (Map.Entry) o; String currentKey = (String) e.getKey(); String currentValue = (String) e.getValue(); wrapperElementPrefix += currentKey + "=\"" + currentValue @@ -855,7 +852,7 @@ public class DOMUtilities extends XMLUtilities implements XMLConstants { * Parses a 'xml-stylesheet' processing instruction data section and * puts the pseudo attributes in the given table. */ - public static void parseStyleSheetPIData(String data, HashTable table) { + public static void parseStyleSheetPIData(String data, HashMap table) { // !!! Internationalization char c; int i = 0; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTable.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTable.java deleted file mode 100644 index 1dc190eb6..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTable.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - */ -package org.apache.batik.dom.util; - -import java.io.Serializable; - -/** - * A simple hashtable, not synchronized, with fixed load factor. - * - * @author Stephane Hillion - * @version $Id$ - */ -public class HashTable implements Serializable { - - /** - * The initial capacity - */ - protected static final int INITIAL_CAPACITY = 11; - - /** - * The underlying array - */ - protected Entry[] table; - - /** - * The number of entries - */ - protected int count; - - /** - * Creates a new table. - */ - public HashTable() { - table = new Entry[INITIAL_CAPACITY]; - } - - /** - * Creates a new table. - * - * @param c The initial capacity. - */ - public HashTable( int c ) { - table = new Entry[c]; - } - - /** - * Creates a copy of the given HashTable object. - * @param t The table to copy. - */ - public HashTable( HashTable t ) { - count = t.count; - table = new Entry[t.table.length]; - for ( int i = 0; i < table.length; i++ ) { - Entry e = t.table[ i ]; - Entry n = null; - if ( e != null ) { - n = new Entry( e.hash, e.key, e.value, null ); - table[ i ] = n; - e = e.next; - while ( e != null ) { - n.next = new Entry( e.hash, e.key, e.value, null ); - n = n.next; - e = e.next; - } - } - } - } - - /** - * Returns the size of this table. - */ - public int size() { - return count; - } - - /** - * Gets the value of a variable - * @return the value or null - */ - public Object get(Object key) { - int hash = key == null ? 0 : key.hashCode() & 0x7FFFFFFF; - int index = hash % table.length; - - for (Entry e = table[index]; e != null; e = e.next) { - if (e.hash == hash - && (e.key == null && key == null - || e.key != null && e.key.equals(key))) { - return e.value; - } - } - return null; - } - - /** - * Sets a new value for the given variable - * @return the old value or null - */ - public Object put(Object key, Object value) { - int hash = key == null ? 0 : key.hashCode() & 0x7FFFFFFF; - int index = hash % table.length; - - for (Entry e = table[index]; e != null; e = e.next) { - if (e.hash == hash - && (e.key == null && key == null - || e.key != null && e.key.equals(key))) { - Object old = e.value; - e.value = value; - return old; - } - } - - // The key is not in the hash table - int len = table.length; - if (count++ >= (len - ( len >> 2 ))) { - // more than 75% loaded: grow - rehash(); - index = hash % table.length; - } - - Entry e = new Entry(hash, key, value, table[index]); - table[index] = e; - return null; - } - - /** - * Removes an entry from the table. - * - * @return the value or null. - */ - public Object remove( Object key ) { - int hash = key == null ? 0 : key.hashCode() & 0x7FFFFFFF; - int index = hash % table.length; - - Entry p = null; - for ( Entry e = table[ index ]; e != null; e = e.next ) { - if ( e.hash == hash - && ( e.key == null && key == null - || e.key != null && e.key.equals( key ) ) ) { - Object result = e.value; - if ( p == null ) { - table[ index ] = e.next; - } else { - p.next = e.next; - } - count--; - return result; - } - p = e; - } - return null; - } - - /** - * Returns the key at the given position or null. - */ - public Object key( int index ) { - if ( index < 0 || index >= count ) { - return null; - } - int j = 0; - for ( int i = 0; i < table.length; i++ ) { - Entry e = table[ i ]; - if ( e == null ) { - continue; - } - do { - if ( j++ == index ) { - return e.key; - } - e = e.next; - } while ( e != null ); - } - return null; - } - - /** - * Returns the item at the given position. - */ - public Object item( int index ) { - if ( index < 0 || index >= count ) { - return null; - } - int j = 0; - for ( int i = 0; i < table.length; i++ ) { - Entry e = table[ i ]; - if ( e == null ) { - continue; - } - do { - if ( j++ == index ) { - return e.value; - } - e = e.next; - } while ( e != null ); - } - return null; - } - - /** - * Clears the map. - */ - public void clear() { - for ( int i = 0; i < table.length; i++ ) { - table[ i ] = null; - } - count = 0; - } - - /** - * Rehash the table - */ - protected void rehash() { - Entry[] oldTable = table; - - table = new Entry[oldTable.length * 2 + 1]; - - for ( int i = oldTable.length - 1; i >= 0; i-- ) { - for ( Entry old = oldTable[ i ]; old != null; ) { - Entry e = old; - old = old.next; - - int index = e.hash % table.length; - e.next = table[ index ]; - table[ index ] = e; - } - } - } - - /** - * To manage collisions - */ - protected static class Entry - implements Serializable { - - /** - * The hash code - */ - public int hash; - - /** - * The key - */ - public Object key; - - /** - * The value - */ - public Object value; - - /** - * The next entry - */ - public Entry next; - - /** - * Creates a new entry - */ - public Entry( int hash, Object key, Object value, Entry next ) { - this.hash = hash; - this.key = key; - this.value = value; - this.next = next; - } - } -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTableStack.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTableStack.java index 0918a0780..afb04925a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTableStack.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/HashTableStack.java @@ -18,6 +18,8 @@ */ package org.apache.batik.dom.util; +import java.util.HashMap; + /** * This class represents a stack of HashTable objects. * @@ -86,7 +88,7 @@ public class HashTableStack { /** * The table. */ - public HashTable table; + public HashMap table; /** * The next link. @@ -108,7 +110,7 @@ public class HashTableStack { * Creates a new link. */ public Link(Link n) { - table = new HashTable(); + table = new HashMap(); next = n; if (next != null) defaultStr = next.defaultStr; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/ListNodeList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/ListNodeList.java index dc62ff65d..98b344aae 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/ListNodeList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/ListNodeList.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.util; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXDocumentFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXDocumentFactory.java index 302190a8c..633070a0e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXDocumentFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXDocumentFactory.java @@ -49,7 +49,7 @@ import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; import org.apache.batik.util.HaltingThread; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; /** * This class contains methods for creating Document instances diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXIOException.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXIOException.java index fa6e245dc..bba55f8a9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXIOException.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/SAXIOException.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.util; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XLinkSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XLinkSupport.java index a6c75bb22..0a05c3370 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XLinkSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XLinkSupport.java @@ -18,7 +18,7 @@ */ package org.apache.batik.dom.util; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.DOMException; import org.w3c.dom.Element; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XMLSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XMLSupport.java index 83f68f153..1f6588635 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XMLSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/dom/util/XMLSupport.java @@ -15,11 +15,11 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.dom.util; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/LinearGradientPaint.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/LinearGradientPaint.java index b35a1069e..be0fb2852 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/LinearGradientPaint.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/LinearGradientPaint.java @@ -44,7 +44,6 @@ import java.awt.image.ColorModel; * For example: *
        * - *

        * Point2D start = new Point2D.Float(0, 0);
        * Point2D end = new Point2D.Float(100,100);
        * float[] dist = {0.0, 0.2, 1.0};
        @@ -73,7 +72,7 @@ import java.awt.image.ColorModel; *

        The following image demonstrates the options NO_CYCLE and REFLECT. * *

        - * + * * *

        The colorSpace parameter allows the user to specify in which colorspace * the interpolation should be performed, default sRGB or linearized RGB. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/MultipleGradientPaint.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/MultipleGradientPaint.java index 84fa6890b..b9708c7eb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/MultipleGradientPaint.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/MultipleGradientPaint.java @@ -167,8 +167,8 @@ public abstract class MultipleGradientPaint implements Paint { // Process transparency boolean opaque = true; - for(int i=0; i - * + * *

        * This image demonstrates a radial gradient with NO_CYCLE and default focus. *

        * - * + * *

        * This image demonstrates a radial gradient with NO_CYCLE and non-centered * focus. *

        * - * + * *

        * This image demonstrates a radial gradient with REFLECT and non-centered * focus. @@ -138,7 +138,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * * */ @@ -174,7 +174,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * * */ @@ -218,7 +218,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * * */ @@ -260,7 +260,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * */ public RadialGradientPaint(Point2D center, float radius, @@ -305,7 +305,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * */ public RadialGradientPaint(Point2D center, float radius, @@ -356,7 +356,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * */ public RadialGradientPaint(Point2D center, @@ -407,7 +407,7 @@ public final class RadialGradientPaint extends MultipleGradientPaint { * * @throws IllegalArgumentException * if fractions.length != colors.length, or if colors is less - * than 2 in size, or if radius < 0 + * than 2 in size, or if radius < 0 * */ public RadialGradientPaint(Rectangle2D gradientBounds, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/TranscodingHintKey.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/TranscodingHintKey.java index 56cf3ca58..f0b853d70 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/TranscodingHintKey.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/TranscodingHintKey.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java index e924aa5c8..57cea1535 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java @@ -83,7 +83,7 @@ public class ICCColorSpaceExt extends ICC_ColorSpace { case SATURATION: return saturationToRGB(values); default: - throw new Error("invalid intent:" + intent ); + throw new RuntimeException("invalid intent:" + intent ); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/NamedProfileCache.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/NamedProfileCache.java index f6ffb34a4..54021ac8c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/NamedProfileCache.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/color/NamedProfileCache.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.color; @@ -69,7 +69,7 @@ public class NamedProfileCache extends SoftReferenceCache { * If this returns null then you are now 'on the hook'. * to put the ICCColorSpaceExt associated with String into the * cache. - * @param the profile name + * @param profileName the profile name */ public synchronized ICCColorSpaceWithIntent request(String profileName) { return (ICCColorSpaceWithIntent)super.requestImpl(profileName); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/font/TextPathLayout.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/font/TextPathLayout.java index bab277749..fcd2a1899 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/font/TextPathLayout.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/font/TextPathLayout.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.font; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/AbstractGraphics2D.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/AbstractGraphics2D.java index 9e2cf5f94..53d759adc 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/AbstractGraphics2D.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/AbstractGraphics2D.java @@ -605,7 +605,7 @@ public abstract class AbstractGraphics2D extends Graphics2D implements Cloneable * @see java.awt.Graphics#drawChars */ public void drawString(String str, int x, int y){ - drawString(str, (float)x, (float)y); + drawString(str, (float)x, y); } @@ -623,7 +623,7 @@ public abstract class AbstractGraphics2D extends Graphics2D implements Cloneable */ public void drawString(AttributedCharacterIterator iterator, int x, int y){ - drawString(iterator, (float)x, (float)y); + drawString(iterator, (float)x, y); } /** @@ -880,7 +880,7 @@ public abstract class AbstractGraphics2D extends Graphics2D implements Cloneable } catch(NoninvertibleTransformException e){ // Should never happen since we checked the // matrix determinant - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } gc.transform(xform); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/TransformType.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/TransformType.java index 74a45c933..5e8902d23 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/TransformType.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/g2d/TransformType.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.g2d; @@ -25,7 +25,7 @@ package org.apache.batik.ext.awt.g2d; * @author Vincent Hardy * @version $Id$ */ -public class TransformType{ +public final class TransformType{ /* * Transform type constants */ @@ -105,7 +105,7 @@ public class TransformType{ case TRANSFORM_GENERAL: return TransformType.GENERAL; default: - throw new Error("Unknown TransformType value:" + val ); + throw new RuntimeException("Unknown TransformType value:" + val ); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Cubic.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Cubic.java index 688cedf7a..fd5c49156 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Cubic.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Cubic.java @@ -157,8 +157,8 @@ public class Cubic extends AbstractSegment { /** * Subdivides this Cubic curve into two curves at t = 0.5. * can be done with getSegment but this is more efficent. - * @param s0 if non-null contains portion of curve from 0->.5 - * @param s1 if non-null contains portion of curve from .5->1 + * @param s0 if non-null contains portion of curve from 0->.5 + * @param s1 if non-null contains portion of curve from .5->1 */ public void subdivide(Segment s0, Segment s1) { Cubic c0=null, c1=null; @@ -169,8 +169,8 @@ public class Cubic extends AbstractSegment { /** * Subdivides this Cubic curve into two curves at given t. - * @param s0 if non-null contains portion of curve from 0->t. - * @param s1 if non-null contains portion of curve from t->1. + * @param s0 if non-null contains portion of curve from 0->t. + * @param s1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Segment s0, Segment s1) { Cubic c0=null, c1=null; @@ -182,8 +182,8 @@ public class Cubic extends AbstractSegment { /** * Subdivides this Cubic curve into two curves at t = 0.5. * can be done with getSegment but this is more efficent. - * @param c0 if non-null contains portion of curve from 0->.5 - * @param c1 if non-null contains portion of curve from .5->1 + * @param c0 if non-null contains portion of curve from 0->.5 + * @param c1 if non-null contains portion of curve from .5->1 */ public void subdivide(Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; @@ -221,8 +221,8 @@ public class Cubic extends AbstractSegment { /** * Subdivides this Cubic curve into two curves at given t. - * @param c0 if non-null contains portion of curve from 0->t. - * @param c1 if non-null contains portion of curve from t->1. + * @param c0 if non-null contains portion of curve from 0->t. + * @param c1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Linear.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Linear.java index 5fa3669e3..baa4d1441 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Linear.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Linear.java @@ -131,8 +131,8 @@ public class Linear implements Segment { /** * Subdivides this Linear segment into two segments at t = 0.5. * can be done with getSegment but this is more efficent. - * @param s0 if non-null contains portion of curve from 0->.5 - * @param s1 if non-null contains portion of curve from .5->1 + * @param s0 if non-null contains portion of curve from 0->.5 + * @param s1 if non-null contains portion of curve from .5->1 */ public void subdivide(Segment s0, Segment s1) { Linear l0=null, l1=null; @@ -143,8 +143,8 @@ public class Linear implements Segment { /** * Subdivides this Linear segment into two segments at given t. - * @param s0 if non-null contains portion of curve from 0->t. - * @param s1 if non-null contains portion of curve from t->1. + * @param s0 if non-null contains portion of curve from 0->t. + * @param s1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Segment s0, Segment s1) { Linear l0=null, l1=null; @@ -156,8 +156,8 @@ public class Linear implements Segment { /** * Subdivides this Cubic curve into two curves at t = 0.5. * Can be done with getSegment but this is more efficent. - * @param l0 if non-null contains portion of curve from 0->.5 - * @param l1 if non-null contains portion of curve from .5->1 + * @param l0 if non-null contains portion of curve from 0->.5 + * @param l1 if non-null contains portion of curve from .5->1 */ public void subdivide(Linear l0, Linear l1) { if ((l0 == null) && (l1 == null)) return; @@ -183,8 +183,8 @@ public class Linear implements Segment { * Subdivides this Cubic curve into two curves. * Can be done with getSegment but this is more efficent. * @param t position to split the curve - * @param l0 if non-null contains portion of curve from 0->t - * @param l1 if non-null contains portion of curve from t->1 + * @param l0 if non-null contains portion of curve from 0->t + * @param l1 if non-null contains portion of curve from t->1 */ public void subdivide(double t, Linear l0, Linear l1) { if ((l0 == null) && (l1 == null)) return; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/PathLength.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/PathLength.java index 3f6e117ca..5f1db733f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/PathLength.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/PathLength.java @@ -133,7 +133,7 @@ public class PathLength { while (!pi.isDone()) { origIndex++; - indexes.add(new Integer(index)); + indexes.add(index); segType = pi.currentSegment(seg); switch (segType) { case PathIterator.SEG_MOVETO: @@ -189,7 +189,7 @@ public class PathLength { } segmentIndexes = new int[indexes.size()]; for (int i = 0; i < segmentIndexes.length; i++) { - segmentIndexes[i] = ((Integer) indexes.get(i)).intValue(); + segmentIndexes[i] = (Integer) indexes.get(i); } initialised = true; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polygon2D.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polygon2D.java index 683cd654a..7bbab55c6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polygon2D.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polygon2D.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.geom; @@ -293,7 +293,7 @@ public class Polygon2D implements Shape, Cloneable, Serializable { * false otherwise. */ public boolean contains(int x, int y) { - return contains((double) x, (double) y); + return contains((double) x, y); } /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polyline2D.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polyline2D.java index bf1bd32ad..c8235607a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polyline2D.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Polyline2D.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.geom; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Quadradic.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Quadradic.java index 529391287..e6a725e64 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Quadradic.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/Quadradic.java @@ -148,8 +148,8 @@ public class Quadradic extends AbstractSegment { /** * Subdivides this Quadradic curve into two curves at t = 0.5. * can be done with getSegment but this is more efficent. - * @param q0 if non-null contains portion of curve from 0->.5 - * @param q1 if non-null contains portion of curve from .5->1 + * @param q0 if non-null contains portion of curve from 0->.5 + * @param q1 if non-null contains portion of curve from .5->1 */ public void subdivide(Quadradic q0, Quadradic q1) { if ((q0 == null) && (q1 == null)) return; @@ -181,8 +181,8 @@ public class Quadradic extends AbstractSegment { /** * Subdivides this Quadradic curve into two curves at given t. - * @param q0 if non-null contains portion of curve from 0->t. - * @param q1 if non-null contains portion of curve from t->1. + * @param q0 if non-null contains portion of curve from 0->t. + * @param q1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Quadradic q0, Quadradic q1) { Point2D.Double np = eval(t); @@ -210,8 +210,8 @@ public class Quadradic extends AbstractSegment { /** * Subdivides this Quadradic curve into two curves at t = 0.5. * can be done with getSegment but this is more efficent. - * @param s0 if non-null contains portion of curve from 0->.5 - * @param s1 if non-null contains portion of curve from .5->1 + * @param s0 if non-null contains portion of curve from 0->.5 + * @param s1 if non-null contains portion of curve from .5->1 */ public void subdivide(Segment s0, Segment s1) { Quadradic q0=null, q1=null; @@ -223,8 +223,8 @@ public class Quadradic extends AbstractSegment { /** * Subdivides this Quadradic curve into two curves at t. * can be done with getSegment but this is more efficent. - * @param s0 if non-null contains portion of curve from 0->.5 - * @param s1 if non-null contains portion of curve from .5->1 + * @param s0 if non-null contains portion of curve from 0->.5 + * @param s1 if non-null contains portion of curve from .5->1 */ public void subdivide(double t, Segment s0, Segment s1) { Quadradic q0=null, q1=null; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/SegmentList.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/SegmentList.java index 2d9992d42..d2ea8435c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/SegmentList.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/geom/SegmentList.java @@ -126,13 +126,13 @@ public class SegmentList { } Segment [] resAbove = results.getAbove(); - for(int i=0; i + * Ad = As + Ad*(1-As) * */ public static final CompositeRule OVER = new CompositeRule(RULE_OVER); @@ -236,7 +236,7 @@ public final class CompositeRule implements java.io.Serializable { case RULE_LIGHTEN: return LIGHTEN; default: - throw new Error("Unknown Composite Rule type"); + throw new RuntimeException("Unknown Composite Rule type"); } } @@ -271,7 +271,7 @@ public final class CompositeRule implements java.io.Serializable { case RULE_LIGHTEN: return "[CompositeRule: LIGHTEN]"; default: - throw new Error("Unknown Composite Rule type"); + throw new RuntimeException("Unknown Composite Rule type"); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/ConcreteComponentTransferFunction.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/ConcreteComponentTransferFunction.java index de6f4ca4c..e54e73806 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/ConcreteComponentTransferFunction.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/ConcreteComponentTransferFunction.java @@ -27,7 +27,7 @@ package org.apache.batik.ext.awt.image; * @author Vincent Hardy * @version $Id$ */ -public class ConcreteComponentTransferFunction implements ComponentTransferFunction { +public final class ConcreteComponentTransferFunction implements ComponentTransferFunction { private int type; private float slope; private float[] tableValues; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/GraphicsUtil.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/GraphicsUtil.java index 65ce925b2..b16c4de4b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/GraphicsUtil.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/GraphicsUtil.java @@ -495,7 +495,7 @@ public class GraphicsUtil { try { String s = System.getProperty ("org.apache.batik.warn_destination", "true"); - warn = Boolean.valueOf(s).booleanValue(); + warn = Boolean.valueOf(s); } catch (SecurityException se) { } catch (NumberFormatException nfe) { } finally { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/PadMode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/PadMode.java index 4de5cc670..2f9c06ec9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/PadMode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/PadMode.java @@ -76,7 +76,7 @@ public final class PadMode implements java.io.Serializable { case MODE_WRAP: return WRAP; default: - throw new Error("Unknown Pad Mode type"); + throw new RuntimeException("Unknown Pad Mode type"); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/URLImageCache.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/URLImageCache.java index 47f2216c4..0dcaad39e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/URLImageCache.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/URLImageCache.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.image; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java index a2f71b9c8..34d03f8cc 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java @@ -42,7 +42,9 @@ public class PNGTranscoderImageIOWriteAdapter implements /** * @throws TranscoderException - * @see org.apache.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage(org.apache.batik.transcoder.image.PNGTranscoder, java.awt.image.BufferedImage, org.apache.batik.transcoder.TranscoderOutput) + * @see org.apache.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage( + * org.apache.batik.transcoder.image.PNGTranscoder, java.awt.image.BufferedImage, + * org.apache.batik.transcoder.TranscoderOutput) */ public void writeImage(PNGTranscoder transcoder, BufferedImage img, TranscoderOutput output) throws TranscoderException { @@ -51,7 +53,7 @@ public class PNGTranscoderImageIOWriteAdapter implements int n = -1; if (hints.containsKey(PNGTranscoder.KEY_INDEXED)) { - n=((Integer)hints.get(PNGTranscoder.KEY_INDEXED)).intValue(); + n= (Integer) hints.get(PNGTranscoder.KEY_INDEXED); if (n==1||n==2||n==4||n==8) //PNGEncodeParam.Palette can handle these numbers only. img = IndexImage.getIndexedImage(img, 1< * * where gamma_from_file is the gamma of the file - * data, as determined by the gAMA, sRGB, + * data, as determined by the gAMA, sRGB, * and/or iCCP chunks, and display_exponent * is the exponent of the intrinsic transfer curve of the display, * generally 2.2. @@ -260,7 +260,7 @@ public class PNGDecodeParam implements ImageDecodeParam { * * * where gamma_from_file is the gamma of the file - * data, as determined by the gAMA, sRGB, + * data, as determined by the gAMA, sRGB, * and/or iCCP chunks, and user_exponent * is an additional user-supplied parameter. * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGEncodeParam.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGEncodeParam.java index e2ba17ba2..a7c8d9653 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGEncodeParam.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGEncodeParam.java @@ -165,7 +165,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { IllegalArgumentException(PropertyUtil.getString("PNGEncodeParam1")); } - palette = (int[])(rgb.clone()); + palette = rgb.clone(); paletteSet = true; } @@ -183,7 +183,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!paletteSet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam3")); } - return (int[])(palette.clone()); + return palette.clone(); } /** @@ -517,7 +517,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { *

        The 'tRNS' chunk will encode this information. */ public void setTransparentRGB(int[] transparentRGB) { - transparency = (int[])(transparentRGB.clone()); + transparency = transparentRGB.clone(); transparencySet = true; } @@ -534,7 +534,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!transparencySet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam10")); } - return (int[])(transparency.clone()); + return transparency.clone(); } } @@ -640,7 +640,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (chromaticity.length != 8) { throw new IllegalArgumentException(); } - this.chromaticity = (float[])(chromaticity.clone()); + this.chromaticity = chromaticity.clone(); chromaticitySet = true; } @@ -679,7 +679,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!chromaticitySet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam12")); } - return (float[])(chromaticity.clone()); + return chromaticity.clone(); } /** @@ -754,7 +754,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { *

        The 'hIST' chunk will encode this information. */ public void setPaletteHistogram(int[] paletteHistogram) { - this.paletteHistogram = (int[])(paletteHistogram.clone()); + this.paletteHistogram = paletteHistogram.clone(); paletteHistogramSet = true; } @@ -800,7 +800,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { *

        The 'iCCP' chunk will encode this information. */ public void setICCProfileData(byte[] ICCProfileData) { - this.ICCProfileData = (byte[])(ICCProfileData.clone()); + this.ICCProfileData = ICCProfileData.clone(); ICCProfileDataSet = true; } @@ -816,7 +816,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!ICCProfileDataSet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam15")); } - return (byte[])(ICCProfileData.clone()); + return ICCProfileData.clone(); } /** @@ -849,7 +849,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { *

        The 'pHYS' chunk will encode this information. */ public void setPhysicalDimension(int[] physicalDimension) { - this.physicalDimension = (int[])(physicalDimension.clone()); + this.physicalDimension = physicalDimension.clone(); physicalDimensionSet = true; } @@ -882,7 +882,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!physicalDimensionSet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam16")); } - return (int[])(physicalDimension.clone()); + return physicalDimension.clone(); } /** @@ -913,7 +913,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { *

        The 'sPLT' chunk will encode this information. */ public void setSuggestedPalette(PNGSuggestedPaletteEntry[] palette) { - suggestedPalette = (PNGSuggestedPaletteEntry[])(palette.clone()); + suggestedPalette = palette.clone(); suggestedPaletteSet = true; } @@ -932,7 +932,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!suggestedPaletteSet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam17")); } - return (PNGSuggestedPaletteEntry[])(suggestedPalette.clone()); + return suggestedPalette.clone(); } /** @@ -966,7 +966,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { *

        The 'sBIT' chunk will encode this information. */ public void setSignificantBits(int[] significantBits) { - this.significantBits = (int[])(significantBits.clone()); + this.significantBits = significantBits.clone(); significantBitsSet = true; } @@ -984,7 +984,7 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { if (!significantBitsSet) { throw new IllegalStateException(PropertyUtil.getString("PNGEncodeParam18")); } - return (int[])significantBits.clone(); + return significantBits.clone(); } /** @@ -1342,9 +1342,9 @@ public abstract class PNGEncodeParam implements ImageEncodeParam { * could be implemented (non-optimally) as follows: * *

        -     * for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
        -     *     int curr = currRow[i] & 0xff;
        -     *     int left = currRow[i - bytesPerPixel] & 0xff;
        +     * for (int i = bytesPerPixel; i < bytesPerRow + bytesPerPixel; i++) {
        +     *     int curr = currRow[i] & 0xff;
        +     *     int left = currRow[i - bytesPerPixel] & 0xff;
              *     scratchRow[PNG_FILTER_SUB][i] = (byte)(curr - left);
              * }
              * return PNG_FILTER_SUB;
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageDecoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageDecoder.java
        index a6a5837c4..a2293916c 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageDecoder.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageDecoder.java
        @@ -588,7 +588,7 @@ class PNGImage extends SimpleRenderedImage {
                     encodeParam.setBitDepth(bitDepth);
                 }
                 if (emitProperties) {
        -            properties.put("bit_depth", new Integer(bitDepth));
        +            properties.put("bit_depth", bitDepth);
                 }
         
                 if (performGammaCorrection) {
        @@ -598,7 +598,7 @@ class PNGImage extends SimpleRenderedImage {
                         encodeParam.setGamma(gamma);
                     }
                     if (emitProperties) {
        -                properties.put("gamma", new Float(gamma));
        +                properties.put("gamma", gamma);
                     }
                 }
         
        @@ -1073,14 +1073,14 @@ class PNGImage extends SimpleRenderedImage {
                     encodeParam.setChromaticity(chromaticity);
                 }
                 if (emitProperties) {
        -            properties.put("white_point_x", new Float(chromaticity[0]));
        -            properties.put("white_point_y", new Float(chromaticity[1]));
        -            properties.put("red_x", new Float(chromaticity[2]));
        -            properties.put("red_y", new Float(chromaticity[3]));
        -            properties.put("green_x", new Float(chromaticity[4]));
        -            properties.put("green_y", new Float(chromaticity[5]));
        -            properties.put("blue_x", new Float(chromaticity[6]));
        -            properties.put("blue_y", new Float(chromaticity[7]));
        +            properties.put("white_point_x", chromaticity[0]);
        +            properties.put("white_point_y", chromaticity[1]);
        +            properties.put("red_x", chromaticity[2]);
        +            properties.put("red_y", chromaticity[3]);
        +            properties.put("green_x", chromaticity[4]);
        +            properties.put("green_y", chromaticity[5]);
        +            properties.put("blue_x", chromaticity[6]);
        +            properties.put("blue_y", chromaticity[7]);
                 }
             }
         
        @@ -1098,7 +1098,7 @@ class PNGImage extends SimpleRenderedImage {
                     encodeParam.setGamma(fileGamma*exp);
                 }
                 if (emitProperties) {
        -            properties.put("gamma", new Float(fileGamma*exp));
        +            properties.put("gamma", fileGamma * exp);
                 }
             }
         
        @@ -1140,10 +1140,10 @@ class PNGImage extends SimpleRenderedImage {
                                                      unitSpecifier);
                 }
                 if (emitProperties) {
        -            properties.put("x_pixels_per_unit", new Integer(xPixelsPerUnit));
        -            properties.put("y_pixels_per_unit", new Integer(yPixelsPerUnit));
        +            properties.put("x_pixels_per_unit", xPixelsPerUnit);
        +            properties.put("y_pixels_per_unit", yPixelsPerUnit);
                     properties.put("pixel_aspect_ratio",
        -                           new Float((float)xPixelsPerUnit/yPixelsPerUnit));
        +                    (float) xPixelsPerUnit / yPixelsPerUnit);
                     if (unitSpecifier == 1) {
                         properties.put("pixel_units", "Meters");
                     } else if (unitSpecifier != 0) {
        @@ -1205,15 +1205,15 @@ class PNGImage extends SimpleRenderedImage {
                         encodeParam.setChromaticity(chromaticity);
                     }
                     if (emitProperties) {
        -                properties.put("gamma", new Float(gamma));
        -                properties.put("white_point_x", new Float(chromaticity[0]));
        -                properties.put("white_point_y", new Float(chromaticity[1]));
        -                properties.put("red_x", new Float(chromaticity[2]));
        -                properties.put("red_y", new Float(chromaticity[3]));
        -                properties.put("green_x", new Float(chromaticity[4]));
        -                properties.put("green_y", new Float(chromaticity[5]));
        -                properties.put("blue_x", new Float(chromaticity[6]));
        -                properties.put("blue_y", new Float(chromaticity[7]));
        +                properties.put("gamma", gamma);
        +                properties.put("white_point_x", chromaticity[0]);
        +                properties.put("white_point_y", chromaticity[1]);
        +                properties.put("red_x", chromaticity[2]);
        +                properties.put("red_y", chromaticity[3]);
        +                properties.put("green_x", chromaticity[4]);
        +                properties.put("green_y", chromaticity[5]);
        +                properties.put("blue_x", chromaticity[6]);
        +                properties.put("blue_y", chromaticity[7]);
                     }
                 }
             }
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageEncoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageEncoder.java
        index e40685a50..b11de1741 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageEncoder.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageEncoder.java
        @@ -571,8 +571,8 @@ public class PNGImageEncoder extends ImageEncoderImpl {
                     ChunkStream cs = new ChunkStream("sBIT");
                     int[] significantBits = param.getSignificantBits();
                     int len = significantBits.length;
        -            for (int i = 0; i < len; i++) {
        -                cs.writeByte(significantBits[i]);
        +            for (int significantBit : significantBits) {
        +                cs.writeByte(significantBit);
                     }
                     cs.writeToStream(dataOutput);
                     cs.close();
        @@ -642,8 +642,8 @@ public class PNGImageEncoder extends ImageEncoderImpl {
                     ChunkStream cs = new ChunkStream("hIST");
         
                     int[] hist = param.getPaletteHistogram();
        -            for (int i = 0; i < hist.length; i++) {
        -                cs.writeShort(hist[i]);
        +            for (int aHist : hist) {
        +                cs.writeShort(aHist);
                     }
         
                     cs.writeToStream(dataOutput);
        @@ -660,8 +660,8 @@ public class PNGImageEncoder extends ImageEncoderImpl {
                     if (param instanceof PNGEncodeParam.Palette) {
                         byte[] t =
                             ((PNGEncodeParam.Palette)param).getPaletteTransparency();
        -                for (int i = 0; i < t.length; i++) {
        -                    cs.writeByte(t[i]);
        +                for (byte aT : t) {
        +                    cs.writeByte(aT);
                         }
                     } else if (param instanceof PNGEncodeParam.Gray) {
                         int t = ((PNGEncodeParam.Gray)param).getTransparentGray();
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGRed.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGRed.java
        index 2ed0d5af7..d19862644 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGRed.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGRed.java
        @@ -586,7 +586,7 @@ public class PNGRed extends AbstractRed {
                     encodeParam.setBitDepth(bitDepth);
                 }
                 if (emitProperties) {
        -            properties.put("bit_depth", new Integer(bitDepth));
        +            properties.put("bit_depth", bitDepth);
                 }
         
                 if (performGammaCorrection) {
        @@ -596,7 +596,7 @@ public class PNGRed extends AbstractRed {
                         encodeParam.setGamma(gamma);
                     }
                     if (emitProperties) {
        -                properties.put("gamma", new Float(gamma));
        +                properties.put("gamma", gamma);
                     }
                 }
         
        @@ -1084,14 +1084,14 @@ public class PNGRed extends AbstractRed {
                     encodeParam.setChromaticity(chromaticity);
                 }
                 if (emitProperties) {
        -            properties.put("white_point_x", new Float(chromaticity[0]));
        -            properties.put("white_point_y", new Float(chromaticity[1]));
        -            properties.put("red_x", new Float(chromaticity[2]));
        -            properties.put("red_y", new Float(chromaticity[3]));
        -            properties.put("green_x", new Float(chromaticity[4]));
        -            properties.put("green_y", new Float(chromaticity[5]));
        -            properties.put("blue_x", new Float(chromaticity[6]));
        -            properties.put("blue_y", new Float(chromaticity[7]));
        +            properties.put("white_point_x", chromaticity[0]);
        +            properties.put("white_point_y", chromaticity[1]);
        +            properties.put("red_x", chromaticity[2]);
        +            properties.put("red_y", chromaticity[3]);
        +            properties.put("green_x", chromaticity[4]);
        +            properties.put("green_y", chromaticity[5]);
        +            properties.put("blue_x", chromaticity[6]);
        +            properties.put("blue_y", chromaticity[7]);
                 }
             }
         
        @@ -1109,7 +1109,7 @@ public class PNGRed extends AbstractRed {
                     encodeParam.setGamma(fileGamma*exp);
                 }
                 if (emitProperties) {
        -            properties.put("gamma", new Float(fileGamma*exp));
        +            properties.put("gamma", fileGamma * exp);
                 }
             }
         
        @@ -1151,10 +1151,10 @@ public class PNGRed extends AbstractRed {
                                                      unitSpecifier);
                 }
                 if (emitProperties) {
        -            properties.put("x_pixels_per_unit", new Integer(xPixelsPerUnit));
        -            properties.put("y_pixels_per_unit", new Integer(yPixelsPerUnit));
        +            properties.put("x_pixels_per_unit", xPixelsPerUnit);
        +            properties.put("y_pixels_per_unit", yPixelsPerUnit);
                     properties.put("pixel_aspect_ratio",
        -                           new Float((float)xPixelsPerUnit/yPixelsPerUnit));
        +                    (float) xPixelsPerUnit / yPixelsPerUnit);
                     if (unitSpecifier == 1) {
                         properties.put("pixel_units", "Meters");
                     } else if (unitSpecifier != 0) {
        @@ -1216,15 +1216,15 @@ public class PNGRed extends AbstractRed {
                         encodeParam.setChromaticity(chromaticity);
                     }
                     if (emitProperties) {
        -                properties.put("gamma", new Float(gamma));
        -                properties.put("white_point_x", new Float(chromaticity[0]));
        -                properties.put("white_point_y", new Float(chromaticity[1]));
        -                properties.put("red_x", new Float(chromaticity[2]));
        -                properties.put("red_y", new Float(chromaticity[3]));
        -                properties.put("green_x", new Float(chromaticity[4]));
        -                properties.put("green_y", new Float(chromaticity[5]));
        -                properties.put("blue_x", new Float(chromaticity[6]));
        -                properties.put("blue_y", new Float(chromaticity[7]));
        +                properties.put("gamma", gamma);
        +                properties.put("white_point_x", chromaticity[0]);
        +                properties.put("white_point_y", chromaticity[1]);
        +                properties.put("red_x", chromaticity[2]);
        +                properties.put("red_y", chromaticity[3]);
        +                properties.put("green_x", chromaticity[4]);
        +                properties.put("green_y", chromaticity[5]);
        +                properties.put("blue_x", chromaticity[6]);
        +                properties.put("blue_y", chromaticity[7]);
                     }
                 }
             }
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGTranscoderInternalCodecWriteAdapter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGTranscoderInternalCodecWriteAdapter.java
        index 7336507e5..280119830 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGTranscoderInternalCodecWriteAdapter.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGTranscoderInternalCodecWriteAdapter.java
        @@ -39,7 +39,9 @@ public class PNGTranscoderInternalCodecWriteAdapter implements
         
             /**
              * @throws TranscoderException
        -     * @see org.apache.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage(org.apache.batik.transcoder.image.PNGTranscoder, java.awt.image.BufferedImage, org.apache.batik.transcoder.TranscoderOutput)
        +     * @see org.apache.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage(
        +     * org.apache.batik.transcoder.image.PNGTranscoder, java.awt.image.BufferedImage,
        +     * org.apache.batik.transcoder.TranscoderOutput)
              */
             public void writeImage(PNGTranscoder transcoder, BufferedImage img,
                     TranscoderOutput output) throws TranscoderException {
        @@ -47,7 +49,7 @@ public class PNGTranscoderInternalCodecWriteAdapter implements
         
                 int n=-1;
                 if (hints.containsKey(PNGTranscoder.KEY_INDEXED)) {
        -            n=((Integer)hints.get(PNGTranscoder.KEY_INDEXED)).intValue();
        +            n= (Integer) hints.get(PNGTranscoder.KEY_INDEXED);
                     if (n==1||n==2||n==4||n==8)
                         //PNGEncodeParam.Palette can handle these numbers only.
                         img = IndexImage.getIndexedImage(img,1< 0) {
                         params.setGamma(gamma);
                     }
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SimpleRenderedImage.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SimpleRenderedImage.java
        index 57a46af31..4b37f3cf4 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SimpleRenderedImage.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SimpleRenderedImage.java
        @@ -276,9 +276,9 @@ public abstract class SimpleRenderedImage implements RenderedImage {
                 prefix = prefix.toLowerCase();
         
                 List names = new ArrayList();
        -        for (int i = 0; i < propertyNames.length; i++) {
        -            if (propertyNames[i].startsWith(prefix)) {
        -                names.add(propertyNames[i]);
        +        for (String propertyName : propertyNames) {
        +            if (propertyName.startsWith(prefix)) {
        +                names.add(propertyName);
                     }
                 }
         
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SingleTileRenderedImage.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SingleTileRenderedImage.java
        index 170882d35..2396682ab 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SingleTileRenderedImage.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/util/SingleTileRenderedImage.java
        @@ -15,7 +15,7 @@
            See the License for the specific language governing permissions and
            limitations under the License.
         
        -*/
        + */
         
         package org.apache.batik.ext.awt.image.codec.util;
         
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/AbstractRable.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/AbstractRable.java
        index a817c1e11..0153009fd 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/AbstractRable.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/AbstractRable.java
        @@ -234,9 +234,8 @@ public abstract class AbstractRable implements Filter {
             public Object getProperty(String name) {
                 Object ret = props.get(name);
                 if (ret != null) return ret;
        -        Iterator i = srcs.iterator();
        -        while (i.hasNext()) {
        -            RenderableImage ri = (RenderableImage)i.next();
        +        for (Object src : srcs) {
        +            RenderableImage ri = (RenderableImage) src;
                     ret = ri.getProperty(name);
                     if (ret != null) return ret;
                 }
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ClipRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ClipRable8Bit.java
        index a62f7c789..cd1c08977 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ClipRable8Bit.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ClipRable8Bit.java
        @@ -166,9 +166,7 @@ public class ClipRable8Bit
         
                 if (false) {
                     java.util.Set s = rh.keySet();
        -            java.util.Iterator i = s.iterator();
        -            while (i.hasNext()) {
        -                Object o = i.next();
        +            for (Object o : s) {
                         System.out.println("XXX: " + o + " -> " + rh.get(o));
                     }
                 }
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ColorMatrixRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ColorMatrixRable8Bit.java
        index 5ee3c21d3..c365b65e1 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ColorMatrixRable8Bit.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ColorMatrixRable8Bit.java
        @@ -30,7 +30,7 @@ import org.apache.batik.ext.awt.image.rendered.ColorMatrixRed;
          * @author Vincent Hardy
          * @version $Id$
          */
        -public class ColorMatrixRable8Bit
        +public final class ColorMatrixRable8Bit
             extends    AbstractColorInterpolationRable
             implements ColorMatrixRable {
             /**
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ComponentTransferRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ComponentTransferRable8Bit.java
        index 6acde3cdf..2c28a0991 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ComponentTransferRable8Bit.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ComponentTransferRable8Bit.java
        @@ -226,7 +226,7 @@ public class ComponentTransferRable8Bit
                         break;
                     default:
                         // Should never happen
        -                throw new Error();
        +                throw new RuntimeException();
                     }
                 }
         
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/CompositeRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/CompositeRable8Bit.java
        index d4a8760c4..ffcfca9d5 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/CompositeRable8Bit.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/CompositeRable8Bit.java
        @@ -28,7 +28,6 @@ import java.awt.geom.AffineTransform;
         import java.awt.geom.Rectangle2D;
         import java.awt.image.RenderedImage;
         import java.awt.image.renderable.RenderContext;
        -import java.util.Iterator;
         import java.util.List;
         import java.util.ArrayList;
         
        @@ -116,9 +115,8 @@ public class CompositeRable8Bit
         
                 // System.out.println("drawImage : " + g2dCS +
                 //                    crCS);
        -        Iterator i = getSources().iterator();
        -        while (i.hasNext()) {
        -            GraphicsUtil.drawImage(g2d, (Filter)i.next());
        +        for (Object o : getSources()) {
        +            GraphicsUtil.drawImage(g2d, (Filter) o);
                 }
                 return true;
             }
        @@ -154,10 +152,9 @@ public class CompositeRable8Bit
                 // note: this hides a member in a superclass!
                 List srcs = new ArrayList();
         
        -        Iterator i = getSources().iterator();
        -        while (i.hasNext()) {
        +        for (Object o : getSources()) {
                     // Get the source to work with...
        -            Filter filt = (Filter)i.next();
        +            Filter filt = (Filter) o;
         
                     // Get our sources image...
                     RenderedImage ri = filt.createRendering(rc);
        @@ -169,25 +166,25 @@ public class CompositeRable8Bit
         
                         // Blank image...
                         switch (rule.getRule()) {
        -                case CompositeRule.RULE_IN:
        -                    // For Mode IN One blank image kills all output
        -                    // (including any "future" images to be drawn).
        -                    return null;
        -
        -                case CompositeRule.RULE_OUT:
        -                    // For mode OUT blank image clears output
        -                    // up to this point, so ignore inputs to this point.
        -                    srcs.clear();
        -                    break;
        -
        -                case CompositeRule.RULE_ARITHMETIC:
        -                    srcs.add(new FloodRed(devRect));
        -                    break;
        -
        -                default:
        -                    // All other cases we simple pretend the image didn't
        -                    // exist (fully transparent image has no affect).
        -                    break;
        +                    case CompositeRule.RULE_IN:
        +                        // For Mode IN One blank image kills all output
        +                        // (including any "future" images to be drawn).
        +                        return null;
        +
        +                    case CompositeRule.RULE_OUT:
        +                        // For mode OUT blank image clears output
        +                        // up to this point, so ignore inputs to this point.
        +                        srcs.clear();
        +                        break;
        +
        +                    case CompositeRule.RULE_ARITHMETIC:
        +                        srcs.add(new FloodRed(devRect));
        +                        break;
        +
        +                    default:
        +                        // All other cases we simple pretend the image didn't
        +                        // exist (fully transparent image has no affect).
        +                        break;
                         }
                     }
                 }
        diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ConvolveMatrixRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ConvolveMatrixRable8Bit.java
        index 04a41b2d2..005c44c29 100644
        --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ConvolveMatrixRable8Bit.java
        +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/ConvolveMatrixRable8Bit.java
        @@ -98,8 +98,8 @@ public class ConvolveMatrixRable8Bit
                 this.kernel = k;
                 kernelHasNegValues = false;
                 float [] kv = k.getKernelData(null);
        -        for (int i=0; i
        + * but its resolution can. 
        * The filter chain decomposes as follows: *
          *
        • A pad operation that makes the input image a big as the diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/FilterResRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/FilterResRable8Bit.java index eea28e7c3..af5345ff5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/FilterResRable8Bit.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/FilterResRable8Bit.java @@ -31,7 +31,6 @@ import java.awt.image.renderable.RenderContext; import java.awt.image.renderable.RenderableImage; import java.lang.ref.Reference; import java.lang.ref.SoftReference; -import java.util.Iterator; import java.util.ListIterator; import java.util.List; @@ -146,9 +145,8 @@ public class FilterResRable8Bit extends AbstractRable // No sources and we are PaintRable so the chain is PaintRable. if (v == null) return true; - Iterator i = v.iterator(); - while (i.hasNext()) { - RenderableImage nri = (RenderableImage)i.next(); + for (Object aV : v) { + RenderableImage nri = (RenderableImage) aV; // A source is not paintRable so we are not 100% paintRable. if (!allPaintRable(nri)) return false; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/TurbulenceRable8Bit.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/TurbulenceRable8Bit.java index fc89d5394..bb8d5f125 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/TurbulenceRable8Bit.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/renderable/TurbulenceRable8Bit.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.awt.image.renderable; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractRed.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractRed.java index 4a2f33313..c9d2ae54f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractRed.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractRed.java @@ -31,7 +31,6 @@ import java.awt.image.RenderedImage; import java.awt.image.SampleModel; import java.awt.image.WritableRaster; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -434,9 +433,8 @@ public abstract class AbstractRed implements CachableRed { public Object getProperty(String name) { Object ret = props.get(name); if (ret != null) return ret; - Iterator i = srcs.iterator(); - while (i.hasNext()) { - RenderedImage ri = (RenderedImage)i.next(); + for (Object src : srcs) { + RenderedImage ri = (RenderedImage) src; ret = ri.getProperty(name); if (ret != null) return ret; } @@ -454,15 +452,14 @@ public abstract class AbstractRed implements CachableRed { // ret[i++] = (String)iter.next(); // } - Iterator iter = srcs.iterator(); - while (iter.hasNext()) { - RenderedImage ri = (RenderedImage)iter.next(); - String [] srcProps = ri.getPropertyNames(); + for (Object src : srcs) { + RenderedImage ri = (RenderedImage) src; + String[] srcProps = ri.getPropertyNames(); if (srcProps.length != 0) { - String [] tmp = new String[ret.length+srcProps.length]; - System.arraycopy(ret,0,tmp,0,ret.length); + String[] tmp = new String[ret.length + srcProps.length]; + System.arraycopy(ret, 0, tmp, 0, ret.length); /// ??? System.arraycopy((tmp,ret.length,srcProps,0,srcProps.length); - System.arraycopy( srcProps, 0, tmp, ret.length, srcProps.length); + System.arraycopy(srcProps, 0, tmp, ret.length, srcProps.length); ret = tmp; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractTiledRed.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractTiledRed.java index fee6f0cbf..312d8426f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractTiledRed.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AbstractTiledRed.java @@ -561,11 +561,10 @@ public abstract class AbstractTiledRed int workTileWidth = tileWidth; // local is cheaper int workTileHeight = tileHeight; // local is cheaper int maxTileSize = 0; - for ( int i = 0; i < blocks.length; i++ ) { - TileBlock curr = blocks[ i ]; - int sz = ( ( curr.getWidth() * workTileWidth ) * - ( curr.getHeight() * workTileHeight ) ); - if ( sz > maxTileSize ) { + for (TileBlock curr : blocks) { + int sz = ((curr.getWidth() * workTileWidth) * + (curr.getHeight() * workTileHeight)); + if (sz > maxTileSize) { maxTileSize = sz; } } @@ -576,25 +575,24 @@ public abstract class AbstractTiledRed // cache for reuse in hasBeenHalted() Thread currentThread = Thread.currentThread(); - for ( int i = 0; i < blocks.length; i++ ) { - TileBlock curr = blocks[ i ]; + for (TileBlock curr : blocks) { int xloc = curr.getXLoc() * workTileWidth + tileGridXOff; int yloc = curr.getYLoc() * workTileHeight + tileGridYOff; - Rectangle tb = new Rectangle( xloc, yloc, + Rectangle tb = new Rectangle(xloc, yloc, curr.getWidth() * workTileWidth, - curr.getHeight() * workTileHeight ); - tb = tb.intersection( bounds ); - Point loc = new Point( tb.x, tb.y ); - WritableRaster child = Raster.createPackedRaster( dbi, tb.width, tb.height, tb.width, masks, loc ); - genRect( child ); - if ( use_INT_PACK ) { - GraphicsUtil.copyData_INT_PACK( child, wr ); + curr.getHeight() * workTileHeight); + tb = tb.intersection(bounds); + Point loc = new Point(tb.x, tb.y); + WritableRaster child = Raster.createPackedRaster(dbi, tb.width, tb.height, tb.width, masks, loc); + genRect(child); + if (use_INT_PACK) { + GraphicsUtil.copyData_INT_PACK(child, wr); } else { - GraphicsUtil.copyData_FALLBACK( child, wr ); + GraphicsUtil.copyData_FALLBACK(child, wr); } // Check If we should halt early. - if ( HaltingThread.hasBeenHalted( currentThread ) ) { + if (HaltingThread.hasBeenHalted(currentThread)) { return; } } @@ -610,26 +608,24 @@ public abstract class AbstractTiledRed int workTileWidth = tileWidth; // local is cheaper int workTileHeight = tileHeight; // local is cheaper - for ( int i = 0; i < blocks.length; i++ ) { - TileBlock curr = blocks[ i ]; - + for (TileBlock curr : blocks) { // System.out.println("Block " + i + ":\n" + curr); int xloc = curr.getXLoc() * workTileWidth + tileGridXOff; int yloc = curr.getYLoc() * workTileHeight + tileGridYOff; - Rectangle tb = new Rectangle( xloc, yloc, + Rectangle tb = new Rectangle(xloc, yloc, curr.getWidth() * workTileWidth, - curr.getHeight() * workTileHeight ); - tb = tb.intersection( bounds ); + curr.getHeight() * workTileHeight); + tb = tb.intersection(bounds); WritableRaster child = - wr.createWritableChild( tb.x, tb.y, tb.width, tb.height, - tb.x, tb.y, null ); + wr.createWritableChild(tb.x, tb.y, tb.width, tb.height, + tb.x, tb.y, null); // System.out.println("Computing : " + child); - genRect( child ); + genRect(child); // Check If we should halt early. - if ( HaltingThread.hasBeenHalted( currentThread ) ) { + if (HaltingThread.hasBeenHalted(currentThread)) { return; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AffineRed.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AffineRed.java index bc493ec67..e90597b04 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AffineRed.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/AffineRed.java @@ -190,7 +190,7 @@ public class AffineRed extends AbstractRed { myBI = new BufferedImage(myCM,wr.createWritableTranslatedChild(0,0), myCM.isAlphaPremultiplied(), null); - op.filter(srcBI, myBI); + op.filter(srcBI.getRaster(), myBI.getRaster()); // if ((count % 40) == 0) { // org.apache.batik.ImageDisplay.showImage("Src: " , srcBI); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java index 6262e7ea6..62010942c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java @@ -19,6 +19,9 @@ package org.apache.batik.ext.awt.image.rendered; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics2D; import java.awt.Point; import java.awt.Transparency; import java.awt.color.ColorSpace; @@ -45,19 +48,23 @@ import org.apache.batik.ext.awt.image.GraphicsUtil; * @version $Id$ */ public class Any2LumRed extends AbstractRed { + boolean isColorConvertOpAplhaSupported; + /** * Construct a luminace image from src. * * @param src The image to convert to a luminance image */ public Any2LumRed(CachableRed src) { - super(src,src.getBounds(), + super(src,src.getBounds(), fixColorModel(src), fixSampleModel(src), src.getTileGridXOffset(), src.getTileGridYOffset(), null); + isColorConvertOpAplhaSupported = getColorConvertOpAplhaSupported(); + props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE, ColorSpaceHintKey.VALUE_COLORSPACE_GREY); } @@ -88,31 +95,29 @@ public class Any2LumRed extends AbstractRed { WritableRaster srcWr = (WritableRaster)srcRas; // Divide out alpha if we have it. We need to do this since - // the color convert may not be a linear operation which may + // the color convert may not be a linear operation which may // lead to out of range values. if (srcCM.hasAlpha()) GraphicsUtil.coerceData(srcWr, srcCM, false); BufferedImage srcBI, dstBI; - srcBI = new BufferedImage(srcCM, + srcBI = new BufferedImage(srcCM, srcWr.createWritableTranslatedChild(0,0), - false, + false, null); ColorModel dstCM = getColorModel(); - if (!dstCM.hasAlpha()) { - // No alpha ao we don't have to work around the bug - // in the color convert op. - dstBI = new BufferedImage - (dstCM, wr.createWritableTranslatedChild(0,0), - dstCM.isAlphaPremultiplied(), null); - } else { + + if (dstCM.hasAlpha() && !isColorConvertOpAplhaSupported) { + // All this nonsense is to work around the fact that the // Color convert op doesn't properly copy the Alpha from - // src to dst. + // src to dst: + // https://bugs.openjdk.java.net/browse/JDK-8005930 + PixelInterleavedSampleModel dstSM; dstSM = (PixelInterleavedSampleModel)wr.getSampleModel(); SampleModel smna = new PixelInterleavedSampleModel - (dstSM.getDataType(), + (dstSM.getDataType(), dstSM.getWidth(), dstSM.getHeight(), dstSM.getPixelStride(), dstSM.getScanlineStride(), new int [] { 0 }); @@ -126,14 +131,20 @@ public class Any2LumRed extends AbstractRed { wr.getMinY()-wr.getSampleModelTranslateY(), wr.getWidth(), wr.getHeight(), 0, 0, null); - + ColorModel cmna = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8}, false, false, - Transparency.OPAQUE, + Transparency.OPAQUE, DataBuffer.TYPE_BYTE); dstBI = new BufferedImage(cmna, dstWr, false, null); + } else { + // No alpha ao we don't have to work around the bug + // in the color convert op. + dstBI = new BufferedImage + (dstCM, wr.createWritableTranslatedChild(0,0), + dstCM.isAlphaPremultiplied(), null); } ColorConvertOp op = new ColorConvertOp(null); @@ -163,15 +174,15 @@ public class Any2LumRed extends AbstractRed { (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8,8}, true, cm.isAlphaPremultiplied(), - Transparency.TRANSLUCENT, + Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); return new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8}, false, false, - Transparency.OPAQUE, + Transparency.OPAQUE, DataBuffer.TYPE_BYTE); - } + } else { // No ColorModel so try to make some intelligent // decisions based just on the number of bands... @@ -184,13 +195,13 @@ public class Any2LumRed extends AbstractRed { return new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8,8}, true, - true, Transparency.TRANSLUCENT, + true, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); return new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8}, false, false, - Transparency.OPAQUE, + Transparency.OPAQUE, DataBuffer.TYPE_BYTE); } } @@ -208,7 +219,7 @@ public class Any2LumRed extends AbstractRed { ColorModel cm = src.getColorModel(); if (cm != null) { - if (cm.hasAlpha()) + if (cm.hasAlpha()) return new PixelInterleavedSampleModel (DataBuffer.TYPE_BYTE, width, height, 2, 2*width, new int [] { 0, 1 }); @@ -233,4 +244,38 @@ public class Any2LumRed extends AbstractRed { new int [] { 0 }); } } + + protected static boolean getColorConvertOpAplhaSupported() { + int size = 50; + + // create source image filled with an opaque color + BufferedImage srcImage = new BufferedImage( + size, size, BufferedImage.TYPE_INT_ARGB); + + Graphics2D srcGraphics = srcImage.createGraphics(); + srcGraphics.setColor(Color.red); + srcGraphics.fillRect(0, 0, size, size); + srcGraphics.dispose(); + + // create clear (transparent black) destination image + BufferedImage dstImage = new BufferedImage( + size, size, BufferedImage.TYPE_INT_ARGB); + + Graphics2D dstGraphics = dstImage.createGraphics(); + dstGraphics.setComposite(AlphaComposite.Clear); + dstGraphics.fillRect(0, 0, size, size); + dstGraphics.dispose(); + + ColorSpace grayColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); + ColorConvertOp op = new ColorConvertOp(grayColorSpace, null); + op.filter(srcImage, dstImage); + + return getAlpha(srcImage) == getAlpha(dstImage); + } + + protected static int getAlpha(BufferedImage bufferedImage) { + int x = bufferedImage.getWidth() / 2; + int y = bufferedImage.getHeight() / 2; + return 0xff & (bufferedImage.getRGB(x, y) >> 24); + } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/IndexImage.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/IndexImage.java index c61f2f444..2c59f8a1e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/IndexImage.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/IndexImage.java @@ -452,13 +452,12 @@ public class IndexImage{ for (int k=minIdx[c1]; k<=maxIdx[c1]; k++) { int idx = idx2 | (k<>>24) ) *a)&0xFF00)<<16) | @@ -161,7 +161,7 @@ public class MultiplyAlphaRed extends AbstractRed { int ap = alpBase + y*alpScanStride; int end = sp + rgn.width; while (sp>>24; srcPixels[sp] = ((((sa*a) & 0xFF00)<<16)| srcPixels[sp]&0x00FFFFFF); @@ -210,26 +210,32 @@ public class MultiplyAlphaRed extends AbstractRed { // 2 is probably next most common... switch (bands) { case 2: - for (int x=0; x>8; ++i; - wrData[i] = ((wrData[i]&0xFF)*a)>>8; ++i; + for (int anAlphaData2 : alphaData) { + a = anAlphaData2 & 0xFF; + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; + ++i; + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; + ++i; } break; case 4: - for (int x=0; x>8; ++i; - wrData[i] = ((wrData[i]&0xFF)*a)>>8; ++i; - wrData[i] = ((wrData[i]&0xFF)*a)>>8; ++i; - wrData[i] = ((wrData[i]&0xFF)*a)>>8; ++i; + for (int anAlphaData1 : alphaData) { + a = anAlphaData1 & 0xFF; + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; + ++i; + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; + ++i; + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; + ++i; + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; + ++i; } break; default: - for (int x=0; x>8; + for (int anAlphaData : alphaData) { + a = anAlphaData & 0xFF; + for (b = 0; b < bands; b++) { + wrData[i] = ((wrData[i] & 0xFF) * a) >> 8; ++i; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/ProfileRed.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/ProfileRed.java index 208e9ffcc..51a7e8563 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/ProfileRed.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/ProfileRed.java @@ -274,7 +274,7 @@ public class ProfileRed extends AbstractRed { return argbWR; }catch(Exception e){ e.printStackTrace(); - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/TileBlock.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/TileBlock.java index f6625a3b8..301511761 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/TileBlock.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/rendered/TileBlock.java @@ -140,8 +140,7 @@ public class TileBlock { */ static int getWork(TileBlock [] blocks) { int ret=0; - for (int i=0; i1. + * 'S' from 0->1. * * @author Vincent Hardy * @author Thomas DeWeese @@ -239,8 +239,7 @@ public final class TurbulencePatternRed extends AbstractRed { public boolean[] getChannels(){ boolean[] channels = new boolean[4]; - for(int i=0; i priority) { li.previous(); - li.add(newRE); - return; + break; // Insertion point found. } } li.add(newRE); @@ -296,9 +294,8 @@ public class ImageTagRegistry implements ErrorConstants { return extensions; extensions = new LinkedList(); - Iterator iter = entries.iterator(); - while(iter.hasNext()) { - RegistryEntry re = (RegistryEntry)iter.next(); + for (Object entry : entries) { + RegistryEntry re = (RegistryEntry) entry; extensions.addAll(re.getStandardExtensions()); } extensions = Collections.unmodifiableList(extensions); @@ -315,9 +312,8 @@ public class ImageTagRegistry implements ErrorConstants { return mimeTypes; mimeTypes = new LinkedList(); - Iterator iter = entries.iterator(); - while(iter.hasNext()) { - RegistryEntry re = (RegistryEntry)iter.next(); + for (Object entry : entries) { + RegistryEntry re = (RegistryEntry) entry; mimeTypes.addAll(re.getMimeTypes()); } mimeTypes = Collections.unmodifiableList(mimeTypes); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterParams.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterParams.java index 81bba1fa7..aa9ecaa5a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterParams.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterParams.java @@ -71,7 +71,7 @@ public class ImageWriterParams { * @param dpi the resolution in dpi */ public void setResolution(int dpi) { - this.resolution = new Integer(dpi); + this.resolution = dpi; } /** @@ -80,7 +80,7 @@ public class ImageWriterParams { * @param forceBaseline force baseline quantization table */ public void setJPEGQuality(float quality, boolean forceBaseline) { - this.jpegQuality = new Float(quality); + this.jpegQuality = quality; this.jpegForceBaseline = forceBaseline ? Boolean.TRUE : Boolean.FALSE; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterRegistry.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterRegistry.java index 60e95a6a8..26ddd20a3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterRegistry.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/ImageWriterRegistry.java @@ -28,7 +28,7 @@ import org.apache.batik.util.Service; * * @version $Id$ */ -public class ImageWriterRegistry { +public final class ImageWriterRegistry { private static ImageWriterRegistry instance; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/MagicNumberRegistryEntry.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/MagicNumberRegistryEntry.java index 062af0c9c..1194ce640 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/MagicNumberRegistryEntry.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/spi/MagicNumberRegistryEntry.java @@ -278,8 +278,8 @@ public abstract class MagicNumberRegistryEntry */ public int getReadlimit() { int maxbuf = 0; - for (int i=0; i maxbuf) { maxbuf = req; } @@ -293,8 +293,8 @@ public abstract class MagicNumberRegistryEntry */ public boolean isCompatibleStream(InputStream is) throws StreamCorruptedException { - for (int i=0; i0 && buffer[0]=='-') digit[j++] = buffer[0]; - for (int i = 0; i < buffer.length; i++) { - if(Character.isDigit(buffer[i])) - digit[j++] = buffer[i]; - if(!hasDot && buffer[i]=='.'){ + for (char aBuffer : buffer) { + if (Character.isDigit(aBuffer)) + digit[j++] = aBuffer; + if (!hasDot && aBuffer == '.') { digit[j++] = '.'; hasDot = true; } @@ -101,7 +101,7 @@ public class DoubleDocument extends PlainDocument { }catch(BadLocationException e){ // Will not happen because we are sure // we use the proper range - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/JGridBagPanel.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/JGridBagPanel.java index 492b47aee..78e7774bb 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/JGridBagPanel.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/JGridBagPanel.java @@ -36,7 +36,7 @@ public class JGridBagPanel extends JPanel implements GridBagConstants{ /** * Provides insets desired for a given grid cell */ - public static interface InsetsManager{ + public interface InsetsManager{ /** * Returns the insets for cell (gridx, gridy); */ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/Resources.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/Resources.java index 8b04c56fe..53fb82f82 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/Resources.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/Resources.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.ext.swing; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/GraphicsExtensionElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/GraphicsExtensionElement.java index 8f0969470..9aba44ef0 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/GraphicsExtensionElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/GraphicsExtensionElement.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.extension; import org.apache.batik.anim.dom.SVGLocatableSupport; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/PrefixableStylableExtensionElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/PrefixableStylableExtensionElement.java index 4adc97f52..68d4f4860 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/PrefixableStylableExtensionElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/PrefixableStylableExtensionElement.java @@ -68,7 +68,7 @@ public abstract class PrefixableStylableExtensionElement if (isReadonly()) { throw createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node", - new Object[] { new Integer(getNodeType()), getNodeName() }); + new Object[] {(int) getNodeType(), getNodeName() }); } if (prefix != null && @@ -76,7 +76,7 @@ public abstract class PrefixableStylableExtensionElement !DOMUtilities.isValidName(prefix)) { throw createDOMException (DOMException.INVALID_CHARACTER_ERR, "prefix", - new Object[] { new Integer(getNodeType()), + new Object[] {(int) getNodeType(), getNodeName(), prefix }); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/StylableExtensionElement.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/StylableExtensionElement.java index 3669408a1..d82a8271b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/StylableExtensionElement.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/StylableExtensionElement.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.extension; import org.apache.batik.css.engine.CSSStylableElement; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikFlowTextElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikFlowTextElementBridge.java index 784fe2c5c..fa37a0c41 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikFlowTextElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikFlowTextElementBridge.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.extension.svg; @@ -26,7 +26,6 @@ import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -52,13 +51,13 @@ import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.gvt.text.TextPath; import org.apache.batik.gvt.text.TextPaintInfo; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; import org.w3c.dom.Node; /** - * Bridge class for the <flowText> element. + * Bridge class for the <flowText> element. * * @author Thomas DeWeese * @version $Id$ @@ -83,7 +82,7 @@ public class BatikFlowTextElementBridge extends SVGTextElementBridge = GVTAttributedCharacterIterator.TextAttribute.PREFORMATTED; /** - * Constructs a new bridge for the <flowText> element. + * Constructs a new bridge for the <flowText> element. */ public BatikFlowTextElementBridge() {} @@ -342,13 +341,13 @@ public class BatikFlowTextElementBridge extends SVGTextElementBridge (ctx, e, true, null, null, asb, lnLocs); paraElems.add(e); - paraEnds.add(new Integer(asb.length())); + paraEnds.add(asb.length()); } else if (ln.equals(BATIK_EXT_FLOW_REGION_BREAK_TAG)) { fillAttributedStringBuffer (ctx, e, true, null, null, asb, lnLocs); paraElems.add(e); - paraEnds.add(new Integer(asb.length())); + paraEnds.add(asb.length()); } } divTPI.startChar = 0; @@ -361,16 +360,15 @@ public class BatikFlowTextElementBridge extends SVGTextElementBridge // Note: The Working Group (in conjunction with XHTML working // group) has decided that multiple line elements collapse. int prevLN = 0; - Iterator lnIter = lnLocs.iterator(); - while (lnIter.hasNext()) { - int nextLN = ((Integer)lnIter.next()).intValue(); + for (Object lnLoc : lnLocs) { + int nextLN = (Integer) lnLoc; if (nextLN == prevLN) continue; ret.addAttribute(FLOW_LINE_BREAK, - new Object(), - prevLN, nextLN); + new Object(), + prevLN, nextLN); // System.out.println("Attr: [" + prevLN + "," + nextLN + "]"); - prevLN = nextLN; + prevLN = nextLN; } int start=0; @@ -378,7 +376,7 @@ public class BatikFlowTextElementBridge extends SVGTextElementBridge List emptyPara = null; for (int i=0; i= asb.length()) { - tpi.endChar = asb.length()-1; + tpi.endChar = asb.length() - 1; if (tpi.startChar > tpi.endChar) tpi.startChar = tpi.endChar; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikHistogramNormalizationElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikHistogramNormalizationElementBridge.java index 3ef78afed..46737bad8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikHistogramNormalizationElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikHistogramNormalizationElementBridge.java @@ -43,7 +43,7 @@ public class BatikHistogramNormalizationElementBridge implements BatikExtConstants { /** - * Constructs a new bridge for the <histogramNormalization> element. + * Constructs a new bridge for the <histogramNormalization> element. */ public BatikHistogramNormalizationElementBridge() { /* nothing */ } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikRegularPolygonElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikRegularPolygonElementBridge.java index 2cc8ed8f4..fd63e1a09 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikRegularPolygonElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikRegularPolygonElementBridge.java @@ -40,7 +40,7 @@ public class BatikRegularPolygonElementBridge implements BatikExtConstants { /** - * Constructs a new bridge for the <rect> element. + * Constructs a new bridge for the <rect> element. */ public BatikRegularPolygonElementBridge() { /* nothing */ } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikStarElementBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikStarElementBridge.java index e5f7d725e..8199b249f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikStarElementBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/BatikStarElementBridge.java @@ -40,7 +40,7 @@ public class BatikStarElementBridge implements BatikExtConstants { /** - * Constructs a new bridge for the <rect> element. + * Constructs a new bridge for the <rect> element. */ public BatikStarElementBridge() { /* nothing */ } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/ColorSwitchBridge.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/ColorSwitchBridge.java index 550462b55..be85f9c5c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/ColorSwitchBridge.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/ColorSwitchBridge.java @@ -41,7 +41,7 @@ public class ColorSwitchBridge implements PaintBridge, BatikExtConstants { /** - * Constructs a new bridge for the <batik:colorSwitch> element. + * Constructs a new bridge for the <batik:colorSwitch> element. */ public ColorSwitchBridge() { /* nothing */ } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtGlyphLayout.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtGlyphLayout.java index d61683e89..42d5f4010 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtGlyphLayout.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtGlyphLayout.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.extension.svg; @@ -155,14 +155,13 @@ public class FlowExtGlyphLayout extends GlyphLayout { { List extraP = (List)aci.getAttribute(FLOW_EMPTY_PARAGRAPH); if (extraP != null) { - Iterator epi = extraP.iterator(); - while (epi.hasNext()) { - MarginInfo emi = (MarginInfo)epi.next(); - float inc = ((prevBotMargin > emi.getTopMargin()) - ? prevBotMargin - : emi.getTopMargin()); + for (Object anExtraP : extraP) { + MarginInfo emi = (MarginInfo) anExtraP; + float inc = ((prevBotMargin > emi.getTopMargin()) + ? prevBotMargin + : emi.getTopMargin()); if ((dy + inc <= height) && - !emi.isFlowRegionBreak()) { + !emi.isFlowRegionBreak()) { dy += inc; prevBotMargin = emi.getBottomMargin(); } else { @@ -176,11 +175,11 @@ public class FlowExtGlyphLayout extends GlyphLayout { currentRegion = (RegionInfo) flowRectsIter.next(); height = (float) currentRegion.getHeight(); // start a new alignment offset for this flow rect. - verticalAlignOffset = new Point2D.Float(0,0); + verticalAlignOffset = new Point2D.Float(0, 0); // Don't use this paragraph info in next // flow region! - dy = 0; + dy = 0; prevBotMargin = 0; } } @@ -191,9 +190,8 @@ public class FlowExtGlyphLayout extends GlyphLayout { List gvl = new LinkedList(); List layouts = (List)clIter.next(); - Iterator iter = layouts.iterator(); - while (iter.hasNext()) { - GlyphLayout gl = (GlyphLayout)iter.next(); + for (Object layout : layouts) { + GlyphLayout gl = (GlyphLayout) layout; gvl.add(gl.getGlyphVector()); } GVTGlyphVector gv = new MultiGlyphVector(gvl); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextNode.java index 64f9e75f1..f0da2c84c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextNode.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.extension.svg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextPainter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextPainter.java index 19aa0e90d..78c65b0f8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextPainter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/FlowExtTextPainter.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.extension.svg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/RegionInfo.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/RegionInfo.java index f97f9d857..2d094b602 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/RegionInfo.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/extension/svg/RegionInfo.java @@ -22,7 +22,7 @@ import java.awt.geom.Rectangle2D; /** * This class holds the neccessary information to render a - * <batik:flowRegion> that is defined within the <batik:flowRoot> + * <batik:flowRegion> that is defined within the <batik:flowRoot> * element. Namely it holds the bounds of the region and the desired * vertical alignment. * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/AbstractGraphicsNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/AbstractGraphicsNode.java index 5cd3872c1..398a259c3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/AbstractGraphicsNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/AbstractGraphicsNode.java @@ -193,7 +193,7 @@ public abstract class AbstractGraphicsNode implements GraphicsNode { inverseTransform = transform.createInverse(); }catch(NoninvertibleTransformException e){ // Should never happen. - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } } else { // The transform is not invertible. Use the same diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CanvasGraphicsNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CanvasGraphicsNode.java index b00b3e7f9..00b8af1b4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CanvasGraphicsNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CanvasGraphicsNode.java @@ -94,7 +94,7 @@ public class CanvasGraphicsNode extends CompositeGraphicsNode { inverseTransform = transform.createInverse(); }catch(NoninvertibleTransformException e){ // Should never happen. - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } } else{ @@ -127,7 +127,7 @@ public class CanvasGraphicsNode extends CompositeGraphicsNode { inverseTransform = transform.createInverse(); }catch(NoninvertibleTransformException e){ // Should never happen. - throw new Error( e.getMessage() ); + throw new RuntimeException( e.getMessage() ); } } else{ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CompositeGraphicsNode.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CompositeGraphicsNode.java index ee2197b8b..adc268bc9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CompositeGraphicsNode.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/CompositeGraphicsNode.java @@ -792,7 +792,9 @@ public class CompositeGraphicsNode extends AbstractGraphicsNode } // Remove the node int index = 0; - for (; node != children[index]; index++); // fires exception when node not found! + for (; node != children[index]; index++) { + // fires exception when node not found! + } remove(index); return true; } @@ -804,7 +806,7 @@ public class CompositeGraphicsNode extends AbstractGraphicsNode * * @param index the position of the graphics node to remove * @return the graphics node that was removed - * @exception IndexOutOfBoundsException if index out of range + * @exception IndexOutOfBoundsException if index out of range */ public Object remove(int index) { // Check for correct argument @@ -867,10 +869,9 @@ public class CompositeGraphicsNode extends AbstractGraphicsNode * @param c the collection to be checked for containment */ public boolean containsAll(Collection c) { - Iterator i = c.iterator(); - while (i.hasNext()) { - if (!contains(i.next())) { - return false; + for (Object aC : c) { + if (!contains(aC)) { + return false; } } return true; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/MarkerShapePainter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/MarkerShapePainter.java index 8e947d937..7b84a74c9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/MarkerShapePainter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/MarkerShapePainter.java @@ -27,7 +27,6 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.List; import java.util.ArrayList; -import java.util.Arrays; import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; import org.apache.batik.ext.awt.geom.ExtendedPathIterator; @@ -301,8 +300,8 @@ public class MarkerShapePainter implements ShapePainter { } if (middleMarkerProxies != null) { - for(int i=0; i that is defined within the <batik:flowRoot> + * <batik:flowRegion> that is defined within the <batik:flowRoot> * element. Namely it holds the bounds of the region and the desired * vertical alignment. * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/TextLineBreaks.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/TextLineBreaks.java index d9eff683e..34e066f03 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/TextLineBreaks.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/TextLineBreaks.java @@ -92,7 +92,7 @@ public class TextLineBreaks { prevPrevCls = prevCls, prevCls = curCls) { if (ich == lineEnd) { - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich); wordBegin = ich; @@ -131,14 +131,14 @@ public class TextLineBreaks { continue; // Don't allow break around JOINER. if ((curCls == CHAR_CLASS_BK) || (curCls == CHAR_CLASS_LF)) { - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich); wordBegin = ich; cls = CHAR_CLASS_BK; continue; } if (prevCls == CHAR_CLASS_CR) { - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich-1); wordBegin = ich-1; cls = CHAR_CLASS_BK; @@ -155,7 +155,7 @@ public class TextLineBreaks { if (prevPrevCls != -1) { if (brkPairs[prevPrevCls][CHAR_CLASS_ID] == BREAK_ACTION_DIRECT) { - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich-1); wordBegin = ich-1; // pbrk[ich-2] = BREAK_ACTION_DIRECT; @@ -177,13 +177,13 @@ public class TextLineBreaks { byte brk = brkPairs[cls][curCls]; if (brk == BREAK_ACTION_DIRECT) { - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich); wordBegin = ich; // pbrk[ich-1] = brk; } else if (brk == BREAK_ACTION_INDIRECT) { if (prevCls == CHAR_CLASS_SP) { - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich); wordBegin = ich; } @@ -195,7 +195,7 @@ public class TextLineBreaks { } // always break at the end - as.addAttribute(WORD_LIMIT, new Integer(wordCnt++), + as.addAttribute(WORD_LIMIT, wordCnt++, wordBegin, ich); wordBegin = ich; // pbrk[ich-1] = BREAK_ACTION_DIRECT; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/WordInfo.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/WordInfo.java index 8778473fe..0402c5e48 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/WordInfo.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/flow/WordInfo.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.gvt.flow; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTFontFamily.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTFontFamily.java index b51c05ac3..d56474346 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTFontFamily.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTFontFamily.java @@ -110,7 +110,7 @@ public class AWTFontFamily implements GVTFontFamily { return new AWTGVTFont(font, size); Map fontAttributes = new HashMap(attrs); - fontAttributes.put(TextAttribute.SIZE, new Float(size)); + fontAttributes.put(TextAttribute.SIZE, size); fontAttributes.put(TextAttribute.FAMILY, fontFace.getFamilyName()); fontAttributes.remove(TEXT_COMPOUND_DELIMITER); return new AWTGVTFont(fontAttributes); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTGVTFont.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTGVTFont.java index 350b19f2e..bc73aced1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTGVTFont.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/AWTGVTFont.java @@ -81,8 +81,8 @@ public class AWTGVTFont implements GVTFont { public AWTGVTFont(Map attributes) { Float sz = (Float)attributes.get(TextAttribute.SIZE); if (sz != null) { - this.size = sz.floatValue(); - attributes.put(TextAttribute.SIZE, new Float(FONT_SIZE)); + this.size = sz; + attributes.put(TextAttribute.SIZE, FONT_SIZE); this.awtFont = new Font(attributes); } else { this.awtFont = new Font(attributes); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/Kern.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/Kern.java index 93e86fe88..c81051d3a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/Kern.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/Kern.java @@ -86,8 +86,8 @@ public class Kern { } if (glyphUnicode.length() < 1) return false; char glyphChar = glyphUnicode.charAt(0); - for (int i = 0; i < firstUnicodeRanges.length; i++) { - if (firstUnicodeRanges[i].contains(glyphChar)) + for (UnicodeRange firstUnicodeRange : firstUnicodeRanges) { + if (firstUnicodeRange.contains(glyphChar)) return true; } return false; @@ -107,8 +107,8 @@ public class Kern { int pt = Arrays.binarySearch(firstGlyphCodes, glyphCode); if (pt >= 0) return true; } - for (int i = 0; i < firstUnicodeRanges.length; i++) { - if (firstUnicodeRanges[i].contains(glyphUnicode)) + for (UnicodeRange firstUnicodeRange : firstUnicodeRanges) { + if (firstUnicodeRange.contains(glyphUnicode)) return true; } return false; @@ -131,8 +131,8 @@ public class Kern { } if (glyphUnicode.length() < 1) return false; char glyphChar = glyphUnicode.charAt(0); - for (int i = 0; i < secondUnicodeRanges.length; i++) { - if (secondUnicodeRanges[i].contains(glyphChar)) + for (UnicodeRange secondUnicodeRange : secondUnicodeRanges) { + if (secondUnicodeRange.contains(glyphChar)) return true; } return false; @@ -153,8 +153,8 @@ public class Kern { int pt = Arrays.binarySearch(secondGlyphCodes, glyphCode); if (pt >= 0) return true; } - for (int i = 0; i < secondUnicodeRanges.length; i++) { - if (secondUnicodeRanges[i].contains(glyphUnicode)) + for (UnicodeRange secondUnicodeRange : secondUnicodeRanges) { + if (secondUnicodeRange.contains(glyphUnicode)) return true; } return false; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/KerningTable.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/KerningTable.java index c536147ca..7f7c98066 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/KerningTable.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/KerningTable.java @@ -57,10 +57,10 @@ public class KerningTable { int glyphCode2, String glyphUnicode1, String glyphUnicode2) { - for (int i = 0; i < entries.length; i++) { - if (entries[i].matchesFirstGlyph(glyphCode1, glyphUnicode1) && - entries[i].matchesSecondGlyph(glyphCode2, glyphUnicode2)) { - return entries[i].getAdjustValue(); + for (Kern entry : entries) { + if (entry.matchesFirstGlyph(glyphCode1, glyphUnicode1) && + entry.matchesSecondGlyph(glyphCode2, glyphUnicode2)) { + return entry.getAdjustValue(); } } return 0f; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/MultiGlyphVector.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/MultiGlyphVector.java index 0a7e525f5..9533327dd 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/MultiGlyphVector.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/font/MultiGlyphVector.java @@ -286,11 +286,11 @@ public class MultiGlyphVector implements GVTGlyphVector { */ public Rectangle2D getLogicalBounds() { Rectangle2D ret = null; - for (int idx=0; idxBella Robinson * @version $Id$ */ -public class ArabicTextHandler { +public final class ArabicTextHandler { private static final int arabicStart = 0x0600; private static final int arabicEnd = 0x06FF; @@ -134,7 +134,7 @@ public class ArabicTextHandler { if (x != null && !x.isNaN()) { reorderedAS.addAttribute (GVTAttributedCharacterIterator.TextAttribute.X, - new Float(Float.NaN), charOrder[0], charOrder[0]+1); + Float.NaN, charOrder[0], charOrder[0]+1); reorderedAS.addAttribute (GVTAttributedCharacterIterator.TextAttribute.X, x, 0, 1); @@ -142,7 +142,7 @@ public class ArabicTextHandler { if (y != null && !y.isNaN()) { reorderedAS.addAttribute (GVTAttributedCharacterIterator.TextAttribute.Y, - new Float(Float.NaN), charOrder[0], charOrder[0]+1); + Float.NaN, charOrder[0], charOrder[0]+1); reorderedAS.addAttribute (GVTAttributedCharacterIterator.TextAttribute.Y, y, 0, 1); @@ -207,7 +207,7 @@ public class ArabicTextHandler { if (arabicCharShapesRight(prevChar) && arabicCharShapesLeft(currentChar)) { // Increment the form of the previous char - prevForm = new Integer(prevForm.intValue()+1); + prevForm = prevForm + 1; as.addAttribute(ARABIC_FORM, prevForm, prevCharIndex, prevCharIndex+1); @@ -378,8 +378,8 @@ public class ArabicTextHandler { int [][]remaps = doubleCharRemappings[ch1-doubleCharFirst]; if (remaps == null) return false; - for (int i=0; i -1) { substString.append((char)substChar); i++; @@ -462,7 +462,7 @@ public class ArabicTextHandler { } else if (form.equals(ARABIC_TERMINAL)) { // look for a terminal ligature int substChar = ArabicTextHandler.getSubstituteChar - (c, nextChar,ARABIC_TERMINAL.intValue()); + (c, nextChar, ARABIC_TERMINAL); if (substChar > -1) { substString.append((char)substChar); i++; @@ -472,7 +472,7 @@ public class ArabicTextHandler { && nextForm.equals(ARABIC_MEDIAL)) { // look for a medial ligature int substChar = ArabicTextHandler.getSubstituteChar - (c, nextChar,ARABIC_MEDIAL.intValue()); + (c, nextChar, ARABIC_MEDIAL); if (substChar > -1) { substString.append((char)substChar); i++; @@ -484,8 +484,8 @@ public class ArabicTextHandler { // couldn't find a matching ligature so just look for a // simple substitution - if (form != null && form.intValue() > 0) { - int substChar = getSubstituteChar(c, form.intValue()); + if (form != null && form > 0) { + int substChar = getSubstituteChar(c, form); if (substChar > -1) { c = (char)substChar; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/BidiAttributedCharacterIterator.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/BidiAttributedCharacterIterator.java index 54314820d..f7b616707 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/BidiAttributedCharacterIterator.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/BidiAttributedCharacterIterator.java @@ -23,7 +23,6 @@ import java.awt.font.TextLayout; import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -43,7 +42,7 @@ public class BidiAttributedCharacterIterator implements AttributedCharacterItera private FontRenderContext frc; private int chunkStart; private int [] newCharOrder; - private static final Float FLOAT_NAN = new Float(Float.NaN); + private static final Float FLOAT_NAN = Float.NaN; protected BidiAttributedCharacterIterator @@ -99,11 +98,10 @@ public class BidiAttributedCharacterIterator implements AttributedCharacterItera Map attrMap = aci.getAttributes(); int extent = aci.getRunLimit(); Map destMap = new HashMap(attrMap.size()); - Iterator it = attrMap.entrySet().iterator(); - while (it.hasNext()) { + for (Object o : attrMap.entrySet()) { // Font doesn't like getting attribute sets with // null keys or values so we strip them here. - Map.Entry e = (Map.Entry)it.next(); + Map.Entry e = (Map.Entry) o; Object key = e.getKey(); if (key == null) continue; Object value = e.getValue(); @@ -138,7 +136,7 @@ public class BidiAttributedCharacterIterator implements AttributedCharacterItera if (newBiDi != currBiDi) { as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL, - new Integer(currBiDi), runStart, i); + currBiDi, runStart, i); runStart = i; currBiDi = newBiDi; if (newBiDi > maxBiDi) maxBiDi = newBiDi; @@ -146,7 +144,7 @@ public class BidiAttributedCharacterIterator implements AttributedCharacterItera } as.addAttribute (GVTAttributedCharacterIterator.TextAttribute.BIDI_LEVEL, - new Integer(currBiDi), runStart, numChars); + currBiDi, runStart, numChars); aci = as.getIterator(); @@ -411,7 +409,7 @@ public class BidiAttributedCharacterIterator implements AttributedCharacterItera public Object clone() { return new BidiAttributedCharacterIterator ((AttributedCharacterIterator)reorderedACI.clone(), - frc, chunkStart, (int [])newCharOrder.clone()); + frc, chunkStart, newCharOrder.clone()); } /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTACIImpl.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTACIImpl.java index b8947796b..0c0416483 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTACIImpl.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTACIImpl.java @@ -386,7 +386,7 @@ public class GVTACIImpl * SVGAttributedCharacterIterator.TextAttribute.X, TextAttribute.Y, * TextAttribute.ROTATE attributes to TextAttribute.TRANSFORM attributes. */ - public class TransformAttributeFilter implements + public static class TransformAttributeFilter implements GVTAttributedCharacterIterator.AttributeFilter { /** diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java index b06bf05b0..d6792c63f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java @@ -354,22 +354,22 @@ public interface GVTAttributedCharacterIterator extends AttributedCharacterItera // VALUES /** Value for WRITING_MODE indicating left-to-right */ - public static final Integer WRITING_MODE_LTR = new Integer(0x1); + public static final Integer WRITING_MODE_LTR = 0x1; /** Value for WRITING_MODE indicating right-to-left */ - public static final Integer WRITING_MODE_RTL = new Integer(0x2); + public static final Integer WRITING_MODE_RTL = 0x2; /** Value for WRITING_MODE indicating top-to-botton */ - public static final Integer WRITING_MODE_TTB = new Integer(0x3); + public static final Integer WRITING_MODE_TTB = 0x3; /** Value for VERTICAL_ORIENTATION indicating an angle */ - public static final Integer ORIENTATION_ANGLE = new Integer(0x1); + public static final Integer ORIENTATION_ANGLE = 0x1; /** Value for VERTICAL_ORIENTATION indicating auto */ - public static final Integer ORIENTATION_AUTO = new Integer(0x2); + public static final Integer ORIENTATION_AUTO = 0x2; /** Value for FONT_VARIANT specifying small caps */ - public static final Integer SMALL_CAPS = new Integer(0x10); + public static final Integer SMALL_CAPS = 0x10; /** Value for UNDERLINE specifying underlining-on */ public static final Integer UNDERLINE_ON = @@ -384,18 +384,18 @@ public interface GVTAttributedCharacterIterator extends AttributedCharacterItera /** Value for LENGTH_ADJUST specifying adjustment to inter-glyph spacing */ public static final Integer ADJUST_SPACING = - new Integer(0x0); + 0x0; /** Value for LENGTH_ADJUST specifying overall scaling of layout outlines */ public static final Integer ADJUST_ALL = - new Integer(0x01); + 0x01; // constant values for the arabic glyph forms - public static final Integer ARABIC_NONE = new Integer(0x0); - public static final Integer ARABIC_ISOLATED = new Integer(0x1); - public static final Integer ARABIC_TERMINAL = new Integer(0x2); - public static final Integer ARABIC_INITIAL = new Integer(0x3); - public static final Integer ARABIC_MEDIAL = new Integer(0x4); + public static final Integer ARABIC_NONE = 0x0; + public static final Integer ARABIC_ISOLATED = 0x1; + public static final Integer ARABIC_TERMINAL = 0x2; + public static final Integer ARABIC_INITIAL = 0x3; + public static final Integer ARABIC_MEDIAL = 0x4; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/i18n/LocalizableSupport.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/i18n/LocalizableSupport.java index e4df54124..77d49c05f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/i18n/LocalizableSupport.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/i18n/LocalizableSupport.java @@ -58,7 +58,7 @@ import java.util.MissingResourceException; *
        • * if a Locale has been set by a call to setLocale(), use this Locale, * else, - *
        • + *
        • *
        • * if a Locale has been set by a call to the setDefaultLocale() method * of a LocalizableSupport object in the current LocaleGroup, use this @@ -67,7 +67,7 @@ import java.util.MissingResourceException; *
        • * use the object returned by Locale.getDefault() (and set by * Locale.setDefault()). - *
        • + *
        • *
        * This offers the possibility to have a different Locale for each object, * a Locale for a group of object and/or a Locale for the JVM instance. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AbstractParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AbstractParser.java index b35ccd76f..ae0d70ade 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AbstractParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AbstractParser.java @@ -183,8 +183,8 @@ public abstract class AbstractParser implements Parser { */ protected void reportCharacterExpectedError( char expectedChar, int currentChar ){ reportError("character.expected", - new Object[] { new Character( expectedChar ), - new Integer( currentChar ) }); + new Object[] {expectedChar, + currentChar}); } @@ -196,7 +196,7 @@ public abstract class AbstractParser implements Parser { */ protected void reportUnexpectedCharacterError( int currentChar ){ reportError("character.unexpected", - new Object[] { new Integer( currentChar ) }); + new Object[] {currentChar}); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AngleParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AngleParser.java index 66ab3cedb..f31d839c8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AngleParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/AngleParser.java @@ -132,7 +132,7 @@ public class AngleParser extends NumberParser { skipSpaces(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } } catch (NumberFormatException e) { reportUnexpectedCharacterError( current ); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/ClockParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/ClockParser.java index 670c41cd0..b82fffcd4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/ClockParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/ClockParser.java @@ -68,7 +68,7 @@ public class ClockParser extends TimingParser { float clockValue = parseOffset ? parseOffset() : parseClockValue(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } if (clockHandler != null) { clockHandler.clockValue(clockValue); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/FloatArrayProducer.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/FloatArrayProducer.java index 25bbda42c..43c8545b4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/FloatArrayProducer.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/FloatArrayProducer.java @@ -18,7 +18,6 @@ */ package org.apache.batik.parser; -import java.util.Iterator; import java.util.LinkedList; /** @@ -96,9 +95,8 @@ public class FloatArrayProducer public void endNumberList() throws ParseException { float[] all = new float[count]; int pos = 0; - Iterator it = as.iterator(); - while (it.hasNext()) { - float[] b = (float[]) it.next(); + for (Object a1 : as) { + float[] b = (float[]) a1; System.arraycopy(b, 0, all, pos, b.length); pos += b.length; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/LengthParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/LengthParser.java index cccd62fd2..b3bcc8069 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/LengthParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/LengthParser.java @@ -74,7 +74,7 @@ public class LengthParser extends AbstractParser { skipSpaces(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } lengthHandler.endLength(); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PathParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PathParser.java index 9eaa1f206..77dc3e457 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PathParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PathParser.java @@ -113,7 +113,7 @@ public class PathParser extends NumberParser { skipSpaces(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } pathHandler.endPath(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PreserveAspectRatioParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PreserveAspectRatioParser.java index 78d86ec0c..75795f611 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PreserveAspectRatioParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/PreserveAspectRatioParser.java @@ -335,7 +335,7 @@ public class PreserveAspectRatioParser extends AbstractParser { skipSpaces(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } preserveAspectRatioHandler.endPreserveAspectRatio(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingParser.java index 5ccab9923..1ae192f48 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingParser.java @@ -94,7 +94,7 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || (current == '-' && !escaped) || (current >= '0' && current <= '9')) { float offset = parseOffset(); - ret = new Object[] { new Integer(TIME_OFFSET), new Float(offset) }; + ret = new Object[] {TIME_OFFSET, offset}; } else if (XMLUtilities.isXMLNameFirstCharacter((char) current)) { ret = parseIDValue(escaped); } else { @@ -150,9 +150,9 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || current == '-') { offset = parseOffset(); } - return new Object[] { new Integer(TIME_ACCESSKEY), - new Float(offset), - new Character(key) }; + return new Object[] {TIME_ACCESSKEY, + offset, + key}; } else if (id.equals("accessKey") && useSVG12AccessKeys && !escaped) { if (current != '(') { reportUnexpectedCharacterError( current ); @@ -175,8 +175,8 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || current == '-') { offset = parseOffset(); } - return new Object[] { new Integer(TIME_ACCESSKEY_SVG12), - new Float(offset), + return new Object[] {TIME_ACCESSKEY_SVG12, + offset, keyName.toString() }; } else if (id.equals("wallclock") && !escaped) { if (current != '(') { @@ -188,12 +188,12 @@ public abstract class TimingParser extends AbstractParser { skipSpaces(); if (current != ')') { reportError("character.unexpected", - new Object[] { new Integer(current) }); + new Object[] {current}); } current = reader.read(); - return new Object[] { new Integer(TIME_WALLCLOCK), wallclockValue }; + return new Object[] {TIME_WALLCLOCK, wallclockValue }; } else if (id.equals("indefinite") && !escaped) { - return new Object[] { new Integer(TIME_INDEFINITE) }; + return new Object[] {TIME_INDEFINITE}; } else { if (current == '.') { current = reader.read(); @@ -211,15 +211,15 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || current == '-') { offset = parseOffset(); } - return new Object[] { new Integer(TIME_SYNCBASE), - new Float(offset), + return new Object[] {TIME_SYNCBASE, + offset, id, id2 }; } else if (id2.equals("repeat") && !escaped) { Integer repeatIteration = null; if (current == '(') { current = reader.read(); - repeatIteration = new Integer(parseDigits()); + repeatIteration = parseDigits(); if (current != ')') { reportUnexpectedCharacterError( current ); } @@ -230,8 +230,8 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || current == '-') { offset = parseOffset(); } - return new Object[] { new Integer(TIME_REPEAT), - new Float(offset), + return new Object[] {TIME_REPEAT, + offset, id, repeatIteration }; } else if (id2.equals("marker") && !escaped) { @@ -243,7 +243,7 @@ public abstract class TimingParser extends AbstractParser { reportUnexpectedCharacterError( current ); } current = reader.read(); - return new Object[] { new Integer(TIME_MEDIA_MARKER), + return new Object[] {TIME_MEDIA_MARKER, id, markerName }; } else { @@ -252,8 +252,8 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || current == '-') { offset = parseOffset(); } - return new Object[] { new Integer(TIME_EVENTBASE), - new Float(offset), + return new Object[] {TIME_EVENTBASE, + offset, id, id2 }; } @@ -263,8 +263,8 @@ public abstract class TimingParser extends AbstractParser { if (current == '+' || current == '-') { offset = parseOffset(); } - return new Object[] { new Integer(TIME_EVENTBASE), - new Float(offset), + return new Object[] {TIME_EVENTBASE, + offset, null, id }; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingSpecifierParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingSpecifierParser.java index eafe31609..31cd344aa 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingSpecifierParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TimingSpecifierParser.java @@ -71,7 +71,7 @@ public class TimingSpecifierParser extends TimingParser { skipSpaces(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } handleTimingSpecifier(spec); } @@ -81,40 +81,40 @@ public class TimingSpecifierParser extends TimingParser { * parsed timing specifier. */ protected void handleTimingSpecifier(Object[] spec) { - int type = ((Integer) spec[0]).intValue(); + int type = (Integer) spec[0]; switch (type) { case TIME_OFFSET: - timingSpecifierHandler.offset(((Float) spec[1]).floatValue()); + timingSpecifierHandler.offset((Float) spec[1]); break; case TIME_SYNCBASE: - timingSpecifierHandler.syncbase(((Float) spec[1]).floatValue(), + timingSpecifierHandler.syncbase((Float) spec[1], (String) spec[2], (String) spec[3]); break; case TIME_EVENTBASE: - timingSpecifierHandler.eventbase(((Float) spec[1]).floatValue(), + timingSpecifierHandler.eventbase((Float) spec[1], (String) spec[2], (String) spec[3]); break; case TIME_REPEAT: { - float offset = ((Float) spec[1]).floatValue(); + float offset = (Float) spec[1]; String syncbaseID = (String) spec[2]; if (spec[3] == null) { timingSpecifierHandler.repeat(offset, syncbaseID); } else { timingSpecifierHandler.repeat - (offset, syncbaseID, ((Integer) spec[3]).intValue()); + (offset, syncbaseID, (Integer) spec[3]); } break; } case TIME_ACCESSKEY: timingSpecifierHandler.accesskey - (((Float) spec[1]).floatValue(), - ((Character) spec[2]).charValue()); + ((Float) spec[1], + (Character) spec[2]); break; case TIME_ACCESSKEY_SVG12: timingSpecifierHandler.accessKeySVG12 - (((Float) spec[1]).floatValue(), + ((Float) spec[1], (String) spec[2]); break; case TIME_MEDIA_MARKER: diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TransformListParser.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TransformListParser.java index 48640efb6..028efcbf6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TransformListParser.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/TransformListParser.java @@ -116,7 +116,7 @@ public class TransformListParser extends NumberParser { skipSpaces(); if (current != -1) { reportError("end.of.stream.expected", - new Object[] { new Integer(current) }); + new Object[] {current}); } transformListHandler.endTransformList(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/UnitProcessor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/UnitProcessor.java index 9d0f641d6..34b1069d6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/UnitProcessor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/parser/UnitProcessor.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.parser; import org.w3c.dom.Element; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/ImportInfo.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/ImportInfo.java old mode 100644 new mode 100755 index 59cf2db37..71d56d5dd --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/ImportInfo.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/ImportInfo.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.script; @@ -49,7 +49,7 @@ import java.util.Set; * The remainder of a line is whitespace delimited, fully qualified, * Java class/package name (i.e. java.lang.System). * - * @author deweese * @version $Id$ */ public class ImportInfo { @@ -77,7 +77,7 @@ public class ImportInfo { * This instance is initialized by reading the file * identified by 'importFile'. */ - static public ImportInfo getImports() { + public static ImportInfo getImports() { if (defaultImports == null) defaultImports = readImports(); return defaultImports; @@ -240,4 +240,4 @@ public class ImportInfo { } } } -}; +} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/InterpreterPool.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/InterpreterPool.java index 5541908c3..cab5979d4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/InterpreterPool.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/script/InterpreterPool.java @@ -65,8 +65,8 @@ public class InterpreterPool { InterpreterFactory factory = null; factory = (InterpreterFactory)iter.next(); String[] mimeTypes = factory.getMimeTypes(); - for (int i = 0; i < mimeTypes.length; i++) { - defaultFactories.put(mimeTypes[i], factory); + for (String mimeType : mimeTypes) { + defaultFactories.put(mimeType, factory); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/CachedImageHandlerBase64Encoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/CachedImageHandlerBase64Encoder.java index ddb8973f6..af0c83ae3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/CachedImageHandlerBase64Encoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/CachedImageHandlerBase64Encoder.java @@ -68,7 +68,7 @@ public class CachedImageHandlerBase64Encoder extends DefaultCachedImageHandler { /** * Determines the transformation needed to get the cached image to - * scale & position properly. Sets x and y attributes on the element + * scale & position properly. Sets x and y attributes on the element * accordingly. */ protected AffineTransform handleTransform(Element imageElement, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMGroupManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMGroupManager.java index 82ac60633..1a4b05388 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMGroupManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMGroupManager.java @@ -19,7 +19,6 @@ package org.apache.batik.svggen; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.apache.batik.ext.awt.g2d.GraphicContext; @@ -234,11 +233,10 @@ public class DOMGroupManager implements SVGSyntax, ErrorConstants { // descriptor. If there is, check if the attribute // applies to the input element. If there is none, // assume the attribute applies to the element. - Iterator iter = groupAttrMap.keySet().iterator(); - while(iter.hasNext()){ - String attrName = (String)iter.next(); + for (Object o : groupAttrMap.keySet()) { + String attrName = (String) o; SVGAttribute attr = SVGAttributeMap.get(attrName); - if(attr != null && !attr.appliesTo(tag)) + if (attr != null && !attr.appliesTo(tag)) groupAttrMap.remove(attrName); } } @@ -315,11 +313,10 @@ public class DOMGroupManager implements SVGSyntax, ErrorConstants { static Map processDeltaMap(Map map, Map referenceMap) { // no need to be synch => HashMap Map mapDelta = new HashMap(); - Iterator iter = map.keySet().iterator(); - while (iter.hasNext()){ - String key = (String)iter.next(); - String value = (String)map.get(key); - String refValue = (String)referenceMap.get(key); + for (Object o : map.keySet()) { + String key = (String) o; + String value = (String) map.get(key); + String refValue = (String) referenceMap.get(key); if (!value.equals(refValue)) { /*if(key.equals(SVG_TRANSFORM_ATTRIBUTE)){ // Special handling for the transform attribute. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMTreeManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMTreeManager.java index 16aa38d10..7454e719b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMTreeManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DOMTreeManager.java @@ -18,19 +18,18 @@ */ package org.apache.batik.svggen; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.ArrayList; -import java.util.Collections; - import org.apache.batik.ext.awt.g2d.GraphicContext; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + /** * This class is used by the SVGGraphics2D SVG Generator to manage * addition of new Nodes to the SVG DOM Tree. This class handles @@ -178,9 +177,9 @@ public class DOMTreeManager implements SVGSyntax, ErrorConstants { // we iterate over it. If that would happen, we might skip entries // within the list or ignore new entries at the end. Fix #40686 int nManagers = groupManagers.size(); - for(int i=0; i sections. + * elements to the <defs> sections. */ public void addOtherDef(Element definition){ if (otherDefs == null){ @@ -408,9 +406,7 @@ public class DOMTreeManager implements SVGSyntax, ErrorConstants { topLevelGroup.getFirstChild()); } - Iterator iter = defSet.iterator(); - while(iter.hasNext()) - defElement.appendChild((Element)iter.next()); + for (Object aDefSet : defSet) defElement.appendChild((Element) aDefSet); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultCachedImageHandler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultCachedImageHandler.java index 85d6d48ba..8526f97db 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultCachedImageHandler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultCachedImageHandler.java @@ -269,7 +269,7 @@ public abstract class DefaultCachedImageHandler /** * Determines the transformation needed to get the cached image to - * scale & position properly. Sets x and y attributes on the element + * scale & position properly. Sets x and y attributes on the element * accordingly. */ protected AffineTransform handleTransform(Element imageElement, diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultImageHandler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultImageHandler.java index fced72e78..70fca7aaf 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultImageHandler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultImageHandler.java @@ -22,7 +22,7 @@ import java.awt.Image; import java.awt.image.RenderedImage; import java.awt.image.renderable.RenderableImage; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.Element; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultStyleHandler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultStyleHandler.java index 9e54c1414..199ce6fd6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultStyleHandler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/DefaultStyleHandler.java @@ -20,7 +20,6 @@ package org.apache.batik.svggen; import org.apache.batik.util.SVGConstants; -import java.util.Iterator; import java.util.Map; import java.util.HashMap; import java.util.Set; @@ -74,13 +73,12 @@ public class DefaultStyleHandler implements StyleHandler, SVGConstants { public void setStyle(Element element, Map styleMap, SVGGeneratorContext generatorContext) { String tagName = element.getTagName(); - Iterator iter = styleMap.keySet().iterator(); - while (iter.hasNext()) { - String styleName = (String)iter.next(); - if (element.getAttributeNS(null, styleName).length() == 0){ + for (Object o : styleMap.keySet()) { + String styleName = (String) o; + if (element.getAttributeNS(null, styleName).length() == 0) { if (appliesTo(styleName, tagName)) { element.setAttributeNS(null, styleName, - (String)styleMap.get(styleName)); + (String) styleMap.get(styleName)); } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/ImageCacher.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/ImageCacher.java index 5b7d4f672..b57925623 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/ImageCacher.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/ImageCacher.java @@ -103,7 +103,7 @@ public abstract class ImageCacher implements SVGSyntax, ErrorConstants { // need to check on actual byte-for-byte equality as well. // The checksum will be sufficient in most cases. int checksum = getChecksum(os.toByteArray()); - Integer key = new Integer(checksum); + Integer key = checksum; String href = null; Object data = getCacheableData(os); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGAlphaComposite.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGAlphaComposite.java index 25e0e3f2c..72b489421 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGAlphaComposite.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGAlphaComposite.java @@ -225,7 +225,7 @@ public class SVGAlphaComposite extends AbstractSVGConverter { id = ID_PREFIX_ALPHA_COMPOSITE_DST_OVER; break; default: - throw new Error("invalid rule:" + composite.getRule() ); + throw new RuntimeException("invalid rule:" + composite.getRule() ); } Element compositeFilter = diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGCSSStyler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGCSSStyler.java index eb7532d37..0bc40767f 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGCSSStyler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGCSSStyler.java @@ -79,8 +79,8 @@ public class SVGCSSStyler implements SVGSyntax{ styleAttrBuffer.toString().trim()); int n = toBeRemoved.size(); - for(int i=0; i use HashMap Map groupAttrMap = new HashMap(); - for (int i=0; i + * on the baseline.
        * * * @param ati the iterator whose text is to be rendered @@ -1464,10 +1463,9 @@ public class SVGGraphics2D extends AbstractGraphics2D */ private boolean isUnderline(AttributedCharacterIterator ati) { Object attr = ati.getAttribute(TextAttribute.UNDERLINE); - if (TextAttribute.UNDERLINE_ON.equals(attr)) return true; + return TextAttribute.UNDERLINE_ON.equals(attr); // What to do about UNDERLINE_LOW_*? Right now we don't // draw them since we can't really model them... - else return false; } /** Return true if the AttributedCharacterIterator is striked @@ -1527,9 +1525,8 @@ public class SVGGraphics2D extends AbstractGraphics2D if (unsupportedAttributes == null) return false; Set allAttrs = aci.getAllAttributeKeys(); - Iterator iter = allAttrs.iterator(); - while (iter.hasNext()) { - if (unsupportedAttributes.contains(iter.next())) { + for (Object allAttr : allAttrs) { + if (unsupportedAttributes.contains(allAttr)) { return true; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGIDGenerator.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGIDGenerator.java index 1e951b212..4043b3a57 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGIDGenerator.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGIDGenerator.java @@ -40,16 +40,16 @@ public class SVGIDGenerator { * * @param prefix defines the prefix for which the id should * be generated. - * @return a value of the form + * @return a value of the form <prefix><n> */ public String generateID(String prefix) { Integer maxId = (Integer)prefixMap.get(prefix); if (maxId == null) { - maxId = new Integer(0); + maxId = 0; prefixMap.put(prefix, maxId); } - maxId = new Integer(maxId.intValue()+1); + maxId = maxId + 1; prefixMap.put(prefix, maxId); return prefix + maxId; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPath.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPath.java index eb01005cf..04af01d98 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPath.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPath.java @@ -113,7 +113,7 @@ public class SVGPath extends SVGGraphicObjectConverter { appendPoint(d, seg[4], seg[5], gc); break; default: - throw new Error("invalid segmentType:" + segType ); + throw new RuntimeException("invalid segmentType:" + segType ); } pi.next(); } // while !isDone diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPolygon.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPolygon.java index d6a82091c..c2747d358 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPolygon.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGPolygon.java @@ -62,7 +62,7 @@ public class SVGPolygon extends SVGGraphicObjectConverter { case PathIterator.SEG_QUADTO: case PathIterator.SEG_CUBICTO: default: - throw new Error("invalid segmentType:" + segType ); + throw new RuntimeException("invalid segmentType:" + segType ); } pi.next(); } // while !isDone diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGRenderingHints.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGRenderingHints.java index 72164aa18..f68d8db11 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGRenderingHints.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGRenderingHints.java @@ -26,16 +26,16 @@ import org.apache.batik.ext.awt.g2d.GraphicContext; * Utility class that converts a RenderingHints object into * a set of SVG properties. Here is how individual hints * are converted. - * + RENDERING -> sets all other hints to + * + RENDERING -> sets all other hints to * initial value. - * + FRACTIONAL_METRICS -> sets initial values for + * + FRACTIONAL_METRICS -> sets initial values for * text-rendering and shape-rendering. - * + ALPHA_INTERPOLATION -> Not mapped - * + ANTIALIASING -> shape-rendering and text-rendering - * + COLOR_RENDERING -> color-rendering - * + DITHERING -> not mapped - * + INTERPOLATION -> image-rendering - * + TEXT_ANTIALIASING -> text-rendering + * + ALPHA_INTERPOLATION -> Not mapped + * + ANTIALIASING -> shape-rendering and text-rendering + * + COLOR_RENDERING -> color-rendering + * + DITHERING -> not mapped + * + INTERPOLATION -> image-rendering + * + TEXT_ANTIALIASING -> text-rendering * * @author Vincent Hardy * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGTransform.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGTransform.java index 8c08818d4..b1fc8e324 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGTransform.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SVGTransform.java @@ -256,7 +256,7 @@ public class SVGTransform extends AbstractSVGConverter{ default: // This should never happen. If it does, there is a // serious error. - throw new Error(); + throw new RuntimeException(); } return transformString.toString(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SwingSVGPrettyPrint.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SwingSVGPrettyPrint.java index 8e12a30d1..82260a259 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SwingSVGPrettyPrint.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/SwingSVGPrettyPrint.java @@ -172,7 +172,7 @@ public abstract class SwingSVGPrettyPrint implements SVGSyntax { if(isJComponent) { cr = tmpRect; - ((JComponent)comp).getBounds(cr); + comp.getBounds(cr); } else { cr = comp.getBounds(); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/XmlWriter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/XmlWriter.java index c9f931278..cdd1bd412 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/XmlWriter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/XmlWriter.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.svggen; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Font.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Font.java index abc782d20..c3c08e970 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Font.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Font.java @@ -66,9 +66,9 @@ public class Font { } public Table getTable(int tableType) { - for (int i = 0; i < tables.length; i++) { - if ((tables[i] != null) && (tables[i].getType() == tableType)) { - return tables[i]; + for (Table table : tables) { + if ((table != null) && (table.getType() == tableType)) { + return table; } } return null; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Glyph.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Glyph.java index c2deb2bfc..fc78226c3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Glyph.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/Glyph.java @@ -64,11 +64,11 @@ public class Glyph { * @param factor a 16.16 fixed value */ public void scale(int factor) { - for (int i = 0; i < points.length; i++) { + for (Point point : points) { //points[i].x = ( points[i].x * factor ) >> 6; //points[i].y = ( points[i].y * factor ) >> 6; - points[i].x = ((points[i].x<<10) * factor) >> 26; - points[i].y = ((points[i].y<<10) * factor) >> 26; + point.x = ((point.x << 10) * factor) >> 26; + point.y = ((point.y << 10) * factor) >> 26; } leftSideBearing = (short)(( leftSideBearing * factor) >> 6); advanceWidth = (advanceWidth * factor) >> 6; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/SVGFont.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/SVGFont.java index 794bf3580..70201218e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/SVGFont.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/SVGFont.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.svggen.font; @@ -38,7 +38,7 @@ import org.apache.batik.svggen.font.table.ScriptTags; import org.apache.batik.svggen.font.table.SingleSubst; import org.apache.batik.svggen.font.table.Table; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; /** * Converts a TrueType font to an SVG embedded font. @@ -695,10 +695,18 @@ public class SVGFont implements XMLConstants, SVGConstants, ScriptTags, FeatureT ps.println(" !"#$%&'()*+,-./0123456789:;<>?"); ps.println("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"); ps.println("`abcdefghijklmnopqrstuvwxyz{|}~"); - ps.println("€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"); - ps.println(" ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"); - ps.println("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"); - ps.println("àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"); + ps.println("€‚ƒ„…†‡ˆ‰Š‹ + ŒŽ‘’“”•–—˜™š›œ + žŸ"); + ps.println(" ¡¢£¤¥¦§¨©ª« + ¬­®¯°±²³´µ¶·¸¹º»¼½ + ¾¿"); + ps.println("ÀÁÂÃÄÅÆÇÈÉÊË + ÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝ + Þß"); + ps.println("àáâãäåæçèéêë + ìíîïðñòóôõö÷øùúûüý + þÿ"); ps.println("");*/ } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeComp.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeComp.java index e4c2a920f..14f4dfade 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeComp.java @@ -76,21 +76,21 @@ public class GlyfCompositeComp { // Get the scale values (if any) if ((flags & WE_HAVE_A_SCALE) != 0) { int i = (short)(bais.read()<<8 | bais.read()); - xscale = yscale = (double) i / (double) 0x4000; + xscale = yscale = (double) i / 0x4000; } else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0) { short i = (short)(bais.read()<<8 | bais.read()); - xscale = (double) i / (double) 0x4000; + xscale = (double) i / 0x4000; i = (short)(bais.read()<<8 | bais.read()); - yscale = (double) i / (double) 0x4000; + yscale = (double) i / 0x4000; } else if ((flags & WE_HAVE_A_TWO_BY_TWO) != 0) { int i = (short)(bais.read()<<8 | bais.read()); - xscale = (double) i / (double) 0x4000; + xscale = (double) i / 0x4000; i = (short)(bais.read()<<8 | bais.read()); - scale01 = (double) i / (double) 0x4000; + scale01 = (double) i / 0x4000; i = (short)(bais.read()<<8 | bais.read()); - scale10 = (double) i / (double) 0x4000; + scale10 = (double) i / 0x4000; i = (short)(bais.read()<<8 | bais.read()); - yscale = (double) i / (double) 0x4000; + yscale = (double) i / 0x4000; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java index 0ad1b7e9a..82cd427c3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java @@ -20,7 +20,6 @@ package org.apache.batik.svggen.font.table; import java.io.ByteArrayInputStream; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -66,9 +65,8 @@ public class GlyfCompositeDescript extends GlyfDescript { int firstIndex = 0; int firstContour = 0; - Iterator i = components.iterator(); - while (i.hasNext()) { - GlyfCompositeComp comp = (GlyfCompositeComp)i.next(); + for (Object component : components) { + GlyfCompositeComp comp = (GlyfCompositeComp) component; comp.setFirstIndex(firstIndex); comp.setFirstContour(firstContour); @@ -76,7 +74,7 @@ public class GlyfCompositeDescript extends GlyfDescript { desc = parentTable.getDescription(comp.getGlyphIndex()); if (desc != null) { desc.resolve(); - firstIndex += desc.getPointCount(); + firstIndex += desc.getPointCount(); firstContour += desc.getContourCount(); } } @@ -162,8 +160,8 @@ public class GlyfCompositeDescript extends GlyfDescript { protected GlyfCompositeComp getCompositeComp(int i) { GlyfCompositeComp c; - for (int n = 0; n < components.size(); n++) { - c = (GlyfCompositeComp) components.get(n); + for (Object component : components) { + c = (GlyfCompositeComp) component; GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) { return c; @@ -174,8 +172,8 @@ public class GlyfCompositeDescript extends GlyfDescript { protected GlyfCompositeComp getCompositeCompEndPt(int i) { GlyfCompositeComp c; - for (int j = 0; j < components.size(); j++) { - c = (GlyfCompositeComp) components.get(j); + for (Object component : components) { + c = (GlyfCompositeComp) component; GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex()); if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) { return c; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/TableFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/TableFactory.java index d3137167a..d52fa0064 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/TableFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/svggen/font/table/TableFactory.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.svggen.font.table; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGCanvas.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGCanvas.java index 863828cb1..3bc8c6d3a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGCanvas.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGCanvas.java @@ -30,7 +30,6 @@ import java.awt.event.MouseMotionAdapter; import java.awt.geom.AffineTransform; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -58,7 +57,7 @@ import org.apache.batik.swing.svg.JSVGComponent; import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; import org.apache.batik.swing.svg.SVGUserAgent; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; // import org.apache.batik.util.gui.DOMViewer; // import org.apache.batik.util.gui.DOMViewerController; // import org.apache.batik.util.gui.ElementOverlayManager; @@ -323,25 +322,25 @@ public class JSVGCanvas extends JSVGComponent { key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0); inputMap.put(key, SCROLL_DOWN_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_DOWN_MASK); inputMap.put(key, FAST_SCROLL_RIGHT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_DOWN_MASK); inputMap.put(key, FAST_SCROLL_LEFT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_DOWN_MASK); inputMap.put(key, FAST_SCROLL_UP_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK); inputMap.put(key, FAST_SCROLL_DOWN_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK); inputMap.put(key, ZOOM_IN_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK); inputMap.put(key, ZOOM_OUT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_MASK); + key = KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_DOWN_MASK); inputMap.put(key, RESET_TRANSFORM_ACTION); } @@ -562,23 +561,22 @@ public class JSVGCanvas extends JSVGComponent { protected void installSVGDocument(SVGDocument doc) { if (toolTipDocs != null) { - Iterator i = toolTipDocs.keySet().iterator(); - while (i.hasNext()) { + for (Object o : toolTipDocs.keySet()) { SVGDocument ttdoc; - ttdoc = (SVGDocument)i.next(); + ttdoc = (SVGDocument) o; if (ttdoc == null) continue; NodeEventTarget root; - root = (NodeEventTarget)ttdoc.getRootElement(); + root = (NodeEventTarget) ttdoc.getRootElement(); if (root == null) continue; root.removeEventListenerNS - (XMLConstants.XML_EVENTS_NAMESPACE_URI, - SVGConstants.SVG_EVENT_MOUSEOVER, - toolTipListener, false); + (XMLConstants.XML_EVENTS_NAMESPACE_URI, + SVGConstants.SVG_EVENT_MOUSEOVER, + toolTipListener, false); root.removeEventListenerNS - (XMLConstants.XML_EVENTS_NAMESPACE_URI, - SVGConstants.SVG_EVENT_MOUSEOUT, - toolTipListener, false); + (XMLConstants.XML_EVENTS_NAMESPACE_URI, + SVGConstants.SVG_EVENT_MOUSEOUT, + toolTipListener, false); } toolTipDocs = null; } @@ -683,7 +681,7 @@ public class JSVGCanvas extends JSVGComponent { /** * A swing action to apply a zoom factor to the canvas. - * This can be used to zoom in (scale > 1) and out (scale <1). + * This can be used to zoom in (scale > 1) and out (scale <1). */ public class ZoomAction extends AffineAction { public ZoomAction(double scale) { @@ -776,11 +774,11 @@ public class JSVGCanvas extends JSVGComponent { */ protected Interactor zoomInteractor = new AbstractZoomInteractor() { public boolean startInteraction(InputEvent ie) { - int mods = ie.getModifiers(); + int mods = ie.getModifiersEx(); return ie.getID() == MouseEvent.MOUSE_PRESSED && - (mods & InputEvent.BUTTON1_MASK) != 0 && - (mods & InputEvent.CTRL_MASK) != 0; + (mods & InputEvent.BUTTON1_DOWN_MASK) != 0 && + (mods & InputEvent.CTRL_DOWN_MASK) != 0; } }; @@ -791,11 +789,11 @@ public class JSVGCanvas extends JSVGComponent { protected Interactor imageZoomInteractor = new AbstractImageZoomInteractor() { public boolean startInteraction(InputEvent ie) { - int mods = ie.getModifiers(); + int mods = ie.getModifiersEx(); return ie.getID() == MouseEvent.MOUSE_PRESSED && - (mods & InputEvent.BUTTON3_MASK) != 0 && - (mods & InputEvent.SHIFT_MASK) != 0; + (mods & InputEvent.BUTTON3_DOWN_MASK) != 0 && + (mods & InputEvent.SHIFT_DOWN_MASK) != 0; } }; @@ -805,11 +803,11 @@ public class JSVGCanvas extends JSVGComponent { */ protected Interactor panInteractor = new AbstractPanInteractor() { public boolean startInteraction(InputEvent ie) { - int mods = ie.getModifiers(); + int mods = ie.getModifiersEx(); return ie.getID() == MouseEvent.MOUSE_PRESSED && - (mods & InputEvent.BUTTON1_MASK) != 0 && - (mods & InputEvent.SHIFT_MASK) != 0; + (mods & InputEvent.BUTTON1_DOWN_MASK) != 0 && + (mods & InputEvent.SHIFT_DOWN_MASK) != 0; } }; @@ -819,11 +817,11 @@ public class JSVGCanvas extends JSVGComponent { */ protected Interactor rotateInteractor = new AbstractRotateInteractor() { public boolean startInteraction(InputEvent ie) { - int mods = ie.getModifiers(); + int mods = ie.getModifiersEx(); return ie.getID() == MouseEvent.MOUSE_PRESSED && - (mods & InputEvent.BUTTON3_MASK) != 0 && - (mods & InputEvent.CTRL_MASK) != 0; + (mods & InputEvent.BUTTON3_DOWN_MASK) != 0 && + (mods & InputEvent.CTRL_DOWN_MASK) != 0; } }; @@ -834,12 +832,12 @@ public class JSVGCanvas extends JSVGComponent { protected Interactor resetTransformInteractor = new AbstractResetTransformInteractor() { public boolean startInteraction(InputEvent ie) { - int mods = ie.getModifiers(); + int mods = ie.getModifiersEx(); return ie.getID() == MouseEvent.MOUSE_CLICKED && - (mods & InputEvent.BUTTON3_MASK) != 0 && - (mods & InputEvent.SHIFT_MASK) != 0 && - (mods & InputEvent.CTRL_MASK) != 0; + (mods & InputEvent.BUTTON3_DOWN_MASK) != 0 && + (mods & InputEvent.SHIFT_DOWN_MASK) != 0 && + (mods & InputEvent.CTRL_DOWN_MASK) != 0; } }; @@ -867,9 +865,9 @@ public class JSVGCanvas extends JSVGComponent { /** * The handleElement method builds a tool tip from the * content of a <title> element, a <desc> - * element or both.
        + * element or both.
        * Because these elements can appear in any order, here - * is the algorithm used to build the tool tip:
        + * is the algorithm used to build the tool tip:
        *
          *
        • If a <title> is passed to handleElement * the method checks if there is a >desc> peer. If @@ -995,7 +993,7 @@ public class JSVGCanvas extends JSVGComponent { /** * Converts line breaks to HTML breaks and encodes special entities. - * Poor way of replacing '<', '>' and '&' in content. + * Poor way of replacing '<', '>' and '&' in content. */ public String toFormattedHTML(String str) { StringBuffer sb = new StringBuffer(str); @@ -1155,7 +1153,7 @@ public class JSVGCanvas extends JSVGComponent { * Helper class. Simply keeps track of the last known mouse * position over the canvas. */ - protected class LocationListener extends MouseMotionAdapter { + protected static class LocationListener extends MouseMotionAdapter { protected int lastX, lastY; @@ -1180,7 +1178,7 @@ public class JSVGCanvas extends JSVGComponent { /** * Sets a specific tooltip on the JSVGCanvas when a given event occurs. * This listener is used in the handleElement method to set, remove or - * modify the JSVGCanvas tooltip on mouseover and on mouseout.
          + * modify the JSVGCanvas tooltip on mouseover and on mouseout.
          * * Because we are on a single JComponent we trigger an artificial * MouseEvent when the toolTip is set to a non-null value, so as diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGScrollPane.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGScrollPane.java index ada769239..16a10c1c1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGScrollPane.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/JSVGScrollPane.java @@ -57,7 +57,7 @@ import org.apache.batik.swing.svg.GVTTreeBuilderListener; import org.apache.batik.swing.svg.GVTTreeBuilderEvent; import org.apache.batik.util.SVGConstants; -import org.apache.batik.util.XMLConstants; +import org.apache.batik.constants.XMLConstants; import org.w3c.dom.svg.SVGSVGElement; import org.w3c.dom.svg.SVGDocument; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/Messages.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/Messages.java index ad16cc8a8..085b91ebe 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/Messages.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/Messages.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.swing; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractImageZoomInteractor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractImageZoomInteractor.java index 28c8c56df..4fad1e14e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractImageZoomInteractor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractImageZoomInteractor.java @@ -18,14 +18,13 @@ */ package org.apache.batik.swing.gvt; -import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; /** * This class represents a zoom interactor. * To use it, just redefine the {@link - * InteractorAdapter#startInteraction(InputEvent)} method. + * InteractorAdapter#startInteraction(java.awt.event.InputEvent)} method. * * @author Stephane Hillion * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractPanInteractor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractPanInteractor.java index 24a20e27c..527493e24 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractPanInteractor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractPanInteractor.java @@ -19,14 +19,13 @@ package org.apache.batik.swing.gvt; import java.awt.Cursor; -import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; /** * This class represents a pan interactor. * To use it, just redefine the {@link - * InteractorAdapter#startInteraction(InputEvent)} method. + * InteractorAdapter#startInteraction(java.awt.event.InputEvent)} method. * * @author Stephane Hillion * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractRotateInteractor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractRotateInteractor.java index baf90f68a..a9baade34 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractRotateInteractor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractRotateInteractor.java @@ -19,14 +19,13 @@ package org.apache.batik.swing.gvt; import java.awt.Dimension; -import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; /** * This class represents a rotate interactor. * To use it, just redefine the {@link - * InteractorAdapter#startInteraction(InputEvent)} method. + * InteractorAdapter#startInteraction(java.awt.event.InputEvent)} method. * * @author Stephane Hillion * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractZoomInteractor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractZoomInteractor.java index f73f66288..1835061e5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractZoomInteractor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/AbstractZoomInteractor.java @@ -23,7 +23,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.geom.AffineTransform; import java.awt.geom.Line2D; @@ -31,7 +30,7 @@ import java.awt.geom.Line2D; /** * This class represents a zoom interactor. * To use it, just redefine the {@link - * InteractorAdapter#startInteraction(InputEvent)} method. + * InteractorAdapter#startInteraction(java.awt.event.InputEvent)} method. * * @author Stephane Hillion * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/JGVTComponent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/JGVTComponent.java index 1c03b42ac..63402c7fa 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/JGVTComponent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/JGVTComponent.java @@ -18,7 +18,17 @@ */ package org.apache.batik.swing.gvt; -import java.awt.*; +import java.awt.AWTPermission; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.Toolkit; +import java.awt.Shape; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.ComponentAdapter; @@ -568,9 +578,8 @@ public class JGVTComponent extends JComponent { g2d.drawRenderedImage(image, null); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); - Iterator it = overlays.iterator(); - while (it.hasNext()) { - ((Overlay)it.next()).paint(g); + for (Object overlay : overlays) { + ((Overlay) overlay).paint(g); } } } @@ -724,10 +733,9 @@ public class JGVTComponent extends JComponent { visRect.width, visRect.height); gvtTreeRenderer.setPriority(Thread.MIN_PRIORITY); - Iterator it = gvtTreeRendererListeners.iterator(); - while (it.hasNext()) { + for (Object gvtTreeRendererListener : gvtTreeRendererListeners) { gvtTreeRenderer.addGVTTreeRendererListener - ((GVTTreeRendererListener)it.next()); + ((GVTTreeRendererListener) gvtTreeRendererListener); } // Disable the dispatch during the rendering @@ -1071,7 +1079,7 @@ public class JGVTComponent extends JComponent { (e.getComponent(), MouseEvent.MOUSE_CLICKED, e.getWhen(), - e.getModifiers(), + e.getModifiersEx(), e.getX(), e.getY(), e.getClickCount(), @@ -1180,12 +1188,12 @@ public class JGVTComponent extends JComponent { public void mouseMoved(MouseEvent e) { selectInteractor(e); if (interactor != null) { - // because the mouseDragged event doesn't seem to be generated on OSX when ctrl is held down - if (Platform.isOSX && - interactor instanceof AbstractZoomInteractor) - mouseDragged(e); - else - interactor.mouseMoved(e); + // because the mouseDragged event doesn't seem to be generated on OSX when ctrl is held down + if (Platform.isOSX && + interactor instanceof AbstractZoomInteractor) + mouseDragged(e); + else + interactor.mouseMoved(e); deselectInteractor(); } else if (eventDispatcher != null) { dispatchMouseMoved(e); @@ -1229,9 +1237,8 @@ public class JGVTComponent extends JComponent { !suspendInteractions && interactor == null && gvtRoot != null) { - Iterator it = interactors.iterator(); - while (it.hasNext()) { - Interactor i = (Interactor)it.next(); + for (Object interactor1 : interactors) { + Interactor i = (Interactor) interactor1; if (i.startInteraction(ie)) { interactor = i; break; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/TextSelectionManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/TextSelectionManager.java index 96e9c17b8..5428200d8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/TextSelectionManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/gvt/TextSelectionManager.java @@ -1,21 +1,21 @@ /* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -*/ + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ package org.apache.batik.swing.gvt; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/JSVGComponent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/JSVGComponent.java index 39055488a..ea3d0b3cd 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/JSVGComponent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/JSVGComponent.java @@ -601,10 +601,9 @@ public class JSVGComponent extends JGVTComponent { nextDocumentLoader = new SVGDocumentLoader(url, loader); nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); - Iterator it = svgDocumentLoaderListeners.iterator(); - while (it.hasNext()) { + for (Object svgDocumentLoaderListener : svgDocumentLoaderListeners) { nextDocumentLoader.addSVGDocumentLoaderListener - ((SVGDocumentLoaderListener)it.next()); + ((SVGDocumentLoaderListener) svgDocumentLoaderListener); } startDocumentLoader(); } @@ -771,10 +770,9 @@ public class JSVGComponent extends JGVTComponent { nextGVTTreeBuilder = new GVTTreeBuilder(doc, bridgeContext); nextGVTTreeBuilder.setPriority(Thread.MIN_PRIORITY); - Iterator it = gvtTreeBuilderListeners.iterator(); - while (it.hasNext()) { + for (Object gvtTreeBuilderListener : gvtTreeBuilderListeners) { nextGVTTreeBuilder.addGVTTreeBuilderListener - ((GVTTreeBuilderListener)it.next()); + ((GVTTreeBuilderListener) gvtTreeBuilderListener); } initializeEventHandling(); @@ -885,10 +883,9 @@ public class JSVGComponent extends JGVTComponent { svgDocument, bridgeContext, um); - Iterator it = svgLoadEventDispatcherListeners.iterator(); - while (it.hasNext()) { + for (Object svgLoadEventDispatcherListener : svgLoadEventDispatcherListeners) { svgLoadEventDispatcher.addSVGLoadEventDispatcherListener - ((SVGLoadEventDispatcherListener)it.next()); + ((SVGLoadEventDispatcherListener) svgLoadEventDispatcherListener); } svgLoadEventDispatcher.start(); @@ -1864,9 +1861,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - managerStarted(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + managerStarted(e); } } } @@ -1882,9 +1879,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - managerSuspended(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + managerSuspended(e); } } } @@ -1900,9 +1897,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - managerResumed(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + managerResumed(e); } } } @@ -1921,9 +1918,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - managerStopped(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + managerStopped(e); } } @@ -1958,9 +1955,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - updateStarted(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + updateStarted(e); } } } @@ -1991,9 +1988,8 @@ public class JSVGComponent extends JGVTComponent { List l = e.getDirtyAreas(); if (l != null) { - Iterator i = l.iterator(); - while (i.hasNext()) { - Rectangle r = (Rectangle)i.next(); + for (Object aL : l) { + Rectangle r = (Rectangle) aL; if (updateOverlay != null) { updateOverlay.addRect(r); r = getRenderRect(); @@ -2019,9 +2015,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - updateCompleted(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + updateCompleted(e); } } } @@ -2037,9 +2033,9 @@ public class JSVGComponent extends JGVTComponent { Object[] dll = updateManagerListeners.toArray(); if (dll.length > 0) { - for (int i = 0; i < dll.length; i++) { - ((UpdateManagerListener)dll[i]). - updateFailed(e); + for (Object aDll : dll) { + ((UpdateManagerListener) aDll). + updateFailed(e); } } } @@ -2233,7 +2229,7 @@ public class JSVGComponent extends JGVTComponent { MouseDraggedRunnable mdr; mdr = (MouseDraggedRunnable)next; MouseEvent mev = mdr.event; - if (mev.getModifiers() == e.getModifiers()) { + if (mev.getModifiersEx() == e.getModifiersEx()) { mdr.event = e; } return; @@ -2277,7 +2273,7 @@ public class JSVGComponent extends JGVTComponent { MouseMovedRunnable mmr; mmr = (MouseMovedRunnable)next; MouseEvent mev = mmr.event; - if (mev.getModifiers() == e.getModifiers()) { + if (mev.getModifiersEx() == e.getModifiersEx()) { mmr.event = e; } return; @@ -3051,7 +3047,7 @@ public class JSVGComponent extends JGVTComponent { /** * This Implementation simply forwards the request to the AWT thread. * - * @param e The element that can't be loaded. + * @param e The <image> element that can't be loaded. * @param url The resolved url that can't be loaded. * @param msg As best as can be determined the reason it can't be * loaded (not available, corrupt, unknown format,...). @@ -3379,8 +3375,8 @@ public class JSVGComponent extends JGVTComponent { LinkActivationEvent ev; ev = new LinkActivationEvent(JSVGComponent.this, elt, href); - for (int i = 0; i < ll.length; i++) { - LinkActivationListener l = (LinkActivationListener)ll[i]; + for (Object aLl : ll) { + LinkActivationListener l = (LinkActivationListener) aLl; l.linkActivated(ev); } } @@ -3647,7 +3643,7 @@ public class JSVGComponent extends JGVTComponent { * for content referenced by images so you can't actually see * the info). * - * @param e The <image> element that can't be loaded. + * @param e The <image> element that can't be loaded. * @param url The resolved url that can't be loaded. * @param message As best as can be determined the reason it can't be * loaded (not available, corrupt, unknown format,...). diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/SVGUserAgentGUIAdapter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/SVGUserAgentGUIAdapter.java index 9b317de84..fcf847df6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/SVGUserAgentGUIAdapter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/swing/svg/SVGUserAgentGUIAdapter.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.swing.svg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/SVGAbstractTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/SVGAbstractTranscoder.java index fc2bb86f5..99ed8d976 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/SVGAbstractTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/SVGAbstractTranscoder.java @@ -18,14 +18,6 @@ */ package org.apache.batik.transcoder; -import java.awt.Dimension; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.awt.geom.Rectangle2D; -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - import org.apache.batik.anim.dom.SAXSVGDocumentFactory; import org.apache.batik.anim.dom.SVGDOMImplementation; import org.apache.batik.anim.dom.SVGOMDocument; @@ -33,7 +25,9 @@ import org.apache.batik.bridge.BaseScriptingEnvironment; import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.BridgeException; import org.apache.batik.bridge.DefaultScriptSecurity; +import org.apache.batik.bridge.ExternalResourceSecurity; import org.apache.batik.bridge.GVTBuilder; +import org.apache.batik.bridge.NoLoadExternalResourceSecurity; import org.apache.batik.bridge.NoLoadScriptSecurity; import org.apache.batik.bridge.RelaxedScriptSecurity; import org.apache.batik.bridge.SVGUtilities; @@ -58,11 +52,19 @@ import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.svg.SVGSVGElement; +import java.util.LinkedList; +import java.util.List; +import java.util.StringTokenizer; +import java.awt.Dimension; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.geom.Rectangle2D; + /** * This class may be the base class of all transcoders which take an * SVG document as input and which need to build a DOM tree. The * SVGAbstractTranscoder uses several different hints that - * guide it's behaviour:
          + * guide it's behaviour:
          * *
            *
          • KEY_WIDTH, KEY_HEIGHT can be used to specify how to scale the @@ -184,9 +186,9 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { } if (hints.containsKey(KEY_WIDTH)) - width = ((Float)hints.get(KEY_WIDTH)).floatValue(); + width = (Float) hints.get(KEY_WIDTH); if (hints.containsKey(KEY_HEIGHT)) - height = ((Float)hints.get(KEY_HEIGHT)).floatValue(); + height = (Float) hints.get(KEY_HEIGHT); SVGOMDocument svgDoc = (SVGOMDocument)document; @@ -198,7 +200,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { // flag that indicates if the document is dynamic boolean isDynamic = hints.containsKey(KEY_EXECUTE_ONLOAD) && - ((Boolean)hints.get(KEY_EXECUTE_ONLOAD)).booleanValue(); + (Boolean) hints.get(KEY_EXECUTE_ONLOAD); GraphicsNode gvtRoot; try { @@ -215,7 +217,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { se.dispatchSVGLoadEvent(); if (hints.containsKey(KEY_SNAPSHOT_TIME)) { float t = - ((Float) hints.get(KEY_SNAPSHOT_TIME)).floatValue(); + (Float) hints.get(KEY_SNAPSHOT_TIME); ctx.getAnimationEngine().setCurrentTime(t); } else if (ctx.isSVG12()) { float t = SVGUtilities.convertSnapshotTime(root, null); @@ -223,7 +225,6 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { } } } catch (BridgeException ex) { - ex.printStackTrace(); throw new TranscoderException(ex); } @@ -350,11 +351,11 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { // Compute the image's width and height according the hints float imgWidth = -1; if (hints.containsKey(KEY_WIDTH)) { - imgWidth = ((Float)hints.get(KEY_WIDTH)).floatValue(); + imgWidth = (Float) hints.get(KEY_WIDTH); } float imgHeight = -1; if (hints.containsKey(KEY_HEIGHT)) { - imgHeight = ((Float)hints.get(KEY_HEIGHT)).floatValue(); + imgHeight = (Float) hints.get(KEY_HEIGHT); } if (imgWidth > 0 && imgHeight > 0) { @@ -374,11 +375,11 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { // Limit image size according to the maximuxm size hints. float imgMaxWidth = -1; if (hints.containsKey(KEY_MAX_WIDTH)) { - imgMaxWidth = ((Float)hints.get(KEY_MAX_WIDTH)).floatValue(); + imgMaxWidth = (Float) hints.get(KEY_MAX_WIDTH); } float imgMaxHeight = -1; if (hints.containsKey(KEY_MAX_HEIGHT)) { - imgMaxHeight = ((Float)hints.get(KEY_MAX_HEIGHT)).floatValue(); + imgMaxHeight = (Float) hints.get(KEY_MAX_HEIGHT); } if ((imgMaxHeight > 0) && (height > imgMaxHeight)) { @@ -398,7 +399,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The image width key. - *
SourceVersion string
+ *
* * * @@ -425,7 +426,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The image height key. - *
Key:KEY_WIDTH
+ *
* * * @@ -453,7 +454,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The maximum width of the image key. - *
Key:KEY_HEIGHT
+ *
* * * @@ -483,7 +484,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The maximux height of the image key. - *
Key:KEY_MAX_WIDTH
+ *
* * * @@ -513,7 +514,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The area of interest key. - *
Key:KEY_MAX_HEIGHT
+ *
* * * @@ -543,7 +544,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The language key. - *
Key:KEY_AOI
+ *
* * * @@ -571,7 +572,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The media key. - *
Key:KEY_LANGUAGE
+ *
* * * @@ -600,7 +601,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The default font-family key. * - *
Key:KEY_MEDIA
+ *
* * * @@ -630,7 +631,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The alternate stylesheet key. - *
Key:KEY_DEFAULT_FONT_FAMILY
+ *
* * * @@ -658,7 +659,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The user stylesheet URI key. - *
Key:KEY_ALTERNATE_STYLESHEET
+ *
* * * @@ -686,7 +687,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The number of millimeters in each pixel key. - *
Key:KEY_USER_STYLESHEET_URI
+ *
* * * @@ -717,7 +718,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { * @deprecated As of Batik Version 1.5b3 * @see #KEY_PIXEL_UNIT_TO_MILLIMETER * - *
Key:KEY_PIXEL_UNIT_TO_MILLIMETER
+ *
* * * @@ -745,7 +746,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The 'onload' execution key. - *
Key:KEY_PIXEL_TO_MM
+ *
* * * @@ -774,7 +775,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** * The snapshot time key. - *
Key:KEY_EXECUTE_ONLOAD
+ *
* * * @@ -806,7 +807,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { * The set of supported script languages (i.e., the set of possible * values for the <script> tag's type attribute). * - *
Key:KEY_SNAPSHOT_TIME
+ *
* * * @@ -848,7 +849,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { * Controls whether or not scripts can only be loaded from the * same location as the document which references them. * - *
Key:KEY_ALLOWED_SCRIPT_TYPES
+ *
* * * @@ -878,6 +879,9 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { = new BooleanKey(); + public static final TranscodingHints.Key KEY_ALLOW_EXTERNAL_RESOURCES + = new BooleanKey(); + /** * A user agent implementation for PrintTranscoder. */ @@ -958,7 +962,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { Object obj = SVGAbstractTranscoder.this.hints.get (KEY_PIXEL_UNIT_TO_MILLIMETER); if (obj != null) { - return ((Float)obj).floatValue(); + return (Float) obj; } return super.getPixelUnitToMillimeter(); @@ -1041,7 +1045,7 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { Boolean b = (Boolean)SVGAbstractTranscoder.this.hints.get (KEY_XML_PARSER_VALIDATING); if (b != null) - return b.booleanValue(); + return b; return super.isXMLParserValidating(); } @@ -1076,8 +1080,8 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { if (SVGAbstractTranscoder.this.hints.containsKey (KEY_CONSTRAIN_SCRIPT_ORIGIN)) { constrainOrigin = - ((Boolean)SVGAbstractTranscoder.this.hints.get - (KEY_CONSTRAIN_SCRIPT_ORIGIN)).booleanValue(); + (Boolean) SVGAbstractTranscoder.this.hints.get + (KEY_CONSTRAIN_SCRIPT_ORIGIN); } if (constrainOrigin) { @@ -1110,5 +1114,19 @@ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { } } + public ExternalResourceSecurity getExternalResourceSecurity(ParsedURL resourceURL, ParsedURL docURL) { + if (isAllowExternalResources()) { + return super.getExternalResourceSecurity(resourceURL, docURL); + } + return new NoLoadExternalResourceSecurity(); + } + + public boolean isAllowExternalResources() { + Boolean b = (Boolean)SVGAbstractTranscoder.this.hints.get(KEY_ALLOW_EXTERNAL_RESOURCES); + if (b != null) { + return b; + } + return true; + } } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/ToSVGAbstractTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/ToSVGAbstractTranscoder.java index c7a3d8eef..76361f977 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/ToSVGAbstractTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/ToSVGAbstractTranscoder.java @@ -42,48 +42,42 @@ import org.w3c.dom.Element; /** This class allows to simplify the creation of a transcoder which transcodes to * SVG content. - *

To use this class, you just have to implement the transcode method of + * To use this class, you just have to implement the transcode method of * the AbstractTranscoder class : - *

    - *
  • first get the associated Document from the TranscoderOutput : + * first get the associated Document from the TranscoderOutput : * {@link #createDocument(TranscoderOutput)}, then create a new - * {@link org.apache.batik.svggen.SVGGraphics2D} with this Document
  • + * {@link org.apache.batik.svggen.SVGGraphics2D} with this Document *
      *    Document doc = this.createDocument(output);
      *    svgGenerator = new SVGGraphics2D(doc);
      *  
    - *
  • Perform the effective transcoding, using the - * {@link org.apache.batik.svggen.SVGGraphics2D} previously created
  • - *
  • then call the + * Perform the effective transcoding, using the + * {@link org.apache.batik.svggen.SVGGraphics2D} previously created + * then call the * {@link #writeSVGToOutput(SVGGraphics2D, Element, TranscoderOutput)} to create the - * effective output file (if the output is set to be a File or URI)
  • + * effective output file (if the output is set to be a File or URI) *
      *    Element svgRoot = svgGenerator.getRoot();
      *    writeSVGToOutput(svgGenerator, svgRoot, output);
      *  
    - *
- *

* *

Several transcoding hints are defined for this abstract transcoder, but no default * implementation is provided. Subclasses must implement which keys are relevant to them :

*
    *
  • KEY_INPUT_WIDTH, KEY_INPUT_HEIGHT, KEY_XOFFSET, KEY_YOFFSET : this Integer keys allows to * set the portion of the image to transcode, defined by the width, height, and offset - * of this portion in Metafile units. + * of this portion in Metafile units.
  • *
  • KEY_ESCAPED : this Boolean ley allow to escape XML characters in the output
  • *
*
- *     transcoder.addTranscodingHint(ToSVGAbstractTranscoder.KEY_INPUT_WIDTH, new Integer(input_width));
+ *     transcoder.addTranscodingHint(ToSVGAbstractTranscoder.KEY_INPUT_WIDTH, Integer.valueOf(input_width));
  *  
- * - *
  • KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output: - * + * + * KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output: + * *
    - *     transcoder.addTranscodingHint(ToSVGAbstractTranscoder.KEY_WIDTH, new Float(width));
    + *     transcoder.addTranscodingHint(ToSVGAbstractTranscoder.KEY_WIDTH, Float.valueOf(width));
      *  
    - *
  • - * - * * * @version $Id$ */ @@ -93,7 +87,7 @@ public abstract class ToSVGAbstractTranscoder extends AbstractTranscoder public static float PIXEL_TO_MILLIMETERS; public static float PIXEL_PER_INCH; static { - PIXEL_TO_MILLIMETERS = 25.4f / (float)Platform.getScreenResolution(); + PIXEL_TO_MILLIMETERS = 25.4f / Platform.getScreenResolution(); PIXEL_PER_INCH = Platform.getScreenResolution(); } @@ -187,7 +181,7 @@ public abstract class ToSVGAbstractTranscoder extends AbstractTranscoder try { boolean escaped = false; if (hints.containsKey(KEY_ESCAPED)) { - escaped = ((Boolean)hints.get(KEY_ESCAPED)).booleanValue(); + escaped = (Boolean) hints.get(KEY_ESCAPED); } // Output stream OutputStream os = output.getOutputStream(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscoderException.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscoderException.java index 84024a063..672841c1c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscoderException.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscoderException.java @@ -51,7 +51,7 @@ public class TranscoderException extends Exception { * @param ex the original exception */ public TranscoderException(String s, Exception ex) { - super(s); + super(s, ex); this.ex = ex; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscodingHints.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscodingHints.java index 8f9d72cfa..f1c5b8e03 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscodingHints.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/TranscodingHints.java @@ -19,7 +19,6 @@ package org.apache.batik.transcoder; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; /** @@ -129,9 +128,8 @@ public class TranscodingHints extends HashMap { if (m instanceof TranscodingHints) { putAll(((TranscodingHints) m)); } else { - Iterator iter = m.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); + for (Object o : m.entrySet()) { + Map.Entry entry = (Map.Entry) o; put(entry.getKey(), entry.getValue()); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/XMLAbstractTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/XMLAbstractTranscoder.java index 65f7d1c8b..7ba97d5c1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/XMLAbstractTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/XMLAbstractTranscoder.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder; @@ -107,7 +107,7 @@ public abstract class XMLAbstractTranscoder extends AbstractTranscoder { // parse the XML document DocumentFactory f = createDocumentFactory(domImpl, parserClassname); Object xmlParserValidating = hints.get(KEY_XML_PARSER_VALIDATING); - boolean validating = xmlParserValidating != null && ((Boolean) xmlParserValidating).booleanValue(); + boolean validating = xmlParserValidating != null && (Boolean) xmlParserValidating; f.setValidating(validating); try { if (input.getInputStream() != null) { @@ -181,7 +181,7 @@ public abstract class XMLAbstractTranscoder extends AbstractTranscoder { /** * XML parser classname key. - *
    Key:KEY_CONSTRAIN_SCRIPT_ORIGIN
    + *
    * * * @@ -209,7 +209,7 @@ public abstract class XMLAbstractTranscoder extends AbstractTranscoder { /** * The validation mode of the XML parser. - *
    Key:KEY_XML_PARSER_CLASSNAME
    + *
    * * * @@ -237,7 +237,7 @@ public abstract class XMLAbstractTranscoder extends AbstractTranscoder { /** * Document element key. - *
    Key:KEY_XML_PARSER_VALIDATING
    + *
    * * * @@ -266,7 +266,7 @@ public abstract class XMLAbstractTranscoder extends AbstractTranscoder { /** * Document element namespace URI key. - *
    Key:KEY_DOCUMENT_ELEMENT
    + *
    * * * @@ -295,7 +295,7 @@ public abstract class XMLAbstractTranscoder extends AbstractTranscoder { /** * DOM Implementation key. - *
    Key:KEY_DOCUMENT_ELEMENT_NAMESPACE_URI
    + *
    * * * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/ImageTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/ImageTranscoder.java index 8ecc6efd3..9786eff5d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/ImageTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/ImageTranscoder.java @@ -18,16 +18,6 @@ */ package org.apache.batik.transcoder.image; -import java.awt.AlphaComposite; -import java.awt.Graphics2D; -import java.awt.Paint; -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferInt; -import java.awt.image.SinglePixelPackedSampleModel; - import org.apache.batik.ext.awt.image.GraphicsUtil; import org.apache.batik.gvt.renderer.ConcreteImageRendererFactory; import org.apache.batik.gvt.renderer.ImageRenderer; @@ -40,6 +30,16 @@ import org.apache.batik.transcoder.keys.BooleanKey; import org.apache.batik.transcoder.keys.PaintKey; import org.w3c.dom.Document; +import java.awt.AlphaComposite; +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; +import java.awt.image.SinglePixelPackedSampleModel; + /** * This class enables to transcode an input to an image of any format. * @@ -59,7 +59,7 @@ import org.w3c.dom.Document; * processor can be specified: * *

    KEY_LANGUAGE to set the default language to use (may be - * used by a <switch> SVG element for example), + * used by a <switch> SVG element for example), * KEY_USER_STYLESHEET_URI to fix the URI of a user * stylesheet, and KEY_MM_PER_PIXEL to specify the number of * millimeters in each pixel . @@ -206,7 +206,7 @@ public abstract class ImageTranscoder extends SVGAbstractTranscoder { /** * The image background paint key. - *

    Key:KEY_DOM_IMPLEMENTATION
    + *
    * * * @@ -237,7 +237,7 @@ public abstract class ImageTranscoder extends SVGAbstractTranscoder { /** * The forceTransparentWhite key. * - *
    Key:KEY_BACKGROUND_COLOR
    + *
    * * * @@ -262,11 +262,11 @@ public abstract class ImageTranscoder extends SVGAbstractTranscoder { * the encoded file is displayed in a browser which does not * support transparency correctly and lets the image display with * a white background instead of a black background. - *
    + *
    * However, note that the modified image will display differently * over a white background in a viewer that supports * transparency. - *
    + *
    * Not all Transcoders use this key (in particular some formats * can't preserve the alpha channel at all in which case this * is not used). diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/JPEGTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/JPEGTranscoder.java index 8d52df6a5..c36106e33 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/JPEGTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/JPEGTranscoder.java @@ -72,7 +72,7 @@ public class JPEGTranscoder extends ImageTranscoder { try { float quality; if (hints.containsKey(KEY_QUALITY)) { - quality = ((Float)hints.get(KEY_QUALITY)).floatValue(); + quality = (Float) hints.get(KEY_QUALITY); } else { TranscoderException te; te = new TranscoderException @@ -101,7 +101,7 @@ public class JPEGTranscoder extends ImageTranscoder { /** * The encoder quality factor key. - *
    Key:KEY_FORCE_TRANSPARENT_WHITE
    + *
    * * * @@ -112,7 +112,7 @@ public class JPEGTranscoder extends ImageTranscoder { * * * - * + * * * * @@ -133,7 +133,7 @@ public class JPEGTranscoder extends ImageTranscoder { private static class QualityKey extends TranscodingHints.Key { public boolean isCompatibleValue(Object v) { if (v instanceof Float) { - float q = ((Float)v).floatValue(); + float q = (Float) v; return (q > 0 && q <= 1.0f); } else { return false; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/PNGTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/PNGTranscoder.java index e9aa19a08..d1f095006 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/PNGTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/PNGTranscoder.java @@ -21,6 +21,7 @@ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.image.SinglePixelPackedSampleModel; import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; import org.apache.batik.bridge.UserAgent; import org.apache.batik.transcoder.TranscoderException; @@ -63,7 +64,7 @@ public class PNGTranscoder extends ImageTranscoder { WriteAdapter adapter; try { Class clazz = Class.forName(className); - adapter = (WriteAdapter)clazz.newInstance(); + adapter = (WriteAdapter)clazz.getDeclaredConstructor().newInstance(); return adapter; } catch (ClassNotFoundException e) { return null; @@ -71,6 +72,10 @@ public class PNGTranscoder extends ImageTranscoder { return null; } catch (IllegalAccessException e) { return null; + } catch (NoSuchMethodException e) { + return null; + } catch (InvocationTargetException e) { + return null; } } @@ -97,8 +102,8 @@ public class PNGTranscoder extends ImageTranscoder { if (hints.containsKey(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)) { forceTransparentWhite = - ((Boolean)hints.get - (PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)).booleanValue(); + (Boolean) hints.get + (PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE); } if (forceTransparentWhite) { @@ -152,7 +157,7 @@ public class PNGTranscoder extends ImageTranscoder { /** * The gamma correction key. * - *
    Key:KEY_QUALITY
    Default:1 (no lossy)0.75 (lossy)
    Required:
    + *
    * * * @@ -193,7 +198,7 @@ public class PNGTranscoder extends ImageTranscoder { * The color indexed image key to specify number of colors used in * palette. * - *
    Key:KEY_GAMMA
    + *
    * * * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/TIFFTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/TIFFTranscoder.java index 57c4f69e4..6955fc67a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/TIFFTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/TIFFTranscoder.java @@ -15,12 +15,13 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.image.SinglePixelPackedSampleModel; +import java.lang.reflect.InvocationTargetException; import org.apache.batik.bridge.UserAgent; import org.apache.batik.transcoder.TranscoderException; @@ -62,7 +63,7 @@ public class TIFFTranscoder extends ImageTranscoder { WriteAdapter adapter; try { Class clazz = Class.forName(className); - adapter = (WriteAdapter)clazz.newInstance(); + adapter = (WriteAdapter)clazz.getDeclaredConstructor().newInstance(); return adapter; } catch (ClassNotFoundException e) { return null; @@ -70,6 +71,10 @@ public class TIFFTranscoder extends ImageTranscoder { return null; } catch (IllegalAccessException e) { return null; + } catch (NoSuchMethodException e) { + return null; + } catch (InvocationTargetException e) { + return null; } } @@ -90,8 +95,8 @@ public class TIFFTranscoder extends ImageTranscoder { if (hints.containsKey(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)) { forceTransparentWhite = - ((Boolean)hints.get - (PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE)).booleanValue(); + (Boolean) hints.get + (PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE); } if (forceTransparentWhite) { @@ -104,7 +109,7 @@ public class TIFFTranscoder extends ImageTranscoder { "org.apache.batik.ext.awt.image.codec.tiff.TIFFTranscoderInternalCodecWriteAdapter"); if (adapter == null) { adapter = getWriteAdapter( - "org.apache.batik.transcoder.image.TIFFTranscoderImageIOWriteAdapter"); + "org.apache.batik.ext.awt.image.codec.imageio.TIFFTranscoderImageIOWriteAdapter"); } if (adapter == null) { throw new TranscoderException( @@ -145,7 +150,7 @@ public class TIFFTranscoder extends ImageTranscoder { /** * The forceTransparentWhite key. * - *
    Key:KEY_INDEXED
    + *
    * * * @@ -170,7 +175,7 @@ public class TIFFTranscoder extends ImageTranscoder { * encoded TIFF is displayed in a viewer which does not support TIFF * transparency and lets the image display with a white background instead * of a black background. - *
    + *
    * However, note that the modified image will display differently * over a white background in a viewer that supports * transparency. @@ -182,7 +187,7 @@ public class TIFFTranscoder extends ImageTranscoder { /** * The compression method for the image. - *
    Key:KEY_FORCE_TRANSPARENT_WHITE
    + *
    * * * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/resources/Messages.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/resources/Messages.java index ebf87b72e..34cc8e8cd 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/resources/Messages.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/image/resources/Messages.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.image.resources; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/LengthKey.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/LengthKey.java index 0a523099e..af7f6ea00 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/LengthKey.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/LengthKey.java @@ -30,6 +30,6 @@ import org.apache.batik.transcoder.TranscodingHints; public class LengthKey extends TranscodingHints.Key { public boolean isCompatibleValue(Object v) { - return (v instanceof Float && ((Float)v).floatValue() > 0); + return (v instanceof Float && (Float) v > 0); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/StringKey.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/StringKey.java index 4d49232e6..7cf555a29 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/StringKey.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/keys/StringKey.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.keys; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/print/PrintTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/print/PrintTranscoder.java index c7fe9e1d1..5b1731e62 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/print/PrintTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/print/PrintTranscoder.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.print; import java.awt.Graphics; @@ -52,13 +52,13 @@ import org.w3c.dom.Document; * This class is a Transcoder that prints SVG images. * This class works as follows: any-time the transcode method * is invoked, the corresponding input is cached and nothing - * else happens.
    + * else happens.
    * However, the PrintTranscoder is also a Printable. If used * in a print operation, it will print each of the input * it cached, one input per page. - *
    + *
    * The PrintTranscoder uses several different hints that - * guide its printing:
    + * guide its printing:
    *
      *
    • KEY_LANGUAGE, KEY_USER_STYLESHEET_URI, KEY_PIXEL_TO_MM, * KEY_XML_PARSER_CLASSNAME can be used to set the defaults for @@ -183,12 +183,12 @@ public class PrintTranscoder extends SVGAbstractTranscoder Float pageWidth = (Float)hints.get(KEY_PAGE_WIDTH); Float pageHeight = (Float)hints.get(KEY_PAGE_HEIGHT); if(pageWidth != null){ - paper.setSize(pageWidth.floatValue(), + paper.setSize(pageWidth, paper.getHeight()); } if(pageHeight != null){ paper.setSize(paper.getWidth(), - pageHeight.floatValue()); + pageHeight); } float x=0, y=0; @@ -201,18 +201,18 @@ public class PrintTranscoder extends SVGAbstractTranscoder Float bottomMargin = (Float)hints.get(KEY_MARGIN_BOTTOM); if(leftMargin != null){ - x = leftMargin.floatValue(); - width -= leftMargin.floatValue(); + x = leftMargin; + width -= leftMargin; } if(topMargin != null){ - y = topMargin.floatValue(); - height -= topMargin.floatValue(); + y = topMargin; + height -= topMargin; } if(rightMargin != null){ - width -= rightMargin.floatValue(); + width -= rightMargin; } if(bottomMargin != null){ - height -= bottomMargin.floatValue(); + height -= bottomMargin; } paper.setImageableArea(x, y, width, height); @@ -235,7 +235,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder // If required, pop up a dialog to adjust the page format // Boolean showPageFormat = (Boolean)hints.get(KEY_SHOW_PAGE_DIALOG); - if ((showPageFormat != null) && (showPageFormat.booleanValue())) { + if ((showPageFormat != null) && (showPageFormat)) { PageFormat tmpPageFormat = printerJob.pageDialog(pageFormat); if(tmpPageFormat == pageFormat){ // Dialog was cancelled, meaning that the print process should @@ -255,7 +255,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder // Boolean showPrinterDialog; showPrinterDialog = (Boolean)hints.get(KEY_SHOW_PRINTER_DIALOG); - if(showPrinterDialog != null && showPrinterDialog.booleanValue()){ + if(showPrinterDialog != null && showPrinterDialog){ if(!printerJob.printDialog()){ // Dialog was cancelled, meaning that the print process // should be stopped. @@ -378,7 +378,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder protected void setImageSize(float docWidth, float docHeight) { // Check hint to know if scaling is really needed Boolean scaleToPage = (Boolean)hints.get(KEY_SCALE_TO_PAGE); - if(scaleToPage != null && !scaleToPage.booleanValue()) { + if(scaleToPage != null && !scaleToPage) { float w = docWidth; float h = docHeight; if (hints.containsKey(KEY_AOI)) { @@ -404,7 +404,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The showPageDialog key. - *
    Key:KEY_COMPRESSION_METHOD
    + *
    * * * @@ -434,7 +434,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The showPrinterDialog key. - *
    Key:KEY_SHOW_PAGE_DIALOG
    + *
    * * * @@ -467,7 +467,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The pageWidth key. - *
    Key:KEY_SHOW_PAGE_DIALOG
    + *
    * * * @@ -495,7 +495,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The pageHeight key. - *
    Key:KEY_PAGE_WIDTH
    + *
    * * * @@ -523,7 +523,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The marginTop key. - *
    Key:KEY_PAGE_HEIGHT
    + *
    * * * @@ -550,7 +550,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The marginRight key. - *
    Key:KEY_MARGIN_TOP
    + *
    * * * @@ -578,7 +578,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The marginBottom key. - *
    Key:KEY_MARGIN_RIGHT
    + *
    * * * @@ -606,7 +606,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The marginLeft key. - *
    Key:KEY_MARGIN_BOTTOM
    + *
    * * * @@ -629,7 +629,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The pageOrientation key. - *
    Key:KEY_MARGIN_LEFT
    + *
    * * * @@ -658,7 +658,7 @@ public class PrintTranscoder extends SVGAbstractTranscoder /** * The scaleToPage key. - *
    Key:KEY_PAGE_ORIENTATION
    + *
    * * * @@ -781,9 +781,9 @@ public class PrintTranscoder extends SVGAbstractTranscoder // First, request the transcoder to transcode // each of the input files // - for(int i=0; i= prettyPrinter.getDocumentWidth())) { printNewline(); printString(margin.toString()); @@ -725,8 +724,8 @@ public class OutputManager { */ protected int newlines(char[] text) { int result = 0; - for (int i = 0; i < text.length; i++) { - if (text[i] == 10) { + for (char aText : text) { + if (aText == 10) { result++; } } @@ -737,8 +736,8 @@ public class OutputManager { * Tells whether the given character represents white spaces. */ protected boolean isWhiteSpace(char[] text) { - for (int i = 0; i < text.length; i++) { - if (!XMLUtilities.isXMLSpace(text[i])) { + for (char aText : text) { + if (!XMLUtilities.isXMLSpace(aText)) { return false; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/svg2svg/SVGTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/svg2svg/SVGTranscoder.java index 2abf462f0..ec82c9103 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/svg2svg/SVGTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/svg2svg/SVGTranscoder.java @@ -15,16 +15,10 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.svg2svg; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; - import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.transcoder.AbstractTranscoder; import org.apache.batik.transcoder.ErrorHandler; @@ -37,6 +31,12 @@ import org.apache.batik.transcoder.keys.IntegerKey; import org.apache.batik.transcoder.keys.StringKey; import org.w3c.dom.Document; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; + /** * This class is a trancoder from SVG to SVG. * @@ -170,18 +170,18 @@ public class SVGTranscoder extends AbstractTranscoder { if (r == null) { Document d = input.getDocument(); if (d == null) { - throw new Error("Reader or Document expected"); + throw new RuntimeException("Reader or Document expected"); } StringWriter sw = new StringWriter( 1024 ); try { DOMUtilities.writeDocument(d, sw); } catch ( IOException ioEx ) { - throw new Error("IO:" + ioEx.getMessage() ); + throw new RuntimeException("IO:" + ioEx.getMessage() ); } r = new StringReader(sw.toString()); } if (w == null) { - throw new Error("Writer expected"); + throw new RuntimeException("Writer expected"); } prettyPrint(r, w); } @@ -199,15 +199,15 @@ public class SVGTranscoder extends AbstractTranscoder { } Boolean b = (Boolean)hints.get(KEY_FORMAT); if (b != null) { - pp.setFormat(b.booleanValue()); + pp.setFormat(b); } Integer i = (Integer)hints.get(KEY_TABULATION_WIDTH); if (i != null) { - pp.setTabulationWidth(i.intValue()); + pp.setTabulationWidth(i); } i = (Integer)hints.get(KEY_DOCUMENT_WIDTH); if (i != null) { - pp.setDocumentWidth(i.intValue()); + pp.setDocumentWidth(i); } DoctypeValue dtv = (DoctypeValue)hints.get(KEY_DOCTYPE); if (dtv != null) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/WMFConstants.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/WMFConstants.java index 183b00fb5..034f6631e 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/WMFConstants.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/WMFConstants.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java index 7d57c668b..e0235ca1c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -64,10 +64,10 @@ public class AbstractWMFPainter { */ protected BufferedImage getImage(byte[] bit, int width, int height) { // get the header of the bitmap, first the width and height - int _width = (((int)bit[7] & 0x00ff) << 24) | (((int)bit[6] & 0x00ff) << 16) - | (((int)bit[5] & 0x00ff) << 8) | (int)bit[4] & 0x00ff; - int _height = (((int)bit[11] & 0x00ff) << 24) | (((int)bit[10] & 0x00ff) << 16) - | (((int)bit[9] & 0x00ff) <<8) | (int)bit[8] & 0x00ff; + int _width = ((bit[7] & 0x00ff) << 24) | ((bit[6] & 0x00ff) << 16) + | ((bit[5] & 0x00ff) << 8) | bit[4] & 0x00ff; + int _height = ((bit[11] & 0x00ff) << 24) | ((bit[10] & 0x00ff) << 16) + | ((bit[9] & 0x00ff) <<8) | bit[8] & 0x00ff; // if width and height of the bitmap are different from advertised, we abort if ((width != _width) || (height != _height)) return null; @@ -76,10 +76,10 @@ public class AbstractWMFPainter { protected Dimension getImageDimension(byte[] bit) { // get the header of the bitmap, first the width and height - int _width = (((int)bit[7] & 0x00ff) << 24) | (((int)bit[6] & 0x00ff) << 16) - | (((int)bit[5] & 0x00ff) << 8) | (int)bit[4] & 0x00ff; - int _height = (((int)bit[11] & 0x00ff) << 24) | (((int)bit[10] & 0x00ff) << 16) - | (((int)bit[9] & 0x00ff) << 8) | (int)bit[8] & 0x00ff; + int _width = ((bit[7] & 0x00ff) << 24) | ((bit[6] & 0x00ff) << 16) + | ((bit[5] & 0x00ff) << 8) | bit[4] & 0x00ff; + int _height = ((bit[11] & 0x00ff) << 24) | ((bit[10] & 0x00ff) << 16) + | ((bit[9] & 0x00ff) << 8) | bit[8] & 0x00ff; return new Dimension(_width, _height); } @@ -91,10 +91,10 @@ public class AbstractWMFPainter { */ protected BufferedImage getImage(byte[] bit) { // get the header of the bitmap, first the width and height - int _width = (((int)bit[7] & 0x00ff) << 24) | (((int)bit[6] & 0x00ff) << 16) - | (((int)bit[5] & 0x00ff) << 8) | (int)bit[4] & 0x00ff; - int _height = (((int)bit[11] & 0x00ff) << 24) | (((int)bit[10] & 0x00ff) << 16) - | (((int)bit[9] & 0x00ff) << 8) | (int)bit[8] & 0x00ff; + int _width = ((bit[7] & 0x00ff) << 24) | ((bit[6] & 0x00ff) << 16) + | ((bit[5] & 0x00ff) << 8) | bit[4] & 0x00ff; + int _height = ((bit[11] & 0x00ff) << 24) | ((bit[10] & 0x00ff) << 16) + | ((bit[9] & 0x00ff) << 8) | bit[8] & 0x00ff; // OK, we can safely create the data array now int[] bitI = new int[_width * _height]; @@ -103,22 +103,22 @@ public class AbstractWMFPainter { // retrieve useful informations in bitmap header // size of header - int _headerSize = (((int)bit[3] & 0x00ff) << 24) | (((int)bit[2] & 0x00ff)<<16) - | (((int)bit[1] & 0x00ff) << 8) | (int)bit[0] & 0x00ff; + int _headerSize = ((bit[3] & 0x00ff) << 24) | ((bit[2] & 0x00ff)<<16) + | ((bit[1] & 0x00ff) << 8) | bit[0] & 0x00ff; // number of planes - int _planes = (((int)bit[13] & 0x00ff) << 8) | (int)bit[12] & 0x00ff; + int _planes = ((bit[13] & 0x00ff) << 8) | bit[12] & 0x00ff; // number of bits per pixel - int _nbit = (((int)bit[15] & 0x00ff) << 8) | (int)bit[14] & 0x00ff; + int _nbit = ((bit[15] & 0x00ff) << 8) | bit[14] & 0x00ff; // compression factor : unused // size of the image - int _size = (((int)bit[23] & 0x00ff) << 24) | (((int)bit[22] & 0x00ff) << 16) - | (((int)bit[21] & 0x00ff) << 8) | (int)bit[20] & 0x00ff; + int _size = ((bit[23] & 0x00ff) << 24) | ((bit[22] & 0x00ff) << 16) + | ((bit[21] & 0x00ff) << 8) | bit[20] & 0x00ff; // infer the size of image if it is not given in the file if (_size == 0) _size = ((((_width * _nbit) + 31) & ~31 ) >> 3) * _height; // number of used colors - int _clrused = (((int)bit[35] & 0x00ff) << 24) | (((int)bit[34]&0x00ff) << 16) - | (((int)bit[33] & 0x00ff) << 8) | (int)bit[32]&0x00ff; + int _clrused = ((bit[35] & 0x00ff) << 24) | ((bit[34] &0x00ff) << 16) + | ((bit[33] & 0x00ff) << 8) | bit[32] &0x00ff; // 24 bit image if (_nbit == 24) { @@ -129,8 +129,8 @@ public class AbstractWMFPainter { for (int j = 0; j < _height; j++) { for (int i = 0; i < _width; i++) { bitI[_width * (_height - j - 1) + i] = - (255 & 0x00ff) << 24 | (((int)bit[offset+2] & 0x00ff) << 16) - | (((int)bit[offset+1] & 0x00ff) << 8) | (int)bit[offset] & 0x00ff; + (255 & 0x00ff) << 24 | ((bit[offset+2] & 0x00ff) << 16) + | ((bit[offset+1] & 0x00ff) << 8) | bit[offset] & 0x00ff; offset += 3; } offset += pad; @@ -145,9 +145,9 @@ public class AbstractWMFPainter { int offset = _headerSize; int[] palette = new int[nbColors]; for (int i = 0; i < nbColors; i++) { - palette[i] = (255 & 0x00ff) << 24 | (((int)bit[offset+2] & 0x00ff) << 16) - | (((int)bit[offset+1] & 0x00ff) << 8) - | (int)bit[offset] & 0x00ff; + palette[i] = (255 & 0x00ff) << 24 | ((bit[offset+2] & 0x00ff) << 16) + | ((bit[offset+1] & 0x00ff) << 8) + | bit[offset] & 0x00ff; offset += 4; } @@ -159,7 +159,7 @@ public class AbstractWMFPainter { int pad = (_size / _height) - _width; for (int j = 0; j < _height; j++) { for (int i = 0; i < _width; i++) { - bitI[_width*(_height-j-1)+i] = palette [((int)bit[offset] & 0x00ff)]; + bitI[_width*(_height-j-1)+i] = palette [(bit[offset] & 0x00ff)]; offset++; } offset += pad; @@ -172,9 +172,9 @@ public class AbstractWMFPainter { int offset = _headerSize; int[] palette = new int[nbColors]; for (int i = 0; i < nbColors; i++) { - palette[i] = (255 & 0x00ff) << 24 | (((int)bit[offset+2] & 0x00ff) << 16) - | (((int)bit[offset+1] & 0x00ff) << 8) - | (int)bit[offset] & 0x00ff; + palette[i] = (255 & 0x00ff) << 24 | ((bit[offset+2] & 0x00ff) << 16) + | ((bit[offset+1] & 0x00ff) << 8) + | bit[offset] & 0x00ff; offset += 4; } @@ -224,7 +224,7 @@ public class AbstractWMFPainter { protected AttributedString getAttributedString(Graphics2D g2d, String sr, WMFFont wmffont) { AttributedString ats = new AttributedString(sr); Font font = g2d.getFont(); - ats.addAttribute(TextAttribute.SIZE, new Float(font.getSize2D())); + ats.addAttribute(TextAttribute.SIZE, font.getSize2D()); ats.addAttribute(TextAttribute.FONT, font); if (wmfFont.underline != 0) ats.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java index 32d6647bb..1269d7388 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -80,7 +80,7 @@ public abstract class AbstractWMFReader { * Read the next short (2 bytes) value in the DataInputStream. */ protected short readShort(DataInputStream is) throws IOException { - byte js[] = new byte[ 2 ]; + byte[] js = new byte[ 2 ]; is.readFully(js); int iTemp = ((0xff) & js[ 1 ] ) << 8; short i = (short)(0xffff & iTemp); @@ -92,7 +92,7 @@ public abstract class AbstractWMFReader { * Read the next int (4 bytes) value in the DataInputStream. */ protected int readInt( DataInputStream is) throws IOException { - byte js[] = new byte[ 4 ]; + byte[] js = new byte[ 4 ]; is.readFully(js); int i = ((0xff) & js[ 3 ] ) << 24; i |= ((0xff) & js[ 2 ] ) << 16; @@ -119,34 +119,34 @@ public abstract class AbstractWMFReader { * Returns the viewport width, in inches. */ public float getViewportWidthInch() { - return (float)vpW / (float)inch; + return (float)vpW / inch; } /** * Returns the viewport height, in inches. */ public float getViewportHeightInch() { - return (float)vpH / (float)inch; + return (float)vpH / inch; } /** Return the number of pixels per unit. */ public float getPixelsPerUnit() { - return PIXEL_PER_INCH / (float)inch; + return PIXEL_PER_INCH / inch; } /** * Returns the viewport width, in pixels. */ public int getVpW() { - return (int)(PIXEL_PER_INCH * (float)vpW / (float)inch); + return (int)(PIXEL_PER_INCH * vpW / inch); } /** * Returns the viewport height, in pixels. */ public int getVpH() { - return (int)(PIXEL_PER_INCH * (float)vpH / (float)inch); + return (int)(PIXEL_PER_INCH * vpH / inch); } /** get the left units in the WMF Metafile. This value is given @@ -214,10 +214,10 @@ public abstract class AbstractWMFReader { /** get the Rectangle defining the viewport of the WMF Metafile, in pixels. */ public Rectangle2D getRectanglePixel() { - float _left = PIXEL_PER_INCH * (float)left / (float)inch; - float _right = PIXEL_PER_INCH * (float)right / (float)inch; - float _top = PIXEL_PER_INCH * (float)top / (float)inch; - float _bottom = PIXEL_PER_INCH * (float)bottom / (float)inch; + float _left = PIXEL_PER_INCH * left / inch; + float _right = PIXEL_PER_INCH * right / inch; + float _top = PIXEL_PER_INCH * top / inch; + float _bottom = PIXEL_PER_INCH * bottom / inch; Rectangle2D.Float rec = new Rectangle2D.Float(_left, _top, _right - _left, _bottom - _top); @@ -227,10 +227,10 @@ public abstract class AbstractWMFReader { /** get the Rectangle defining the viewport of the WMF Metafile, in inchs. */ public Rectangle2D getRectangleInch() { - float _left = (float)left / (float)inch; - float _right = (float)right / (float)inch; - float _top = (float)top / (float)inch; - float _bottom = (float)bottom / (float)inch; + float _left = (float)left / inch; + float _right = (float)right / inch; + float _top = (float)top / inch; + float _bottom = (float)bottom / inch; Rectangle2D.Float rec = new Rectangle2D.Float(_left, _top, _right - _left, _bottom - _top); @@ -240,31 +240,31 @@ public abstract class AbstractWMFReader { /** get the width of the WMF Metafile, in pixels. */ public int getWidthPixels() { - return (int)(PIXEL_PER_INCH * (float)width / (float)inch); + return (int)(PIXEL_PER_INCH * width / inch); } /** get the factor to transform Metafile dimensions in pixels */ public float getUnitsToPixels() { - return (PIXEL_PER_INCH / (float)inch); + return (PIXEL_PER_INCH / inch); } /** get the factor to transform logical units width in pixels */ public float getVpWFactor() { - return (PIXEL_PER_INCH * (float)width / (float)inch) / (float)vpW; + return (PIXEL_PER_INCH * width / inch) / vpW; } /** get the factor to transform logical units height in pixels */ public float getVpHFactor() { - return (PIXEL_PER_INCH * (float)height / (float)inch) / (float)vpH; + return (PIXEL_PER_INCH * height / inch) / vpH; } /** get the height of the WMF Metafile, in pixels. */ public int getHeightPixels() { - return (int)(PIXEL_PER_INCH * (float)height / (float)inch); + return (int)(PIXEL_PER_INCH * height / inch); } /** Return the sign of X coordinates. It is equal to 1 by default, but can be -1 if @@ -298,7 +298,7 @@ public abstract class AbstractWMFReader { /** Read this InputStream records. The aldus placeable header have already been * read (see {@link #read(DataInputStream)}). The behavior of this method is left * to the subclass. - *

    Each Metafile record is composed of : + * Each Metafile record is composed of : *

      *
    • the size of the Record in int (32 bits)
    • *
    • the function ID for the Record on a short word (16 bits)
    • @@ -306,14 +306,14 @@ public abstract class AbstractWMFReader { * the remaining size in short words (16 bits) for the parameters is equal to * the total size for the record minus 3 short words (= 16 + 32 bits) *
    - *

    + * *

    Example :

    - *
    while (functionId > 0) {
    +     * 
    while (functionId > 0) {
          *        recSize = readInt( is );
          *        // Subtract size in 16-bit words of recSize and functionId;
          *        recSize -= 3;
          *        functionId = readShort( is );
    -     *        if ( functionId <= 0 )
    +     *        if ( functionId <= 0 )
          *          break;
          *        switch ( functionId ) {
          *          case WMFConstants.<a WMF function ID> {
    @@ -322,7 +322,7 @@ public abstract class AbstractWMFReader {
          *          break;
          *
          *          default:
    -     *             for ( int j = 0; j < recSize; j++ )
    +     *             for ( int j = 0; j < recSize; j++ )
          *               readShort(is);
          *          break;
          * 
    diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/GdiObject.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/GdiObject.java index 71c12eb77..f55c8bb39 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/GdiObject.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/GdiObject.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/MetaRecord.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/MetaRecord.java index d1fa51545..f18db6a3d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/MetaRecord.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/MetaRecord.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -52,13 +52,13 @@ public class MetaRecord /*implements Serializable*/ { } /** - * helper method to add int-values. This way we keep the call to new Integer() + * helper method to add int-values. This way we keep the call to Integer.valueOf() * in one place, here. * * @param iValue the value to add to ptVector, wrapped in an Integer */ public final void addElement( int iValue ){ - ptVector.add( new Integer( iValue ) ); + ptVector.add(iValue); } /** @@ -77,7 +77,7 @@ public class MetaRecord /*implements Serializable*/ { * @return the intValue of the element at offset */ public final int elementAt( int offset ){ - return ((Integer)ptVector.get( offset )).intValue(); + return (Integer) ptVector.get(offset); } /** A record that contain byte arrays elements. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/RecordStore.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/RecordStore.java index 29f8f16e3..2c9672841 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/RecordStore.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/RecordStore.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -116,7 +116,7 @@ public class RecordStore { mr.functionId = functionId; for ( int j = 0; j < numPts; j++ ){ - mr.AddElement( new Integer( is.readShort())); + mr.AddElement((int) is.readShort()); } records.add( mr ); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/TextureFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/TextureFactory.java index e037d4940..9d68448b8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/TextureFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/TextureFactory.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -36,7 +36,7 @@ import org.apache.batik.transcoder.wmf.WMFConstants; * * @version $Id$ */ -public class TextureFactory { +public final class TextureFactory { private static TextureFactory fac = null; private Map textures = new HashMap(1); private static final int SIZE = 10; @@ -71,7 +71,7 @@ public class TextureFactory { * texture will be cached, so the Paint will only be created once. */ public Paint getTexture(int textureId) { - Integer _itexture = new Integer(textureId); + Integer _itexture = textureId; if (textures.containsKey( _itexture)) { Paint paint = (Paint)(textures.get(_itexture)); return paint; @@ -170,7 +170,7 @@ public class TextureFactory { /** Contain a handle to a Colored texture, with optional foreground and * background colors. */ - private class ColoredTexture { + private static class ColoredTexture { final int textureId; final Color foreground; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFFont.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFFont.java index 6366a6cf2..53b62e6ca 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFFont.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFFont.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java index d0eaebd55..f46e6ca70 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -45,7 +45,7 @@ import org.apache.batik.transcoder.wmf.WMFConstants; */ public class WMFHeaderProperties extends AbstractWMFReader { - private static final Integer INTEGER_0 = new Integer( 0 ); + private static final Integer INTEGER_0 = 0; protected DataInputStream stream; private int _bleft, _bright, _btop, _bbottom, _bwidth, _bheight; @@ -169,7 +169,7 @@ public class WMFHeaderProperties extends AbstractWMFReader { case WMFConstants.META_SETWINDOWEXT: { vpH = readShort( is ); vpW = readShort( is ); - if (! isotropic) scaleXY = (float)vpW / (float)vpH; + if (! isotropic) scaleXY = (float)vpW / vpH; vpW = (int)(vpW * scaleXY); } break; @@ -304,14 +304,14 @@ public class WMFHeaderProperties extends AbstractWMFReader { int lfHeight = readShort( is ); float size = (int)(scaleY * lfHeight); int lfWidth = readShort( is ); - int escape = (int)readShort( is ); - int orient = (int)readShort( is ); - int weight = (int)readShort( is ); - - int italic = (int)is.readByte(); - int underline = (int)is.readByte(); - int strikeOut = (int)is.readByte(); - int charset = (int)(is.readByte() & 0x00ff); + int escape = readShort( is ); + int orient = readShort( is ); + int weight = readShort( is ); + + int italic = is.readByte(); + int underline = is.readByte(); + int strikeOut = is.readByte(); + int charset = is.readByte() & 0x00ff; int lfOutPrecision = is.readByte(); int lfClipPrecision = is.readByte(); int lfQuality = is.readByte(); @@ -527,12 +527,12 @@ public class WMFHeaderProperties extends AbstractWMFReader { readShort( is ); // widthSrc readShort( is ); // sy readShort( is ); // sx - float heightDst = (float)readShort( is ); - float widthDst = (float)readShort( is ) * scaleXY; - float dy = (float)readShort( is ) * getVpWFactor() * (float)inch / PIXEL_PER_INCH; - float dx = (float)readShort( is ) * getVpWFactor() * (float)inch / PIXEL_PER_INCH * scaleXY; - widthDst = widthDst * getVpWFactor() * (float)inch / PIXEL_PER_INCH; - heightDst = heightDst * getVpHFactor() * (float)inch / PIXEL_PER_INCH; + float heightDst = readShort( is ); + float widthDst = readShort( is ) * scaleXY; + float dy = readShort( is ) * getVpWFactor() * inch / PIXEL_PER_INCH; + float dx = readShort( is ) * getVpWFactor() * inch / PIXEL_PER_INCH * scaleXY; + widthDst = widthDst * getVpWFactor() * inch / PIXEL_PER_INCH; + heightDst = heightDst * getVpHFactor() * inch / PIXEL_PER_INCH; resizeImageBounds((int)dx, (int)dy); resizeImageBounds((int)(dx + widthDst), (int)(dy + heightDst)); @@ -547,17 +547,17 @@ public class WMFHeaderProperties extends AbstractWMFReader { readShort( is ); // widthSrc readShort( is ); // sy readShort( is ); // sx - float heightDst = (float)readShort( is ); - float widthDst = (float)readShort( is ) * scaleXY; - float dy = (float)readShort( is ) * getVpHFactor() * (float)inch / PIXEL_PER_INCH; - float dx = (float)readShort( is ) * getVpHFactor() * (float)inch / PIXEL_PER_INCH * scaleXY; - widthDst = widthDst * getVpWFactor() * (float)inch / PIXEL_PER_INCH; - heightDst = heightDst * getVpHFactor() * (float)inch / PIXEL_PER_INCH; + float heightDst = readShort( is ); + float widthDst = readShort( is ) * scaleXY; + float dy = readShort( is ) * getVpHFactor() * inch / PIXEL_PER_INCH; + float dx = readShort( is ) * getVpHFactor() * inch / PIXEL_PER_INCH * scaleXY; + widthDst = widthDst * getVpWFactor() * inch / PIXEL_PER_INCH; + heightDst = heightDst * getVpHFactor() * inch / PIXEL_PER_INCH; resizeImageBounds((int)dx, (int)dy); resizeImageBounds((int)(dx + widthDst), (int)(dy + heightDst)); int len = 2*recSize - 22; - byte bitmap[] = new byte[len]; + byte[] bitmap = new byte[len]; for (int i = 0; i < len; i++) bitmap[i] = is.readByte(); } break; @@ -571,9 +571,9 @@ public class WMFHeaderProperties extends AbstractWMFReader { float width = readShort( is ) * (float)inch / PIXEL_PER_INCH * getVpWFactor() * scaleXY; float dy = - (float)inch / PIXEL_PER_INCH * getVpHFactor() * readShort( is ); + inch / PIXEL_PER_INCH * getVpHFactor() * readShort( is ); float dx = - (float)inch / PIXEL_PER_INCH * getVpWFactor() * readShort( is ) * scaleXY; + inch / PIXEL_PER_INCH * getVpWFactor() * readShort( is ) * scaleXY; resizeImageBounds((int)dx, (int)dy); resizeImageBounds((int)(dx + width), (int)(dy + height)); } @@ -617,14 +617,14 @@ public class WMFHeaderProperties extends AbstractWMFReader { * the Metafile, in Metafile Units. */ public int getWidthBoundsUnits() { - return (int)((float)inch * (float)_bwidth / PIXEL_PER_INCH); + return (int)((float)inch * _bwidth / PIXEL_PER_INCH); } /** @return the height of the Rectangle bounding the figures enclosed in * the Metafile in Metafile Units. */ public int getHeightBoundsUnits() { - return (int)((float)inch * (float)_bheight / PIXEL_PER_INCH); + return (int)((float)inch * _bheight / PIXEL_PER_INCH); } /** @return the X offset of the Rectangle bounding the figures enclosed in @@ -643,7 +643,7 @@ public class WMFHeaderProperties extends AbstractWMFReader { private void resetBounds() { // calculate geometry size - scale = (float)getWidthPixels() / (float)vpW ; + scale = (float)getWidthPixels() / vpW; if (_bright != -1) { _bright = (int)(scale * (vpX +_bright)); _bleft = (int)(scale * (vpX +_bleft)); @@ -653,10 +653,10 @@ public class WMFHeaderProperties extends AbstractWMFReader { // calculate image size if (_iright != -1) { - _iright = (int)((float)_iright * (float)getWidthPixels() / (float)width); - _ileft = (int)((float)_ileft * (float)getWidthPixels() / (float)width); - _ibottom = (int)((float)_ibottom * (float)getWidthPixels() / (float)width); - _itop = (int)((float)_itop * (float)getWidthPixels() / (float)width); + _iright = (int)((float)_iright * getWidthPixels() / width); + _ileft = (int)((float)_ileft * getWidthPixels() / width); + _ibottom = (int)((float)_ibottom * getWidthPixels() / width); + _itop = (int)((float)_itop * getWidthPixels() / width); // merge image and geometry size if ((_bright == -1) || (_iright > _bright)) _bright = _iright; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java index e2d0d2bd5..e43cd51f4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java @@ -43,7 +43,6 @@ import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.io.BufferedInputStream; import java.text.AttributedCharacterIterator; -import java.util.Iterator; import java.util.Stack; import java.util.List; import java.util.ArrayList; @@ -66,7 +65,7 @@ public class WMFPainter extends AbstractWMFPainter { */ private static final int INPUT_BUFFER_SIZE = 30720; - private static final Integer INTEGER_0 = new Integer( 0 ); + private static final Integer INTEGER_0 = 0; private float scale, scaleX, scaleY, conv; private float xOffset, yOffset; @@ -114,12 +113,12 @@ public class WMFPainter extends AbstractWMFPainter { this.conv = scale; this.xOffset = -xOffset; this.yOffset = -yOffset; - this.scale = (float)currentStore.getWidthPixels() / (float)currentStore.getWidthUnits() * scale; - this.scale = this.scale * (float)currentStore.getWidthPixels() / (float)currentStore.getVpW() ; - float xfactor = (float)currentStore.getVpW() / (float)currentStore.getWidthPixels() - * (float)currentStore.getWidthUnits() / (float)currentStore.getWidthPixels(); - float yfactor = (float)currentStore.getVpH() / (float)currentStore.getHeightPixels() - * (float)currentStore.getHeightUnits() / (float)currentStore.getHeightPixels(); + this.scale = (float)currentStore.getWidthPixels() / currentStore.getWidthUnits() * scale; + this.scale = this.scale * currentStore.getWidthPixels() / currentStore.getVpW(); + float xfactor = (float)currentStore.getVpW() / currentStore.getWidthPixels() + * currentStore.getWidthUnits() / currentStore.getWidthPixels(); + float yfactor = (float)currentStore.getVpH() / currentStore.getHeightPixels() + * currentStore.getHeightUnits() / currentStore.getHeightPixels(); this.xOffset = this.xOffset * xfactor; this.yOffset = this.yOffset * yfactor; scaleX = this.scale; @@ -180,16 +179,16 @@ public class WMFPainter extends AbstractWMFPainter { switch ( mr.functionId ) { case WMFConstants.META_SETWINDOWORG: - currentStore.setVpX( vpX = -(float)mr.elementAt( 0 ) ); - currentStore.setVpY( vpY = -(float)mr.elementAt( 1 ) ); + currentStore.setVpX( vpX = -mr.elementAt( 0 )); + currentStore.setVpY( vpY = -mr.elementAt( 1 )); vpX = vpX * scale; vpY = vpY * scale; break; case WMFConstants.META_SETWINDOWORG_EX: // ???? LOOKS SUSPICIOUS case WMFConstants.META_SETWINDOWEXT: - vpW = (float)mr.elementAt( 0 ); - vpH = (float)mr.elementAt( 1 ); + vpW = mr.elementAt( 0 ); + vpH = mr.elementAt( 1 ); scaleX = scale; @@ -513,10 +512,10 @@ public class WMFPainter extends AbstractWMFPainter { float x1, y1, x2, y2, x3, y3; x1 = scaleX * ( vpX + xOffset + mr.elementAt( 0 ) ); x2 = scaleX * ( vpX + xOffset + mr.elementAt( 2 ) ); - x3 = scaleX * (float)(mr.elementAt( 4 ) ); + x3 = scaleX * (mr.elementAt( 4 ) ); y1 = scaleY * ( vpY + yOffset + mr.elementAt( 1 ) ); y2 = scaleY * ( vpY + yOffset + mr.elementAt( 3 ) ); - y3 = scaleY * (float)(mr.elementAt( 5 ) ); + y3 = scaleY * (mr.elementAt( 5 ) ); RoundRectangle2D rec = new RoundRectangle2D.Float(x1, y1, x2-x1, y2-y1, x3, y3); @@ -695,12 +694,12 @@ public class WMFPainter extends AbstractWMFPainter { break; case WMFConstants.META_SAVEDC: - dcStack.push( new Float( penWidth )); - dcStack.push( new Float( startX )); - dcStack.push( new Float( startY )); - dcStack.push( new Integer( brushObject )); - dcStack.push( new Integer( penObject )); - dcStack.push( new Integer( fontObject )); + dcStack.push(penWidth); + dcStack.push(startX); + dcStack.push(startY); + dcStack.push(brushObject); + dcStack.push(penObject); + dcStack.push(fontObject); dcStack.push( frgdColor ); dcStack.push( bkgdColor ); break; @@ -708,12 +707,12 @@ public class WMFPainter extends AbstractWMFPainter { case WMFConstants.META_RESTOREDC: bkgdColor = (Color)dcStack.pop(); frgdColor = (Color)dcStack.pop(); - fontObject = ((Integer)(dcStack.pop())).intValue(); - penObject = ((Integer)(dcStack.pop())).intValue(); - brushObject = ((Integer)(dcStack.pop())).intValue(); - startY = ((Float)(dcStack.pop())).floatValue(); - startX = ((Float)(dcStack.pop())).floatValue(); - penWidth = ((Float)(dcStack.pop())).floatValue(); + fontObject = (Integer) (dcStack.pop()); + penObject = (Integer) (dcStack.pop()); + brushObject = (Integer) (dcStack.pop()); + startY = (Float) (dcStack.pop()); + startX = (Float) (dcStack.pop()); + penWidth = (Float) (dcStack.pop()); break; case WMFConstants.META_POLYBEZIER16: @@ -777,7 +776,7 @@ public class WMFPainter extends AbstractWMFPainter { //UPDATED : added SETROP2 case WMFConstants.META_SETROP2: { - float rop = (float)(mr.ElementAt( 0 ).intValue()); + float rop = (float)(mr.ElementAt(0)); Paint paint = null; boolean ok = false; if (rop == WMFConstants.META_BLACKNESS) { @@ -804,9 +803,9 @@ public class WMFPainter extends AbstractWMFPainter { break; case WMFConstants.META_PATBLT: { - float rop = (float)(mr.elementAt( 0 ) ); - float height = scaleY * (float)(mr.elementAt( 1 ) ); - float width = scaleX * (float)(mr.elementAt( 2 ) ); + float rop = (mr.elementAt( 0 ) ); + float height = scaleY * (mr.elementAt( 1 ) ); + float width = scaleX * (mr.elementAt( 2 ) ); float left = scaleX * (vpX + xOffset + mr.elementAt( 3 ) ); float top = scaleY * (vpY + yOffset + mr.elementAt( 4 ) ); @@ -850,8 +849,8 @@ public class WMFPainter extends AbstractWMFPainter { int sx = mr.elementAt( 4 ); float dy = conv * currentStore.getVpWFactor() * (vpY + yOffset + mr.elementAt( 7 ) ); float dx = conv * currentStore.getVpHFactor() * (vpX + xOffset + mr.elementAt( 8 ) ); - float heightDst = (float)(mr.elementAt( 5 ) ); - float widthDst = (float)(mr.elementAt( 6 ) ); + float heightDst = (mr.elementAt( 5 ) ); + float widthDst = (mr.elementAt( 6 ) ); widthDst = widthDst * conv * currentStore.getVpWFactor(); heightDst = heightDst * conv * currentStore.getVpHFactor(); byte[] bitmap = ((MetaRecord.ByteRecord)mr).bstr; @@ -870,11 +869,11 @@ public class WMFPainter extends AbstractWMFPainter { int sy = mr.elementAt( 3 ); int sx = mr.elementAt( 4 ); float dy = conv * currentStore.getVpWFactor() * - (vpY + yOffset + (float)mr.elementAt( 7 )); + (vpY + yOffset + mr.elementAt( 7 )); float dx = conv * currentStore.getVpHFactor() * - (vpX + xOffset + (float)mr.elementAt( 8 )); - float heightDst = (float)(mr.elementAt( 5 )); - float widthDst = (float)(mr.elementAt( 6 )); + (vpX + xOffset + mr.elementAt( 8 )); + float heightDst = (mr.elementAt( 5 )); + float widthDst = (mr.elementAt( 6 )); widthDst = widthDst * conv * currentStore.getVpWFactor(); heightDst = heightDst * conv * currentStore.getVpHFactor(); byte[] bitmap = ((MetaRecord.ByteRecord)mr).bstr; @@ -896,19 +895,19 @@ public class WMFPainter extends AbstractWMFPainter { break; case WMFConstants.META_DIBBITBLT: { - int rop = mr.ElementAt( 0 ).intValue(); - float height = (mr.ElementAt( 1 ).intValue() * + int rop = mr.ElementAt(0); + float height = (mr.ElementAt(1) * conv * currentStore.getVpWFactor()); - float width = (mr.ElementAt( 2 ).intValue() * + float width = (mr.ElementAt(2) * conv * currentStore.getVpHFactor()); - int sy = mr.ElementAt( 3 ).intValue(); - int sx = mr.ElementAt( 4 ).intValue(); + int sy = mr.ElementAt(3); + int sx = mr.ElementAt(4); float dy = (conv * currentStore.getVpWFactor() * (vpY + yOffset + - (float)mr.ElementAt( 5 ).intValue())); + (float) mr.ElementAt(5))); float dx = (conv * currentStore.getVpHFactor() * (vpX + xOffset + - (float)mr.ElementAt( 6 ).intValue())); + (float) mr.ElementAt(6))); if (mr instanceof MetaRecord.ByteRecord) { byte[] bitmap = ((MetaRecord.ByteRecord)mr).bstr; @@ -978,7 +977,7 @@ public class WMFPainter extends AbstractWMFPainter { private Paint getPaint(byte[] bit) { Dimension d = getImageDimension(bit); BufferedImage img = getImage(bit); - Rectangle2D rec = new Rectangle2D.Float(0, 0, (float)d.width, (float)d.height); + Rectangle2D rec = new Rectangle2D.Float(0, 0, d.width, d.height); TexturePaint paint = new TexturePaint(img, rec); return paint; } @@ -1065,9 +1064,8 @@ public class WMFPainter extends AbstractWMFPainter { /** Just to be consistent with PolyPolygon filling. */ private void drawPolyPolygon(Graphics2D g2d, List pols) { - Iterator it = pols.iterator(); - while (it.hasNext()) { - Polygon2D pol = (Polygon2D)(it.next()); + for (Object pol1 : pols) { + Polygon2D pol = (Polygon2D) (pol1); g2d.draw(pol); } } @@ -1081,8 +1079,8 @@ public class WMFPainter extends AbstractWMFPainter { g2d.fill((Polygon2D)(pols.get(0))); } else { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); - for (int i = 0; i < pols.size(); i++) { - Polygon2D pol = (Polygon2D)(pols.get(i)); + for (Object pol1 : pols) { + Polygon2D pol = (Polygon2D) pol1; path.append(pol, false); } g2d.fill(path); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFRecordStore.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFRecordStore.java index 141d62fec..0671ae71c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFRecordStore.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFRecordStore.java @@ -300,8 +300,8 @@ public class WMFRecordStore extends AbstractWMFReader { mr.addElement( xnum ); mr.addElement( ynum ); records.add( mr ); - scaleX = scaleX * (float)xdenom / (float)xnum; - scaleY = scaleY * (float)ydenom / (float)ynum; + scaleX = scaleX * xdenom / xnum; + scaleY = scaleY * ydenom / ynum; } break; @@ -641,7 +641,7 @@ public class WMFRecordStore extends AbstractWMFReader { int dx = (int)(readShort( is ) * xSign * scaleXY); int len = 2*recSize - 22; - byte bitmap[] = new byte[len]; + byte[] bitmap = new byte[len]; for (int i = 0; i < len; i++) bitmap[i] = is.readByte(); mr = new MetaRecord.ByteRecord(bitmap); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java index 03c15d787..c2945624c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.transcoder.wmf.tosvg; @@ -70,22 +70,16 @@ import org.w3c.dom.Element; * } *
    *

    Several transcoding hints are available for this transcoder :

    - *
      - *
    • KEY_INPUT_WIDTH, KEY_INPUT_HEIGHT, KEY_XOFFSET, KEY_YOFFSET : this Integer values allows to + * KEY_INPUT_WIDTH, KEY_INPUT_HEIGHT, KEY_XOFFSET, KEY_YOFFSET : this Integer values allows to * set the portion of the image to transcode, defined by the width, height, and offset * of this portion in Metafile units. - *
    *
    - *     transcoder.addTranscodingHint(FromWMFTranscoder.KEY_INPUT_WIDTH, new Integer(input_width));
    + *     transcoder.addTranscodingHint(FromWMFTranscoder.KEY_INPUT_WIDTH, Integer.valueOf(input_width));
      *  
    - * - *
  • KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output: - * + * KEY_WIDTH, KEY_HEIGHT : this Float values allows to force the width and height of the output: *
    - *     transcoder.addTranscodingHint(FromWMFTranscoder.KEY_WIDTH, new Float(width));
    + *     transcoder.addTranscodingHint(FromWMFTranscoder.KEY_WIDTH, Float.valueOf(width));
      *  
    - *
  • - * * * @version $Id$ */ @@ -127,8 +121,8 @@ public class WMFTranscoder extends ToSVGAbstractTranscoder { float conv = 1.0f; // conversion factor if (hints.containsKey(KEY_INPUT_WIDTH)) { - wmfwidth = ((Integer)hints.get(KEY_INPUT_WIDTH)).intValue(); - wmfheight = ((Integer)hints.get(KEY_INPUT_HEIGHT)).intValue(); + wmfwidth = (Integer) hints.get(KEY_INPUT_WIDTH); + wmfheight = (Integer) hints.get(KEY_INPUT_HEIGHT); } else { wmfwidth = currentStore.getWidthPixels(); wmfheight = currentStore.getHeightPixels(); @@ -138,7 +132,7 @@ public class WMFTranscoder extends ToSVGAbstractTranscoder { // change the output width and height if required if (hints.containsKey(KEY_WIDTH)) { - width = ((Float)hints.get(KEY_WIDTH)).floatValue(); + width = (Float) hints.get(KEY_WIDTH); conv = width / wmfwidth; height = height * width / wmfwidth; } @@ -147,10 +141,10 @@ public class WMFTranscoder extends ToSVGAbstractTranscoder { int xOffset = 0; int yOffset = 0; if (hints.containsKey(KEY_XOFFSET)) { - xOffset = ((Integer)hints.get(KEY_XOFFSET)).intValue(); + xOffset = (Integer) hints.get(KEY_XOFFSET); } if (hints.containsKey(KEY_YOFFSET)) { - yOffset = ((Integer)hints.get(KEY_YOFFSET)).intValue(); + yOffset = (Integer) hints.get(KEY_YOFFSET); } // Set the size and viewBox on the output document @@ -163,8 +157,8 @@ public class WMFTranscoder extends ToSVGAbstractTranscoder { int vpH; // if we took only a part of the image, we use its dimension for computing if (hints.containsKey(KEY_INPUT_WIDTH)) { - vpW = (int)(((Integer)hints.get(KEY_INPUT_WIDTH)).intValue() * conv); - vpH = (int)(((Integer)hints.get(KEY_INPUT_HEIGHT)).intValue() * conv); + vpW = (int)((Integer) hints.get(KEY_INPUT_WIDTH) * conv); + vpH = (int)((Integer) hints.get(KEY_INPUT_HEIGHT) * conv); // else we took the whole image dimension } else { vpW = (int)(currentStore.getWidthUnits() * sizeFactor); @@ -248,13 +242,11 @@ public class WMFTranscoder extends ToSVGAbstractTranscoder { WMFTranscoder transcoder = new WMFTranscoder(); int nFiles = args.length; - for(int i=0; i + *
    * It is used by the Squiggle browser as well as the rasterizer. - *
    + *
    * This class can install a SecurityManager for an application * and resolves whether the application runs in a development * environment or from a jar file (in other words, it resolves code-base * issues for the application). - *
    + *
    * - * @author Vincent Hardy + * @author Vincent Hardy * @version $Id$ */ public class ApplicationSecurityEnforcer { @@ -236,7 +236,7 @@ public class ApplicationSecurityEnforcer { if (mainClassURL == null){ // Something is really wrong: we would be running a class // which can't be found.... - throw new Error(appMainClassRelativeURL); + throw new RuntimeException(appMainClassRelativeURL); } String expandedMainClassName = mainClassURL.toString(); @@ -274,7 +274,7 @@ public class ApplicationSecurityEnforcer { // Something is seriously wrong. This should *never* happen // as the APP_SECURITY_POLICY_URL is such that it will be // a substring of its corresponding URL value - throw new Error(); + throw new RuntimeException(); } String appCodeBase = expandedMainClassName.substring(0, codeBaseEnd); @@ -312,7 +312,7 @@ public class ApplicationSecurityEnforcer { // Something is seriously wrong. This should *never* happen // as the APP_SECURITY_POLICY_URL is such that it will be // a substring of its corresponding URL value - throw new Error(); + throw new RuntimeException(); } String appCodeBase = expandedMainClassName.substring(0, codeBaseEnd); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Base64DecodeStream.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Base64DecodeStream.java index 2d310a340..5f4945af9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Base64DecodeStream.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Base64DecodeStream.java @@ -102,7 +102,7 @@ public class Base64DecodeStream extends InputStream { } } - return ((int)out_buffer[out_offset++])&0xFF; + return out_buffer[out_offset++] &0xFF; } public int read(byte []out, int offset, int len) @@ -146,10 +146,10 @@ public class Base64DecodeStream extends InputStream { off = out; } - a = pem_array[((int)decode_buffer[0])&0xFF]; - b = pem_array[((int)decode_buffer[1])&0xFF]; - c = pem_array[((int)decode_buffer[2])&0xFF]; - d = pem_array[((int)decode_buffer[3])&0xFF]; + a = pem_array[decode_buffer[0] &0xFF]; + b = pem_array[decode_buffer[1] &0xFF]; + c = pem_array[decode_buffer[2] &0xFF]; + d = pem_array[decode_buffer[3] &0xFF]; out_buffer[0] = (byte)((a<<2) | (b>>>4)); out_buffer[1] = (byte)((b<<4) | (c>>>2)); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/BatikSecurityManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/BatikSecurityManager.java index 426a47326..fe9273a75 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/BatikSecurityManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/BatikSecurityManager.java @@ -23,7 +23,7 @@ package org.apache.batik.util; * method so that it can be used by the BatikSecuritySupport or other * security related class. * - * @author Vincent Hardy + * @author Vincent Hardy * @version $Id$ */ public class BatikSecurityManager extends SecurityManager { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ClassFileUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ClassFileUtilities.java index 6953f324e..a7331757b 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ClassFileUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ClassFileUtilities.java @@ -90,9 +90,9 @@ public class ClassFileUtilities { File cwd = new File("."); File buildDir = null; String[] cwdFiles = cwd.list(); - for (int i = 0; i < cwdFiles.length; i++) { - if (cwdFiles[i].startsWith("batik-")) { - buildDir = new File(cwdFiles[i]); + for (String cwdFile : cwdFiles) { + if (cwdFile.startsWith("batik-")) { + buildDir = new File(cwdFile); if (!buildDir.isDirectory()) { buildDir = null; } else { @@ -122,9 +122,8 @@ public class ClassFileUtilities { // System.out.println(fromFile.name); Set result = getClassDependencies(fromFile.getInputStream(), classpath, false); - Iterator j = result.iterator(); - while (j.hasNext()) { - ClassFile toFile = (ClassFile) cs.get(j.next()); + for (Object aResult : result) { + ClassFile toFile = (ClassFile) cs.get(aResult); if (fromFile != toFile && toFile != null) { fromFile.deps.add(toFile); } @@ -134,9 +133,8 @@ public class ClassFileUtilities { i = cs.values().iterator(); while (i.hasNext()) { ClassFile fromFile = (ClassFile) i.next(); - Iterator j = fromFile.deps.iterator(); - while (j.hasNext()) { - ClassFile toFile = (ClassFile) j.next(); + for (Object dep : fromFile.deps) { + ClassFile toFile = (ClassFile) dep; Jar fromJar = fromFile.jar; Jar toJar = toFile.jar; if (fromFile.name.equals(toFile.name) @@ -146,9 +144,9 @@ public class ClassFileUtilities { } Integer n = (Integer) fromJar.deps.get(toJar); if (n == null) { - fromJar.deps.put(toJar, new Integer(1)); + fromJar.deps.put(toJar, 1); } else { - fromJar.deps.put(toJar, new Integer(n.intValue() + 1)); + fromJar.deps.put(toJar, n + 1); } } } @@ -157,13 +155,12 @@ public class ClassFileUtilities { i = js.values().iterator(); while (i.hasNext()) { Jar fromJar = (Jar) i.next(); - Iterator j = fromJar.deps.keySet().iterator(); - while (j.hasNext()) { - Jar toJar = (Jar) j.next(); + for (Object o : fromJar.deps.keySet()) { + Jar toJar = (Jar) o; Triple t = new Triple(); t.from = fromJar; t.to = toJar; - t.count = ((Integer) fromJar.deps.get(toJar)).intValue(); + t.count = (Integer) fromJar.deps.get(toJar); triples.add(t); } } @@ -175,17 +172,15 @@ public class ClassFileUtilities { System.out.println (t.count + "," + t.from.name + "," + t.to.name); if (showFiles) { - Iterator j = t.from.files.iterator(); - while (j.hasNext()) { - ClassFile fromFile = (ClassFile) j.next(); - Iterator k = fromFile.deps.iterator(); - while (k.hasNext()) { - ClassFile toFile = (ClassFile) k.next(); + for (Object file : t.from.files) { + ClassFile fromFile = (ClassFile) file; + for (Object dep : fromFile.deps) { + ClassFile toFile = (ClassFile) dep; if (toFile.jar == t.to && !t.from.files.contains(toFile.name)) { System.out.println - ("\t" + fromFile.name + " --> " - + toFile.name); + ("\t" + fromFile.name + " --> " + + toFile.name); } } } @@ -224,13 +219,13 @@ public class ClassFileUtilities { private static void collectJars(File dir, Map jars, Map classFiles) throws IOException { File[] files = dir.listFiles(); - for (int i = 0; i < files.length; i++) { - String n = files[i].getName(); - if (n.endsWith(".jar") && files[i].isFile()) { + for (File file : files) { + String n = file.getName(); + if (n.endsWith(".jar") && file.isFile()) { Jar j = new Jar(); - j.name = files[i].getPath(); - j.file = files[i]; - j.jarFile = new JarFile(files[i]); + j.name = file.getPath(); + j.file = file; + j.jarFile = new JarFile(file); jars.put(j.name, j); Enumeration entries = j.jarFile.entries(); @@ -245,8 +240,8 @@ public class ClassFileUtilities { j.files.add(cf); } } - } else if (files[i].isDirectory()) { - collectJars(files[i], jars, classFiles); + } else if (file.isDirectory()) { + collectJars(file, jars, classFiles); } } } @@ -286,17 +281,15 @@ public class ClassFileUtilities { boolean rec) throws IOException { - Iterator it = getClassDependencies(is).iterator(); - while (it.hasNext()) { - String s = (String)it.next(); + for (Object o : getClassDependencies(is)) { + String s = (String) o; if (!done.contains(s)) { done.add(s); - Iterator cpit = classpath.iterator(); - while (cpit.hasNext()) { + for (Object aClasspath : classpath) { InputStream depis = null; String path = null; - Object cpEntry = cpit.next(); + Object cpEntry = aClasspath; if (cpEntry instanceof JarFile) { JarFile jarFile = (JarFile) cpEntry; String classFileName = s + ".class"; @@ -318,7 +311,7 @@ public class ClassFileUtilities { if (rec) { computeClassDependencies - (depis, classpath, done, result, rec); + (depis, classpath, done, result, rec); } } } @@ -362,7 +355,7 @@ public class ClassFileUtilities { break; case CONSTANT_CLASS_INFO: - classes.add(new Integer(dis.readShort() & 0xffff)); + classes.add(dis.readShort() & 0xffff); break; case CONSTANT_STRING_INFO: @@ -371,7 +364,7 @@ public class ClassFileUtilities { case CONSTANT_NAMEANDTYPE_INFO: dis.readShort(); - desc.add(new Integer(dis.readShort() & 0xffff)); + desc.add(dis.readShort() & 0xffff); break; case CONSTANT_UTF8_INFO: @@ -387,12 +380,12 @@ public class ClassFileUtilities { Iterator it = classes.iterator(); while (it.hasNext()) { - result.add(strs[((Integer)it.next()).intValue()]); + result.add(strs[((Integer) it.next())]); } it = desc.iterator(); while (it.hasNext()) { - result.addAll(getDescriptorClasses(strs[((Integer)it.next()).intValue()])); + result.addAll(getDescriptorClasses(strs[((Integer) it.next())])); } return result; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/CleanerThread.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/CleanerThread.java index 33df77200..219989365 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/CleanerThread.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/CleanerThread.java @@ -53,7 +53,7 @@ public class CleanerThread extends Thread { * this class implement this interface then the 'cleared' method * will be called when the reference is queued. */ - public static interface ReferenceCleared { + public interface ReferenceCleared { /* Called when the reference is cleared */ void cleared(); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/DoublyIndexedTable.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/DoublyIndexedTable.java index 65e31df31..d17240e08 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/DoublyIndexedTable.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/DoublyIndexedTable.java @@ -168,8 +168,8 @@ public class DoublyIndexedTable { Object[] values = new Object[count]; int i = 0; - for (int index = 0; index < table.length; index++) { - for (Entry e = table[index]; e != null; e = e.next) { + for (Entry aTable : table) { + for (Entry e = aTable; e != null; e = e.next) { values[i++] = e.value; } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/HaltingThread.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/HaltingThread.java index 50c3323fb..eeb84e432 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/HaltingThread.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/HaltingThread.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURL.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURL.java index d2065d8ca..c74907be8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURL.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURL.java @@ -424,8 +424,7 @@ public class ParsedURL { */ public InputStream openStream(String [] mimeTypes) throws IOException { List mt = new ArrayList(mimeTypes.length); - for (int i=0; i>>4) <= 7)) { // Check for a zlib (deflate) stream - int chk = ((((int)data[0])&0xFF)*256+ - (((int)data[1])&0xFF)); + int chk = ((data[0] &0xFF)*256+ + (data[1] &0xFF)); if ((chk %31) == 0) { try { // I'm not really as certain of this check @@ -556,7 +556,11 @@ loop2: while (i < len) { if (urlC instanceof HttpURLConnection) { // bug 49889: if available, return the error stream // (allow interpretation of content in the HTTP error response) - return (stream = ((HttpURLConnection) urlC).getErrorStream()); + stream = ((HttpURLConnection) urlC).getErrorStream(); + if (stream == null) { + throw e; + } + return stream; } else { throw e; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURLJarProtocolHandler.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURLJarProtocolHandler.java index dd9714b5c..869ed100c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURLJarProtocolHandler.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/ParsedURLJarProtocolHandler.java @@ -24,7 +24,7 @@ import java.net.URL; /** * Protocol Handler for the 'jar' protocol. * This appears to have the format: - * jar:! + * jar:<URL for jar file>!<path in jar file> * * @author Thomas DeWeese * @version $Id$ diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/PreferenceManager.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/PreferenceManager.java index d34057e3b..cc7fe838a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/PreferenceManager.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/PreferenceManager.java @@ -591,7 +591,7 @@ public class PreferenceManager { int defaultValue = 0; if (getDefault(key) != null) - defaultValue = ((Integer)getDefault(key)).intValue(); + defaultValue = (Integer) getDefault(key); String sp = internal.getProperty(key); if (sp == null) { return defaultValue; @@ -613,7 +613,7 @@ public class PreferenceManager { float defaultValue = 0; if (getDefault(key) != null) - defaultValue = ((Float)getDefault(key)).floatValue(); + defaultValue = (Float) getDefault(key); String sp = internal.getProperty(key); if (sp == null) { return defaultValue; @@ -637,7 +637,7 @@ public class PreferenceManager return internal.getProperty(key).equals("true"); else if (getDefault(key) != null) - return ((Boolean)getDefault(key)).booleanValue(); + return (Boolean) getDefault(key); else return false; } @@ -720,9 +720,9 @@ public class PreferenceManager { int j = 0; if (values != null) - for (int i = 0; i < values.length; i++) { - if (values[i] != null) { - setString(mkey+j, values[i]); + for (String value : values) { + if (value != null) { + setString(mkey + j, value); j++; } } @@ -756,9 +756,9 @@ public class PreferenceManager { int j = 0; if (values != null) - for (int i = 0 ; i < values.length; i++) { - if (values[i] != null) { - setURL(mkey+j, values[i]); + for (URL value : values) { + if (value != null) { + setURL(mkey + j, value); j++; } } @@ -792,9 +792,9 @@ public class PreferenceManager { int j = 0; if (values != null) - for (int i = 0 ; i < values.length; i++) { - if (values[i] != null) { - setFile(mkey+j, values[i]); + for (File value : values) { + if (value != null) { + setFile(mkey + j, value); j++; } } @@ -815,7 +815,7 @@ public class PreferenceManager public void setInteger(String key, int value) { if (getDefault(key) != null && - ((Integer)getDefault(key)).intValue() != value) + (Integer) getDefault(key) != value) internal.setProperty(key, Integer.toString(value)); else internal.remove(key); @@ -827,7 +827,7 @@ public class PreferenceManager public void setFloat(String key, float value) { if (getDefault(key) != null && - ((Float)getDefault(key)).floatValue() != value) + (Float) getDefault(key) != value) internal.setProperty(key, Float.toString(value)); else internal.remove(key); @@ -839,7 +839,7 @@ public class PreferenceManager public void setBoolean(String key, boolean value) { if (getDefault(key) != null && - ((Boolean)getDefault(key)).booleanValue() != value) { + (Boolean) getDefault(key) != value) { internal.setProperty(key, value?"true":"false"); } else { internal.remove(key); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVG12CSSConstants.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVG12CSSConstants.java index b37940c6e..19b57d4e5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVG12CSSConstants.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVG12CSSConstants.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVGConstants.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVGConstants.java index d28c9df89..18bb1dce1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVGConstants.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/SVGConstants.java @@ -18,6 +18,8 @@ */ package org.apache.batik.util; +import org.apache.batik.constants.XMLConstants; + /** * Define SVG constants, such as tag names, attribute names and URI * diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Service.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Service.java index 14ea4d395..068610578 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Service.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/Service.java @@ -34,7 +34,7 @@ import java.util.List; * This class handles looking up service providers on the class path. * It implements the system described in: * - * JAR + * JAR * File Specification Under Service Provider. Note that this * interface is very similar to the one they describe which seems to * be missing in the JDK. @@ -120,7 +120,7 @@ public class Service { // System.out.println("Line: " + line); // Try and load the class - Object obj = cl.loadClass(line).newInstance(); + Object obj = cl.loadClass(line).getDeclaredConstructor().newInstance(); // stick it into our vector... l.add(obj); } catch (Exception ex) { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLResourceDescriptor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLResourceDescriptor.java index 4300620e0..ad7c5a727 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLResourceDescriptor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/XMLResourceDescriptor.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/CSSMediaPanel.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/CSSMediaPanel.java index c9f075659..ad8752f02 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/CSSMediaPanel.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/CSSMediaPanel.java @@ -28,7 +28,6 @@ import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -182,9 +181,8 @@ public class CSSMediaPanel extends JPanel implements ActionMap { */ public void setMedia(List mediaList) { listModel.removeAllElements(); - Iterator iter = mediaList.iterator(); - while (iter.hasNext()) { - listModel.addElement(iter.next()); + for (Object aMediaList : mediaList) { + listModel.addElement(aMediaList); } } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/DropDownComponent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/DropDownComponent.java index e74906474..80692816d 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/DropDownComponent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/DropDownComponent.java @@ -136,7 +136,7 @@ public class DropDownComponent extends JPanel { new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { setEnabled - (((Boolean) evt.getNewValue()).booleanValue()); + ((Boolean) evt.getNewValue()); } }); @@ -246,7 +246,7 @@ public class DropDownComponent extends JPanel { /** * The scrollable pop up menu item. */ - public static interface ScrollablePopupMenuItem { + public interface ScrollablePopupMenuItem { /** * Selects and deselects the item. @@ -401,7 +401,7 @@ public class DropDownComponent extends JPanel { /** * The scrollable popup menu model. */ - public static interface ScrollablePopupMenuModel { + public interface ScrollablePopupMenuModel { /** * Gets the footer text for the ScrollablePopupMenu's footer item. @@ -579,8 +579,8 @@ public class DropDownComponent extends JPanel { private int getPreferredWidth() { Component[] components = menuPanel.getComponents(); int maxWidth = 0; - for (int i = 0; i < components.length; i++) { - int currentWidth = components[i].getPreferredSize().width; + for (Component component : components) { + int currentWidth = component.getPreferredSize().width; if (maxWidth < currentWidth) { maxWidth = currentWidth; } @@ -627,8 +627,8 @@ public class DropDownComponent extends JPanel { item.setSelected(wasSelected); } } else { - for (int i = 0; i < n; i++) { - ScrollablePopupMenuItem item = (ScrollablePopupMenuItem) comps[i]; + for (Component comp : comps) { + ScrollablePopupMenuItem item = (ScrollablePopupMenuItem) comp; if (item == targetItem) { break; } @@ -667,8 +667,8 @@ public class DropDownComponent extends JPanel { public int getSelectedItemsCount() { int selectionCount = 0; Component[] components = menuPanel.getComponents(); - for (int i = 0; i < components.length; i++) { - ScrollablePopupMenuItem item = (ScrollablePopupMenuItem) components[i]; + for (Component component : components) { + ScrollablePopupMenuItem item = (ScrollablePopupMenuItem) component; if (item.isSelected()) { selectionCount++; } @@ -842,7 +842,7 @@ public class DropDownComponent extends JPanel { * The ScrollablePopupMenu listener. Handles the events that * ScrollablePopupMenu fires */ - public static interface ScrollablePopupMenuListener extends EventListener { + public interface ScrollablePopupMenuListener extends EventListener { /** * Handles the 'itemsWereAdded' event. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/JErrorPane.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/JErrorPane.java index 20513259c..b57c3a9b5 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/JErrorPane.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/JErrorPane.java @@ -44,7 +44,6 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.JTextArea; -import javax.swing.SwingUtilities; import org.apache.batik.util.gui.resource.ActionMap; import org.apache.batik.util.gui.resource.ButtonFactory; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/MemoryMonitor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/MemoryMonitor.java index 936b19cb9..b5cc2a731 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/MemoryMonitor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/MemoryMonitor.java @@ -168,7 +168,7 @@ public class MemoryMonitor extends JFrame implements ActionMap { /** * The action associated with the 'Collect' button of the memory monitor. */ - protected class CollectButtonAction extends AbstractAction { + protected static class CollectButtonAction extends AbstractAction { public void actionPerformed(ActionEvent e) { System.gc(); } @@ -571,7 +571,7 @@ public class MemoryMonitor extends JFrame implements ActionMap { freeMemory = free; // Add a new point to the data - data.add(new Long(totalMemory - freeMemory)); + data.add(totalMemory - freeMemory); if (data.size() > 190) { data.remove(0); xShift = (xShift + 1) % 10; @@ -580,11 +580,11 @@ public class MemoryMonitor extends JFrame implements ActionMap { // Create the path that match the data Iterator it = data.iterator(); GeneralPath p = new GeneralPath(); - long l = ((Long)it.next()).longValue(); + long l = (Long) it.next(); p.moveTo(5, ((float)(totalMemory - l) / totalMemory) * 80 + 10); int i = 6; while (it.hasNext()) { - l = ((Long)it.next()).longValue(); + l = (Long) it.next(); p.lineTo(i, ((float)(totalMemory - l) / totalMemory) * 80 + 10); i++; } @@ -723,10 +723,9 @@ public class MemoryMonitor extends JFrame implements ActionMap { public void run() { long free = runtime.freeMemory(); long total = runtime.totalMemory(); - Iterator it = components.iterator(); - while (it.hasNext()) { - Component c = (Component)it.next(); - ((MemoryChangeListener)c).memoryStateChanged(total, free); + for (Object component : components) { + Component c = (Component) component; + ((MemoryChangeListener) c).memoryStateChanged(total, free); c.repaint(); } synchronized (this) { inEventQueue = false; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/UserStyleDialog.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/UserStyleDialog.java index 868b61898..c6b176e38 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/UserStyleDialog.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/UserStyleDialog.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util.gui; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/MenuFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/MenuFactory.java index 7f855d87c..06718a449 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/MenuFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/MenuFactory.java @@ -19,7 +19,6 @@ package org.apache.batik.util.gui.resource; import java.net.URL; -import java.util.Iterator; import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -146,10 +145,9 @@ public class MenuFactory extends ResourceManager { MissingListenerException { JMenuBar result = new JMenuBar(); List menus = getSpecializedStringList(name, specialization); - Iterator it = menus.iterator(); - while (it.hasNext()) { - result.add(createJMenuComponent((String)it.next(), specialization)); + for (Object menu : menus) { + result.add(createJMenuComponent((String) menu, specialization)); } return result; } @@ -295,10 +293,9 @@ public class MenuFactory extends ResourceManager { initializeJMenuItem(result, name, specialization); List items = getSpecializedStringList(name, specialization); - Iterator it = items.iterator(); - while (it.hasNext()) { - result.add(createJMenuComponent((String)it.next(), specialization)); + for (Object item : items) { + result.add(createJMenuComponent((String) item, specialization)); } return result; } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/ToolBarFactory.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/ToolBarFactory.java index ba4be17ad..4473912d3 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/ToolBarFactory.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/resource/ToolBarFactory.java @@ -15,11 +15,10 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util.gui.resource; -import java.util.Iterator; import java.util.List; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -83,10 +82,9 @@ public class ToolBarFactory extends ResourceManager { MissingListenerException { JToolBar result = new JToolBar(); List buttons = getStringList(name); - Iterator it = buttons.iterator(); - while (it.hasNext()) { - String s = (String)it.next(); + for (Object button : buttons) { + String s = (String) button; if (s.equals(SEPARATOR)) { result.add(new JToolbarSeparator()); } else { diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLContext.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLContext.java index 39bc5b1c0..d95b9b0c8 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLContext.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLContext.java @@ -43,10 +43,10 @@ public class XMLContext extends StyleContext { public static final String ATTRIBUTE_VALUE_STYLE = "attribute_value"; public static final String CDATA_STYLE = "cdata"; - /** Map */ + //Map protected Map syntaxForegroundMap = null; - /** Map */ + //Map protected Map syntaxFontMap = null; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLScanner.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLScanner.java index 9477b34b3..af199d85c 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLScanner.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLScanner.java @@ -65,7 +65,7 @@ public class XMLScanner { protected int nextChar() { try { - current = (int)string.charAt(position); + current = string.charAt(position); position++; } catch (Exception ex) { current = -1; @@ -198,7 +198,7 @@ public class XMLScanner { end = false; } else if (current == ']') { end = true; - } else if (current == '>' && end == true) { + } else if (current == '>' && end) { return CHARACTER_DATA_CONTEXT; } nextChar(); diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLTextEditor.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLTextEditor.java index 07c0708b7..eec7b5c56 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLTextEditor.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/gui/xmleditor/XMLTextEditor.java @@ -19,7 +19,6 @@ package org.apache.batik.util.gui.xmleditor; import java.awt.Color; -import java.awt.Font; import javax.swing.JEditorPane; import javax.swing.event.UndoableEditEvent; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/io/UTF8Decoder.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/io/UTF8Decoder.java index 22f410595..65dec62b4 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/io/UTF8Decoder.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/io/UTF8Decoder.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util.io; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/resources/Messages.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/resources/Messages.java index d5e3e9ce6..447fd83f6 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/resources/Messages.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/util/resources/Messages.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.util.resources; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/CustomEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/CustomEvent.java index 2814edc46..cfe5981dd 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/CustomEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/CustomEvent.java @@ -32,7 +32,7 @@ public interface CustomEvent extends Event { /** * Specifies some detail information about the Event. */ - public Object getDetail(); + Object getDetail(); /** * The initCustomEventNS method is used to initialize the @@ -49,10 +49,10 @@ public interface CustomEvent extends Event { * @param detailArg Specifies CustomEvent.detail. This * value may be null. */ - public void initCustomEventNS(String namespaceURI, - String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - Object detailArg); + void initCustomEventNS(String namespaceURI, + String typeArg, + boolean canBubbleArg, + boolean cancelableArg, + Object detailArg); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/DocumentEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/DocumentEvent.java deleted file mode 100644 index 3e4831679..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/DocumentEvent.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -import org.w3c.dom.DOMException; - -/** - * The DocumentEvent interface provides a mechanism by which the - * user can create an Event object of a type supported by the - * implementation. If the feature "Events" is supported by the - * Document object, the DocumentEvent interface - * must be implemented on the same object. If the feature "+Events" is - * supported by the Document object, an object that supports - * the DocumentEvent interface must be returned by invoking the - * method Node.getFeature("+Events", "3.0") on the - * Document object. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface DocumentEvent { - /** - * - * @param eventType The eventType parameter specifies the - * name of the DOM Events interface to be supported by the created - * event object, e.g. "Event", "MouseEvent", - * "MutationEvent" and so on. If the Event - * is to be dispatched via the EventTarget.dispatchEvent() - * method the appropriate event init method must be called after - * creation in order to initialize the Event's values. - * As an example, a user wishing to synthesize some kind of - * UIEvent would invoke - * DocumentEvent.createEvent("UIEvent"). The - * UIEvent.initUIEventNS() method could then be called on - * the newly created UIEvent object to set the specific - * type of user interface event to be dispatched, DOMActivate for - * example, and set its context information, e.g. - * UIEvent.detail in this example. - *

    Note: For backward compatibility reason, "UIEvents", - * "MouseEvents", "MutationEvents", and "HTMLEvents" feature names are - * valid values for the parameter eventType and represent - * respectively the interfaces "UIEvent", "MouseEvent", - * "MutationEvent", and "Event". - * @return The newly created event object. - * @exception DOMException - * NOT_SUPPORTED_ERR: Raised if the implementation does not support the - * Event interface requested. - */ - public Event createEvent(String eventType) - throws DOMException; - - /** - * Test if the implementation can generate events of a specified type. - * @param namespaceURI Specifies the Event.namespaceURI of - * the event. - * @param type Specifies the Event.type of the event. - * @return true if the implementation can generate and - * dispatch this event type, false otherwise. - * @since DOM Level 3 - */ - public boolean canDispatch(String namespaceURI, - String type); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/Event.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/Event.java deleted file mode 100644 index e1a92c92f..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/Event.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -/** - * The Event interface is used to provide contextual information - * about an event to the listener processing the event. An object which - * implements the Event interface is passed as the parameter to - * an EventListener. More specific context information is - * passed to event listeners by deriving additional interfaces from - * Event which contain information directly relating to the - * type of event they represent. These derived interfaces are also - * implemented by the object passed to the event listener. - *

    To create an instance of the Event interface, use the - * DocumentEvent.createEvent("Event") method call. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface Event { - // PhaseType - /** - * The current event phase is the capture phase. - */ - public static final short CAPTURING_PHASE = 1; - /** - * The current event is in the target phase, i.e. it is being evaluated - * at the event target. - */ - public static final short AT_TARGET = 2; - /** - * The current event phase is the bubbling phase. - */ - public static final short BUBBLING_PHASE = 3; - - /** - * The local name of the event type. The name must be an NCName as defined in [XML Namespaces 1.1] - * and is case-sensitive. - */ - public String getType(); - - /** - * Used to indicate the event target. This attribute contains the target - * node when used with the . - */ - public EventTarget getTarget(); - - /** - * Used to indicate the EventTarget whose - * EventListeners are currently being processed. This is - * particularly useful during the capture and bubbling phases. This - * attribute could contain the target node or a target ancestor when - * used with the . - */ - public EventTarget getCurrentTarget(); - - /** - * Used to indicate which phase of event flow is currently being - * accomplished. - */ - public short getEventPhase(); - - /** - * Used to indicate whether or not an event is a bubbling event. If the - * event can bubble the value is true, otherwise the value - * is false. - */ - public boolean getBubbles(); - - /** - * Used to indicate whether or not an event can have its default action - * prevented (see also ). If the default action can be prevented the - * value is true, otherwise the value is false - * . - */ - public boolean getCancelable(); - - /** - * Used to specify the time at which the event was created in - * milliseconds relative to 1970-01-01T00:00:00Z. Due to the fact that - * some systems may not provide this information the value of - * timeStamp may be not available for all events. When not - * available, the value is 0. - */ - public long getTimeStamp(); - - /** - * This method is used to prevent event listeners of the same group to be - * triggered but its effect is deferred until all event listeners - * attached on the Event.currentTarget have been triggered - * (see ). Once it has been called, further calls to that method have no - * additional effect. - *

    Note: This method does not prevent the default action from - * being invoked; use Event.preventDefault() for that - * effect. - */ - public void stopPropagation(); - - /** - * If an event is cancelable, the preventDefault method is - * used to signify that the event is to be canceled, meaning any default - * action normally taken by the implementation as a result of the event - * will not occur (see also ), and thus independently of event groups. - * Calling this method for a non-cancelable event has no effect. - *

    Note: This method does not stop the event propagation; use - * Event.stopPropagation() or - * Event.stopImmediatePropagation() for that effect. - */ - public void preventDefault(); - - /** - * The initEvent method is used to initialize the value of - * an Event created through the - * DocumentEvent.createEvent method. This method may only - * be called before the Event has been dispatched via the - * EventTarget.dispatchEvent() method. If the method is - * called several times before invoking - * EventTarget.dispatchEvent, only the final invocation - * takes precedence. This method has no effect if called after the event - * has been dispatched. If called from a subclass of the - * Event interface only the values specified in this method - * are modified, all other attributes are left unchanged. - *
    This method sets the Event.type attribute to - * eventTypeArg, and Event.namespaceURI to - * null. To initialize an event with a namespace URI, use - * the Event.initEventNS() method. - * @param eventTypeArg Specifies Event.type, the local name - * of the event type. - * @param canBubbleArg Specifies Event.bubbles. This - * parameter overrides the intrinsic bubbling behavior of the event. - * @param cancelableArg Specifies Event.cancelable. This - * parameter overrides the intrinsic cancelable behavior of the event. - * - */ - public void initEvent(String eventTypeArg, - boolean canBubbleArg, - boolean cancelableArg); - - /** - * The namespace URI associated with this event at creation time, or - * null if it is unspecified. - *
    For events initialized with a DOM Level 2 Events method, such as - * Event.initEvent(), this is always null. - * @since DOM Level 3 - */ - public String getNamespaceURI(); - - /** - * This method is used to prevent event listeners of the same group to be - * triggered and, unlike Event.stopPropagation() its effect - * is immediate (see ). Once it has been called, further calls to that - * method have no additional effect. - *

    Note: This method does not prevent the default action from - * being invoked; use Event.preventDefault() for that - * effect. - * @since DOM Level 3 - */ - public void stopImmediatePropagation(); - - /** - * Used to indicate whether Event.preventDefault() has been - * called for this event. - * @since DOM Level 3 - */ - public boolean getDefaultPrevented(); - - /** - * The initEventNS method is used to initialize the value of - * an Event object and has the same behavior as - * Event.initEvent(). - * @param namespaceURIArg Specifies Event.namespaceURI, the - * namespace URI associated with this event, or null if - * no namespace. - * @param eventTypeArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @param canBubbleArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @param cancelableArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @since DOM Level 3 - */ - public void initEventNS(String namespaceURIArg, - String eventTypeArg, - boolean canBubbleArg, - boolean cancelableArg); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventException.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventException.java deleted file mode 100644 index 87af5fe3f..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -/** - * Event operations may throw an EventException as specified in - * their method descriptions. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public class EventException extends RuntimeException { - public EventException(short code, String message) { - super(message); - this.code = code; - } - public short code; - // EventExceptionCode - /** - * If the Event.type was not specified by initializing the - * event before the method was called. Specification of the - * Event.type as null or an empty string will - * also trigger this exception. - */ - public static final short UNSPECIFIED_EVENT_TYPE_ERR = 0; - /** - * If the Event object is already dispatched in the tree. - * @since DOM Level 3 - */ - public static final short DISPATCH_REQUEST_ERR = 1; - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventListener.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventListener.java deleted file mode 100644 index 7be62ae02..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -/** - * The EventListener interface is the primary way for handling - * events. Users implement the EventListener interface and - * register their event listener on an EventTarget. The users - * should also remove their EventListener from its - * EventTarget after they have completed using the listener. - *

    Copying a Node, with methods such as - * Node.cloneNode or Range.cloneContents, does not - * copy the event listeners attached to it. Event listeners must be attached - * to the newly created Node afterwards if so desired. - *

    Moving a Node, with methods Document.adoptNode - * , Node.appendChild, or Range.extractContents, - * does not affect the event listeners attached to it. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface EventListener { - /** - * This method is called whenever an event occurs of the event type for - * which the EventListener interface was registered. - * @param evt The Event contains contextual information - * about the event. - */ - public void handleEvent(Event evt); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventTarget.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventTarget.java deleted file mode 100644 index 47ad86793..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/EventTarget.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -import org.w3c.dom.DOMException; - -/** - * The EventTarget interface is implemented by all the objects - * which could be event targets in an implementation which supports the . - * The interface allows registration and removal of event listeners, and - * dispatch of events to an event target. - *

    When used with , this interface is implemented by all target nodes and - * target ancestors, i.e. all DOM Nodes of the tree support - * this interface when the implementation conforms to DOM Level 3 Events - * and, therefore, this interface can be obtained by using binding-specific - * casting methods on an instance of the Node interface. - *

    Invoking addEventListener or - * addEventListenerNS repeatedly on the same - * EventTarget with the same values for the parameters - * namespaceURI, type, listener, and - * useCapture has no effect. Doing so does not cause the - * EventListener to be called more than once and does not cause - * a change in the triggering order. In order to register a listener for a - * different event group () the previously registered listener has to be - * removed first. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface EventTarget { - /** - * This method allows the registration of an event listener in the - * default group and, depending on the useCapture - * parameter, on the capture phase of the DOM event flow or its target - * and bubbling phases. Invoking this method is equivalent to invoking - * addEventListenerNS with the same values for the - * parameters type, listener, and - * useCapture, and the value null for the - * parameters namespaceURI and evtGroup. - * @param type Specifies the Event.type associated with the - * event for which the user is registering. - * @param listener The listener parameter takes an object - * implemented by the user which implements the - * EventListener interface and contains the method to be - * called when the event occurs. - * @param useCapture If true, useCapture indicates that the - * user wishes to add the event listener for the capture phase only, - * i.e. this event listener will not be triggered during the target - * and bubbling phases. If false, the event listener will - * only be triggered during the target and bubbling phases. - */ - public void addEventListener(String type, - EventListener listener, - boolean useCapture); - - /** - * This method allows the removal of event listeners from the default - * group. Calling removeEventListener with arguments which - * do not identify any currently registered EventListener - * on the EventTarget has no effect. The - * Event.namespaceURI for which the user registered the - * event listener is implied and is null. - *

    Note: Event listeners registered for other event groups - * than the default group cannot be removed using this method; see - * EventTarget.removeEventListenerNS() for that effect. - * @param type Specifies the Event.type for which the user - * registered the event listener. - * @param listener The EventListener to be removed. - * @param useCapture Specifies whether the EventListener - * being removed was registered for the capture phase or not. If a - * listener was registered twice, once for the capture phase and once - * for the target and bubbling phases, each must be removed - * separately. Removal of an event listener registered for the capture - * phase does not affect the same event listener registered for the - * target and bubbling phases, and vice versa. - */ - public void removeEventListener(String type, - EventListener listener, - boolean useCapture); - - /** - * This method allows the dispatch of events into the implementation's - * event model. The event target of the event is the - * EventTarget object on which dispatchEvent - * is called. - * @param evt The event to be dispatched. - * @return Indicates whether any of the listeners which handled the - * event called Event.preventDefault(). If - * Event.preventDefault() was called the returned value - * is false, else it is true. - * @exception EventException - * UNSPECIFIED_EVENT_TYPE_ERR: Raised if the Event.type - * was not specified by initializing the event before - * dispatchEvent was called. Specification of the - * Event.type as null or an empty string - * will also trigger this exception. - *
    DISPATCH_REQUEST_ERR: Raised if the Event object is - * already being dispatched. - * @exception DOMException - * NOT_SUPPORTED_ERR: Raised if the Event object has not - * been created using DocumentEvent.createEvent(). - *
    INVALID_CHARACTER_ERR: Raised if Event.type is not - * an NCName as defined in [XML Namespaces 1.1] - * . - * @version DOM Level 3 - */ - public boolean dispatchEvent(Event evt) - throws EventException, DOMException; - - /** - * This method allows the registration of an event listener in a - * specified group or the default group and, depending on the - * useCapture parameter, on the capture phase of the DOM - * event flow or its target and bubbling phases. - * @param namespaceURI Specifies the Event.namespaceURI - * associated with the event for which the user is registering. - * @param type Refer to the EventTarget.addEventListener() - * method for a description of this parameter. - * @param listener Refer to the - * EventTarget.addEventListener() method for a - * description of this parameter. - * @param useCapture Refer to the - * EventTarget.addEventListener() method for a - * description of this parameter. - * @param evtGroup The object that represents the event group to - * associate with the EventListener (see also ). Use - * null to attach the event listener to the default - * group. - * @since DOM Level 3 - */ - public void addEventListenerNS(String namespaceURI, - String type, - EventListener listener, - boolean useCapture, - Object evtGroup); - - /** - * This method allows the removal of an event listener, independently of - * the associated event group. Calling removeEventListenerNS - * with arguments which do not identify any currently registered - * EventListener on the EventTarget has no - * effect. - * @param namespaceURI Specifies the Event.namespaceURI - * associated with the event for which the user registered the event - * listener. - * @param type Refer to the - * EventTarget.removeEventListener() method for a - * description of this parameter. - * @param listener Refer to the - * EventTarget.removeEventListener() method for a - * description of this parameter. - * @param useCapture Refer to the - * EventTarget.removeEventListener() method for a - * description of this parameter. - * @since DOM Level 3 - */ - public void removeEventListenerNS(String namespaceURI, - String type, - EventListener listener, - boolean useCapture); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/KeyboardEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/KeyboardEvent.java index 682e346b2..6eb4ce6a7 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/KeyboardEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/KeyboardEvent.java @@ -42,25 +42,25 @@ public interface KeyboardEvent extends UIEvent { * originate with a virtual key corresponding to the numeric keypad). * Example: the 'Q' key on a PC 101 Key US keyboard. */ - public static final int DOM_KEY_LOCATION_STANDARD = 0x00; + int DOM_KEY_LOCATION_STANDARD = 0x00; /** * The key activated is in the left key location (there is more than one * possible location for this key). Example: the left Shift key on a PC * 101 Key US keyboard. */ - public static final int DOM_KEY_LOCATION_LEFT = 0x01; + int DOM_KEY_LOCATION_LEFT = 0x01; /** * The key activation is in the right key location (there is more than * one possible location for this key). Example: the right Shift key on * a PC 101 Key US keyboard. */ - public static final int DOM_KEY_LOCATION_RIGHT = 0x02; + int DOM_KEY_LOCATION_RIGHT = 0x02; /** * The key activation originated on the numeric keypad or with a virtual * key corresponding to the numeric keypad. Example: the '1' key on a PC * 101 Key US keyboard located on the numeric pad. */ - public static final int DOM_KEY_LOCATION_NUMPAD = 0x03; + int DOM_KEY_LOCATION_NUMPAD = 0x03; /** * keyIdentifier holds the identifier of the key. The key @@ -68,37 +68,37 @@ public interface KeyboardEvent extends UIEvent { * unable to identify a key must use the key identifier * "Unidentified". */ - public String getKeyIdentifier(); + String getKeyIdentifier(); /** * The keyLocation attribute contains an indication of the * location of they key on the device, as described in . */ - public int getKeyLocation(); + int getKeyLocation(); /** * true if the control (Ctrl) key modifier is activated. */ - public boolean getCtrlKey(); + boolean getCtrlKey(); /** * true if the shift (Shift) key modifier is activated. */ - public boolean getShiftKey(); + boolean getShiftKey(); /** * true if the alternative (Alt) key modifier is activated. *

    Note: The Option key modifier on Macintosh systems must be * represented using this key modifier. */ - public boolean getAltKey(); + boolean getAltKey(); /** * true if the meta (Meta) key modifier is activated. *

    Note: The Command key modifier on Macintosh systems must be * represented using this key modifier. */ - public boolean getMetaKey(); + boolean getMetaKey(); /** * This methods queries the state of a modifier using a key identifier. @@ -114,7 +114,7 @@ public interface KeyboardEvent extends UIEvent { * @return true if it is modifier key and the modifier is * activated, false otherwise. */ - public boolean getModifierState(String keyIdentifierArg); + boolean getModifierState(String keyIdentifierArg); /** * The initKeyboardEvent method is used to initialize the @@ -133,16 +133,17 @@ public interface KeyboardEvent extends UIEvent { * KeyboardEvent.keyIdentifier. * @param keyLocationArg Specifies KeyboardEvent.keyLocation * . - * @param modifiersList A white space separated list of modifier key identifiers to be activated on this + * @param modifiersList A white space separated + * list of modifier key identifiers to be activated on this * object. */ - public void initKeyboardEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - String keyIdentifierArg, - int keyLocationArg, - String modifiersList); + void initKeyboardEvent(String typeArg, + boolean canBubbleArg, + boolean cancelableArg, + AbstractView viewArg, + String keyIdentifierArg, + int keyLocationArg, + String modifiersList); /** * The initKeyboardEventNS method is used to initialize the @@ -165,17 +166,18 @@ public interface KeyboardEvent extends UIEvent { * @param keyLocationArg Refer to the * KeyboardEvent.initKeyboardEvent() method for a * description of this parameter. - * @param modifiersList A white space separated list of modifier key identifiers to be activated on this + * @param modifiersList A white space separated + * list of modifier key identifiers to be activated on this * object. As an example, "Control Alt" will activated * the control and alt modifiers. */ - public void initKeyboardEventNS(String namespaceURI, - String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - String keyIdentifierArg, - int keyLocationArg, - String modifiersList); + void initKeyboardEventNS(String namespaceURI, + String typeArg, + boolean canBubbleArg, + boolean cancelableArg, + AbstractView viewArg, + String keyIdentifierArg, + int keyLocationArg, + String modifiersList); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MouseEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MouseEvent.java deleted file mode 100644 index fd2bfe8cb..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MouseEvent.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -import org.w3c.dom.views.AbstractView; - -/** - * The MouseEvent interface provides specific contextual - * information associated with Mouse events. - *

    In the case of nested elements mouse events are always targeted at the - * most deeply nested element. Ancestors of the targeted element may use - * bubbling to obtain notification of mouse events which occur within theirs - * descendent elements. - *

    To create an instance of the MouseEvent interface, use the - * DocumentEvent.createEvent("MouseEvent") method call. - *

    Note: When initializing MouseEvent objects using - * initMouseEvent or initMouseEventNS, - * implementations should use the client coordinates clientX - * and clientY for calculation of other coordinates (such as - * target coordinates exposed by DOM Level 0 implementations). - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface MouseEvent extends UIEvent { - /** - * The horizontal coordinate at which the event occurred relative to the - * origin of the screen coordinate system. - */ - public int getScreenX(); - - /** - * The vertical coordinate at which the event occurred relative to the - * origin of the screen coordinate system. - */ - public int getScreenY(); - - /** - * The horizontal coordinate at which the event occurred relative to the - * DOM implementation's client area. - */ - public int getClientX(); - - /** - * The vertical coordinate at which the event occurred relative to the - * DOM implementation's client area. - */ - public int getClientY(); - - /** - * true if the control (Ctrl) key modifier is activated. - */ - public boolean getCtrlKey(); - - /** - * true if the shift (Shift) key modifier is activated. - */ - public boolean getShiftKey(); - - /** - * true if the alt (alternative) key modifier is activated. - *

    Note: The Option key modifier on Macintosh systems must be - * represented using this key modifier. - */ - public boolean getAltKey(); - - /** - * true if the meta (Meta) key modifier is activated. - *

    Note: The Command key modifier on Macintosh system must be - * represented using this meta key. - */ - public boolean getMetaKey(); - - /** - * During mouse events caused by the depression or release of a mouse - * button, button is used to indicate which mouse button - * changed state. 0 indicates the normal button of the - * mouse (in general on the left or the one button on Macintosh mice, - * used to activate a button or select text). 2 indicates - * the contextual property (in general on the right, used to display a - * context menu) button of the mouse if present. 1 - * indicates the extra (in general in the middle and often combined with - * the mouse wheel) button. Some mice may provide or simulate more - * buttons, and values higher than 2 can be used to - * represent such buttons. - */ - public short getButton(); - - /** - * Used to identify a secondary EventTarget related to a UI - * event, depending on the type of event. - */ - public EventTarget getRelatedTarget(); - - /** - * The initMouseEvent method is used to initialize the value - * of a MouseEvent object and has the same behavior as - * UIEvent.initUIEvent(). - * @param typeArg Refer to the UIEvent.initUIEvent() method - * for a description of this parameter. - * @param canBubbleArg Refer to the UIEvent.initUIEvent() - * method for a description of this parameter. - * @param cancelableArg Refer to the UIEvent.initUIEvent() - * method for a description of this parameter. - * @param viewArg Refer to the UIEvent.initUIEvent() method - * for a description of this parameter. - * @param detailArg Refer to the UIEvent.initUIEvent() - * method for a description of this parameter. - * @param screenXArg Specifies MouseEvent.screenX. - * @param screenYArg Specifies MouseEvent.screenY. - * @param clientXArg Specifies MouseEvent.clientX. - * @param clientYArg Specifies MouseEvent.clientY. - * @param ctrlKeyArg Specifies MouseEvent.ctrlKey. - * @param altKeyArg Specifies MouseEvent.altKey. - * @param shiftKeyArg Specifies MouseEvent.shiftKey. - * @param metaKeyArg Specifies MouseEvent.metaKey. - * @param buttonArg Specifies MouseEvent.button. - * @param relatedTargetArg Specifies - * MouseEvent.relatedTarget. This value may be - * null. - */ - public void initMouseEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - int detailArg, - int screenXArg, - int screenYArg, - int clientXArg, - int clientYArg, - boolean ctrlKeyArg, - boolean altKeyArg, - boolean shiftKeyArg, - boolean metaKeyArg, - short buttonArg, - EventTarget relatedTargetArg); - - /** - * This methods queries the state of a modifier using a key identifier. - * See also . - * @param keyIdentifierArg A modifier key identifier, as defined by the - * KeyboardEvent.keyIdentifier attribute. Common modifier - * keys are "Alt", "AltGraph", - * "CapsLock", "Control", "Meta" - * , "NumLock", "Scroll", or - * "Shift". - *

    Note: If an application wishes to distinguish between - * right and left modifiers, this information could be deduced using - * keyboard events and KeyboardEvent.keyLocation. - * @return true if it is modifier key and the modifier is - * activated, false otherwise. - * @since DOM Level 3 - */ - public boolean getModifierState(String keyIdentifierArg); - - /** - * The initMouseEventNS method is used to initialize the - * value of a MouseEvent object and has the same behavior - * as UIEvent.initUIEventNS(). - * @param namespaceURI Refer to the UIEvent.initUIEventNS() - * method for a description of this parameter. - * @param typeArg Refer to the UIEvent.initUIEventNS() - * method for a description of this parameter. - * @param canBubbleArg Refer to the UIEvent.initUIEventNS() - * method for a description of this parameter. - * @param cancelableArg Refer to the UIEvent.initUIEventNS() - * method for a description of this parameter. - * @param viewArg Refer to the UIEvent.initUIEventNS() - * method for a description of this parameter. - * @param detailArg Refer to the UIEvent.initUIEventNS() - * method for a description of this parameter. - * @param screenXArg Refer to the - * MouseEvent.initMouseEvent() method for a description - * of this parameter. - * @param screenYArg Refer to the - * MouseEvent.initMouseEvent() method for a description - * of this parameter. - * @param clientXArg Refer to the - * MouseEvent.initMouseEvent() method for a description - * of this parameter. - * @param clientYArg Refer to the - * MouseEvent.initMouseEvent() method for a description - * of this parameter. - * @param buttonArg Refer to the MouseEvent.initMouseEvent() - * method for a description of this parameter. - * @param relatedTargetArg Refer to the - * MouseEvent.initMouseEvent() method for a description - * of this parameter. - * @param modifiersList A white space separated list of modifier key identifiers to be activated on this - * object. As an example, "Control Alt" will activated - * the control and alt modifiers. - * @since DOM Level 3 - */ - public void initMouseEventNS(String namespaceURI, - String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - int detailArg, - int screenXArg, - int screenYArg, - int clientXArg, - int clientYArg, - short buttonArg, - EventTarget relatedTargetArg, - String modifiersList); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationEvent.java deleted file mode 100644 index 33cba64f0..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationEvent.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -import org.w3c.dom.Node; - -/** - * The MutationEvent interface provides specific contextual - * information associated with Mutation events. - *

    To create an instance of the MutationEvent interface, use - * the DocumentEvent.createEvent("MutationEvent") method call. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface MutationEvent extends Event { - // attrChangeType - /** - * The Attr was modified in place. - */ - public static final short MODIFICATION = 1; - /** - * The Attr was just added. - */ - public static final short ADDITION = 2; - /** - * The Attr was just removed. - */ - public static final short REMOVAL = 3; - - /** - * relatedNode is used to identify a secondary node related - * to a mutation event. For example, if a mutation event is dispatched - * to a node indicating that its parent has changed, the - * relatedNode is the changed parent. If an event is - * instead dispatched to a subtree indicating a node was changed within - * it, the relatedNode is the changed node. In the case of - * the DOMAttrModified event it indicates the Attr node - * which was modified, added, or removed. - */ - public Node getRelatedNode(); - - /** - * prevValue indicates the previous value of the - * Attr node in DOMAttrModified events, and of the - * CharacterData node in DOMCharacterDataModified events. - */ - public String getPrevValue(); - - /** - * newValue indicates the new value of the Attr - * node in DOMAttrModified events, and of the CharacterData - * node in DOMCharacterDataModified events. - */ - public String getNewValue(); - - /** - * attrName indicates the name of the changed - * Attr node in a DOMAttrModified event. - */ - public String getAttrName(); - - /** - * attrChange indicates the type of change which triggered - * the DOMAttrModified event. The values can be MODIFICATION - * , ADDITION, or REMOVAL. - */ - public short getAttrChange(); - - /** - * The initMutationEvent method is used to initialize the - * value of a MutationEvent object and has the same - * behavior as Event.initEvent(). - * @param typeArg Refer to the Event.initEvent() method for - * a description of this parameter. - * @param canBubbleArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @param cancelableArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @param relatedNodeArg Specifies MutationEvent.relatedNode - * . - * @param prevValueArg Specifies MutationEvent.prevValue. - * This value may be null. - * @param newValueArg Specifies MutationEvent.newValue. - * This value may be null. - * @param attrNameArg Specifies MutationEvent.attrname. - * This value may be null. - * @param attrChangeArg Specifies MutationEvent.attrChange. - * This value may be null. - */ - public void initMutationEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - Node relatedNodeArg, - String prevValueArg, - String newValueArg, - String attrNameArg, - short attrChangeArg); - - /** - * The initMutationEventNS method is used to initialize the - * value of a MutationEvent object and has the same - * behavior as Event.initEventNS(). - * @param namespaceURI Refer to the Event.initEventNS() - * method for a description of this parameter. - * @param typeArg Refer to the Event.initEventNS() method - * for a description of this parameter. - * @param canBubbleArg Refer to the Event.initEventNS() - * method for a description of this parameter. - * @param cancelableArg Refer to the Event.initEventNS() - * method for a description of this parameter. - * @param relatedNodeArg Refer to the - * MutationEvent.initMutationEvent() method for a - * description of this parameter. - * @param prevValueArg Refer to the - * MutationEvent.initMutationEvent() method for a - * description of this parameter. - * @param newValueArg Refer to the - * MutationEvent.initMutationEvent() method for a - * description of this parameter. - * @param attrNameArg Refer to the - * MutationEvent.initMutationEvent() method for a - * description of this parameter. - * @param attrChangeArg Refer to the - * MutationEvent.initMutationEvent() method for a - * description of this parameter. - * @since DOM Level 3 - */ - public void initMutationEventNS(String namespaceURI, - String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - Node relatedNodeArg, - String prevValueArg, - String newValueArg, - String attrNameArg, - short attrChangeArg); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationNameEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationNameEvent.java index bc30073c9..df8a58ff1 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationNameEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/MutationNameEvent.java @@ -31,13 +31,13 @@ public interface MutationNameEvent extends MutationEvent { * The previous value of the relatedNode's * namespaceURI. */ - public String getPrevNamespaceURI(); + String getPrevNamespaceURI(); /** * The previous value of the relatedNode's * nodeName. */ - public String getPrevNodeName(); + String getPrevNodeName(); /** * The initMutationNameEvent method is used to initialize @@ -62,12 +62,12 @@ public interface MutationNameEvent extends MutationEvent { * MutationNameEvent.prevNodeName. * @since DOM Level 3 */ - public void initMutationNameEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - Node relatedNodeArg, - String prevNamespaceURIArg, - String prevNodeNameArg); + void initMutationNameEvent(String typeArg, + boolean canBubbleArg, + boolean cancelableArg, + Node relatedNodeArg, + String prevNamespaceURIArg, + String prevNodeNameArg); /** * The initMutationNameEventNS method is used to initialize @@ -96,12 +96,12 @@ public interface MutationNameEvent extends MutationEvent { * description of this parameter. * @since DOM Level 3 */ - public void initMutationNameEventNS(String namespaceURI, - String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - Node relatedNodeArg, - String prevNamespaceURIArg, - String prevNodeNameArg); + void initMutationNameEventNS(String namespaceURI, + String typeArg, + boolean canBubbleArg, + boolean cancelableArg, + Node relatedNodeArg, + String prevNamespaceURIArg, + String prevNodeNameArg); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/TextEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/TextEvent.java index 7bab3958f..0efb66aed 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/TextEvent.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/TextEvent.java @@ -33,7 +33,7 @@ public interface TextEvent extends UIEvent { * normalization form NFC, defined in [UAX #15]. This attribute * cannot be null or contain the empty string. */ - public String getData(); + String getData(); /** * The initTextEvent method is used to initialize the value @@ -50,11 +50,11 @@ public interface TextEvent extends UIEvent { * for a description of this parameter. * @param dataArg Specifies TextEvent.data. */ - public void initTextEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - String dataArg); + void initTextEvent(String typeArg, + boolean canBubbleArg, + boolean cancelableArg, + AbstractView viewArg, + String dataArg); /** * The initTextEventNS method is used to initialize the @@ -74,11 +74,11 @@ public interface TextEvent extends UIEvent { * @param dataArg Refer to the TextEvent.initTextEvent() * method for a description of this parameter. */ - public void initTextEventNS(String namespaceURI, - String type, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - String dataArg); + void initTextEventNS(String namespaceURI, + String type, + boolean canBubbleArg, + boolean cancelableArg, + AbstractView viewArg, + String dataArg); } diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/UIEvent.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/UIEvent.java deleted file mode 100644 index 4171d7cfa..000000000 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/w3c/dom/events/UIEvent.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2006 World Wide Web Consortium, - * - * (Massachusetts Institute of Technology, European Research Consortium for - * Informatics and Mathematics, Keio University). All Rights Reserved. This - * work is distributed under the W3C(r) Software License [1] 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. - * - * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 - */ - -package org.apache.batik.w3c.dom.events; - -import org.w3c.dom.views.AbstractView; - -/** - * The UIEvent interface provides specific contextual - * information associated with User Interface events. - *

    To create an instance of the UIEvent interface, use the - * DocumentEvent.createEvent("UIEvent") method call. - *

    See also the - Document Object Model (DOM) Level 3 Events Specification - . - * @since DOM Level 2 - */ -public interface UIEvent extends Event { - /** - * The view attribute identifies the - * AbstractView from which the event was generated. - */ - public AbstractView getView(); - - /** - * Specifies some detail information about the Event, - * depending on the type of event. - */ - public int getDetail(); - - /** - * The initUIEvent method is used to initialize the value of - * a UIEvent object and has the same behavior as - * Event.initEvent(). - * @param typeArg Refer to the Event.initEvent() method for - * a description of this parameter. - * @param canBubbleArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @param cancelableArg Refer to the Event.initEvent() - * method for a description of this parameter. - * @param viewArg Specifies UIEvent.view. This value may be - * null. - * @param detailArg Specifies UIEvent.detail. - */ - public void initUIEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - int detailArg); - - /** - * The initUIEventNS method is used to initialize the value - * of a UIEvent object and has the same behavior as - * Event.initEventNS(). - * @param namespaceURI Refer to the Event.initEventNS() - * method for a description of this parameter. - * @param typeArg Refer to the Event.initEventNS() method - * for a description of this parameter. - * @param canBubbleArg Refer to the Event.initEventNS() - * method for a description of this parameter. - * @param cancelableArg Refer to the Event.initEventNS() - * method for a description of this parameter. - * @param viewArg Refer to the UIEvent.initUIEvent() method - * for a description of this parameter. - * @param detailArg Refer to the UIEvent.initUIEvent() - * method for a description of this parameter. - * @since DOM Level 3 - */ - public void initUIEventNS(String namespaceURI, - String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - int detailArg); - -} diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLScanner.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLScanner.java index 239d0c79a..00d586af9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLScanner.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLScanner.java @@ -2073,8 +2073,8 @@ public class XMLScanner implements Localizable { try { m = formatMessage(message, new Object[] { - new Integer(reader.getLine()), - new Integer(reader.getColumn()) + reader.getLine(), + reader.getColumn() }); } catch (MissingResourceException e) { m = message; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLUtilities.java b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLUtilities.java index b91179f05..daf72a4e2 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLUtilities.java +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/xml/XMLUtilities.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. -*/ + */ package org.apache.batik.xml; @@ -91,7 +91,7 @@ public class XMLUtilities extends XMLCharacters { * Tests whether the given 32 bits character is valid in XML documents. * Because the majority of code-points is covered by the table-lookup-test, * we do it first. - * This method gives meaningful results only for c >= 0. + * This method gives meaningful results only for c >= 0. */ public static boolean isXMLCharacter(int c) { @@ -275,7 +275,9 @@ public class XMLUtilities extends XMLCharacters { return e; } - while (isXMLSpace((char)(c = r.read()))); + while (isXMLSpace((char)(c = r.read()))) { + //skip + } if (c != 'v') { return e; @@ -308,7 +310,9 @@ public class XMLUtilities extends XMLCharacters { return e; } - while (isXMLSpace((char)(c = r.read()))); + while (isXMLSpace((char)(c = r.read()))) { + //skip + } if (c != '"' && c != '\'') { return e; @@ -328,7 +332,9 @@ public class XMLUtilities extends XMLCharacters { if (!isXMLSpace((char)(c = r.read()))) { return e; } - while (isXMLSpace((char)(c = r.read()))); + while (isXMLSpace((char)(c = r.read()))) { + //skip + } if (c != 'e') { return e; @@ -364,7 +370,9 @@ public class XMLUtilities extends XMLCharacters { return e; } - while (isXMLSpace((char)(c = r.read()))); + while (isXMLSpace((char)(c = r.read()))) { + //skip + } if (c != '"' && c != '\'') { return e; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/LICENSE b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/LICENSE new file mode 100644 index 000000000..3e4e3d004 --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/imports/script.txt b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/imports/script.txt new file mode 100755 index 000000000..b85dc2531 --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/imports/script.txt @@ -0,0 +1,252 @@ +class java.lang.System # Optional + +# The rest are needed for SVG DOM conformance. +# class org.apache.batik.w3c.dom.Window # conflicts with our Window class.. +class org.apache.batik.w3c.dom.Location +class org.w3c.dom.Attr +class org.w3c.dom.CDATASection +class org.w3c.dom.CharacterData +class org.w3c.dom.Comment +class org.w3c.dom.DOMConfiguration +class org.w3c.dom.DOMError +class org.w3c.dom.DOMErrorHandler +class org.w3c.dom.DOMException +class org.w3c.dom.DOMImplementation +class org.w3c.dom.DOMImplementationList +class org.w3c.dom.DOMImplementationSource +class org.w3c.dom.DOMLocator +class org.w3c.dom.DOMStringList +class org.w3c.dom.Document +class org.w3c.dom.DocumentFragment +class org.w3c.dom.DocumentType +class org.w3c.dom.Element +class org.w3c.dom.Entity +class org.w3c.dom.EntityReference +class org.w3c.dom.NameList +class org.w3c.dom.NamedNodeMap +class org.w3c.dom.Node +class org.w3c.dom.NodeList +class org.w3c.dom.Notation +class org.w3c.dom.ProcessingInstruction +class org.w3c.dom.Text +class org.w3c.dom.TypeInfo +class org.w3c.dom.UserDataHandler +class org.w3c.dom.css.CSS2Properties +class org.w3c.dom.css.CSSCharsetRule +class org.w3c.dom.css.CSSFontFaceRule +class org.w3c.dom.css.CSSImportRule +class org.w3c.dom.css.CSSMediaRule +class org.w3c.dom.css.CSSPageRule +class org.w3c.dom.css.CSSPrimitiveValue +class org.w3c.dom.css.CSSRule +class org.w3c.dom.css.CSSRuleList +class org.w3c.dom.css.CSSStyleDeclaration +class org.w3c.dom.css.CSSStyleRule +class org.w3c.dom.css.CSSStyleSheet +class org.w3c.dom.css.CSSUnknownRule +class org.w3c.dom.css.CSSValue +class org.w3c.dom.css.CSSValueList +class org.w3c.dom.css.Counter +class org.w3c.dom.css.DOMImplementationCSS +class org.w3c.dom.css.DocumentCSS +class org.w3c.dom.css.ElementCSSInlineStyle +class org.w3c.dom.css.RGBColor +class org.w3c.dom.css.Rect +class org.w3c.dom.css.ViewCSS +class org.w3c.dom.events.DocumentEvent +class org.w3c.dom.events.Event +class org.w3c.dom.events.EventException +class org.w3c.dom.events.EventListener +class org.w3c.dom.events.EventTarget +class org.w3c.dom.events.MouseEvent +class org.w3c.dom.events.MutationEvent +class org.w3c.dom.events.UIEvent +class org.w3c.dom.stylesheets.DocumentStyle +class org.w3c.dom.stylesheets.LinkStyle +class org.w3c.dom.stylesheets.MediaList +class org.w3c.dom.stylesheets.StyleSheet +class org.w3c.dom.stylesheets.StyleSheetList +class org.w3c.dom.views.AbstractView +class org.w3c.dom.views.DocumentView +class org.w3c.dom.xpath.XPathEvaluator +class org.w3c.dom.xpath.XPathException +class org.w3c.dom.xpath.XPathExpression +class org.w3c.dom.xpath.XPathNSResolver +class org.w3c.dom.xpath.XPathNamespace +class org.w3c.dom.xpath.XPathResult +class org.w3c.dom.smil.ElementTimeControl +class org.w3c.dom.smil.TimeEvent +class org.w3c.dom.svg.EventListenerInitializer +class org.w3c.dom.svg.GetSVGDocument +class org.w3c.dom.svg.SVGAElement +class org.w3c.dom.svg.SVGAltGlyphDefElement +class org.w3c.dom.svg.SVGAltGlyphElement +class org.w3c.dom.svg.SVGAltGlyphItemElement +class org.w3c.dom.svg.SVGAngle +class org.w3c.dom.svg.SVGAnimateColorElement +class org.w3c.dom.svg.SVGAnimateElement +class org.w3c.dom.svg.SVGAnimateMotionElement +class org.w3c.dom.svg.SVGAnimateTransformElement +class org.w3c.dom.svg.SVGAnimatedAngle +class org.w3c.dom.svg.SVGAnimatedBoolean +class org.w3c.dom.svg.SVGAnimatedEnumeration +class org.w3c.dom.svg.SVGAnimatedInteger +class org.w3c.dom.svg.SVGAnimatedLength +class org.w3c.dom.svg.SVGAnimatedLengthList +class org.w3c.dom.svg.SVGAnimatedNumber +class org.w3c.dom.svg.SVGAnimatedNumberList +class org.w3c.dom.svg.SVGAnimatedPathData +class org.w3c.dom.svg.SVGAnimatedPoints +class org.w3c.dom.svg.SVGAnimatedPreserveAspectRatio +class org.w3c.dom.svg.SVGAnimatedRect +class org.w3c.dom.svg.SVGAnimatedString +class org.w3c.dom.svg.SVGAnimatedTransformList +class org.w3c.dom.svg.SVGAnimationElement +class org.w3c.dom.svg.SVGCSSRule +class org.w3c.dom.svg.SVGCircleElement +class org.w3c.dom.svg.SVGClipPathElement +class org.w3c.dom.svg.SVGColor +class org.w3c.dom.svg.SVGColorProfileElement +class org.w3c.dom.svg.SVGColorProfileRule +class org.w3c.dom.svg.SVGComponentTransferFunctionElement +class org.w3c.dom.svg.SVGCursorElement +class org.w3c.dom.svg.SVGDefinitionSrcElement +class org.w3c.dom.svg.SVGDefsElement +class org.w3c.dom.svg.SVGDescElement +class org.w3c.dom.svg.SVGDocument +class org.w3c.dom.svg.SVGElement +class org.w3c.dom.svg.SVGElementInstance +class org.w3c.dom.svg.SVGElementInstanceList +class org.w3c.dom.svg.SVGEllipseElement +class org.w3c.dom.svg.SVGEvent +class org.w3c.dom.svg.SVGException +class org.w3c.dom.svg.SVGExternalResourcesRequired +class org.w3c.dom.svg.SVGFEBlendElement +class org.w3c.dom.svg.SVGFEColorMatrixElement +class org.w3c.dom.svg.SVGFEComponentTransferElement +class org.w3c.dom.svg.SVGFECompositeElement +class org.w3c.dom.svg.SVGFEConvolveMatrixElement +class org.w3c.dom.svg.SVGFEDiffuseLightingElement +class org.w3c.dom.svg.SVGFEDisplacementMapElement +class org.w3c.dom.svg.SVGFEDistantLightElement +class org.w3c.dom.svg.SVGFEFloodElement +class org.w3c.dom.svg.SVGFEFuncAElement +class org.w3c.dom.svg.SVGFEFuncBElement +class org.w3c.dom.svg.SVGFEFuncGElement +class org.w3c.dom.svg.SVGFEFuncRElement +class org.w3c.dom.svg.SVGFEGaussianBlurElement +class org.w3c.dom.svg.SVGFEImageElement +class org.w3c.dom.svg.SVGFEMergeElement +class org.w3c.dom.svg.SVGFEMergeNodeElement +class org.w3c.dom.svg.SVGFEMorphologyElement +class org.w3c.dom.svg.SVGFEOffsetElement +class org.w3c.dom.svg.SVGFEPointLightElement +class org.w3c.dom.svg.SVGFESpecularLightingElement +class org.w3c.dom.svg.SVGFESpotLightElement +class org.w3c.dom.svg.SVGFETileElement +class org.w3c.dom.svg.SVGFETurbulenceElement +class org.w3c.dom.svg.SVGFilterElement +class org.w3c.dom.svg.SVGFilterPrimitiveStandardAttributes +class org.w3c.dom.svg.SVGFitToViewBox +class org.w3c.dom.svg.SVGFontElement +class org.w3c.dom.svg.SVGFontFaceElement +class org.w3c.dom.svg.SVGFontFaceFormatElement +class org.w3c.dom.svg.SVGFontFaceNameElement +class org.w3c.dom.svg.SVGFontFaceSrcElement +class org.w3c.dom.svg.SVGFontFaceUriElement +class org.w3c.dom.svg.SVGForeignObjectElement +class org.w3c.dom.svg.SVGGElement +class org.w3c.dom.svg.SVGGlyphElement +class org.w3c.dom.svg.SVGGlyphRefElement +class org.w3c.dom.svg.SVGGradientElement +class org.w3c.dom.svg.SVGHKernElement +class org.w3c.dom.svg.SVGICCColor +class org.w3c.dom.svg.SVGImageElement +class org.w3c.dom.svg.SVGLangSpace +class org.w3c.dom.svg.SVGLength +class org.w3c.dom.svg.SVGLengthList +class org.w3c.dom.svg.SVGLineElement +class org.w3c.dom.svg.SVGLinearGradientElement +class org.w3c.dom.svg.SVGLocatable +class org.w3c.dom.svg.SVGMPathElement +class org.w3c.dom.svg.SVGMarkerElement +class org.w3c.dom.svg.SVGMaskElement +class org.w3c.dom.svg.SVGMatrix +class org.w3c.dom.svg.SVGMetadataElement +class org.w3c.dom.svg.SVGMissingGlyphElement +class org.w3c.dom.svg.SVGNumber +class org.w3c.dom.svg.SVGNumberList +class org.w3c.dom.svg.SVGPaint +class org.w3c.dom.svg.SVGPathElement +class org.w3c.dom.svg.SVGPathSeg +class org.w3c.dom.svg.SVGPathSegArcAbs +class org.w3c.dom.svg.SVGPathSegArcRel +class org.w3c.dom.svg.SVGPathSegClosePath +class org.w3c.dom.svg.SVGPathSegCurvetoCubicAbs +class org.w3c.dom.svg.SVGPathSegCurvetoCubicRel +class org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothAbs +class org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothRel +class org.w3c.dom.svg.SVGPathSegCurvetoQuadraticAbs +class org.w3c.dom.svg.SVGPathSegCurvetoQuadraticRel +class org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothAbs +class org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothRel +class org.w3c.dom.svg.SVGPathSegLinetoAbs +class org.w3c.dom.svg.SVGPathSegLinetoHorizontalAbs +class org.w3c.dom.svg.SVGPathSegLinetoHorizontalRel +class org.w3c.dom.svg.SVGPathSegLinetoRel +class org.w3c.dom.svg.SVGPathSegLinetoVerticalAbs +class org.w3c.dom.svg.SVGPathSegLinetoVerticalRel +class org.w3c.dom.svg.SVGPathSegList +class org.w3c.dom.svg.SVGPathSegMovetoAbs +class org.w3c.dom.svg.SVGPathSegMovetoRel +class org.w3c.dom.svg.SVGPatternElement +class org.w3c.dom.svg.SVGPoint +class org.w3c.dom.svg.SVGPointList +class org.w3c.dom.svg.SVGPolygonElement +class org.w3c.dom.svg.SVGPolylineElement +class org.w3c.dom.svg.SVGPreserveAspectRatio +class org.w3c.dom.svg.SVGRadialGradientElement +class org.w3c.dom.svg.SVGRect +class org.w3c.dom.svg.SVGRectElement +class org.w3c.dom.svg.SVGRenderingIntent +class org.w3c.dom.svg.SVGSVGElement +class org.w3c.dom.svg.SVGScriptElement +class org.w3c.dom.svg.SVGSetElement +class org.w3c.dom.svg.SVGStopElement +class org.w3c.dom.svg.SVGStringList +class org.w3c.dom.svg.SVGStylable +class org.w3c.dom.svg.SVGStyleElement +class org.w3c.dom.svg.SVGSwitchElement +class org.w3c.dom.svg.SVGSymbolElement +class org.w3c.dom.svg.SVGTRefElement +class org.w3c.dom.svg.SVGTSpanElement +class org.w3c.dom.svg.SVGTests +class org.w3c.dom.svg.SVGTextContentElement +class org.w3c.dom.svg.SVGTextElement +class org.w3c.dom.svg.SVGTextPathElement +class org.w3c.dom.svg.SVGTextPositioningElement +class org.w3c.dom.svg.SVGTitleElement +class org.w3c.dom.svg.SVGTransform +class org.w3c.dom.svg.SVGTransformList +class org.w3c.dom.svg.SVGTransformable +class org.w3c.dom.svg.SVGURIReference +class org.w3c.dom.svg.SVGUnitTypes +class org.w3c.dom.svg.SVGUseElement +class org.w3c.dom.svg.SVGVKernElement +class org.w3c.dom.svg.SVGViewElement +class org.w3c.dom.svg.SVGViewSpec +class org.w3c.dom.svg.SVGZoomAndPan +class org.w3c.dom.svg.SVGZoomEvent +class org.apache.batik.w3c.dom.events.CustomEvent +class org.w3c.dom.events.DocumentEvent +class org.w3c.dom.events.EventException +class org.w3c.dom.events.Event +class org.w3c.dom.events.EventListener +class org.w3c.dom.events.EventTarget +class org.apache.batik.w3c.dom.events.KeyboardEvent +class org.w3c.dom.events.MouseEvent +class org.w3c.dom.events.MutationEvent +class org.apache.batik.w3c.dom.events.MutationNameEvent +class org.apache.batik.w3c.dom.events.TextEvent +class org.w3c.dom.events.UIEvent +class org.apache.batik.w3c.dom.ElementTraversal diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.RegistryEntry b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.RegistryEntry index 34472550f..585682083 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.RegistryEntry +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.RegistryEntry @@ -20,9 +20,7 @@ # $Id$ # ----------------------------------------------------------------------------- -# NOTE: the "codec" package is deprecated, there entries are kept here for compatibility with older JVM versions -# (uses "sun.image", which is only supported in Sun Java implementations and was retired in JDK 7) -#org.apache.batik.ext.awt.image.codec.png.PNGRegistryEntry +org.apache.batik.ext.awt.image.codec.png.PNGRegistryEntry org.apache.batik.ext.awt.image.codec.imageio.ImageIOJPEGRegistryEntry org.apache.batik.ext.awt.image.codec.imageio.ImageIOPNGRegistryEntry diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/NOTICE b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/NOTICE new file mode 100644 index 000000000..146dcd046 --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/NOTICE @@ -0,0 +1,18 @@ +Apache Batik +Copyright 1999-2020 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +This software contains code from the World Wide Web Consortium (W3C) for the +Document Object Model API (DOM API) and SVG Document Type Definition (DTD). + +This software contains code from the International Organisation for +Standardization for the definition of character entities used in the software's +documentation. + +This product includes images from the Tango Desktop Project +(http://tango.freedesktop.org/). + +This product includes images from the Pasodoble Icon Theme +(http://www.jesusda.com/projects/pasodoble). diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/Messages.properties b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/Messages.properties index 60bdd2627..15206868a 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/Messages.properties +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/Messages.properties @@ -42,7 +42,7 @@ SVGConverter.error.cannot.read.source = \ Error: cannot read source ({0}) SVGConverter.error.cannot.open.source = \ -Error: cannot open source {0} +Error: cannot open source {0} {1} SVGConverterURLSource.error.invalid.url = \ Error: invalid url ({0}) diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.bin.policy b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.bin.policy index c9ccd5cf3..dbd208315 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.bin.policy +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.bin.policy @@ -90,7 +90,7 @@ grant codeBase "${app.jar.base}/lib/batik-xml.jar" { permission java.security.AllPermission; }; - grant codeBase "${app.jar.base}/lib/xmlgraphics-commons-svn-trunk" { + grant codeBase "${app.jar.base}/lib/xmlgraphics-commons-${xmlgraphics.commons.version}" { permission java.security.AllPermission; }; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.policy b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.policy index de1350591..9d0fbb8f9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.policy +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/rasterizer/resources/rasterizer.policy @@ -30,11 +30,11 @@ grant codeBase "${app.dev.base}/lib/xerces_2_5_0.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.dev.base}/lib/fop-transcoder-allinone-svn-trunk.jar" { +grant codeBase "${app.dev.base}/lib/fop-transcoder-allinone-${xmlgraphics.commons.version}.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.dev.base}/lib/xmlgraphics-commons-svn-trunk.jar" { +grant codeBase "${app.dev.base}/lib/xmlgraphics-commons-${xmlgraphics.commons.version}.jar" { permission java.security.AllPermission; }; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.bin.policy b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.bin.policy index 5ccbf885b..4349c85ae 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.bin.policy +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.bin.policy @@ -90,7 +90,7 @@ grant codeBase "${app.jar.base}/lib/batik-xml.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.jar.base}/lib/xmlgraphics-commons-svn-trunk" { +grant codeBase "${app.jar.base}/lib/xmlgraphics-commons-${xmlgraphics.commons.version}" { permission java.security.AllPermission; }; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy index 6cf729eba..efcef1055 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy @@ -18,23 +18,115 @@ // $Id$ // ----------------------------------------------------------------------------- -grant codeBase "${app.dev.base}/classes/" { +grant codeBase "${app.jar.base}/xml-apis-ext-${xmlapis.version}.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.dev.base}/lib/xml-apis-1.3.04.jar" { +grant codeBase "${app.jar.base}/xml-apis-${xmlapis.version}.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.dev.base}/lib/xml-apis-ext-1.3.04.jar" { +grant codeBase "${app.jar.base}/xalan-${xalan.version}.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.dev.base}/lib/xerces_2_5_0.jar" { +grant codeBase "${app.jar.base}/xercesImpl-2.9.1.jar" { permission java.security.AllPermission; }; -grant codeBase "${app.dev.base}/lib/js.jar" { +grant codeBase "${app.jar.base}/../batik-rasterizer-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-svgrasterizer-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-ext-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-dom-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-css-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-svg-dom-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-gvt-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-parser-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-script-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-bridge-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-swing-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-transcoder-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-gui-util-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-awt-util-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-util-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-xml-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/fop-transcoder-allinone-${xmlgraphics.commons.version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/xmlgraphics-commons-${xmlgraphics.commons.version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-anim-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-codec-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-extension-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-svggen-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/batik-svgbrowser-${version}.jar" { + permission java.security.AllPermission; +}; + +grant codeBase "${app.jar.base}/js.jar" { permission java.lang.RuntimePermission "createClassLoader"; permission java.net.SocketPermission "*", "listen, connect, resolve, accept"; permission java.lang.RuntimePermission "accessDeclaredMembers"; @@ -46,7 +138,6 @@ grant codeBase "${app.dev.base}/lib/js.jar" { }; grant { - permission java.io.FilePermission "resources/org/apache/batik/dom/svg/resources/svg10.dtd", "read"; - permission java.io.FilePermission "resources/org/apache/batik/dom/svg/resources/UserAgentStyleSheet.css", "read"; + permission java.io.FilePermission "${app.jar.base}/batik-svg-dom-${version}.jar", "read"; }; diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/properties b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/ext/awt/image/codec/properties similarity index 100% rename from fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/awt/image/codec/properties rename to fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/ext/awt/image/codec/properties diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/resources/Messages.properties b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/ext/swing/resources/Messages.properties similarity index 100% rename from fine-xmlgraphics/xmlgraphics-batik/src/main/java/org/apache/batik/ext/swing/resources/Messages.properties rename to fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/ext/swing/resources/Messages.properties diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/extensions/README.txt b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/extensions/README.txt new file mode 100644 index 000000000..c256cf90e --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/extensions/README.txt @@ -0,0 +1,13 @@ +The Jar files in this directory start the same application as in the +parent directory, except they include the Batik Extensions on the jar +file class path. This means that that the Batik Extensions will work +with the applications started by these jar files. + +Great care should be used when using the Batik Extensions as these are +not part of the SVG standard. If you write content that uses these +extensions you must be aware that this is not conformant SVG content +and other SVG renderers will not render these documents. These +extensions should only be used in content used in closed systems. + +The primary purpose of these extensions is demonstrative and to +generate feedback to the development of the SVG standard. diff --git a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/transcoder/image/resources/Messages.properties b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/transcoder/image/resources/Messages.properties index a892fc41d..f855cf1f9 100644 --- a/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/transcoder/image/resources/Messages.properties +++ b/fine-xmlgraphics/xmlgraphics-batik/src/main/resources/org/apache/batik/transcoder/image/resources/Messages.properties @@ -28,7 +28,7 @@ jpeg.badoutput = \ Invalid output. JPEG transcoder only supports a byte stream output jpeg.unspecifiedQuality = \ -The JPEG quality has not been specified. Use the default one: no compression +The JPEG quality has not been specified. Use the default one: medium compression png.badoutput = \ Invalid output. PNG transcoder only supports a byte stream output diff --git a/fine-xmlgraphics/xmlgraphics-commons/README.md b/fine-xmlgraphics/xmlgraphics-commons/README.md index 7e64d82bd..7d20420df 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/README.md +++ b/fine-xmlgraphics/xmlgraphics-commons/README.md @@ -1,2 +1,2 @@ æºç åœ°å€:https://github.com/apache/xmlgraphics-commons
    -版本:2.2 \ No newline at end of file +版本:2.6 \ No newline at end of file diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java index ae4ee5550..ceaa79684 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java @@ -19,6 +19,8 @@ package org.apache.xmlgraphics.fonts; +import com.fr.third.org.apache.commons.io.IOUtils; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -29,8 +31,6 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import com.fr.third.org.apache.commons.io.IOUtils; - /** * This class provides a number of constants for glyph management. */ @@ -680,8 +680,8 @@ public final class Glyphs { String[] arr = new String[lines.size() * 2]; int pos = 0; StringBuffer buf = new StringBuffer(); - for (int i = 0, c = lines.size(); i < c; i++) { - String line = (String)lines.get(i); + for (Object line1 : lines) { + String line = (String) line1; int semicolon = line.indexOf(';'); if (semicolon <= 0) { continue; diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/GraphicsConstants.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/GraphicsConstants.java old mode 100644 new mode 100755 diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java index dae51a64a..0fd4acd8a 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/png/PNGImageEncoder.java @@ -601,9 +601,8 @@ public class PNGImageEncoder extends ImageEncoderImpl { ChunkStream cs = new ChunkStream("sBIT"); try { int[] significantBits = param.getSignificantBits(); - int len = significantBits.length; - for (int i = 0; i < len; i++) { - cs.writeByte(significantBits[i]); + for (int significantBit : significantBits) { + cs.writeByte(significantBit); } cs.writeToStream(dataOutput); } finally { @@ -682,8 +681,8 @@ public class PNGImageEncoder extends ImageEncoderImpl { ChunkStream cs = new ChunkStream("hIST"); try { int[] hist = param.getPaletteHistogram(); - for (int i = 0; i < hist.length; i++) { - cs.writeShort(hist[i]); + for (int aHist : hist) { + cs.writeShort(aHist); } cs.writeToStream(dataOutput); @@ -702,8 +701,8 @@ public class PNGImageEncoder extends ImageEncoderImpl { if (param instanceof PNGEncodeParam.Palette) { byte[] t = ((PNGEncodeParam.Palette)param).getPaletteTransparency(); - for (int i = 0; i < t.length; i++) { - cs.writeByte(t[i]); + for (byte aT : t) { + cs.writeByte(aT); } } else if (param instanceof PNGEncodeParam.Gray) { int t = ((PNGEncodeParam.Gray)param).getTransparentGray(); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoder.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoder.java index 28e6c444f..1e9ee7735 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoder.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoder.java @@ -382,15 +382,11 @@ public class TIFFImageEncoder extends ImageEncoderImpl { // Add extra fields specified via the encoding parameters. TIFFField[] extraFields = encodeParam.getExtraFields(); List extantTags = new ArrayList(fields.size()); - Iterator fieldIter = fields.iterator(); - while (fieldIter.hasNext()) { - TIFFField fld = (TIFFField)fieldIter.next(); + for (TIFFField fld : fields) { extantTags.add(fld.getTag()); } - int numExtraFields = extraFields.length; - for (int i = 0; i < numExtraFields; i++) { - TIFFField fld = extraFields[i]; + for (TIFFField fld : extraFields) { Integer tagValue = fld.getTag(); if (!extantTags.contains(tagValue)) { fields.add(fld); @@ -1003,10 +999,9 @@ public class TIFFImageEncoder extends ImageEncoderImpl { int dirSize = 2 + numEntries * 12 + 4; // Loop over fields adding the size of all values > 4 bytes. - Iterator iter = fields.iterator(); - while (iter.hasNext()) { + for (Object field1 : fields) { // Get the field. - TIFFField field = (TIFFField)iter.next(); + TIFFField field = (TIFFField) field1; // Determine the size of the field value. int valueSize = field.getCount() * SIZE_OF_TYPE[field.getType()]; @@ -1048,11 +1043,10 @@ public class TIFFImageEncoder extends ImageEncoderImpl { // Write number of fields in the IFD writeUnsignedShort(numEntries); - Iterator iter = fields.iterator(); - while (iter.hasNext()) { + for (Object field1 : fields) { // 12 byte field entry TIFFField - TIFFField field = (TIFFField)iter.next(); + TIFFField field = (TIFFField) field1; // byte 0-1 Tag that identifies a field int tag = field.getTag(); @@ -1086,8 +1080,8 @@ public class TIFFImageEncoder extends ImageEncoderImpl { writeLong(nextIFDOffset); // Write the tag values that did not fit into 4 bytes - for (int i = 0; i < tooBig.size(); i++) { - writeValues((TIFFField)tooBig.get(i)); + for (Object aTooBig : tooBig) { + writeValues((TIFFField) aTooBig); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFLZWDecoder.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFLZWDecoder.java index d96657467..c22748602 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFLZWDecoder.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/tiff/TIFFLZWDecoder.java @@ -170,8 +170,8 @@ public class TIFFLZWDecoder { */ public void writeString(byte[] string) { - for (int i = 0; i < string.length; i++) { - uncompData[dstIndex++] = string[i]; + for (byte aString : string) { + uncompData[dstIndex++] = aString; } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/util/SimpleRenderedImage.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/util/SimpleRenderedImage.java index d72c7f84b..9902d6177 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/util/SimpleRenderedImage.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/codec/util/SimpleRenderedImage.java @@ -273,9 +273,9 @@ public abstract class SimpleRenderedImage implements RenderedImage { prefix = prefix.toLowerCase(Locale.getDefault()); List names = new ArrayList(); - for (int i = 0; i < propertyNames.length; i++) { - if (propertyNames[i].startsWith(prefix)) { - names.add(propertyNames[i]); + for (String propertyName : propertyNames) { + if (propertyName.startsWith(prefix)) { + names.add(propertyName); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java index b159024fc..2aefbb927 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/ImageManager.java @@ -348,9 +348,8 @@ public class ImageManager { ImageInfo info = image.getInfo(); Image img = null; - int count = flavors.length; - for (int i = 0; i < count; i++) { - if (image.getFlavor().equals(flavors[i])) { + for (ImageFlavor flavor : flavors) { + if (image.getFlavor().equals(flavor)) { //Shortcut (the image is already in one of the requested formats) return image; } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java index 53f712f93..4f69c12d9 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/cache/ImageCache.java @@ -23,7 +23,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -293,9 +292,8 @@ public class ImageCache { private void doInvalidURIHouseKeeping() { final Set currentEntries = new HashSet(this.invalidURIs.keySet()); - final Iterator iter = currentEntries.iterator(); - while (iter.hasNext()) { - final String key = (String) iter.next(); + for (Object currentEntry : currentEntries) { + final String key = (String) currentEntry; removeInvalidURIIfExpired(key); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java index 04128528c..d51d38278 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java @@ -19,33 +19,32 @@ package org.apache.xmlgraphics.image.loader.impl; +import com.fr.third.org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.image.loader.ImageSessionContext; +import org.apache.xmlgraphics.image.loader.ImageSource; +import org.apache.xmlgraphics.image.loader.util.ImageUtil; +import org.apache.xmlgraphics.image.loader.util.SoftMapCache; +import org.apache.xmlgraphics.io.XmlSourceUtil; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageInputStream; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamSource; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.net.MalformedURLException; import java.net.URL; -import javax.imageio.ImageIO; -import javax.imageio.stream.ImageInputStream; -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stream.StreamSource; - -import com.fr.third.org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.xmlgraphics.image.loader.ImageSessionContext; -import org.apache.xmlgraphics.image.loader.ImageSource; -import org.apache.xmlgraphics.image.loader.util.ImageUtil; -import org.apache.xmlgraphics.image.loader.util.SoftMapCache; -import org.apache.xmlgraphics.io.XmlSourceUtil; - /** * Abstract base class for classes implementing ImageSessionContext. This class provides all the * special treatment for Source creation, i.e. it provides optimized Source objects where possible. @@ -119,15 +118,19 @@ public abstract class AbstractImageSessionContext implements ImageSessionContext /** {@inheritDoc} */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if ("close".equals(method.getName())) { - try { + try { + if ("close".equals(method.getName())) { + try { + return method.invoke(iin, args); + } finally { + IOUtils.closeQuietly(this.in); + this.in = null; + } + } else { return method.invoke(iin, args); - } finally { - IOUtils.closeQuietly(this.in); - this.in = null; } - } else { - return method.invoke(iin, args); + } catch (InvocationTargetException e) { + throw e.getCause(); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/CompositeImageLoader.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/CompositeImageLoader.java index 889511e64..f0ffcaa5e 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/CompositeImageLoader.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/CompositeImageLoader.java @@ -78,8 +78,7 @@ public class CompositeImageLoader extends AbstractImageLoader { public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session) throws ImageException, IOException { ImageException firstException = null; - for (int i = 0, c = this.loaders.length; i < c; i++) { - ImageLoader loader = this.loaders[i]; + for (ImageLoader loader : this.loaders) { try { Image img = loader.loadImage(info, hints, session); if (img != null && firstException != null) { diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java index 7e34868d9..5176962ba 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java @@ -19,11 +19,7 @@ package org.apache.xmlgraphics.image.loader.impl; -import java.io.IOException; -import java.util.Map; - import com.fr.third.org.apache.commons.io.output.ByteArrayOutputStream; - import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; @@ -32,6 +28,9 @@ import org.apache.xmlgraphics.image.writer.ImageWriterParams; import org.apache.xmlgraphics.image.writer.ImageWriterRegistry; import org.apache.xmlgraphics.util.MimeConstants; +import java.io.IOException; +import java.util.Map; + /** * This ImageConverter converts Rendered to PNG images. */ diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawPNG.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawPNG.java index 4c0a1fc22..edfca6141 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawPNG.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawPNG.java @@ -70,7 +70,7 @@ public class ImageLoaderRawPNG extends AbstractImageLoader { // Remove streams as we do things with them at some later time. XmlSourceUtil.removeStreams(src); SeekableStream seekStream = new ImageInputStreamSeekableStreamAdapter(in); - PNGFile im = new PNGFile(seekStream); + PNGFile im = new PNGFile(seekStream, info.getOriginalURI()); ImageRawPNG irpng = im.getImageRawPNG(info); return irpng; } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java index b1e1857ae..65ca62a5f 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java @@ -19,17 +19,16 @@ package org.apache.xmlgraphics.image.loader.impl; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - import com.fr.third.org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.MimeEnabledImageFlavor; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + /** * This class is an implementation of the Image interface exposing an InputStream for loading the * raw/undecoded image. diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/PNGFile.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/PNGFile.java index 7787fed75..c743520fb 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/PNGFile.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/PNGFile.java @@ -69,7 +69,7 @@ class PNGFile implements PNGConstants { private boolean hasPalette; private boolean hasAlphaPalette; - public PNGFile(InputStream stream) throws IOException, ImageException { + public PNGFile(InputStream stream, String uri) throws IOException, ImageException { if (!stream.markSupported()) { stream = new BufferedInputStream(stream); } @@ -107,12 +107,14 @@ class PNGFile implements PNGConstants { chunk = PNGChunk.readChunk(distream); parse_sRGB_chunk(chunk); } else { - // chunk = PNGChunk.readChunk(distream); + if (Character.isUpperCase(chunkType.charAt(0))) { + throw new ImageException("PNG unknown critical chunk: " + chunkType); + } PNGChunk.skipChunk(distream); } } catch (Exception e) { String msg = PropertyUtil.getString("PNGImageDecoder2"); - throw new RuntimeException(msg, e); + throw new RuntimeException(msg + " " + uri, e); } } while (true); } @@ -190,10 +192,6 @@ class PNGFile implements PNGConstants { private void parse_IHDR_chunk(PNGChunk chunk) { bitDepth = chunk.getInt1(8); - if (bitDepth != 8) { - // this is a limitation of the current implementation - throw new RuntimeException("Unsupported bit depth: " + bitDepth); - } colorType = chunk.getInt1(9); int compressionMethod = chunk.getInt1(10); if (compressionMethod != 0) { diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageIOUtil.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageIOUtil.java index f99bf2378..9adcce193 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageIOUtil.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageIOUtil.java @@ -104,9 +104,9 @@ public final class ImageIOUtil { */ public static void dumpMetadataToSystemOut(IIOMetadata iiometa) { String[] metanames = iiometa.getMetadataFormatNames(); - for (int j = 0; j < metanames.length; j++) { - System.out.println("--->" + metanames[j]); - dumpNodeToSystemOut(iiometa.getAsTree(metanames[j])); + for (String metaname : metanames) { + System.out.println("--->" + metaname); + dumpNodeToSystemOut(iiometa.getAsTree(metaname)); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java index 950406e1b..286d25427 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java @@ -300,8 +300,7 @@ public class ImageLoaderImageIO extends AbstractImageLoader { private ICC_Profile tryToExctractICCProfile(IIOMetadata iiometa) { ICC_Profile iccProf = null; String[] supportedFormats = iiometa.getMetadataFormatNames(); - for (int i = 0; i < supportedFormats.length; i++) { - String format = supportedFormats[i]; + for (String format : supportedFormats) { Element root = (Element) iiometa.getAsTree(format); if (PNG_METADATA_NODE.equals(format)) { iccProf = this diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java index 2507acbff..806645143 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java @@ -19,18 +19,9 @@ package org.apache.xmlgraphics.image.loader.pipeline; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - import com.fr.third.org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; @@ -43,6 +34,13 @@ import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry; import org.apache.xmlgraphics.image.loader.spi.ImageLoader; import org.apache.xmlgraphics.image.loader.util.Penalty; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.List; +import java.util.Map; + /** * Represents a pipeline of ImageConverters with an ImageLoader at the beginning of the * pipeline. @@ -292,9 +290,8 @@ public class ImageProviderPipeline { registry.getAdditionalPenalty(loader.getClass().getName())); } } - Iterator iter = converters.iterator(); - while (iter.hasNext()) { - ImageConverter converter = (ImageConverter)iter.next(); + for (Object converter1 : converters) { + ImageConverter converter = (ImageConverter) converter1; penalty = penalty.add(converter.getConversionPenalty()); if (registry != null) { penalty = penalty.add( diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/PipelineFactory.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/PipelineFactory.java index 638caef6f..eb1117b19 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/PipelineFactory.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/PipelineFactory.java @@ -23,7 +23,6 @@ import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -74,9 +73,8 @@ public class PipelineFactory { //Rebuild edge directory DefaultEdgeDirectory dir = new DefaultEdgeDirectory(); - Iterator iter = converters.iterator(); - while (iter.hasNext()) { - ImageConverter converter = (ImageConverter)iter.next(); + for (Object converter1 : converters) { + ImageConverter converter = (ImageConverter) converter1; Penalty penalty = Penalty.toPenalty(converter.getConversionPenalty()); penalty = penalty.add( registry.getAdditionalPenalty(converter.getClass().getName())); @@ -177,13 +175,12 @@ public class PipelineFactory { if (loaderFactories != null) { //Find best pipeline -> best loader - for (int i = 0, ci = loaderFactories.length; i < ci; i++) { - ImageLoaderFactory loaderFactory = loaderFactories[i]; + for (ImageLoaderFactory loaderFactory : loaderFactories) { ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(originalMime); - for (int j = 0, cj = flavors.length; j < cj; j++) { - ImageProviderPipeline pipeline = findPipeline(dir, flavors[j], destination); + for (ImageFlavor flavor : flavors) { + ImageProviderPipeline pipeline = findPipeline(dir, flavor, destination); if (pipeline != null) { - ImageLoader loader = loaderFactory.newImageLoader(flavors[j]); + ImageLoader loader = loaderFactory.newImageLoader(flavor); pipeline.setImageLoader(loader); candidates.add(pipeline); } @@ -235,9 +232,8 @@ public class PipelineFactory { prev = pred; } ImageProviderPipeline pipeline = new ImageProviderPipeline(manager.getCache(), null); - Iterator iter = stops.iterator(); - while (iter.hasNext()) { - ImageConversionEdge edge = (ImageConversionEdge)iter.next(); + for (Object stop : stops) { + ImageConversionEdge edge = (ImageConversionEdge) stop; pipeline.addConverter(edge.getImageConverter()); } return pipeline; @@ -254,10 +250,9 @@ public class PipelineFactory { public ImageProviderPipeline[] determineCandidatePipelines(ImageInfo imageInfo, ImageFlavor[] flavors) { List candidates = new java.util.ArrayList(); - int count = flavors.length; - for (int i = 0; i < count; i++) { + for (ImageFlavor flavor : flavors) { //Find the best pipeline for each flavor - ImageProviderPipeline pipeline = newImageConverterPipeline(imageInfo, flavors[i]); + ImageProviderPipeline pipeline = newImageConverterPipeline(imageInfo, flavor); if (pipeline == null) { continue; //No suitable pipeline found for flavor } @@ -280,10 +275,9 @@ public class PipelineFactory { public ImageProviderPipeline[] determineCandidatePipelines(Image sourceImage, ImageFlavor[] flavors) { List candidates = new java.util.ArrayList(); - int count = flavors.length; - for (int i = 0; i < count; i++) { + for (ImageFlavor flavor : flavors) { //Find the best pipeline for each flavor - ImageProviderPipeline pipeline = newImageConverterPipeline(sourceImage, flavors[i]); + ImageProviderPipeline pipeline = newImageConverterPipeline(sourceImage, flavor); if (pipeline != null) { candidates.add(pipeline); } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java index 4b3c2e416..3f03cadaa 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/loader/spi/ImageImplRegistry.java @@ -19,9 +19,11 @@ package org.apache.xmlgraphics.image.loader.spi; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -187,23 +189,19 @@ public class ImageImplRegistry { return; } String[] mimes = loaderFactory.getSupportedMIMETypes(); - for (int i = 0, ci = mimes.length; i < ci; i++) { - String mime = mimes[i]; - + for (String mime : mimes) { synchronized (loaders) { - Map flavorMap = (Map)loaders.get(mime); + Map flavorMap = (Map) loaders.get(mime); if (flavorMap == null) { - flavorMap = new java.util.HashMap(); + flavorMap = new HashMap(); loaders.put(mime, flavorMap); } ImageFlavor[] flavors = loaderFactory.getSupportedFlavors(mime); - for (int j = 0, cj = flavors.length; j < cj; j++) { - ImageFlavor flavor = flavors[j]; - - List factoryList = (List)flavorMap.get(flavor); + for (ImageFlavor flavor : flavors) { + List factoryList = (List) flavorMap.get(flavor); if (factoryList == null) { - factoryList = new java.util.ArrayList(); + factoryList = new ArrayList(); flavorMap.put(flavor, factoryList); } factoryList.add(loaderFactory); @@ -332,9 +330,8 @@ public class ImageImplRegistry { if (checkFlavor.isCompatible(flavor)) { List factoryList = (List)e.getValue(); if (factoryList != null && factoryList.size() > 0) { - Iterator factoryIter = factoryList.iterator(); - while (factoryIter.hasNext()) { - ImageLoaderFactory factory = (ImageLoaderFactory)factoryIter.next(); + for (Object aFactoryList : factoryList) { + ImageLoaderFactory factory = (ImageLoaderFactory) aFactoryList; if (factory.isSupported(imageInfo)) { matches.add(factory); } @@ -387,9 +384,8 @@ public class ImageImplRegistry { Map flavorMap = (Map)loaders.get(mime); if (flavorMap != null) { Set factories = new java.util.HashSet(); - Iterator iter = flavorMap.values().iterator(); - while (iter.hasNext()) { - List factoryList = (List)iter.next(); + for (Object o : flavorMap.values()) { + List factoryList = (List) o; factories.addAll(factoryList); } int factoryCount = factories.size(); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/rendered/AbstractRed.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/rendered/AbstractRed.java index 7ea2f12a9..ef7855bb2 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/rendered/AbstractRed.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/rendered/AbstractRed.java @@ -32,7 +32,6 @@ import java.awt.image.RenderedImage; import java.awt.image.SampleModel; import java.awt.image.WritableRaster; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -460,9 +459,8 @@ public abstract class AbstractRed implements CachableRed { if (ret != null) { return ret; } - Iterator i = srcs.iterator(); - while (i.hasNext()) { - RenderedImage ri = (RenderedImage)i.next(); + for (Object src : srcs) { + RenderedImage ri = (RenderedImage) src; ret = ri.getProperty(name); if (ret != null) { return ret; @@ -476,9 +474,8 @@ public abstract class AbstractRed implements CachableRed { String[] ret = new String[keys.size()]; keys.toArray(ret); - Iterator iter = srcs.iterator(); - while (iter.hasNext()) { - RenderedImage ri = (RenderedImage)iter.next(); + for (Object src : srcs) { + RenderedImage ri = (RenderedImage) src; String[] srcProps = ri.getPropertyNames(); if (srcProps.length != 0) { String[] tmp = new String[ret.length + srcProps.length]; diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java index c5a2318cb..78bb6668e 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistry.java @@ -166,9 +166,7 @@ public final class ImageWriterRegistry { if (entries == null) { return null; } - Iterator iter = entries.iterator(); - while (iter.hasNext()) { - ImageWriter writer = iter.next(); + for (ImageWriter writer : entries) { if (writer.isFunctional()) { return writer; } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java index b0969d762..e611d0a38 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java @@ -19,12 +19,12 @@ package org.apache.xmlgraphics.image.writer; -import java.awt.image.RenderedImage; +import com.fr.third.org.apache.commons.io.IOUtils; + import java.io.File; import java.io.IOException; import java.io.OutputStream; - -import com.fr.third.org.apache.commons.io.IOUtils; +import java.awt.image.RenderedImage; /** * Convenience methods around ImageWriter for the most important tasks. diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriter.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriter.java index e800f47f4..801ab6149 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriter.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriter.java @@ -46,8 +46,12 @@ public class ImageIOTIFFImageWriter extends ImageIOImageWriter { private static final String SUN_TIFF_NATIVE_FORMAT = "com_sun_media_imageio_plugins_tiff_image_1.0"; + private static final String JAVA_TIFF_NATIVE_FORMAT + = "javax_imageio_tiff_image_1.0"; private static final String SUN_TIFF_NATIVE_STREAM_FORMAT = "com_sun_media_imageio_plugins_tiff_stream_1.0"; + private static final String JAVA_TIFF_NATIVE_STREAM_FORMAT + = "javax_imageio_tiff_stream_1.0"; /** * Main constructor. @@ -65,14 +69,12 @@ public class ImageIOTIFFImageWriter extends ImageIOImageWriter { //it doesn't work properly through the standard metadata. Haven't figured out why //that happens. if (params.getResolution() != null) { - if (SUN_TIFF_NATIVE_FORMAT.equals(meta.getNativeMetadataFormatName())) { - //IIOMetadataNode root = (IIOMetadataNode)meta.getAsTree(SUN_TIFF_NATIVE_FORMAT); - IIOMetadataNode root = new IIOMetadataNode(SUN_TIFF_NATIVE_FORMAT); + if (SUN_TIFF_NATIVE_FORMAT.equals(meta.getNativeMetadataFormatName()) + || JAVA_TIFF_NATIVE_FORMAT.equals(meta.getNativeMetadataFormatName())) { + IIOMetadataNode root = new IIOMetadataNode(meta.getNativeMetadataFormatName()); IIOMetadataNode ifd = getChildNode(root, "TIFFIFD"); if (ifd == null) { ifd = new IIOMetadataNode("TIFFIFD"); - ifd.setAttribute("tagSets", - "com.sun.media.imageio.plugins.tiff.BaselineTIFFTagSet"); root.appendChild(ifd); } ifd.appendChild(createResolutionUnitField(params)); @@ -85,7 +87,7 @@ public class ImageIOTIFFImageWriter extends ImageIOImageWriter { "RowsPerStrip", Integer.toString(rows))); try { - meta.mergeTree(SUN_TIFF_NATIVE_FORMAT, root); + meta.mergeTree(meta.getNativeMetadataFormatName(), root); } catch (IIOInvalidTreeException e) { throw new RuntimeException("Cannot update image metadata: " + e.getMessage(), e); @@ -221,20 +223,27 @@ public class ImageIOTIFFImageWriter extends ImageIOImageWriter { //Try changing the Byte Order IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam); - Set names = new java.util.HashSet( - Arrays.asList(streamMetadata.getMetadataFormatNames())); - if (names.contains(SUN_TIFF_NATIVE_STREAM_FORMAT)) { - Node root = streamMetadata.getAsTree(SUN_TIFF_NATIVE_STREAM_FORMAT); + if (streamMetadata != null) { + Set names = new java.util.HashSet( + Arrays.asList(streamMetadata.getMetadataFormatNames())); + setFromTree(names, streamMetadata, endian, SUN_TIFF_NATIVE_STREAM_FORMAT); + setFromTree(names, streamMetadata, endian, JAVA_TIFF_NATIVE_STREAM_FORMAT); + } + return streamMetadata; + } + + private void setFromTree(Set names, IIOMetadata streamMetadata, Endianness endian, String format) { + if (names.contains(format)) { + Node root = streamMetadata.getAsTree(format); root.getFirstChild().getAttributes().item(0).setNodeValue(endian.toString()); try { - streamMetadata.setFromTree(SUN_TIFF_NATIVE_STREAM_FORMAT, root); + streamMetadata.setFromTree(format, root); } catch (IIOInvalidTreeException e) { //This should not happen since we check if the format is supported. throw new IllegalStateException( "Could not replace TIFF stream metadata: " + e.getMessage(), e); } } - return streamMetadata; } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java index 01bf84648..8ce6720be 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java @@ -17,11 +17,11 @@ package org.apache.xmlgraphics.io; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; +import com.fr.third.org.apache.commons.io.IOUtils; +import org.apache.xmlgraphics.image.loader.ImageSource; +import org.apache.xmlgraphics.image.loader.util.ImageInputStreamAdapter; +import org.apache.xmlgraphics.image.loader.util.ImageUtil; +import org.xml.sax.InputSource; import javax.xml.transform.Source; import javax.xml.transform.TransformerFactory; @@ -29,14 +29,11 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; - -import org.xml.sax.InputSource; - -import com.fr.third.org.apache.commons.io.IOUtils; - -import org.apache.xmlgraphics.image.loader.ImageSource; -import org.apache.xmlgraphics.image.loader.util.ImageInputStreamAdapter; -import org.apache.xmlgraphics.image.loader.util.ImageUtil; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; /** * A utility class for handling {@link Source} objects, more specficially the streams that back diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GeneralGraphics2DImagePainter.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GeneralGraphics2DImagePainter.java index 3b0065435..411aa0f2c 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GeneralGraphics2DImagePainter.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GeneralGraphics2DImagePainter.java @@ -25,4 +25,5 @@ import org.apache.xmlgraphics.ps.PSGenerator; public interface GeneralGraphics2DImagePainter extends Graphics2DImagePainter { Graphics2D getGraphics(boolean textAsShapes, PSGenerator gen); + void addFallbackFont(String name, Object font); } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java index 03fc9550e..4ad28af16 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithTransparency.java @@ -73,7 +73,7 @@ public class GraphicsConfigurationWithTransparency extends AbstractGraphicsConfi * @return the bounds of the document page */ public Rectangle getBounds() { - return null; + return new Rectangle(); } /** diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java index 9a4a9e9a8..35494b865 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/GraphicsConfigurationWithoutTransparency.java @@ -84,6 +84,6 @@ public class GraphicsConfigurationWithoutTransparency extends AbstractGraphicsCo @Override public Rectangle getBounds() { - return null; + return new Rectangle(); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java index e0f18fd40..c17cfeb99 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java @@ -201,9 +201,9 @@ public class ColorWithAlternatives extends Color { */ public Color getFirstAlternativeOfType(int colorSpaceType) { if (hasAlternativeColors()) { - for (int i = 0, c = this.alternativeColors.length; i < c; i++) { - if (this.alternativeColors[i].getColorSpace().getType() == colorSpaceType) { - return this.alternativeColors[i]; + for (Color alternativeColor : this.alternativeColors) { + if (alternativeColor.getColorSpace().getType() == colorSpaceType) { + return alternativeColor; } } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java index 62b155f5f..ee3f66379 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java @@ -73,9 +73,9 @@ public class NamedColorProfile { */ public NamedColorSpace getNamedColor(String name) { if (this.namedColors != null) { - for (int i = 0, c = this.namedColors.length; i < c; i++) { - if (this.namedColors[i].getColorName().equals(name)) { - return this.namedColors[i]; + for (NamedColorSpace namedColor : this.namedColors) { + if (namedColor.getColorName().equals(name)) { + return namedColor; } } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java index e05523abc..130738009 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java @@ -23,6 +23,7 @@ package org.apache.xmlgraphics.java2d.ps; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; +import java.awt.Composite; import java.awt.Dimension; import java.awt.GradientPaint; import java.awt.Graphics; @@ -248,8 +249,11 @@ public class PSGraphics2D extends AbstractGraphics2D { * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) */ - public boolean drawImage(Image img, int x, int y, - ImageObserver observer) { + public boolean drawImage(Image img, int x, int y, ImageObserver observer) { + return drawImage(img, x, y, observer, null); + } + + public boolean drawImage(Image img, int x, int y, ImageObserver observer, Color mask) { preparePainting(); if (DEBUG) { System.out.println("drawImage: " + x + ", " + y + " " + img.getClass().getName()); @@ -281,8 +285,7 @@ public class PSGraphics2D extends AbstractGraphics2D { gen.concatMatrix(at); Shape imclip = getClip(); writeClip(imclip); - PSImageUtils.renderBitmapImage(buf, - x, y, width, height, gen); + PSImageUtils.renderBitmapImage(buf, x, y, width, height, gen, mask); gen.restoreGraphicsState(); } catch (IOException ioe) { handleIOException(ioe); @@ -566,7 +569,7 @@ public class PSGraphics2D extends AbstractGraphics2D { // create pattern with texture and use it for filling of a graphics object PSTilingPattern psTilingPattern = new PSTilingPattern("Pattern1", (TexturePaint)paint, 0, 0, 3, null); - gen.write(psTilingPattern.toString()); + gen.write(psTilingPattern.toString(gen.isAcrobatDownsample())); gen.writeln("/Pattern " + gen.mapCommand("setcolorspace")); gen.writeln(psTilingPattern.getName() + " " + gen.mapCommand("setcolor")); } catch (IOException ioe) { @@ -682,7 +685,7 @@ public class PSGraphics2D extends AbstractGraphics2D { Shape imclip = getClip(); writeClip(imclip); PSImageUtils.renderBitmapImage(img, - 0, 0, img.getWidth(), img.getHeight(), gen); + 0, 0, img.getWidth(), img.getHeight(), gen, null); gen.restoreGraphicsState(); } catch (IOException ioe) { handleIOException(ioe); @@ -785,35 +788,42 @@ public class PSGraphics2D extends AbstractGraphics2D { * @see #setClip */ public void fill(Shape s) { - preparePainting(); - try { - gen.saveGraphicsState(); + if (!hasAlpha()) { + preparePainting(); + try { + gen.saveGraphicsState(); - AffineTransform trans = getTransform(); - boolean newTransform = !trans.isIdentity(); + AffineTransform trans = getTransform(); + boolean newTransform = !trans.isIdentity(); - if (newTransform) { - gen.concatMatrix(trans); - } - Shape imclip = getClip(); - if (shouldBeClipped(imclip, s)) { - writeClip(imclip); - } + if (newTransform) { + gen.concatMatrix(trans); + } + Shape imclip = getClip(); + if (shouldBeClipped(imclip, s)) { + writeClip(imclip); + } - establishColor(getColor()); + establishColor(getColor()); - applyPaint(getPaint(), true); + applyPaint(getPaint(), true); - gen.writeln(gen.mapCommand("newpath")); - int windingRule = processShape(s, true); - doDrawing(true, false, + gen.writeln(gen.mapCommand("newpath")); + int windingRule = processShape(s, true); + doDrawing(true, false, windingRule == PathIterator.WIND_EVEN_ODD); - gen.restoreGraphicsState(); - } catch (IOException ioe) { - handleIOException(ioe); + gen.restoreGraphicsState(); + } catch (IOException ioe) { + handleIOException(ioe); + } } } + private boolean hasAlpha() { + Composite composite = getComposite(); + return composite instanceof AlphaComposite && ((AlphaComposite) composite).getAlpha() == 0f; + } + /** * Commits a painting operation. * @param fill filling diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java index 8f32750ab..04bd55faa 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java @@ -19,9 +19,13 @@ package org.apache.xmlgraphics.java2d.ps; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.util.List; /** @@ -361,7 +365,7 @@ public class PSTilingPattern { * * @return The string which contains postscript code of pattern definition */ - public String toString() { + public String toString(boolean acrobatDownsample) { StringBuffer sb = new StringBuffer("<<\n"); sb.append("/PatternType " + this.patternType + "\n"); sb.append("/PaintType " + paintType + "\n"); @@ -393,26 +397,18 @@ public class PSTilingPattern { // define color image: width height bits/comp matrix // datasrc0 datasrcncomp-1 multi ncomp colorimage - sb.append(width + " " + height + " 8 " + "matrix\n"); // width height bits/comp matrix - int [] argb = new int[width * height]; // datasrc0 datasrcncomp-1 - sb.append("{<"); - texture.getImage().getRGB(0, 0, width, height, argb, 0, width); - int count = 0; - for (int i = 0; i < argb.length; i++) { - if ((i % width == 0) || (count > 249)) { - sb.append("\n"); - count = 0; // line should not be longer than 255 characters - } - // delete alpha canal and write to output - StringBuffer sRGB = new StringBuffer(Integer.toHexString(argb[i] & 0x00ffffff)); - if (sRGB.length() != 6) { - sRGB.insert(0, "000000"); // zero padding - sRGB = new StringBuffer(sRGB.substring(sRGB.length() - 6)); - } - sb.append(sRGB); - count += 6; + // width height bits/comp matrix + int bits = 8; + if (acrobatDownsample) { + bits = 4; } - sb.append("\n>} false 3 colorimage"); // multi ncomp colorimage + sb.append(width).append(" ").append(height).append(" ").append(bits).append(" ").append("matrix\n"); + int [] argb = new int[width * height]; // datasrc0 datasrcncomp-1 + getAsRGB().getRGB(0, 0, width, height, argb, 0, width); + + writeImage(sb, argb, width, bits); + + sb.append(" false 3 colorimage"); // multi ncomp colorimage } else { sb.append(paintProc); } @@ -429,6 +425,58 @@ public class PSTilingPattern { return sb.toString(); } + private void writeImage(StringBuffer sb, int[] argb, int width, int bits) { + int count = 0; + sb.append("{<"); + for (int i = 0; i < argb.length; i++) { + if ((i % width == 0) || (count > 249)) { + sb.append('\n'); + count = 0; // line should not be longer than 255 characters + } + if (bits == 4) { + Color c = new Color(argb[i]); + int v = c.getRed() / 16; + String s = Integer.toHexString(v); + sb.append(s); + + v = c.getGreen() / 16; + s = Integer.toHexString(v); + sb.append(s); + + v = c.getBlue() / 16; + s = Integer.toHexString(v); + sb.append(s); + + count += 3; + } else { + // delete alpha canal and write to output + StringBuffer sRGB = new StringBuffer(Integer.toHexString(argb[i] & 0x00ffffff)); + if (sRGB.length() != 6) { + sRGB.insert(0, "000000"); // zero padding + sRGB = new StringBuffer(sRGB.substring(sRGB.length() - 6)); + } + sb.append(sRGB); + count += 6; + } + } + sb.append("\n>}"); + } + + private BufferedImage getAsRGB() { + BufferedImage img = texture.getImage(); + if (img.getType() != BufferedImage.TYPE_INT_RGB) { + BufferedImage buf = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); + Graphics2D g = buf.createGraphics(); + g.setComposite(AlphaComposite.SrcOver); + g.setBackground(Color.white); + g.fillRect(0, 0, img.getWidth(), img.getHeight()); + g.drawImage(img, 0, 0, null); + g.dispose(); + return buf; + } + return img; + } + /** {@inheritDoc} */ public int hashCode() { return diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/ImageFormGenerator.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/ImageFormGenerator.java index a249a6d01..8f7ee383b 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/ImageFormGenerator.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/ImageFormGenerator.java @@ -114,7 +114,7 @@ public class ImageFormGenerator extends FormGenerator { return "/ASCII85Decode filter " + implicitFilter + " filter"; } else { if (gen.getPSLevel() >= 3) { - return "/ASCII85Decode filter /FlateDecode filter"; + return "/ASCII85Decode filter"; } else { return "/ASCII85Decode filter /RunLengthDecode filter"; } @@ -133,6 +133,12 @@ public class ImageFormGenerator extends FormGenerator { dataSource = "{ " + getDataName() + " i get /i i 1 add store } bind"; } else { dataSource = getDataName(); + if (gen.getPSLevel() >= 3) { + String implicitFilter = encoder.getImplicitFilter(); + if (implicitFilter == null) { + dataSource += " /FlateDecode filter"; + } + } } AffineTransform at = new AffineTransform(); at.scale(getDimensions().getWidth(), getDimensions().getHeight()); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSDictionary.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSDictionary.java index 75c8cc338..965d6949e 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSDictionary.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSDictionary.java @@ -19,7 +19,7 @@ package org.apache.xmlgraphics.ps; -import java.util.Iterator; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -196,9 +196,9 @@ public class PSDictionary extends java.util.HashMap { } Token valueToken = nextToken(str, keyToken.endIndex + 1); String[] braces = null; - for (int i = 0; i < BRACES.length; i++) { - if (valueToken.value.startsWith(BRACES[i][OPENING])) { - braces = BRACES[i]; + for (String[] brace : BRACES) { + if (valueToken.value.startsWith(brace[OPENING])) { + braces = brace; break; } } @@ -276,8 +276,7 @@ public class PSDictionary extends java.util.HashMap { /** {@inheritDoc} */ public int hashCode() { int hashCode = 7; - for (Iterator it = values().iterator(); it.hasNext();) { - Object value = it.next(); + for (Object value : values()) { hashCode += value.hashCode(); } return hashCode; @@ -289,15 +288,14 @@ public class PSDictionary extends java.util.HashMap { return ""; } StringBuffer sb = new StringBuffer("<<\n"); - for (Iterator it = super.keySet().iterator(); it.hasNext();) { - String key = (String) it.next(); + for (Object o : super.keySet()) { + String key = (String) o; sb.append(" " + key + " "); Object obj = super.get(key); - if (obj instanceof java.util.ArrayList) { - List array = (List)obj; + if (obj instanceof ArrayList) { + List array = (List) obj; StringBuilder str = new StringBuilder("["); - for (int i = 0; i < array.size(); i++) { - Object element = array.get(i); + for (Object element : array) { str.append(element + " "); } String str2 = str.toString().trim(); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java index d4724de32..e72157291 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java @@ -19,17 +19,16 @@ package org.apache.xmlgraphics.ps; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; - import com.fr.third.org.apache.commons.io.EndianUtils; import com.fr.third.org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.fonts.Glyphs; import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream; import org.apache.xmlgraphics.util.io.SubInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; + // CSOFF: HideUtilityClassConstructor /** diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java index 7f4e996e0..04a41b82e 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java @@ -19,29 +19,26 @@ package org.apache.xmlgraphics.ps; -import java.awt.Color; -import java.awt.color.ColorSpace; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.DateFormat; -import java.util.Date; -import java.util.Stack; - -import javax.xml.transform.Source; - import com.fr.third.org.apache.commons.io.IOUtils; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.xmlgraphics.java2d.color.ColorUtil; import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.xmlgraphics.ps.dsc.ResourceTracker; import org.apache.xmlgraphics.util.DoubleFormatUtil; +import javax.xml.transform.Source; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.DateFormat; +import java.util.Date; +import java.util.Stack; +import java.awt.Color; +import java.awt.color.ColorSpace; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + /** * This class is used to output PostScript code to an OutputStream. This class assumes that * the {@link PSProcSets#STD_PROCSET} has been added to the PostScript file. @@ -71,6 +68,7 @@ public class PSGenerator implements PSCommandMap { private Log log = LogFactory.getLog(getClass()); private OutputStream out; private int psLevel = DEFAULT_LANGUAGE_LEVEL; + private boolean acrobatDownsample; private boolean commentsEnabled = true; private boolean compactMode = true; private PSCommandMap commandMap = PSProcSets.STD_COMMAND_MAP; @@ -166,6 +164,14 @@ public class PSGenerator implements PSCommandMap { this.psLevel = level; } + public boolean isAcrobatDownsample() { + return acrobatDownsample; + } + + public void setAcrobatDownsample(boolean b) { + acrobatDownsample = b; + } + /** * Attempts to resolve the given URI. PSGenerator should be subclasses to provide more * sophisticated URI resolution. @@ -680,8 +686,7 @@ public class PSGenerator implements PSCommandMap { ColorWithAlternatives colExt = (ColorWithAlternatives)color; //Alternative colors have priority Color[] alt = colExt.getAlternativeColors(); - for (int i = 0, c = alt.length; i < c; i++) { - Color col = alt[i]; + for (Color col : alt) { established = establishColorFromColor(codeBuffer, col); if (established) { break; diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java index a93da72c7..3d5ccb4f3 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java @@ -19,6 +19,16 @@ package org.apache.xmlgraphics.ps; +import com.fr.third.org.apache.commons.io.IOUtils; +import org.apache.xmlgraphics.util.io.ASCII85OutputStream; +import org.apache.xmlgraphics.util.io.Finalizable; +import org.apache.xmlgraphics.util.io.FlateEncodeOutputStream; +import org.apache.xmlgraphics.util.io.RunLengthEncodeOutputStream; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Arrays; import java.awt.Color; import java.awt.Dimension; import java.awt.color.ColorSpace; @@ -30,17 +40,6 @@ import java.awt.image.DataBufferByte; import java.awt.image.IndexColorModel; import java.awt.image.Raster; import java.awt.image.RenderedImage; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Arrays; - -import com.fr.third.org.apache.commons.io.IOUtils; - -import org.apache.xmlgraphics.util.io.ASCII85OutputStream; -import org.apache.xmlgraphics.util.io.Finalizable; -import org.apache.xmlgraphics.util.io.FlateEncodeOutputStream; -import org.apache.xmlgraphics.util.io.RunLengthEncodeOutputStream; // CSOFF: HideUtilityClassConstructor @@ -463,7 +462,7 @@ public class PSImageUtils { * @throws IOException In case of an I/O problem while rendering the image */ public static void renderBitmapImage(RenderedImage img, - float x, float y, float w, float h, PSGenerator gen) + float x, float y, float w, float h, PSGenerator gen, Color mask) throws IOException { Rectangle2D targetRect = new Rectangle2D.Double(x, y, w, h); ImageEncoder encoder = ImageEncodingHelper.createRenderedImageEncoder(img); @@ -472,7 +471,11 @@ public class PSImageUtils { ImageEncodingHelper helper = new ImageEncodingHelper(img); ColorModel cm = helper.getEncodedColorModel(); - writeImage(encoder, imgDim, imgDescription, targetRect, cm, gen, img); + if (mask == null) { + writeImage(encoder, imgDim, imgDescription, targetRect, cm, gen, img); + } else { + writeImage(encoder, imgDim, imgDescription, targetRect, cm, gen, img, mask); + } } /** diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSProcSets.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSProcSets.java index d410d6e11..2e02b72d3 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSProcSets.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSProcSets.java @@ -21,7 +21,6 @@ package org.apache.xmlgraphics.ps; import java.io.IOException; import java.util.Collections; -import java.util.Iterator; import java.util.Map; /** @@ -99,9 +98,8 @@ public final class PSProcSets { gen.writeln("/bd{bind def}bind def"); gen.writeln("/ld{load def}bd"); - Iterator iter = STANDARD_MACROS.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry)iter.next(); + for (Object o : STANDARD_MACROS.entrySet()) { + Map.Entry entry = (Map.Entry) o; gen.writeln("/" + entry.getValue() + "/" + entry.getKey() + " ld"); } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSState.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSState.java index 97b5f9afd..7b0ef38e4 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSState.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/PSState.java @@ -221,8 +221,8 @@ public class PSState implements Serializable { * @exception IOException In case of an I/O problem */ public void reestablish(PSGenerator gen) throws IOException { - for (int i = 0, len = transformConcatList.size(); i < len; i++) { - gen.concatMatrix((AffineTransform)transformConcatList.get(i)); + for (Object aTransformConcatList : transformConcatList) { + gen.concatMatrix((AffineTransform) aTransformConcatList); } gen.useLineCap(linecap); gen.useLineWidth(linewidth); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java index d2ab1e873..b23953076 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java @@ -23,7 +23,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; @@ -250,9 +249,8 @@ public class DSCParser implements DSCParserConstants { this.filterListener.processEvent(this.currentEvent, this); } if (this.listeners != null) { - Iterator iter = this.listeners.iterator(); - while (iter.hasNext()) { - ((DSCListener)iter.next()).processEvent(this.currentEvent, this); + for (Object listener : this.listeners) { + ((DSCListener) listener).processEvent(this.currentEvent, this); } } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/EventRecorder.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/EventRecorder.java index 2dce74945..b03917386 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/EventRecorder.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/EventRecorder.java @@ -20,7 +20,6 @@ package org.apache.xmlgraphics.ps.dsc; import java.io.IOException; -import java.util.Iterator; import java.util.List; import org.apache.xmlgraphics.ps.dsc.events.DSCComment; @@ -38,15 +37,13 @@ public class EventRecorder implements DSCHandler { * @throws IOException In case of an I/O error */ public void replay(DSCHandler handler) throws IOException { - Iterator iter = events.iterator(); - while (iter.hasNext()) { - Object obj = iter.next(); + for (Object obj : events) { if (obj instanceof PSLine) { - handler.line(((PSLine)obj).getLine()); + handler.line(((PSLine) obj).getLine()); } else if (obj instanceof PSComment) { - handler.comment(((PSComment)obj).getComment()); + handler.comment(((PSComment) obj).getComment()); } else if (obj instanceof DSCComment) { - handler.handleDSCComment((DSCComment)obj); + handler.handleDSCComment((DSCComment) obj); } else { throw new IllegalStateException("Unsupported class type"); } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/ResourceTracker.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/ResourceTracker.java index 798607d4d..fcf34362e 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/ResourceTracker.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/ResourceTracker.java @@ -22,7 +22,6 @@ package org.apache.xmlgraphics.ps.dsc; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -145,9 +144,8 @@ public class ResourceTracker { */ public void notifyResourceUsageOnPage(Collection resources) { preparePageResources(); - Iterator iter = resources.iterator(); - while (iter.hasNext()) { - PSResource res = (PSResource)iter.next(); + for (Object resource : resources) { + PSResource res = (PSResource) resource; notifyResourceUsageOnPage(res); } } @@ -198,9 +196,8 @@ public class ResourceTracker { */ public void writeDocumentResources(PSGenerator gen) throws IOException { if (usedResources != null) { - Iterator iter = usedResources.iterator(); - while (iter.hasNext()) { - PSResource res = (PSResource)iter.next(); + for (Object usedResource : usedResources) { + PSResource res = (PSResource) usedResource; if (documentSuppliedResources == null || !documentSuppliedResources.contains(res)) { registerNeededResource(res); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/events/AbstractResourcesDSCComment.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/events/AbstractResourcesDSCComment.java index 036b8023f..da5dabb53 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/events/AbstractResourcesDSCComment.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/ps/dsc/events/AbstractResourcesDSCComment.java @@ -149,14 +149,13 @@ public abstract class AbstractResourcesDSCComment extends AbstractDSCComment { StringBuffer sb = new StringBuffer(); sb.append("%%").append(getName()).append(": "); boolean first = true; - Iterator i = resources.iterator(); - while (i.hasNext()) { + for (Object resource : resources) { if (!first) { gen.writeln(sb.toString()); sb.setLength(0); sb.append("%%+ "); } - PSResource res = (PSResource)i.next(); + PSResource res = (PSResource) resource; sb.append(res.getResourceSpecification()); first = false; } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/ClasspathResource.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/ClasspathResource.java index 3ede2c237..06d7a58a1 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/ClasspathResource.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/ClasspathResource.java @@ -25,7 +25,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -113,9 +112,8 @@ public final class ClasspathResource { Enumeration e; try { - Iterator it = getClassLoadersForResources().iterator(); - while (it.hasNext()) { - ClassLoader classLoader = (ClassLoader) it.next(); + for (Object o1 : getClassLoadersForResources()) { + ClassLoader classLoader = (ClassLoader) o1; e = classLoader.getResources(MANIFEST_PATH); @@ -124,11 +122,8 @@ public final class ClasspathResource { try { final Manifest manifest = new Manifest(u.openStream()); final Map entries = manifest.getEntries(); - final Iterator entrysetiterator = entries.entrySet() - .iterator(); - while (entrysetiterator.hasNext()) { - final Map.Entry entry = (Map.Entry) entrysetiterator - .next(); + for (Object o : entries.entrySet()) { + final Map.Entry entry = (Map.Entry) o; final String name = (String) entry.getKey(); final Attributes attributes = (Attributes) entry .getValue(); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/Service.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/Service.java index 9b30153c4..fd4bd6ba3 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/Service.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/Service.java @@ -19,6 +19,8 @@ package org.apache.xmlgraphics.util; +import com.fr.third.org.apache.commons.io.IOUtils; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -30,8 +32,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import com.fr.third.org.apache.commons.io.IOUtils; - /** * This class handles looking up service providers on the class path. * It implements the system described in: diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/ASCII85OutputStream.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/ASCII85OutputStream.java index e08462f97..ad12efdd4 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/ASCII85OutputStream.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/ASCII85OutputStream.java @@ -153,10 +153,10 @@ public class ASCII85OutputStream extends FilterOutputStream }; if (DEBUG) { - for (int i = 0; i < ret.length; i++) { - if (ret[i] < 33 || ret[i] > 117) { + for (byte aRet : ret) { + if (aRet < 33 || aRet > 117) { System.out.println("Illegal char value " - + Integer.valueOf(ret[i])); + + (int) aRet); } } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/RunLengthEncodeOutputStream.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/RunLengthEncodeOutputStream.java index 7835d6c7f..e6a715e2c 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/RunLengthEncodeOutputStream.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/io/RunLengthEncodeOutputStream.java @@ -140,8 +140,8 @@ public class RunLengthEncodeOutputStream extends FilterOutputStream public void write(byte[] b) throws IOException { - for (int i = 0; i < b.length; i++) { - this.write(b[i]); + for (byte aB : b) { + this.write(aB); } } diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/CommonURIResolver.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/CommonURIResolver.java index a5f3182f2..5ec3107e7 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/CommonURIResolver.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/CommonURIResolver.java @@ -70,9 +70,8 @@ public class CommonURIResolver implements URIResolver { /** {@inheritDoc} */ public Source resolve(String href, String base) { synchronized (uriResolvers) { - Iterator it = uriResolvers.iterator(); - while (it.hasNext()) { - final URIResolver currentResolver = (URIResolver) it.next(); + for (Object uriResolver : uriResolvers) { + final URIResolver currentResolver = (URIResolver) uriResolver; try { final Source result = currentResolver.resolve(href, base); if (result != null) { diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java index a294dc5d1..a97cbd439 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java @@ -19,16 +19,15 @@ package org.apache.xmlgraphics.util.uri; +import com.fr.third.org.apache.commons.io.IOUtils; +import org.apache.xmlgraphics.util.WriterOutputStream; +import org.apache.xmlgraphics.util.io.Base64EncodeStream; + import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.io.Writer; -import com.fr.third.org.apache.commons.io.IOUtils; - -import org.apache.xmlgraphics.util.WriterOutputStream; -import org.apache.xmlgraphics.util.io.Base64EncodeStream; - /** * Utility classes for generating RFC 2397 data URLs. */ diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/Metadata.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/Metadata.java index 2fc54a29f..d1feb7512 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/Metadata.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/Metadata.java @@ -84,9 +84,8 @@ public class Metadata implements XMLizable, PropertyAccess { */ public void mergeInto(Metadata target, List exclude) { XMPSchemaRegistry registry = XMPSchemaRegistry.getInstance(); - Iterator iter = properties.values().iterator(); - while (iter.hasNext()) { - XMPProperty prop = (XMPProperty)iter.next(); + for (Object o : properties.values()) { + XMPProperty prop = (XMPProperty) o; XMPSchema schema = registry.getSchema(prop.getNamespace()); if (!exclude.contains(schema.getClass())) { MergeRuleSet rules = schema.getDefaultMergeRuleSet(); @@ -120,9 +119,8 @@ public class Metadata implements XMLizable, PropertyAccess { boolean first = true; boolean empty = true; - Iterator props = properties.values().iterator(); - while (props.hasNext()) { - XMPProperty prop = (XMPProperty)props.next(); + for (Object o : properties.values()) { + XMPProperty prop = (XMPProperty) o; if (prop.getName().getNamespaceURI().equals(ns)) { if (first) { if (prefix == null) { diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java index 46f488226..ebaba0c71 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java @@ -19,18 +19,17 @@ package org.apache.xmlgraphics.xmp; +import com.fr.third.org.apache.commons.io.IOUtils; +import com.fr.third.org.apache.commons.io.output.ByteArrayOutputStream; + +import javax.xml.transform.TransformerException; +import javax.xml.transform.stream.StreamSource; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.stream.StreamSource; - -import com.fr.third.org.apache.commons.io.IOUtils; -import com.fr.third.org.apache.commons.io.output.ByteArrayOutputStream; - /** * This class is a parser for XMP packets. By default, it tries to locate the first XMP packet * it finds and parses it. diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPParser.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPParser.java index 5e7d8b637..e907e8981 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPParser.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPParser.java @@ -21,6 +21,7 @@ package org.apache.xmlgraphics.xmp; import java.net.URL; +import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; @@ -54,6 +55,8 @@ public final class XMPParser { */ public static Metadata parseXMP(Source src) throws TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); + tFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + tFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); Transformer transformer = tFactory.newTransformer(); XMPHandler handler = createXMPHandler(); SAXResult res = new SAXResult(handler); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java index 333b20b1c..ab6d0b4d8 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java @@ -73,7 +73,7 @@ public class XMPSchemaAdapter { */ private void addStringToArray(String propName, String value, XMPArrayType arrayType) { if (value == null || value.length() == 0) { - throw new IllegalArgumentException("Value must not be empty"); + throw new IllegalArgumentException("'" + propName + "' value must not be empty"); } addObjectToArray(propName, value, arrayType); } @@ -86,7 +86,7 @@ public class XMPSchemaAdapter { */ protected void addObjectToArray(String propName, Object value, XMPArrayType arrayType) { if (value == null) { - throw new IllegalArgumentException("Value must not be null"); + throw new IllegalArgumentException("'" + propName + "' value must not be null"); } QName name = getQName(propName); XMPProperty prop = meta.getProperty(name); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPStructure.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPStructure.java index cfc6342b5..86f3d20be 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPStructure.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/XMPStructure.java @@ -88,11 +88,10 @@ public class XMPStructure extends XMPComplexValue implements PropertyAccess { atts.clear(); handler.startElement(XMPConstants.RDF_NAMESPACE, "RDF", "rdf:Description", atts); - Iterator props = properties.values().iterator(); - while (props.hasNext()) { - XMPProperty prop = (XMPProperty)props.next(); + for (Object o : properties.values()) { + XMPProperty prop = (XMPProperty) o; //if (prop.getName().getNamespaceURI().equals(ns)) { - prop.toSAX(handler); + prop.toSAX(handler); //} } handler.endElement(XMPConstants.RDF_NAMESPACE, "RDF", "rdf:Description"); diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java index 1de27b566..bbe054e4f 100644 --- a/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/java/org/apache/xmlgraphics/xmp/schemas/DublinCoreAdapter.java @@ -150,9 +150,9 @@ public class DublinCoreAdapter extends XMPSchemaAdapter { Date[] dates = getDates(); if (dates != null) { Date latest = null; - for (int i = 0, c = dates.length; i < c; i++) { - if (latest == null || dates[i].getTime() > latest.getTime()) { - latest = dates[i]; + for (Date date : dates) { + if (latest == null || date.getTime() > latest.getTime()) { + latest = date; } } return latest; diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/fonts/glyphlist.txt b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/fonts/glyphlist.txt new file mode 100644 index 000000000..0304ffc66 --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/fonts/glyphlist.txt @@ -0,0 +1,4322 @@ +# ################################################################################### +# Copyright (c) 1997,1998,2002,2007 Adobe Systems Incorporated +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this documentation file to use, copy, publish, distribute, +# sublicense, and/or sell copies of the documentation, and to permit +# others to do the same, provided that: +# - No modification, editing or other alteration of this document is +# allowed; and +# - The above copyright notice and this permission notice shall be +# included in all copies of the documentation. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this documentation file, to create their own derivative works +# from the content of this document to use, copy, publish, distribute, +# sublicense, and/or sell the derivative works, and to permit others to do +# the same, provided that the derived work is not represented as being a +# copy or version of this document. +# +# Adobe shall not be liable to any party for any loss of revenue or profit +# or for indirect, incidental, special, consequential, or other similar +# damages, whether based on tort (including without limitation negligence +# or strict liability), contract or other legal or equitable grounds even +# if Adobe has been advised or had reason to know of the possibility of +# such damages.Ê The Adobe materials are provided on an "AS IS" basis.Ê +# Adobe specifically disclaims all express, statutory, or implied +# warranties relating to the Adobe materials, including but not limited to +# those concerning merchantability or fitness for a particular purpose or +# non-infringement of any third party rights regarding the Adobe +# materials. +# ################################################################################### +# Name: Adobe Glyph List +# Table version: 2.0 +# Date: September 20, 2002 +# +# See http://partners.adobe.com/asn/developer/typeforum/unicodegn.html +# +# Format: Semicolon-delimited fields: +# (1) glyph name +# (2) Unicode scalar value +A;0041 +AE;00C6 +AEacute;01FC +AEmacron;01E2 +AEsmall;F7E6 +Aacute;00C1 +Aacutesmall;F7E1 +Abreve;0102 +Abreveacute;1EAE +Abrevecyrillic;04D0 +Abrevedotbelow;1EB6 +Abrevegrave;1EB0 +Abrevehookabove;1EB2 +Abrevetilde;1EB4 +Acaron;01CD +Acircle;24B6 +Acircumflex;00C2 +Acircumflexacute;1EA4 +Acircumflexdotbelow;1EAC +Acircumflexgrave;1EA6 +Acircumflexhookabove;1EA8 +Acircumflexsmall;F7E2 +Acircumflextilde;1EAA +Acute;F6C9 +Acutesmall;F7B4 +Acyrillic;0410 +Adblgrave;0200 +Adieresis;00C4 +Adieresiscyrillic;04D2 +Adieresismacron;01DE +Adieresissmall;F7E4 +Adotbelow;1EA0 +Adotmacron;01E0 +Agrave;00C0 +Agravesmall;F7E0 +Ahookabove;1EA2 +Aiecyrillic;04D4 +Ainvertedbreve;0202 +Alpha;0391 +Alphatonos;0386 +Amacron;0100 +Amonospace;FF21 +Aogonek;0104 +Aring;00C5 +Aringacute;01FA +Aringbelow;1E00 +Aringsmall;F7E5 +Asmall;F761 +Atilde;00C3 +Atildesmall;F7E3 +Aybarmenian;0531 +B;0042 +Bcircle;24B7 +Bdotaccent;1E02 +Bdotbelow;1E04 +Becyrillic;0411 +Benarmenian;0532 +Beta;0392 +Bhook;0181 +Blinebelow;1E06 +Bmonospace;FF22 +Brevesmall;F6F4 +Bsmall;F762 +Btopbar;0182 +C;0043 +Caarmenian;053E +Cacute;0106 +Caron;F6CA +Caronsmall;F6F5 +Ccaron;010C +Ccedilla;00C7 +Ccedillaacute;1E08 +Ccedillasmall;F7E7 +Ccircle;24B8 +Ccircumflex;0108 +Cdot;010A +Cdotaccent;010A +Cedillasmall;F7B8 +Chaarmenian;0549 +Cheabkhasiancyrillic;04BC +Checyrillic;0427 +Chedescenderabkhasiancyrillic;04BE +Chedescendercyrillic;04B6 +Chedieresiscyrillic;04F4 +Cheharmenian;0543 +Chekhakassiancyrillic;04CB +Cheverticalstrokecyrillic;04B8 +Chi;03A7 +Chook;0187 +Circumflexsmall;F6F6 +Cmonospace;FF23 +Coarmenian;0551 +Csmall;F763 +D;0044 +DZ;01F1 +DZcaron;01C4 +Daarmenian;0534 +Dafrican;0189 +Dcaron;010E +Dcedilla;1E10 +Dcircle;24B9 +Dcircumflexbelow;1E12 +Dcroat;0110 +Ddotaccent;1E0A +Ddotbelow;1E0C +Decyrillic;0414 +Deicoptic;03EE +Delta;2206 +Deltagreek;0394 +Dhook;018A +Dieresis;F6CB +DieresisAcute;F6CC +DieresisGrave;F6CD +Dieresissmall;F7A8 +Digammagreek;03DC +Djecyrillic;0402 +Dlinebelow;1E0E +Dmonospace;FF24 +Dotaccentsmall;F6F7 +Dslash;0110 +Dsmall;F764 +Dtopbar;018B +Dz;01F2 +Dzcaron;01C5 +Dzeabkhasiancyrillic;04E0 +Dzecyrillic;0405 +Dzhecyrillic;040F +E;0045 +Eacute;00C9 +Eacutesmall;F7E9 +Ebreve;0114 +Ecaron;011A +Ecedillabreve;1E1C +Echarmenian;0535 +Ecircle;24BA +Ecircumflex;00CA +Ecircumflexacute;1EBE +Ecircumflexbelow;1E18 +Ecircumflexdotbelow;1EC6 +Ecircumflexgrave;1EC0 +Ecircumflexhookabove;1EC2 +Ecircumflexsmall;F7EA +Ecircumflextilde;1EC4 +Ecyrillic;0404 +Edblgrave;0204 +Edieresis;00CB +Edieresissmall;F7EB +Edot;0116 +Edotaccent;0116 +Edotbelow;1EB8 +Efcyrillic;0424 +Egrave;00C8 +Egravesmall;F7E8 +Eharmenian;0537 +Ehookabove;1EBA +Eightroman;2167 +Einvertedbreve;0206 +Eiotifiedcyrillic;0464 +Elcyrillic;041B +Elevenroman;216A +Emacron;0112 +Emacronacute;1E16 +Emacrongrave;1E14 +Emcyrillic;041C +Emonospace;FF25 +Encyrillic;041D +Endescendercyrillic;04A2 +Eng;014A +Enghecyrillic;04A4 +Enhookcyrillic;04C7 +Eogonek;0118 +Eopen;0190 +Epsilon;0395 +Epsilontonos;0388 +Ercyrillic;0420 +Ereversed;018E +Ereversedcyrillic;042D +Escyrillic;0421 +Esdescendercyrillic;04AA +Esh;01A9 +Esmall;F765 +Eta;0397 +Etarmenian;0538 +Etatonos;0389 +Eth;00D0 +Ethsmall;F7F0 +Etilde;1EBC +Etildebelow;1E1A +Euro;20AC +Ezh;01B7 +Ezhcaron;01EE +Ezhreversed;01B8 +F;0046 +Fcircle;24BB +Fdotaccent;1E1E +Feharmenian;0556 +Feicoptic;03E4 +Fhook;0191 +Fitacyrillic;0472 +Fiveroman;2164 +Fmonospace;FF26 +Fourroman;2163 +Fsmall;F766 +G;0047 +GBsquare;3387 +Gacute;01F4 +Gamma;0393 +Gammaafrican;0194 +Gangiacoptic;03EA +Gbreve;011E +Gcaron;01E6 +Gcedilla;0122 +Gcircle;24BC +Gcircumflex;011C +Gcommaaccent;0122 +Gdot;0120 +Gdotaccent;0120 +Gecyrillic;0413 +Ghadarmenian;0542 +Ghemiddlehookcyrillic;0494 +Ghestrokecyrillic;0492 +Gheupturncyrillic;0490 +Ghook;0193 +Gimarmenian;0533 +Gjecyrillic;0403 +Gmacron;1E20 +Gmonospace;FF27 +Grave;F6CE +Gravesmall;F760 +Gsmall;F767 +Gsmallhook;029B +Gstroke;01E4 +H;0048 +H18533;25CF +H18543;25AA +H18551;25AB +H22073;25A1 +HPsquare;33CB +Haabkhasiancyrillic;04A8 +Hadescendercyrillic;04B2 +Hardsigncyrillic;042A +Hbar;0126 +Hbrevebelow;1E2A +Hcedilla;1E28 +Hcircle;24BD +Hcircumflex;0124 +Hdieresis;1E26 +Hdotaccent;1E22 +Hdotbelow;1E24 +Hmonospace;FF28 +Hoarmenian;0540 +Horicoptic;03E8 +Hsmall;F768 +Hungarumlaut;F6CF +Hungarumlautsmall;F6F8 +Hzsquare;3390 +I;0049 +IAcyrillic;042F +IJ;0132 +IUcyrillic;042E +Iacute;00CD +Iacutesmall;F7ED +Ibreve;012C +Icaron;01CF +Icircle;24BE +Icircumflex;00CE +Icircumflexsmall;F7EE +Icyrillic;0406 +Idblgrave;0208 +Idieresis;00CF +Idieresisacute;1E2E +Idieresiscyrillic;04E4 +Idieresissmall;F7EF +Idot;0130 +Idotaccent;0130 +Idotbelow;1ECA +Iebrevecyrillic;04D6 +Iecyrillic;0415 +Ifraktur;2111 +Igrave;00CC +Igravesmall;F7EC +Ihookabove;1EC8 +Iicyrillic;0418 +Iinvertedbreve;020A +Iishortcyrillic;0419 +Imacron;012A +Imacroncyrillic;04E2 +Imonospace;FF29 +Iniarmenian;053B +Iocyrillic;0401 +Iogonek;012E +Iota;0399 +Iotaafrican;0196 +Iotadieresis;03AA +Iotatonos;038A +Ismall;F769 +Istroke;0197 +Itilde;0128 +Itildebelow;1E2C +Izhitsacyrillic;0474 +Izhitsadblgravecyrillic;0476 +J;004A +Jaarmenian;0541 +Jcircle;24BF +Jcircumflex;0134 +Jecyrillic;0408 +Jheharmenian;054B +Jmonospace;FF2A +Jsmall;F76A +K;004B +KBsquare;3385 +KKsquare;33CD +Kabashkircyrillic;04A0 +Kacute;1E30 +Kacyrillic;041A +Kadescendercyrillic;049A +Kahookcyrillic;04C3 +Kappa;039A +Kastrokecyrillic;049E +Kaverticalstrokecyrillic;049C +Kcaron;01E8 +Kcedilla;0136 +Kcircle;24C0 +Kcommaaccent;0136 +Kdotbelow;1E32 +Keharmenian;0554 +Kenarmenian;053F +Khacyrillic;0425 +Kheicoptic;03E6 +Khook;0198 +Kjecyrillic;040C +Klinebelow;1E34 +Kmonospace;FF2B +Koppacyrillic;0480 +Koppagreek;03DE +Ksicyrillic;046E +Ksmall;F76B +L;004C +LJ;01C7 +LL;F6BF +Lacute;0139 +Lambda;039B +Lcaron;013D +Lcedilla;013B +Lcircle;24C1 +Lcircumflexbelow;1E3C +Lcommaaccent;013B +Ldot;013F +Ldotaccent;013F +Ldotbelow;1E36 +Ldotbelowmacron;1E38 +Liwnarmenian;053C +Lj;01C8 +Ljecyrillic;0409 +Llinebelow;1E3A +Lmonospace;FF2C +Lslash;0141 +Lslashsmall;F6F9 +Lsmall;F76C +M;004D +MBsquare;3386 +Macron;F6D0 +Macronsmall;F7AF +Macute;1E3E +Mcircle;24C2 +Mdotaccent;1E40 +Mdotbelow;1E42 +Menarmenian;0544 +Mmonospace;FF2D +Msmall;F76D +Mturned;019C +Mu;039C +N;004E +NJ;01CA +Nacute;0143 +Ncaron;0147 +Ncedilla;0145 +Ncircle;24C3 +Ncircumflexbelow;1E4A +Ncommaaccent;0145 +Ndotaccent;1E44 +Ndotbelow;1E46 +Nhookleft;019D +Nineroman;2168 +Nj;01CB +Njecyrillic;040A +Nlinebelow;1E48 +Nmonospace;FF2E +Nowarmenian;0546 +Nsmall;F76E +Ntilde;00D1 +Ntildesmall;F7F1 +Nu;039D +O;004F +OE;0152 +OEsmall;F6FA +Oacute;00D3 +Oacutesmall;F7F3 +Obarredcyrillic;04E8 +Obarreddieresiscyrillic;04EA +Obreve;014E +Ocaron;01D1 +Ocenteredtilde;019F +Ocircle;24C4 +Ocircumflex;00D4 +Ocircumflexacute;1ED0 +Ocircumflexdotbelow;1ED8 +Ocircumflexgrave;1ED2 +Ocircumflexhookabove;1ED4 +Ocircumflexsmall;F7F4 +Ocircumflextilde;1ED6 +Ocyrillic;041E +Odblacute;0150 +Odblgrave;020C +Odieresis;00D6 +Odieresiscyrillic;04E6 +Odieresissmall;F7F6 +Odotbelow;1ECC +Ogoneksmall;F6FB +Ograve;00D2 +Ogravesmall;F7F2 +Oharmenian;0555 +Ohm;2126 +Ohookabove;1ECE +Ohorn;01A0 +Ohornacute;1EDA +Ohorndotbelow;1EE2 +Ohorngrave;1EDC +Ohornhookabove;1EDE +Ohorntilde;1EE0 +Ohungarumlaut;0150 +Oi;01A2 +Oinvertedbreve;020E +Omacron;014C +Omacronacute;1E52 +Omacrongrave;1E50 +Omega;2126 +Omegacyrillic;0460 +Omegagreek;03A9 +Omegaroundcyrillic;047A +Omegatitlocyrillic;047C +Omegatonos;038F +Omicron;039F +Omicrontonos;038C +Omonospace;FF2F +Oneroman;2160 +Oogonek;01EA +Oogonekmacron;01EC +Oopen;0186 +Oslash;00D8 +Oslashacute;01FE +Oslashsmall;F7F8 +Osmall;F76F +Ostrokeacute;01FE +Otcyrillic;047E +Otilde;00D5 +Otildeacute;1E4C +Otildedieresis;1E4E +Otildesmall;F7F5 +P;0050 +Pacute;1E54 +Pcircle;24C5 +Pdotaccent;1E56 +Pecyrillic;041F +Peharmenian;054A +Pemiddlehookcyrillic;04A6 +Phi;03A6 +Phook;01A4 +Pi;03A0 +Piwrarmenian;0553 +Pmonospace;FF30 +Psi;03A8 +Psicyrillic;0470 +Psmall;F770 +Q;0051 +Qcircle;24C6 +Qmonospace;FF31 +Qsmall;F771 +R;0052 +Raarmenian;054C +Racute;0154 +Rcaron;0158 +Rcedilla;0156 +Rcircle;24C7 +Rcommaaccent;0156 +Rdblgrave;0210 +Rdotaccent;1E58 +Rdotbelow;1E5A +Rdotbelowmacron;1E5C +Reharmenian;0550 +Rfraktur;211C +Rho;03A1 +Ringsmall;F6FC +Rinvertedbreve;0212 +Rlinebelow;1E5E +Rmonospace;FF32 +Rsmall;F772 +Rsmallinverted;0281 +Rsmallinvertedsuperior;02B6 +S;0053 +SF010000;250C +SF020000;2514 +SF030000;2510 +SF040000;2518 +SF050000;253C +SF060000;252C +SF070000;2534 +SF080000;251C +SF090000;2524 +SF100000;2500 +SF110000;2502 +SF190000;2561 +SF200000;2562 +SF210000;2556 +SF220000;2555 +SF230000;2563 +SF240000;2551 +SF250000;2557 +SF260000;255D +SF270000;255C +SF280000;255B +SF360000;255E +SF370000;255F +SF380000;255A +SF390000;2554 +SF400000;2569 +SF410000;2566 +SF420000;2560 +SF430000;2550 +SF440000;256C +SF450000;2567 +SF460000;2568 +SF470000;2564 +SF480000;2565 +SF490000;2559 +SF500000;2558 +SF510000;2552 +SF520000;2553 +SF530000;256B +SF540000;256A +Sacute;015A +Sacutedotaccent;1E64 +Sampigreek;03E0 +Scaron;0160 +Scarondotaccent;1E66 +Scaronsmall;F6FD +Scedilla;015E +Schwa;018F +Schwacyrillic;04D8 +Schwadieresiscyrillic;04DA +Scircle;24C8 +Scircumflex;015C +Scommaaccent;0218 +Sdotaccent;1E60 +Sdotbelow;1E62 +Sdotbelowdotaccent;1E68 +Seharmenian;054D +Sevenroman;2166 +Shaarmenian;0547 +Shacyrillic;0428 +Shchacyrillic;0429 +Sheicoptic;03E2 +Shhacyrillic;04BA +Shimacoptic;03EC +Sigma;03A3 +Sixroman;2165 +Smonospace;FF33 +Softsigncyrillic;042C +Ssmall;F773 +Stigmagreek;03DA +T;0054 +Tau;03A4 +Tbar;0166 +Tcaron;0164 +Tcedilla;0162 +Tcircle;24C9 +Tcircumflexbelow;1E70 +Tcommaaccent;0162 +Tdotaccent;1E6A +Tdotbelow;1E6C +Tecyrillic;0422 +Tedescendercyrillic;04AC +Tenroman;2169 +Tetsecyrillic;04B4 +Theta;0398 +Thook;01AC +Thorn;00DE +Thornsmall;F7FE +Threeroman;2162 +Tildesmall;F6FE +Tiwnarmenian;054F +Tlinebelow;1E6E +Tmonospace;FF34 +Toarmenian;0539 +Tonefive;01BC +Tonesix;0184 +Tonetwo;01A7 +Tretroflexhook;01AE +Tsecyrillic;0426 +Tshecyrillic;040B +Tsmall;F774 +Twelveroman;216B +Tworoman;2161 +U;0055 +Uacute;00DA +Uacutesmall;F7FA +Ubreve;016C +Ucaron;01D3 +Ucircle;24CA +Ucircumflex;00DB +Ucircumflexbelow;1E76 +Ucircumflexsmall;F7FB +Ucyrillic;0423 +Udblacute;0170 +Udblgrave;0214 +Udieresis;00DC +Udieresisacute;01D7 +Udieresisbelow;1E72 +Udieresiscaron;01D9 +Udieresiscyrillic;04F0 +Udieresisgrave;01DB +Udieresismacron;01D5 +Udieresissmall;F7FC +Udotbelow;1EE4 +Ugrave;00D9 +Ugravesmall;F7F9 +Uhookabove;1EE6 +Uhorn;01AF +Uhornacute;1EE8 +Uhorndotbelow;1EF0 +Uhorngrave;1EEA +Uhornhookabove;1EEC +Uhorntilde;1EEE +Uhungarumlaut;0170 +Uhungarumlautcyrillic;04F2 +Uinvertedbreve;0216 +Ukcyrillic;0478 +Umacron;016A +Umacroncyrillic;04EE +Umacrondieresis;1E7A +Umonospace;FF35 +Uogonek;0172 +Upsilon;03A5 +Upsilon1;03D2 +Upsilonacutehooksymbolgreek;03D3 +Upsilonafrican;01B1 +Upsilondieresis;03AB +Upsilondieresishooksymbolgreek;03D4 +Upsilonhooksymbol;03D2 +Upsilontonos;038E +Uring;016E +Ushortcyrillic;040E +Usmall;F775 +Ustraightcyrillic;04AE +Ustraightstrokecyrillic;04B0 +Utilde;0168 +Utildeacute;1E78 +Utildebelow;1E74 +V;0056 +Vcircle;24CB +Vdotbelow;1E7E +Vecyrillic;0412 +Vewarmenian;054E +Vhook;01B2 +Vmonospace;FF36 +Voarmenian;0548 +Vsmall;F776 +Vtilde;1E7C +W;0057 +Wacute;1E82 +Wcircle;24CC +Wcircumflex;0174 +Wdieresis;1E84 +Wdotaccent;1E86 +Wdotbelow;1E88 +Wgrave;1E80 +Wmonospace;FF37 +Wsmall;F777 +X;0058 +Xcircle;24CD +Xdieresis;1E8C +Xdotaccent;1E8A +Xeharmenian;053D +Xi;039E +Xmonospace;FF38 +Xsmall;F778 +Y;0059 +Yacute;00DD +Yacutesmall;F7FD +Yatcyrillic;0462 +Ycircle;24CE +Ycircumflex;0176 +Ydieresis;0178 +Ydieresissmall;F7FF +Ydotaccent;1E8E +Ydotbelow;1EF4 +Yericyrillic;042B +Yerudieresiscyrillic;04F8 +Ygrave;1EF2 +Yhook;01B3 +Yhookabove;1EF6 +Yiarmenian;0545 +Yicyrillic;0407 +Yiwnarmenian;0552 +Ymonospace;FF39 +Ysmall;F779 +Ytilde;1EF8 +Yusbigcyrillic;046A +Yusbigiotifiedcyrillic;046C +Yuslittlecyrillic;0466 +Yuslittleiotifiedcyrillic;0468 +Z;005A +Zaarmenian;0536 +Zacute;0179 +Zcaron;017D +Zcaronsmall;F6FF +Zcircle;24CF +Zcircumflex;1E90 +Zdot;017B +Zdotaccent;017B +Zdotbelow;1E92 +Zecyrillic;0417 +Zedescendercyrillic;0498 +Zedieresiscyrillic;04DE +Zeta;0396 +Zhearmenian;053A +Zhebrevecyrillic;04C1 +Zhecyrillic;0416 +Zhedescendercyrillic;0496 +Zhedieresiscyrillic;04DC +Zlinebelow;1E94 +Zmonospace;FF3A +Zsmall;F77A +Zstroke;01B5 +a;0061 +aabengali;0986 +aacute;00E1 +aadeva;0906 +aagujarati;0A86 +aagurmukhi;0A06 +aamatragurmukhi;0A3E +aarusquare;3303 +aavowelsignbengali;09BE +aavowelsigndeva;093E +aavowelsigngujarati;0ABE +abbreviationmarkarmenian;055F +abbreviationsigndeva;0970 +abengali;0985 +abopomofo;311A +abreve;0103 +abreveacute;1EAF +abrevecyrillic;04D1 +abrevedotbelow;1EB7 +abrevegrave;1EB1 +abrevehookabove;1EB3 +abrevetilde;1EB5 +acaron;01CE +acircle;24D0 +acircumflex;00E2 +acircumflexacute;1EA5 +acircumflexdotbelow;1EAD +acircumflexgrave;1EA7 +acircumflexhookabove;1EA9 +acircumflextilde;1EAB +acute;00B4 +acutebelowcmb;0317 +acutecmb;0301 +acutecomb;0301 +acutedeva;0954 +acutelowmod;02CF +acutetonecmb;0341 +acyrillic;0430 +adblgrave;0201 +addakgurmukhi;0A71 +adeva;0905 +adieresis;00E4 +adieresiscyrillic;04D3 +adieresismacron;01DF +adotbelow;1EA1 +adotmacron;01E1 +ae;00E6 +aeacute;01FD +aekorean;3150 +aemacron;01E3 +afii00208;2015 +afii08941;20A4 +afii10017;0410 +afii10018;0411 +afii10019;0412 +afii10020;0413 +afii10021;0414 +afii10022;0415 +afii10023;0401 +afii10024;0416 +afii10025;0417 +afii10026;0418 +afii10027;0419 +afii10028;041A +afii10029;041B +afii10030;041C +afii10031;041D +afii10032;041E +afii10033;041F +afii10034;0420 +afii10035;0421 +afii10036;0422 +afii10037;0423 +afii10038;0424 +afii10039;0425 +afii10040;0426 +afii10041;0427 +afii10042;0428 +afii10043;0429 +afii10044;042A +afii10045;042B +afii10046;042C +afii10047;042D +afii10048;042E +afii10049;042F +afii10050;0490 +afii10051;0402 +afii10052;0403 +afii10053;0404 +afii10054;0405 +afii10055;0406 +afii10056;0407 +afii10057;0408 +afii10058;0409 +afii10059;040A +afii10060;040B +afii10061;040C +afii10062;040E +afii10063;F6C4 +afii10064;F6C5 +afii10065;0430 +afii10066;0431 +afii10067;0432 +afii10068;0433 +afii10069;0434 +afii10070;0435 +afii10071;0451 +afii10072;0436 +afii10073;0437 +afii10074;0438 +afii10075;0439 +afii10076;043A +afii10077;043B +afii10078;043C +afii10079;043D +afii10080;043E +afii10081;043F +afii10082;0440 +afii10083;0441 +afii10084;0442 +afii10085;0443 +afii10086;0444 +afii10087;0445 +afii10088;0446 +afii10089;0447 +afii10090;0448 +afii10091;0449 +afii10092;044A +afii10093;044B +afii10094;044C +afii10095;044D +afii10096;044E +afii10097;044F +afii10098;0491 +afii10099;0452 +afii10100;0453 +afii10101;0454 +afii10102;0455 +afii10103;0456 +afii10104;0457 +afii10105;0458 +afii10106;0459 +afii10107;045A +afii10108;045B +afii10109;045C +afii10110;045E +afii10145;040F +afii10146;0462 +afii10147;0472 +afii10148;0474 +afii10192;F6C6 +afii10193;045F +afii10194;0463 +afii10195;0473 +afii10196;0475 +afii10831;F6C7 +afii10832;F6C8 +afii10846;04D9 +afii299;200E +afii300;200F +afii301;200D +afii57381;066A +afii57388;060C +afii57392;0660 +afii57393;0661 +afii57394;0662 +afii57395;0663 +afii57396;0664 +afii57397;0665 +afii57398;0666 +afii57399;0667 +afii57400;0668 +afii57401;0669 +afii57403;061B +afii57407;061F +afii57409;0621 +afii57410;0622 +afii57411;0623 +afii57412;0624 +afii57413;0625 +afii57414;0626 +afii57415;0627 +afii57416;0628 +afii57417;0629 +afii57418;062A +afii57419;062B +afii57420;062C +afii57421;062D +afii57422;062E +afii57423;062F +afii57424;0630 +afii57425;0631 +afii57426;0632 +afii57427;0633 +afii57428;0634 +afii57429;0635 +afii57430;0636 +afii57431;0637 +afii57432;0638 +afii57433;0639 +afii57434;063A +afii57440;0640 +afii57441;0641 +afii57442;0642 +afii57443;0643 +afii57444;0644 +afii57445;0645 +afii57446;0646 +afii57448;0648 +afii57449;0649 +afii57450;064A +afii57451;064B +afii57452;064C +afii57453;064D +afii57454;064E +afii57455;064F +afii57456;0650 +afii57457;0651 +afii57458;0652 +afii57470;0647 +afii57505;06A4 +afii57506;067E +afii57507;0686 +afii57508;0698 +afii57509;06AF +afii57511;0679 +afii57512;0688 +afii57513;0691 +afii57514;06BA +afii57519;06D2 +afii57534;06D5 +afii57636;20AA +afii57645;05BE +afii57658;05C3 +afii57664;05D0 +afii57665;05D1 +afii57666;05D2 +afii57667;05D3 +afii57668;05D4 +afii57669;05D5 +afii57670;05D6 +afii57671;05D7 +afii57672;05D8 +afii57673;05D9 +afii57674;05DA +afii57675;05DB +afii57676;05DC +afii57677;05DD +afii57678;05DE +afii57679;05DF +afii57680;05E0 +afii57681;05E1 +afii57682;05E2 +afii57683;05E3 +afii57684;05E4 +afii57685;05E5 +afii57686;05E6 +afii57687;05E7 +afii57688;05E8 +afii57689;05E9 +afii57690;05EA +afii57694;FB2A +afii57695;FB2B +afii57700;FB4B +afii57705;FB1F +afii57716;05F0 +afii57717;05F1 +afii57718;05F2 +afii57723;FB35 +afii57793;05B4 +afii57794;05B5 +afii57795;05B6 +afii57796;05BB +afii57797;05B8 +afii57798;05B7 +afii57799;05B0 +afii57800;05B2 +afii57801;05B1 +afii57802;05B3 +afii57803;05C2 +afii57804;05C1 +afii57806;05B9 +afii57807;05BC +afii57839;05BD +afii57841;05BF +afii57842;05C0 +afii57929;02BC +afii61248;2105 +afii61289;2113 +afii61352;2116 +afii61573;202C +afii61574;202D +afii61575;202E +afii61664;200C +afii63167;066D +afii64937;02BD +agrave;00E0 +agujarati;0A85 +agurmukhi;0A05 +ahiragana;3042 +ahookabove;1EA3 +aibengali;0990 +aibopomofo;311E +aideva;0910 +aiecyrillic;04D5 +aigujarati;0A90 +aigurmukhi;0A10 +aimatragurmukhi;0A48 +ainarabic;0639 +ainfinalarabic;FECA +aininitialarabic;FECB +ainmedialarabic;FECC +ainvertedbreve;0203 +aivowelsignbengali;09C8 +aivowelsigndeva;0948 +aivowelsigngujarati;0AC8 +akatakana;30A2 +akatakanahalfwidth;FF71 +akorean;314F +alef;05D0 +alefarabic;0627 +alefdageshhebrew;FB30 +aleffinalarabic;FE8E +alefhamzaabovearabic;0623 +alefhamzaabovefinalarabic;FE84 +alefhamzabelowarabic;0625 +alefhamzabelowfinalarabic;FE88 +alefhebrew;05D0 +aleflamedhebrew;FB4F +alefmaddaabovearabic;0622 +alefmaddaabovefinalarabic;FE82 +alefmaksuraarabic;0649 +alefmaksurafinalarabic;FEF0 +alefmaksurainitialarabic;FEF3 +alefmaksuramedialarabic;FEF4 +alefpatahhebrew;FB2E +alefqamatshebrew;FB2F +aleph;2135 +allequal;224C +alpha;03B1 +alphatonos;03AC +amacron;0101 +amonospace;FF41 +ampersand;0026 +ampersandmonospace;FF06 +ampersandsmall;F726 +amsquare;33C2 +anbopomofo;3122 +angbopomofo;3124 +angkhankhuthai;0E5A +angle;2220 +anglebracketleft;3008 +anglebracketleftvertical;FE3F +anglebracketright;3009 +anglebracketrightvertical;FE40 +angleleft;2329 +angleright;232A +angstrom;212B +anoteleia;0387 +anudattadeva;0952 +anusvarabengali;0982 +anusvaradeva;0902 +anusvaragujarati;0A82 +aogonek;0105 +apaatosquare;3300 +aparen;249C +apostrophearmenian;055A +apostrophemod;02BC +apple;F8FF +approaches;2250 +approxequal;2248 +approxequalorimage;2252 +approximatelyequal;2245 +araeaekorean;318E +araeakorean;318D +arc;2312 +arighthalfring;1E9A +aring;00E5 +aringacute;01FB +aringbelow;1E01 +arrowboth;2194 +arrowdashdown;21E3 +arrowdashleft;21E0 +arrowdashright;21E2 +arrowdashup;21E1 +arrowdblboth;21D4 +arrowdbldown;21D3 +arrowdblleft;21D0 +arrowdblright;21D2 +arrowdblup;21D1 +arrowdown;2193 +arrowdownleft;2199 +arrowdownright;2198 +arrowdownwhite;21E9 +arrowheaddownmod;02C5 +arrowheadleftmod;02C2 +arrowheadrightmod;02C3 +arrowheadupmod;02C4 +arrowhorizex;F8E7 +arrowleft;2190 +arrowleftdbl;21D0 +arrowleftdblstroke;21CD +arrowleftoverright;21C6 +arrowleftwhite;21E6 +arrowright;2192 +arrowrightdblstroke;21CF +arrowrightheavy;279E +arrowrightoverleft;21C4 +arrowrightwhite;21E8 +arrowtableft;21E4 +arrowtabright;21E5 +arrowup;2191 +arrowupdn;2195 +arrowupdnbse;21A8 +arrowupdownbase;21A8 +arrowupleft;2196 +arrowupleftofdown;21C5 +arrowupright;2197 +arrowupwhite;21E7 +arrowvertex;F8E6 +asciicircum;005E +asciicircummonospace;FF3E +asciitilde;007E +asciitildemonospace;FF5E +ascript;0251 +ascriptturned;0252 +asmallhiragana;3041 +asmallkatakana;30A1 +asmallkatakanahalfwidth;FF67 +asterisk;002A +asteriskaltonearabic;066D +asteriskarabic;066D +asteriskmath;2217 +asteriskmonospace;FF0A +asterisksmall;FE61 +asterism;2042 +asuperior;F6E9 +asymptoticallyequal;2243 +at;0040 +atilde;00E3 +atmonospace;FF20 +atsmall;FE6B +aturned;0250 +aubengali;0994 +aubopomofo;3120 +audeva;0914 +augujarati;0A94 +augurmukhi;0A14 +aulengthmarkbengali;09D7 +aumatragurmukhi;0A4C +auvowelsignbengali;09CC +auvowelsigndeva;094C +auvowelsigngujarati;0ACC +avagrahadeva;093D +aybarmenian;0561 +ayin;05E2 +ayinaltonehebrew;FB20 +ayinhebrew;05E2 +b;0062 +babengali;09AC +backslash;005C +backslashmonospace;FF3C +badeva;092C +bagujarati;0AAC +bagurmukhi;0A2C +bahiragana;3070 +bahtthai;0E3F +bakatakana;30D0 +bar;007C +barmonospace;FF5C +bbopomofo;3105 +bcircle;24D1 +bdotaccent;1E03 +bdotbelow;1E05 +beamedsixteenthnotes;266C +because;2235 +becyrillic;0431 +beharabic;0628 +behfinalarabic;FE90 +behinitialarabic;FE91 +behiragana;3079 +behmedialarabic;FE92 +behmeeminitialarabic;FC9F +behmeemisolatedarabic;FC08 +behnoonfinalarabic;FC6D +bekatakana;30D9 +benarmenian;0562 +bet;05D1 +beta;03B2 +betasymbolgreek;03D0 +betdagesh;FB31 +betdageshhebrew;FB31 +bethebrew;05D1 +betrafehebrew;FB4C +bhabengali;09AD +bhadeva;092D +bhagujarati;0AAD +bhagurmukhi;0A2D +bhook;0253 +bihiragana;3073 +bikatakana;30D3 +bilabialclick;0298 +bindigurmukhi;0A02 +birusquare;3331 +blackcircle;25CF +blackdiamond;25C6 +blackdownpointingtriangle;25BC +blackleftpointingpointer;25C4 +blackleftpointingtriangle;25C0 +blacklenticularbracketleft;3010 +blacklenticularbracketleftvertical;FE3B +blacklenticularbracketright;3011 +blacklenticularbracketrightvertical;FE3C +blacklowerlefttriangle;25E3 +blacklowerrighttriangle;25E2 +blackrectangle;25AC +blackrightpointingpointer;25BA +blackrightpointingtriangle;25B6 +blacksmallsquare;25AA +blacksmilingface;263B +blacksquare;25A0 +blackstar;2605 +blackupperlefttriangle;25E4 +blackupperrighttriangle;25E5 +blackuppointingsmalltriangle;25B4 +blackuppointingtriangle;25B2 +blank;2423 +blinebelow;1E07 +block;2588 +bmonospace;FF42 +bobaimaithai;0E1A +bohiragana;307C +bokatakana;30DC +bparen;249D +bqsquare;33C3 +braceex;F8F4 +braceleft;007B +braceleftbt;F8F3 +braceleftmid;F8F2 +braceleftmonospace;FF5B +braceleftsmall;FE5B +bracelefttp;F8F1 +braceleftvertical;FE37 +braceright;007D +bracerightbt;F8FE +bracerightmid;F8FD +bracerightmonospace;FF5D +bracerightsmall;FE5C +bracerighttp;F8FC +bracerightvertical;FE38 +bracketleft;005B +bracketleftbt;F8F0 +bracketleftex;F8EF +bracketleftmonospace;FF3B +bracketlefttp;F8EE +bracketright;005D +bracketrightbt;F8FB +bracketrightex;F8FA +bracketrightmonospace;FF3D +bracketrighttp;F8F9 +breve;02D8 +brevebelowcmb;032E +brevecmb;0306 +breveinvertedbelowcmb;032F +breveinvertedcmb;0311 +breveinverteddoublecmb;0361 +bridgebelowcmb;032A +bridgeinvertedbelowcmb;033A +brokenbar;00A6 +bstroke;0180 +bsuperior;F6EA +btopbar;0183 +buhiragana;3076 +bukatakana;30D6 +bullet;2022 +bulletinverse;25D8 +bulletoperator;2219 +bullseye;25CE +c;0063 +caarmenian;056E +cabengali;099A +cacute;0107 +cadeva;091A +cagujarati;0A9A +cagurmukhi;0A1A +calsquare;3388 +candrabindubengali;0981 +candrabinducmb;0310 +candrabindudeva;0901 +candrabindugujarati;0A81 +capslock;21EA +careof;2105 +caron;02C7 +caronbelowcmb;032C +caroncmb;030C +carriagereturn;21B5 +cbopomofo;3118 +ccaron;010D +ccedilla;00E7 +ccedillaacute;1E09 +ccircle;24D2 +ccircumflex;0109 +ccurl;0255 +cdot;010B +cdotaccent;010B +cdsquare;33C5 +cedilla;00B8 +cedillacmb;0327 +cent;00A2 +centigrade;2103 +centinferior;F6DF +centmonospace;FFE0 +centoldstyle;F7A2 +centsuperior;F6E0 +chaarmenian;0579 +chabengali;099B +chadeva;091B +chagujarati;0A9B +chagurmukhi;0A1B +chbopomofo;3114 +cheabkhasiancyrillic;04BD +checkmark;2713 +checyrillic;0447 +chedescenderabkhasiancyrillic;04BF +chedescendercyrillic;04B7 +chedieresiscyrillic;04F5 +cheharmenian;0573 +chekhakassiancyrillic;04CC +cheverticalstrokecyrillic;04B9 +chi;03C7 +chieuchacirclekorean;3277 +chieuchaparenkorean;3217 +chieuchcirclekorean;3269 +chieuchkorean;314A +chieuchparenkorean;3209 +chochangthai;0E0A +chochanthai;0E08 +chochingthai;0E09 +chochoethai;0E0C +chook;0188 +cieucacirclekorean;3276 +cieucaparenkorean;3216 +cieuccirclekorean;3268 +cieuckorean;3148 +cieucparenkorean;3208 +cieucuparenkorean;321C +circle;25CB +circlemultiply;2297 +circleot;2299 +circleplus;2295 +circlepostalmark;3036 +circlewithlefthalfblack;25D0 +circlewithrighthalfblack;25D1 +circumflex;02C6 +circumflexbelowcmb;032D +circumflexcmb;0302 +clear;2327 +clickalveolar;01C2 +clickdental;01C0 +clicklateral;01C1 +clickretroflex;01C3 +club;2663 +clubsuitblack;2663 +clubsuitwhite;2667 +cmcubedsquare;33A4 +cmonospace;FF43 +cmsquaredsquare;33A0 +coarmenian;0581 +colon;003A +colonmonetary;20A1 +colonmonospace;FF1A +colonsign;20A1 +colonsmall;FE55 +colontriangularhalfmod;02D1 +colontriangularmod;02D0 +comma;002C +commaabovecmb;0313 +commaaboverightcmb;0315 +commaaccent;F6C3 +commaarabic;060C +commaarmenian;055D +commainferior;F6E1 +commamonospace;FF0C +commareversedabovecmb;0314 +commareversedmod;02BD +commasmall;FE50 +commasuperior;F6E2 +commaturnedabovecmb;0312 +commaturnedmod;02BB +compass;263C +congruent;2245 +contourintegral;222E +control;2303 +controlACK;0006 +controlBEL;0007 +controlBS;0008 +controlCAN;0018 +controlCR;000D +controlDC1;0011 +controlDC2;0012 +controlDC3;0013 +controlDC4;0014 +controlDEL;007F +controlDLE;0010 +controlEM;0019 +controlENQ;0005 +controlEOT;0004 +controlESC;001B +controlETB;0017 +controlETX;0003 +controlFF;000C +controlFS;001C +controlGS;001D +controlHT;0009 +controlLF;000A +controlNAK;0015 +controlRS;001E +controlSI;000F +controlSO;000E +controlSOT;0002 +controlSTX;0001 +controlSUB;001A +controlSYN;0016 +controlUS;001F +controlVT;000B +copyright;00A9 +copyrightsans;F8E9 +copyrightserif;F6D9 +cornerbracketleft;300C +cornerbracketlefthalfwidth;FF62 +cornerbracketleftvertical;FE41 +cornerbracketright;300D +cornerbracketrighthalfwidth;FF63 +cornerbracketrightvertical;FE42 +corporationsquare;337F +cosquare;33C7 +coverkgsquare;33C6 +cparen;249E +cruzeiro;20A2 +cstretched;0297 +curlyand;22CF +curlyor;22CE +currency;00A4 +cyrBreve;F6D1 +cyrFlex;F6D2 +cyrbreve;F6D4 +cyrflex;F6D5 +d;0064 +daarmenian;0564 +dabengali;09A6 +dadarabic;0636 +dadeva;0926 +dadfinalarabic;FEBE +dadinitialarabic;FEBF +dadmedialarabic;FEC0 +dagesh;05BC +dageshhebrew;05BC +dagger;2020 +daggerdbl;2021 +dagujarati;0AA6 +dagurmukhi;0A26 +dahiragana;3060 +dakatakana;30C0 +dalarabic;062F +dalet;05D3 +daletdagesh;FB33 +daletdageshhebrew;FB33 +dalethatafpatah;05D3 05B2 +dalethatafpatahhebrew;05D3 05B2 +dalethatafsegol;05D3 05B1 +dalethatafsegolhebrew;05D3 05B1 +dalethebrew;05D3 +dalethiriq;05D3 05B4 +dalethiriqhebrew;05D3 05B4 +daletholam;05D3 05B9 +daletholamhebrew;05D3 05B9 +daletpatah;05D3 05B7 +daletpatahhebrew;05D3 05B7 +daletqamats;05D3 05B8 +daletqamatshebrew;05D3 05B8 +daletqubuts;05D3 05BB +daletqubutshebrew;05D3 05BB +daletsegol;05D3 05B6 +daletsegolhebrew;05D3 05B6 +daletsheva;05D3 05B0 +daletshevahebrew;05D3 05B0 +dalettsere;05D3 05B5 +dalettserehebrew;05D3 05B5 +dalfinalarabic;FEAA +dammaarabic;064F +dammalowarabic;064F +dammatanaltonearabic;064C +dammatanarabic;064C +danda;0964 +dargahebrew;05A7 +dargalefthebrew;05A7 +dasiapneumatacyrilliccmb;0485 +dblGrave;F6D3 +dblanglebracketleft;300A +dblanglebracketleftvertical;FE3D +dblanglebracketright;300B +dblanglebracketrightvertical;FE3E +dblarchinvertedbelowcmb;032B +dblarrowleft;21D4 +dblarrowright;21D2 +dbldanda;0965 +dblgrave;F6D6 +dblgravecmb;030F +dblintegral;222C +dbllowline;2017 +dbllowlinecmb;0333 +dbloverlinecmb;033F +dblprimemod;02BA +dblverticalbar;2016 +dblverticallineabovecmb;030E +dbopomofo;3109 +dbsquare;33C8 +dcaron;010F +dcedilla;1E11 +dcircle;24D3 +dcircumflexbelow;1E13 +dcroat;0111 +ddabengali;09A1 +ddadeva;0921 +ddagujarati;0AA1 +ddagurmukhi;0A21 +ddalarabic;0688 +ddalfinalarabic;FB89 +dddhadeva;095C +ddhabengali;09A2 +ddhadeva;0922 +ddhagujarati;0AA2 +ddhagurmukhi;0A22 +ddotaccent;1E0B +ddotbelow;1E0D +decimalseparatorarabic;066B +decimalseparatorpersian;066B +decyrillic;0434 +degree;00B0 +dehihebrew;05AD +dehiragana;3067 +deicoptic;03EF +dekatakana;30C7 +deleteleft;232B +deleteright;2326 +delta;03B4 +deltaturned;018D +denominatorminusonenumeratorbengali;09F8 +dezh;02A4 +dhabengali;09A7 +dhadeva;0927 +dhagujarati;0AA7 +dhagurmukhi;0A27 +dhook;0257 +dialytikatonos;0385 +dialytikatonoscmb;0344 +diamond;2666 +diamondsuitwhite;2662 +dieresis;00A8 +dieresisacute;F6D7 +dieresisbelowcmb;0324 +dieresiscmb;0308 +dieresisgrave;F6D8 +dieresistonos;0385 +dihiragana;3062 +dikatakana;30C2 +dittomark;3003 +divide;00F7 +divides;2223 +divisionslash;2215 +djecyrillic;0452 +dkshade;2593 +dlinebelow;1E0F +dlsquare;3397 +dmacron;0111 +dmonospace;FF44 +dnblock;2584 +dochadathai;0E0E +dodekthai;0E14 +dohiragana;3069 +dokatakana;30C9 +dollar;0024 +dollarinferior;F6E3 +dollarmonospace;FF04 +dollaroldstyle;F724 +dollarsmall;FE69 +dollarsuperior;F6E4 +dong;20AB +dorusquare;3326 +dotaccent;02D9 +dotaccentcmb;0307 +dotbelowcmb;0323 +dotbelowcomb;0323 +dotkatakana;30FB +dotlessi;0131 +dotlessj;F6BE +dotlessjstrokehook;0284 +dotmath;22C5 +dottedcircle;25CC +doubleyodpatah;FB1F +doubleyodpatahhebrew;FB1F +downtackbelowcmb;031E +downtackmod;02D5 +dparen;249F +dsuperior;F6EB +dtail;0256 +dtopbar;018C +duhiragana;3065 +dukatakana;30C5 +dz;01F3 +dzaltone;02A3 +dzcaron;01C6 +dzcurl;02A5 +dzeabkhasiancyrillic;04E1 +dzecyrillic;0455 +dzhecyrillic;045F +e;0065 +eacute;00E9 +earth;2641 +ebengali;098F +ebopomofo;311C +ebreve;0115 +ecandradeva;090D +ecandragujarati;0A8D +ecandravowelsigndeva;0945 +ecandravowelsigngujarati;0AC5 +ecaron;011B +ecedillabreve;1E1D +echarmenian;0565 +echyiwnarmenian;0587 +ecircle;24D4 +ecircumflex;00EA +ecircumflexacute;1EBF +ecircumflexbelow;1E19 +ecircumflexdotbelow;1EC7 +ecircumflexgrave;1EC1 +ecircumflexhookabove;1EC3 +ecircumflextilde;1EC5 +ecyrillic;0454 +edblgrave;0205 +edeva;090F +edieresis;00EB +edot;0117 +edotaccent;0117 +edotbelow;1EB9 +eegurmukhi;0A0F +eematragurmukhi;0A47 +efcyrillic;0444 +egrave;00E8 +egujarati;0A8F +eharmenian;0567 +ehbopomofo;311D +ehiragana;3048 +ehookabove;1EBB +eibopomofo;311F +eight;0038 +eightarabic;0668 +eightbengali;09EE +eightcircle;2467 +eightcircleinversesansserif;2791 +eightdeva;096E +eighteencircle;2471 +eighteenparen;2485 +eighteenperiod;2499 +eightgujarati;0AEE +eightgurmukhi;0A6E +eighthackarabic;0668 +eighthangzhou;3028 +eighthnotebeamed;266B +eightideographicparen;3227 +eightinferior;2088 +eightmonospace;FF18 +eightoldstyle;F738 +eightparen;247B +eightperiod;248F +eightpersian;06F8 +eightroman;2177 +eightsuperior;2078 +eightthai;0E58 +einvertedbreve;0207 +eiotifiedcyrillic;0465 +ekatakana;30A8 +ekatakanahalfwidth;FF74 +ekonkargurmukhi;0A74 +ekorean;3154 +elcyrillic;043B +element;2208 +elevencircle;246A +elevenparen;247E +elevenperiod;2492 +elevenroman;217A +ellipsis;2026 +ellipsisvertical;22EE +emacron;0113 +emacronacute;1E17 +emacrongrave;1E15 +emcyrillic;043C +emdash;2014 +emdashvertical;FE31 +emonospace;FF45 +emphasismarkarmenian;055B +emptyset;2205 +enbopomofo;3123 +encyrillic;043D +endash;2013 +endashvertical;FE32 +endescendercyrillic;04A3 +eng;014B +engbopomofo;3125 +enghecyrillic;04A5 +enhookcyrillic;04C8 +enspace;2002 +eogonek;0119 +eokorean;3153 +eopen;025B +eopenclosed;029A +eopenreversed;025C +eopenreversedclosed;025E +eopenreversedhook;025D +eparen;24A0 +epsilon;03B5 +epsilontonos;03AD +equal;003D +equalmonospace;FF1D +equalsmall;FE66 +equalsuperior;207C +equivalence;2261 +erbopomofo;3126 +ercyrillic;0440 +ereversed;0258 +ereversedcyrillic;044D +escyrillic;0441 +esdescendercyrillic;04AB +esh;0283 +eshcurl;0286 +eshortdeva;090E +eshortvowelsigndeva;0946 +eshreversedloop;01AA +eshsquatreversed;0285 +esmallhiragana;3047 +esmallkatakana;30A7 +esmallkatakanahalfwidth;FF6A +estimated;212E +esuperior;F6EC +eta;03B7 +etarmenian;0568 +etatonos;03AE +eth;00F0 +etilde;1EBD +etildebelow;1E1B +etnahtafoukhhebrew;0591 +etnahtafoukhlefthebrew;0591 +etnahtahebrew;0591 +etnahtalefthebrew;0591 +eturned;01DD +eukorean;3161 +euro;20AC +evowelsignbengali;09C7 +evowelsigndeva;0947 +evowelsigngujarati;0AC7 +exclam;0021 +exclamarmenian;055C +exclamdbl;203C +exclamdown;00A1 +exclamdownsmall;F7A1 +exclammonospace;FF01 +exclamsmall;F721 +existential;2203 +ezh;0292 +ezhcaron;01EF +ezhcurl;0293 +ezhreversed;01B9 +ezhtail;01BA +f;0066 +fadeva;095E +fagurmukhi;0A5E +fahrenheit;2109 +fathaarabic;064E +fathalowarabic;064E +fathatanarabic;064B +fbopomofo;3108 +fcircle;24D5 +fdotaccent;1E1F +feharabic;0641 +feharmenian;0586 +fehfinalarabic;FED2 +fehinitialarabic;FED3 +fehmedialarabic;FED4 +feicoptic;03E5 +female;2640 +ff;FB00 +ffi;FB03 +ffl;FB04 +fi;FB01 +fifteencircle;246E +fifteenparen;2482 +fifteenperiod;2496 +figuredash;2012 +filledbox;25A0 +filledrect;25AC +finalkaf;05DA +finalkafdagesh;FB3A +finalkafdageshhebrew;FB3A +finalkafhebrew;05DA +finalkafqamats;05DA 05B8 +finalkafqamatshebrew;05DA 05B8 +finalkafsheva;05DA 05B0 +finalkafshevahebrew;05DA 05B0 +finalmem;05DD +finalmemhebrew;05DD +finalnun;05DF +finalnunhebrew;05DF +finalpe;05E3 +finalpehebrew;05E3 +finaltsadi;05E5 +finaltsadihebrew;05E5 +firsttonechinese;02C9 +fisheye;25C9 +fitacyrillic;0473 +five;0035 +fivearabic;0665 +fivebengali;09EB +fivecircle;2464 +fivecircleinversesansserif;278E +fivedeva;096B +fiveeighths;215D +fivegujarati;0AEB +fivegurmukhi;0A6B +fivehackarabic;0665 +fivehangzhou;3025 +fiveideographicparen;3224 +fiveinferior;2085 +fivemonospace;FF15 +fiveoldstyle;F735 +fiveparen;2478 +fiveperiod;248C +fivepersian;06F5 +fiveroman;2174 +fivesuperior;2075 +fivethai;0E55 +fl;FB02 +florin;0192 +fmonospace;FF46 +fmsquare;3399 +fofanthai;0E1F +fofathai;0E1D +fongmanthai;0E4F +forall;2200 +four;0034 +fourarabic;0664 +fourbengali;09EA +fourcircle;2463 +fourcircleinversesansserif;278D +fourdeva;096A +fourgujarati;0AEA +fourgurmukhi;0A6A +fourhackarabic;0664 +fourhangzhou;3024 +fourideographicparen;3223 +fourinferior;2084 +fourmonospace;FF14 +fournumeratorbengali;09F7 +fouroldstyle;F734 +fourparen;2477 +fourperiod;248B +fourpersian;06F4 +fourroman;2173 +foursuperior;2074 +fourteencircle;246D +fourteenparen;2481 +fourteenperiod;2495 +fourthai;0E54 +fourthtonechinese;02CB +fparen;24A1 +fraction;2044 +franc;20A3 +g;0067 +gabengali;0997 +gacute;01F5 +gadeva;0917 +gafarabic;06AF +gaffinalarabic;FB93 +gafinitialarabic;FB94 +gafmedialarabic;FB95 +gagujarati;0A97 +gagurmukhi;0A17 +gahiragana;304C +gakatakana;30AC +gamma;03B3 +gammalatinsmall;0263 +gammasuperior;02E0 +gangiacoptic;03EB +gbopomofo;310D +gbreve;011F +gcaron;01E7 +gcedilla;0123 +gcircle;24D6 +gcircumflex;011D +gcommaaccent;0123 +gdot;0121 +gdotaccent;0121 +gecyrillic;0433 +gehiragana;3052 +gekatakana;30B2 +geometricallyequal;2251 +gereshaccenthebrew;059C +gereshhebrew;05F3 +gereshmuqdamhebrew;059D +germandbls;00DF +gershayimaccenthebrew;059E +gershayimhebrew;05F4 +getamark;3013 +ghabengali;0998 +ghadarmenian;0572 +ghadeva;0918 +ghagujarati;0A98 +ghagurmukhi;0A18 +ghainarabic;063A +ghainfinalarabic;FECE +ghaininitialarabic;FECF +ghainmedialarabic;FED0 +ghemiddlehookcyrillic;0495 +ghestrokecyrillic;0493 +gheupturncyrillic;0491 +ghhadeva;095A +ghhagurmukhi;0A5A +ghook;0260 +ghzsquare;3393 +gihiragana;304E +gikatakana;30AE +gimarmenian;0563 +gimel;05D2 +gimeldagesh;FB32 +gimeldageshhebrew;FB32 +gimelhebrew;05D2 +gjecyrillic;0453 +glottalinvertedstroke;01BE +glottalstop;0294 +glottalstopinverted;0296 +glottalstopmod;02C0 +glottalstopreversed;0295 +glottalstopreversedmod;02C1 +glottalstopreversedsuperior;02E4 +glottalstopstroke;02A1 +glottalstopstrokereversed;02A2 +gmacron;1E21 +gmonospace;FF47 +gohiragana;3054 +gokatakana;30B4 +gparen;24A2 +gpasquare;33AC +gradient;2207 +grave;0060 +gravebelowcmb;0316 +gravecmb;0300 +gravecomb;0300 +gravedeva;0953 +gravelowmod;02CE +gravemonospace;FF40 +gravetonecmb;0340 +greater;003E +greaterequal;2265 +greaterequalorless;22DB +greatermonospace;FF1E +greaterorequivalent;2273 +greaterorless;2277 +greateroverequal;2267 +greatersmall;FE65 +gscript;0261 +gstroke;01E5 +guhiragana;3050 +guillemotleft;00AB +guillemotright;00BB +guilsinglleft;2039 +guilsinglright;203A +gukatakana;30B0 +guramusquare;3318 +gysquare;33C9 +h;0068 +haabkhasiancyrillic;04A9 +haaltonearabic;06C1 +habengali;09B9 +hadescendercyrillic;04B3 +hadeva;0939 +hagujarati;0AB9 +hagurmukhi;0A39 +haharabic;062D +hahfinalarabic;FEA2 +hahinitialarabic;FEA3 +hahiragana;306F +hahmedialarabic;FEA4 +haitusquare;332A +hakatakana;30CF +hakatakanahalfwidth;FF8A +halantgurmukhi;0A4D +hamzaarabic;0621 +hamzadammaarabic;0621 064F +hamzadammatanarabic;0621 064C +hamzafathaarabic;0621 064E +hamzafathatanarabic;0621 064B +hamzalowarabic;0621 +hamzalowkasraarabic;0621 0650 +hamzalowkasratanarabic;0621 064D +hamzasukunarabic;0621 0652 +hangulfiller;3164 +hardsigncyrillic;044A +harpoonleftbarbup;21BC +harpoonrightbarbup;21C0 +hasquare;33CA +hatafpatah;05B2 +hatafpatah16;05B2 +hatafpatah23;05B2 +hatafpatah2f;05B2 +hatafpatahhebrew;05B2 +hatafpatahnarrowhebrew;05B2 +hatafpatahquarterhebrew;05B2 +hatafpatahwidehebrew;05B2 +hatafqamats;05B3 +hatafqamats1b;05B3 +hatafqamats28;05B3 +hatafqamats34;05B3 +hatafqamatshebrew;05B3 +hatafqamatsnarrowhebrew;05B3 +hatafqamatsquarterhebrew;05B3 +hatafqamatswidehebrew;05B3 +hatafsegol;05B1 +hatafsegol17;05B1 +hatafsegol24;05B1 +hatafsegol30;05B1 +hatafsegolhebrew;05B1 +hatafsegolnarrowhebrew;05B1 +hatafsegolquarterhebrew;05B1 +hatafsegolwidehebrew;05B1 +hbar;0127 +hbopomofo;310F +hbrevebelow;1E2B +hcedilla;1E29 +hcircle;24D7 +hcircumflex;0125 +hdieresis;1E27 +hdotaccent;1E23 +hdotbelow;1E25 +he;05D4 +heart;2665 +heartsuitblack;2665 +heartsuitwhite;2661 +hedagesh;FB34 +hedageshhebrew;FB34 +hehaltonearabic;06C1 +heharabic;0647 +hehebrew;05D4 +hehfinalaltonearabic;FBA7 +hehfinalalttwoarabic;FEEA +hehfinalarabic;FEEA +hehhamzaabovefinalarabic;FBA5 +hehhamzaaboveisolatedarabic;FBA4 +hehinitialaltonearabic;FBA8 +hehinitialarabic;FEEB +hehiragana;3078 +hehmedialaltonearabic;FBA9 +hehmedialarabic;FEEC +heiseierasquare;337B +hekatakana;30D8 +hekatakanahalfwidth;FF8D +hekutaarusquare;3336 +henghook;0267 +herutusquare;3339 +het;05D7 +hethebrew;05D7 +hhook;0266 +hhooksuperior;02B1 +hieuhacirclekorean;327B +hieuhaparenkorean;321B +hieuhcirclekorean;326D +hieuhkorean;314E +hieuhparenkorean;320D +hihiragana;3072 +hikatakana;30D2 +hikatakanahalfwidth;FF8B +hiriq;05B4 +hiriq14;05B4 +hiriq21;05B4 +hiriq2d;05B4 +hiriqhebrew;05B4 +hiriqnarrowhebrew;05B4 +hiriqquarterhebrew;05B4 +hiriqwidehebrew;05B4 +hlinebelow;1E96 +hmonospace;FF48 +hoarmenian;0570 +hohipthai;0E2B +hohiragana;307B +hokatakana;30DB +hokatakanahalfwidth;FF8E +holam;05B9 +holam19;05B9 +holam26;05B9 +holam32;05B9 +holamhebrew;05B9 +holamnarrowhebrew;05B9 +holamquarterhebrew;05B9 +holamwidehebrew;05B9 +honokhukthai;0E2E +hookabovecomb;0309 +hookcmb;0309 +hookpalatalizedbelowcmb;0321 +hookretroflexbelowcmb;0322 +hoonsquare;3342 +horicoptic;03E9 +horizontalbar;2015 +horncmb;031B +hotsprings;2668 +house;2302 +hparen;24A3 +hsuperior;02B0 +hturned;0265 +huhiragana;3075 +huiitosquare;3333 +hukatakana;30D5 +hukatakanahalfwidth;FF8C +hungarumlaut;02DD +hungarumlautcmb;030B +hv;0195 +hyphen;002D +hypheninferior;F6E5 +hyphenmonospace;FF0D +hyphensmall;FE63 +hyphensuperior;F6E6 +hyphentwo;2010 +i;0069 +iacute;00ED +iacyrillic;044F +ibengali;0987 +ibopomofo;3127 +ibreve;012D +icaron;01D0 +icircle;24D8 +icircumflex;00EE +icyrillic;0456 +idblgrave;0209 +ideographearthcircle;328F +ideographfirecircle;328B +ideographicallianceparen;323F +ideographiccallparen;323A +ideographiccentrecircle;32A5 +ideographicclose;3006 +ideographiccomma;3001 +ideographiccommaleft;FF64 +ideographiccongratulationparen;3237 +ideographiccorrectcircle;32A3 +ideographicearthparen;322F +ideographicenterpriseparen;323D +ideographicexcellentcircle;329D +ideographicfestivalparen;3240 +ideographicfinancialcircle;3296 +ideographicfinancialparen;3236 +ideographicfireparen;322B +ideographichaveparen;3232 +ideographichighcircle;32A4 +ideographiciterationmark;3005 +ideographiclaborcircle;3298 +ideographiclaborparen;3238 +ideographicleftcircle;32A7 +ideographiclowcircle;32A6 +ideographicmedicinecircle;32A9 +ideographicmetalparen;322E +ideographicmoonparen;322A +ideographicnameparen;3234 +ideographicperiod;3002 +ideographicprintcircle;329E +ideographicreachparen;3243 +ideographicrepresentparen;3239 +ideographicresourceparen;323E +ideographicrightcircle;32A8 +ideographicsecretcircle;3299 +ideographicselfparen;3242 +ideographicsocietyparen;3233 +ideographicspace;3000 +ideographicspecialparen;3235 +ideographicstockparen;3231 +ideographicstudyparen;323B +ideographicsunparen;3230 +ideographicsuperviseparen;323C +ideographicwaterparen;322C +ideographicwoodparen;322D +ideographiczero;3007 +ideographmetalcircle;328E +ideographmooncircle;328A +ideographnamecircle;3294 +ideographsuncircle;3290 +ideographwatercircle;328C +ideographwoodcircle;328D +ideva;0907 +idieresis;00EF +idieresisacute;1E2F +idieresiscyrillic;04E5 +idotbelow;1ECB +iebrevecyrillic;04D7 +iecyrillic;0435 +ieungacirclekorean;3275 +ieungaparenkorean;3215 +ieungcirclekorean;3267 +ieungkorean;3147 +ieungparenkorean;3207 +igrave;00EC +igujarati;0A87 +igurmukhi;0A07 +ihiragana;3044 +ihookabove;1EC9 +iibengali;0988 +iicyrillic;0438 +iideva;0908 +iigujarati;0A88 +iigurmukhi;0A08 +iimatragurmukhi;0A40 +iinvertedbreve;020B +iishortcyrillic;0439 +iivowelsignbengali;09C0 +iivowelsigndeva;0940 +iivowelsigngujarati;0AC0 +ij;0133 +ikatakana;30A4 +ikatakanahalfwidth;FF72 +ikorean;3163 +ilde;02DC +iluyhebrew;05AC +imacron;012B +imacroncyrillic;04E3 +imageorapproximatelyequal;2253 +imatragurmukhi;0A3F +imonospace;FF49 +increment;2206 +infinity;221E +iniarmenian;056B +integral;222B +integralbottom;2321 +integralbt;2321 +integralex;F8F5 +integraltop;2320 +integraltp;2320 +intersection;2229 +intisquare;3305 +invbullet;25D8 +invcircle;25D9 +invsmileface;263B +iocyrillic;0451 +iogonek;012F +iota;03B9 +iotadieresis;03CA +iotadieresistonos;0390 +iotalatin;0269 +iotatonos;03AF +iparen;24A4 +irigurmukhi;0A72 +ismallhiragana;3043 +ismallkatakana;30A3 +ismallkatakanahalfwidth;FF68 +issharbengali;09FA +istroke;0268 +isuperior;F6ED +iterationhiragana;309D +iterationkatakana;30FD +itilde;0129 +itildebelow;1E2D +iubopomofo;3129 +iucyrillic;044E +ivowelsignbengali;09BF +ivowelsigndeva;093F +ivowelsigngujarati;0ABF +izhitsacyrillic;0475 +izhitsadblgravecyrillic;0477 +j;006A +jaarmenian;0571 +jabengali;099C +jadeva;091C +jagujarati;0A9C +jagurmukhi;0A1C +jbopomofo;3110 +jcaron;01F0 +jcircle;24D9 +jcircumflex;0135 +jcrossedtail;029D +jdotlessstroke;025F +jecyrillic;0458 +jeemarabic;062C +jeemfinalarabic;FE9E +jeeminitialarabic;FE9F +jeemmedialarabic;FEA0 +jeharabic;0698 +jehfinalarabic;FB8B +jhabengali;099D +jhadeva;091D +jhagujarati;0A9D +jhagurmukhi;0A1D +jheharmenian;057B +jis;3004 +jmonospace;FF4A +jparen;24A5 +jsuperior;02B2 +k;006B +kabashkircyrillic;04A1 +kabengali;0995 +kacute;1E31 +kacyrillic;043A +kadescendercyrillic;049B +kadeva;0915 +kaf;05DB +kafarabic;0643 +kafdagesh;FB3B +kafdageshhebrew;FB3B +kaffinalarabic;FEDA +kafhebrew;05DB +kafinitialarabic;FEDB +kafmedialarabic;FEDC +kafrafehebrew;FB4D +kagujarati;0A95 +kagurmukhi;0A15 +kahiragana;304B +kahookcyrillic;04C4 +kakatakana;30AB +kakatakanahalfwidth;FF76 +kappa;03BA +kappasymbolgreek;03F0 +kapyeounmieumkorean;3171 +kapyeounphieuphkorean;3184 +kapyeounpieupkorean;3178 +kapyeounssangpieupkorean;3179 +karoriisquare;330D +kashidaautoarabic;0640 +kashidaautonosidebearingarabic;0640 +kasmallkatakana;30F5 +kasquare;3384 +kasraarabic;0650 +kasratanarabic;064D +kastrokecyrillic;049F +katahiraprolongmarkhalfwidth;FF70 +kaverticalstrokecyrillic;049D +kbopomofo;310E +kcalsquare;3389 +kcaron;01E9 +kcedilla;0137 +kcircle;24DA +kcommaaccent;0137 +kdotbelow;1E33 +keharmenian;0584 +kehiragana;3051 +kekatakana;30B1 +kekatakanahalfwidth;FF79 +kenarmenian;056F +kesmallkatakana;30F6 +kgreenlandic;0138 +khabengali;0996 +khacyrillic;0445 +khadeva;0916 +khagujarati;0A96 +khagurmukhi;0A16 +khaharabic;062E +khahfinalarabic;FEA6 +khahinitialarabic;FEA7 +khahmedialarabic;FEA8 +kheicoptic;03E7 +khhadeva;0959 +khhagurmukhi;0A59 +khieukhacirclekorean;3278 +khieukhaparenkorean;3218 +khieukhcirclekorean;326A +khieukhkorean;314B +khieukhparenkorean;320A +khokhaithai;0E02 +khokhonthai;0E05 +khokhuatthai;0E03 +khokhwaithai;0E04 +khomutthai;0E5B +khook;0199 +khorakhangthai;0E06 +khzsquare;3391 +kihiragana;304D +kikatakana;30AD +kikatakanahalfwidth;FF77 +kiroguramusquare;3315 +kiromeetorusquare;3316 +kirosquare;3314 +kiyeokacirclekorean;326E +kiyeokaparenkorean;320E +kiyeokcirclekorean;3260 +kiyeokkorean;3131 +kiyeokparenkorean;3200 +kiyeoksioskorean;3133 +kjecyrillic;045C +klinebelow;1E35 +klsquare;3398 +kmcubedsquare;33A6 +kmonospace;FF4B +kmsquaredsquare;33A2 +kohiragana;3053 +kohmsquare;33C0 +kokaithai;0E01 +kokatakana;30B3 +kokatakanahalfwidth;FF7A +kooposquare;331E +koppacyrillic;0481 +koreanstandardsymbol;327F +koroniscmb;0343 +kparen;24A6 +kpasquare;33AA +ksicyrillic;046F +ktsquare;33CF +kturned;029E +kuhiragana;304F +kukatakana;30AF +kukatakanahalfwidth;FF78 +kvsquare;33B8 +kwsquare;33BE +l;006C +labengali;09B2 +lacute;013A +ladeva;0932 +lagujarati;0AB2 +lagurmukhi;0A32 +lakkhangyaothai;0E45 +lamaleffinalarabic;FEFC +lamalefhamzaabovefinalarabic;FEF8 +lamalefhamzaaboveisolatedarabic;FEF7 +lamalefhamzabelowfinalarabic;FEFA +lamalefhamzabelowisolatedarabic;FEF9 +lamalefisolatedarabic;FEFB +lamalefmaddaabovefinalarabic;FEF6 +lamalefmaddaaboveisolatedarabic;FEF5 +lamarabic;0644 +lambda;03BB +lambdastroke;019B +lamed;05DC +lameddagesh;FB3C +lameddageshhebrew;FB3C +lamedhebrew;05DC +lamedholam;05DC 05B9 +lamedholamdagesh;05DC 05B9 05BC +lamedholamdageshhebrew;05DC 05B9 05BC +lamedholamhebrew;05DC 05B9 +lamfinalarabic;FEDE +lamhahinitialarabic;FCCA +laminitialarabic;FEDF +lamjeeminitialarabic;FCC9 +lamkhahinitialarabic;FCCB +lamlamhehisolatedarabic;FDF2 +lammedialarabic;FEE0 +lammeemhahinitialarabic;FD88 +lammeeminitialarabic;FCCC +lammeemjeeminitialarabic;FEDF FEE4 FEA0 +lammeemkhahinitialarabic;FEDF FEE4 FEA8 +largecircle;25EF +lbar;019A +lbelt;026C +lbopomofo;310C +lcaron;013E +lcedilla;013C +lcircle;24DB +lcircumflexbelow;1E3D +lcommaaccent;013C +ldot;0140 +ldotaccent;0140 +ldotbelow;1E37 +ldotbelowmacron;1E39 +leftangleabovecmb;031A +lefttackbelowcmb;0318 +less;003C +lessequal;2264 +lessequalorgreater;22DA +lessmonospace;FF1C +lessorequivalent;2272 +lessorgreater;2276 +lessoverequal;2266 +lesssmall;FE64 +lezh;026E +lfblock;258C +lhookretroflex;026D +lira;20A4 +liwnarmenian;056C +lj;01C9 +ljecyrillic;0459 +ll;F6C0 +lladeva;0933 +llagujarati;0AB3 +llinebelow;1E3B +llladeva;0934 +llvocalicbengali;09E1 +llvocalicdeva;0961 +llvocalicvowelsignbengali;09E3 +llvocalicvowelsigndeva;0963 +lmiddletilde;026B +lmonospace;FF4C +lmsquare;33D0 +lochulathai;0E2C +logicaland;2227 +logicalnot;00AC +logicalnotreversed;2310 +logicalor;2228 +lolingthai;0E25 +longs;017F +lowlinecenterline;FE4E +lowlinecmb;0332 +lowlinedashed;FE4D +lozenge;25CA +lparen;24A7 +lslash;0142 +lsquare;2113 +lsuperior;F6EE +ltshade;2591 +luthai;0E26 +lvocalicbengali;098C +lvocalicdeva;090C +lvocalicvowelsignbengali;09E2 +lvocalicvowelsigndeva;0962 +lxsquare;33D3 +m;006D +mabengali;09AE +macron;00AF +macronbelowcmb;0331 +macroncmb;0304 +macronlowmod;02CD +macronmonospace;FFE3 +macute;1E3F +madeva;092E +magujarati;0AAE +magurmukhi;0A2E +mahapakhhebrew;05A4 +mahapakhlefthebrew;05A4 +mahiragana;307E +maichattawalowleftthai;F895 +maichattawalowrightthai;F894 +maichattawathai;0E4B +maichattawaupperleftthai;F893 +maieklowleftthai;F88C +maieklowrightthai;F88B +maiekthai;0E48 +maiekupperleftthai;F88A +maihanakatleftthai;F884 +maihanakatthai;0E31 +maitaikhuleftthai;F889 +maitaikhuthai;0E47 +maitholowleftthai;F88F +maitholowrightthai;F88E +maithothai;0E49 +maithoupperleftthai;F88D +maitrilowleftthai;F892 +maitrilowrightthai;F891 +maitrithai;0E4A +maitriupperleftthai;F890 +maiyamokthai;0E46 +makatakana;30DE +makatakanahalfwidth;FF8F +male;2642 +mansyonsquare;3347 +maqafhebrew;05BE +mars;2642 +masoracirclehebrew;05AF +masquare;3383 +mbopomofo;3107 +mbsquare;33D4 +mcircle;24DC +mcubedsquare;33A5 +mdotaccent;1E41 +mdotbelow;1E43 +meemarabic;0645 +meemfinalarabic;FEE2 +meeminitialarabic;FEE3 +meemmedialarabic;FEE4 +meemmeeminitialarabic;FCD1 +meemmeemisolatedarabic;FC48 +meetorusquare;334D +mehiragana;3081 +meizierasquare;337E +mekatakana;30E1 +mekatakanahalfwidth;FF92 +mem;05DE +memdagesh;FB3E +memdageshhebrew;FB3E +memhebrew;05DE +menarmenian;0574 +merkhahebrew;05A5 +merkhakefulahebrew;05A6 +merkhakefulalefthebrew;05A6 +merkhalefthebrew;05A5 +mhook;0271 +mhzsquare;3392 +middledotkatakanahalfwidth;FF65 +middot;00B7 +mieumacirclekorean;3272 +mieumaparenkorean;3212 +mieumcirclekorean;3264 +mieumkorean;3141 +mieumpansioskorean;3170 +mieumparenkorean;3204 +mieumpieupkorean;316E +mieumsioskorean;316F +mihiragana;307F +mikatakana;30DF +mikatakanahalfwidth;FF90 +minus;2212 +minusbelowcmb;0320 +minuscircle;2296 +minusmod;02D7 +minusplus;2213 +minute;2032 +miribaarusquare;334A +mirisquare;3349 +mlonglegturned;0270 +mlsquare;3396 +mmcubedsquare;33A3 +mmonospace;FF4D +mmsquaredsquare;339F +mohiragana;3082 +mohmsquare;33C1 +mokatakana;30E2 +mokatakanahalfwidth;FF93 +molsquare;33D6 +momathai;0E21 +moverssquare;33A7 +moverssquaredsquare;33A8 +mparen;24A8 +mpasquare;33AB +mssquare;33B3 +msuperior;F6EF +mturned;026F +mu;00B5 +mu1;00B5 +muasquare;3382 +muchgreater;226B +muchless;226A +mufsquare;338C +mugreek;03BC +mugsquare;338D +muhiragana;3080 +mukatakana;30E0 +mukatakanahalfwidth;FF91 +mulsquare;3395 +multiply;00D7 +mumsquare;339B +munahhebrew;05A3 +munahlefthebrew;05A3 +musicalnote;266A +musicalnotedbl;266B +musicflatsign;266D +musicsharpsign;266F +mussquare;33B2 +muvsquare;33B6 +muwsquare;33BC +mvmegasquare;33B9 +mvsquare;33B7 +mwmegasquare;33BF +mwsquare;33BD +n;006E +nabengali;09A8 +nabla;2207 +nacute;0144 +nadeva;0928 +nagujarati;0AA8 +nagurmukhi;0A28 +nahiragana;306A +nakatakana;30CA +nakatakanahalfwidth;FF85 +napostrophe;0149 +nasquare;3381 +nbopomofo;310B +nbspace;00A0 +ncaron;0148 +ncedilla;0146 +ncircle;24DD +ncircumflexbelow;1E4B +ncommaaccent;0146 +ndotaccent;1E45 +ndotbelow;1E47 +nehiragana;306D +nekatakana;30CD +nekatakanahalfwidth;FF88 +newsheqelsign;20AA +nfsquare;338B +ngabengali;0999 +ngadeva;0919 +ngagujarati;0A99 +ngagurmukhi;0A19 +ngonguthai;0E07 +nhiragana;3093 +nhookleft;0272 +nhookretroflex;0273 +nieunacirclekorean;326F +nieunaparenkorean;320F +nieuncieuckorean;3135 +nieuncirclekorean;3261 +nieunhieuhkorean;3136 +nieunkorean;3134 +nieunpansioskorean;3168 +nieunparenkorean;3201 +nieunsioskorean;3167 +nieuntikeutkorean;3166 +nihiragana;306B +nikatakana;30CB +nikatakanahalfwidth;FF86 +nikhahitleftthai;F899 +nikhahitthai;0E4D +nine;0039 +ninearabic;0669 +ninebengali;09EF +ninecircle;2468 +ninecircleinversesansserif;2792 +ninedeva;096F +ninegujarati;0AEF +ninegurmukhi;0A6F +ninehackarabic;0669 +ninehangzhou;3029 +nineideographicparen;3228 +nineinferior;2089 +ninemonospace;FF19 +nineoldstyle;F739 +nineparen;247C +nineperiod;2490 +ninepersian;06F9 +nineroman;2178 +ninesuperior;2079 +nineteencircle;2472 +nineteenparen;2486 +nineteenperiod;249A +ninethai;0E59 +nj;01CC +njecyrillic;045A +nkatakana;30F3 +nkatakanahalfwidth;FF9D +nlegrightlong;019E +nlinebelow;1E49 +nmonospace;FF4E +nmsquare;339A +nnabengali;09A3 +nnadeva;0923 +nnagujarati;0AA3 +nnagurmukhi;0A23 +nnnadeva;0929 +nohiragana;306E +nokatakana;30CE +nokatakanahalfwidth;FF89 +nonbreakingspace;00A0 +nonenthai;0E13 +nonuthai;0E19 +noonarabic;0646 +noonfinalarabic;FEE6 +noonghunnaarabic;06BA +noonghunnafinalarabic;FB9F +noonhehinitialarabic;FEE7 FEEC +nooninitialarabic;FEE7 +noonjeeminitialarabic;FCD2 +noonjeemisolatedarabic;FC4B +noonmedialarabic;FEE8 +noonmeeminitialarabic;FCD5 +noonmeemisolatedarabic;FC4E +noonnoonfinalarabic;FC8D +notcontains;220C +notelement;2209 +notelementof;2209 +notequal;2260 +notgreater;226F +notgreaternorequal;2271 +notgreaternorless;2279 +notidentical;2262 +notless;226E +notlessnorequal;2270 +notparallel;2226 +notprecedes;2280 +notsubset;2284 +notsucceeds;2281 +notsuperset;2285 +nowarmenian;0576 +nparen;24A9 +nssquare;33B1 +nsuperior;207F +ntilde;00F1 +nu;03BD +nuhiragana;306C +nukatakana;30CC +nukatakanahalfwidth;FF87 +nuktabengali;09BC +nuktadeva;093C +nuktagujarati;0ABC +nuktagurmukhi;0A3C +numbersign;0023 +numbersignmonospace;FF03 +numbersignsmall;FE5F +numeralsigngreek;0374 +numeralsignlowergreek;0375 +numero;2116 +nun;05E0 +nundagesh;FB40 +nundageshhebrew;FB40 +nunhebrew;05E0 +nvsquare;33B5 +nwsquare;33BB +nyabengali;099E +nyadeva;091E +nyagujarati;0A9E +nyagurmukhi;0A1E +o;006F +oacute;00F3 +oangthai;0E2D +obarred;0275 +obarredcyrillic;04E9 +obarreddieresiscyrillic;04EB +obengali;0993 +obopomofo;311B +obreve;014F +ocandradeva;0911 +ocandragujarati;0A91 +ocandravowelsigndeva;0949 +ocandravowelsigngujarati;0AC9 +ocaron;01D2 +ocircle;24DE +ocircumflex;00F4 +ocircumflexacute;1ED1 +ocircumflexdotbelow;1ED9 +ocircumflexgrave;1ED3 +ocircumflexhookabove;1ED5 +ocircumflextilde;1ED7 +ocyrillic;043E +odblacute;0151 +odblgrave;020D +odeva;0913 +odieresis;00F6 +odieresiscyrillic;04E7 +odotbelow;1ECD +oe;0153 +oekorean;315A +ogonek;02DB +ogonekcmb;0328 +ograve;00F2 +ogujarati;0A93 +oharmenian;0585 +ohiragana;304A +ohookabove;1ECF +ohorn;01A1 +ohornacute;1EDB +ohorndotbelow;1EE3 +ohorngrave;1EDD +ohornhookabove;1EDF +ohorntilde;1EE1 +ohungarumlaut;0151 +oi;01A3 +oinvertedbreve;020F +okatakana;30AA +okatakanahalfwidth;FF75 +okorean;3157 +olehebrew;05AB +omacron;014D +omacronacute;1E53 +omacrongrave;1E51 +omdeva;0950 +omega;03C9 +omega1;03D6 +omegacyrillic;0461 +omegalatinclosed;0277 +omegaroundcyrillic;047B +omegatitlocyrillic;047D +omegatonos;03CE +omgujarati;0AD0 +omicron;03BF +omicrontonos;03CC +omonospace;FF4F +one;0031 +onearabic;0661 +onebengali;09E7 +onecircle;2460 +onecircleinversesansserif;278A +onedeva;0967 +onedotenleader;2024 +oneeighth;215B +onefitted;F6DC +onegujarati;0AE7 +onegurmukhi;0A67 +onehackarabic;0661 +onehalf;00BD +onehangzhou;3021 +oneideographicparen;3220 +oneinferior;2081 +onemonospace;FF11 +onenumeratorbengali;09F4 +oneoldstyle;F731 +oneparen;2474 +oneperiod;2488 +onepersian;06F1 +onequarter;00BC +oneroman;2170 +onesuperior;00B9 +onethai;0E51 +onethird;2153 +oogonek;01EB +oogonekmacron;01ED +oogurmukhi;0A13 +oomatragurmukhi;0A4B +oopen;0254 +oparen;24AA +openbullet;25E6 +option;2325 +ordfeminine;00AA +ordmasculine;00BA +orthogonal;221F +oshortdeva;0912 +oshortvowelsigndeva;094A +oslash;00F8 +oslashacute;01FF +osmallhiragana;3049 +osmallkatakana;30A9 +osmallkatakanahalfwidth;FF6B +ostrokeacute;01FF +osuperior;F6F0 +otcyrillic;047F +otilde;00F5 +otildeacute;1E4D +otildedieresis;1E4F +oubopomofo;3121 +overline;203E +overlinecenterline;FE4A +overlinecmb;0305 +overlinedashed;FE49 +overlinedblwavy;FE4C +overlinewavy;FE4B +overscore;00AF +ovowelsignbengali;09CB +ovowelsigndeva;094B +ovowelsigngujarati;0ACB +p;0070 +paampssquare;3380 +paasentosquare;332B +pabengali;09AA +pacute;1E55 +padeva;092A +pagedown;21DF +pageup;21DE +pagujarati;0AAA +pagurmukhi;0A2A +pahiragana;3071 +paiyannoithai;0E2F +pakatakana;30D1 +palatalizationcyrilliccmb;0484 +palochkacyrillic;04C0 +pansioskorean;317F +paragraph;00B6 +parallel;2225 +parenleft;0028 +parenleftaltonearabic;FD3E +parenleftbt;F8ED +parenleftex;F8EC +parenleftinferior;208D +parenleftmonospace;FF08 +parenleftsmall;FE59 +parenleftsuperior;207D +parenlefttp;F8EB +parenleftvertical;FE35 +parenright;0029 +parenrightaltonearabic;FD3F +parenrightbt;F8F8 +parenrightex;F8F7 +parenrightinferior;208E +parenrightmonospace;FF09 +parenrightsmall;FE5A +parenrightsuperior;207E +parenrighttp;F8F6 +parenrightvertical;FE36 +partialdiff;2202 +paseqhebrew;05C0 +pashtahebrew;0599 +pasquare;33A9 +patah;05B7 +patah11;05B7 +patah1d;05B7 +patah2a;05B7 +patahhebrew;05B7 +patahnarrowhebrew;05B7 +patahquarterhebrew;05B7 +patahwidehebrew;05B7 +pazerhebrew;05A1 +pbopomofo;3106 +pcircle;24DF +pdotaccent;1E57 +pe;05E4 +pecyrillic;043F +pedagesh;FB44 +pedageshhebrew;FB44 +peezisquare;333B +pefinaldageshhebrew;FB43 +peharabic;067E +peharmenian;057A +pehebrew;05E4 +pehfinalarabic;FB57 +pehinitialarabic;FB58 +pehiragana;307A +pehmedialarabic;FB59 +pekatakana;30DA +pemiddlehookcyrillic;04A7 +perafehebrew;FB4E +percent;0025 +percentarabic;066A +percentmonospace;FF05 +percentsmall;FE6A +period;002E +periodarmenian;0589 +periodcentered;00B7 +periodhalfwidth;FF61 +periodinferior;F6E7 +periodmonospace;FF0E +periodsmall;FE52 +periodsuperior;F6E8 +perispomenigreekcmb;0342 +perpendicular;22A5 +perthousand;2030 +peseta;20A7 +pfsquare;338A +phabengali;09AB +phadeva;092B +phagujarati;0AAB +phagurmukhi;0A2B +phi;03C6 +phi1;03D5 +phieuphacirclekorean;327A +phieuphaparenkorean;321A +phieuphcirclekorean;326C +phieuphkorean;314D +phieuphparenkorean;320C +philatin;0278 +phinthuthai;0E3A +phisymbolgreek;03D5 +phook;01A5 +phophanthai;0E1E +phophungthai;0E1C +phosamphaothai;0E20 +pi;03C0 +pieupacirclekorean;3273 +pieupaparenkorean;3213 +pieupcieuckorean;3176 +pieupcirclekorean;3265 +pieupkiyeokkorean;3172 +pieupkorean;3142 +pieupparenkorean;3205 +pieupsioskiyeokkorean;3174 +pieupsioskorean;3144 +pieupsiostikeutkorean;3175 +pieupthieuthkorean;3177 +pieuptikeutkorean;3173 +pihiragana;3074 +pikatakana;30D4 +pisymbolgreek;03D6 +piwrarmenian;0583 +plus;002B +plusbelowcmb;031F +pluscircle;2295 +plusminus;00B1 +plusmod;02D6 +plusmonospace;FF0B +plussmall;FE62 +plussuperior;207A +pmonospace;FF50 +pmsquare;33D8 +pohiragana;307D +pointingindexdownwhite;261F +pointingindexleftwhite;261C +pointingindexrightwhite;261E +pointingindexupwhite;261D +pokatakana;30DD +poplathai;0E1B +postalmark;3012 +postalmarkface;3020 +pparen;24AB +precedes;227A +prescription;211E +primemod;02B9 +primereversed;2035 +product;220F +projective;2305 +prolongedkana;30FC +propellor;2318 +propersubset;2282 +propersuperset;2283 +proportion;2237 +proportional;221D +psi;03C8 +psicyrillic;0471 +psilipneumatacyrilliccmb;0486 +pssquare;33B0 +puhiragana;3077 +pukatakana;30D7 +pvsquare;33B4 +pwsquare;33BA +q;0071 +qadeva;0958 +qadmahebrew;05A8 +qafarabic;0642 +qaffinalarabic;FED6 +qafinitialarabic;FED7 +qafmedialarabic;FED8 +qamats;05B8 +qamats10;05B8 +qamats1a;05B8 +qamats1c;05B8 +qamats27;05B8 +qamats29;05B8 +qamats33;05B8 +qamatsde;05B8 +qamatshebrew;05B8 +qamatsnarrowhebrew;05B8 +qamatsqatanhebrew;05B8 +qamatsqatannarrowhebrew;05B8 +qamatsqatanquarterhebrew;05B8 +qamatsqatanwidehebrew;05B8 +qamatsquarterhebrew;05B8 +qamatswidehebrew;05B8 +qarneyparahebrew;059F +qbopomofo;3111 +qcircle;24E0 +qhook;02A0 +qmonospace;FF51 +qof;05E7 +qofdagesh;FB47 +qofdageshhebrew;FB47 +qofhatafpatah;05E7 05B2 +qofhatafpatahhebrew;05E7 05B2 +qofhatafsegol;05E7 05B1 +qofhatafsegolhebrew;05E7 05B1 +qofhebrew;05E7 +qofhiriq;05E7 05B4 +qofhiriqhebrew;05E7 05B4 +qofholam;05E7 05B9 +qofholamhebrew;05E7 05B9 +qofpatah;05E7 05B7 +qofpatahhebrew;05E7 05B7 +qofqamats;05E7 05B8 +qofqamatshebrew;05E7 05B8 +qofqubuts;05E7 05BB +qofqubutshebrew;05E7 05BB +qofsegol;05E7 05B6 +qofsegolhebrew;05E7 05B6 +qofsheva;05E7 05B0 +qofshevahebrew;05E7 05B0 +qoftsere;05E7 05B5 +qoftserehebrew;05E7 05B5 +qparen;24AC +quarternote;2669 +qubuts;05BB +qubuts18;05BB +qubuts25;05BB +qubuts31;05BB +qubutshebrew;05BB +qubutsnarrowhebrew;05BB +qubutsquarterhebrew;05BB +qubutswidehebrew;05BB +question;003F +questionarabic;061F +questionarmenian;055E +questiondown;00BF +questiondownsmall;F7BF +questiongreek;037E +questionmonospace;FF1F +questionsmall;F73F +quotedbl;0022 +quotedblbase;201E +quotedblleft;201C +quotedblmonospace;FF02 +quotedblprime;301E +quotedblprimereversed;301D +quotedblright;201D +quoteleft;2018 +quoteleftreversed;201B +quotereversed;201B +quoteright;2019 +quoterightn;0149 +quotesinglbase;201A +quotesingle;0027 +quotesinglemonospace;FF07 +r;0072 +raarmenian;057C +rabengali;09B0 +racute;0155 +radeva;0930 +radical;221A +radicalex;F8E5 +radoverssquare;33AE +radoverssquaredsquare;33AF +radsquare;33AD +rafe;05BF +rafehebrew;05BF +ragujarati;0AB0 +ragurmukhi;0A30 +rahiragana;3089 +rakatakana;30E9 +rakatakanahalfwidth;FF97 +ralowerdiagonalbengali;09F1 +ramiddlediagonalbengali;09F0 +ramshorn;0264 +ratio;2236 +rbopomofo;3116 +rcaron;0159 +rcedilla;0157 +rcircle;24E1 +rcommaaccent;0157 +rdblgrave;0211 +rdotaccent;1E59 +rdotbelow;1E5B +rdotbelowmacron;1E5D +referencemark;203B +reflexsubset;2286 +reflexsuperset;2287 +registered;00AE +registersans;F8E8 +registerserif;F6DA +reharabic;0631 +reharmenian;0580 +rehfinalarabic;FEAE +rehiragana;308C +rehyehaleflamarabic;0631 FEF3 FE8E 0644 +rekatakana;30EC +rekatakanahalfwidth;FF9A +resh;05E8 +reshdageshhebrew;FB48 +reshhatafpatah;05E8 05B2 +reshhatafpatahhebrew;05E8 05B2 +reshhatafsegol;05E8 05B1 +reshhatafsegolhebrew;05E8 05B1 +reshhebrew;05E8 +reshhiriq;05E8 05B4 +reshhiriqhebrew;05E8 05B4 +reshholam;05E8 05B9 +reshholamhebrew;05E8 05B9 +reshpatah;05E8 05B7 +reshpatahhebrew;05E8 05B7 +reshqamats;05E8 05B8 +reshqamatshebrew;05E8 05B8 +reshqubuts;05E8 05BB +reshqubutshebrew;05E8 05BB +reshsegol;05E8 05B6 +reshsegolhebrew;05E8 05B6 +reshsheva;05E8 05B0 +reshshevahebrew;05E8 05B0 +reshtsere;05E8 05B5 +reshtserehebrew;05E8 05B5 +reversedtilde;223D +reviahebrew;0597 +reviamugrashhebrew;0597 +revlogicalnot;2310 +rfishhook;027E +rfishhookreversed;027F +rhabengali;09DD +rhadeva;095D +rho;03C1 +rhook;027D +rhookturned;027B +rhookturnedsuperior;02B5 +rhosymbolgreek;03F1 +rhotichookmod;02DE +rieulacirclekorean;3271 +rieulaparenkorean;3211 +rieulcirclekorean;3263 +rieulhieuhkorean;3140 +rieulkiyeokkorean;313A +rieulkiyeoksioskorean;3169 +rieulkorean;3139 +rieulmieumkorean;313B +rieulpansioskorean;316C +rieulparenkorean;3203 +rieulphieuphkorean;313F +rieulpieupkorean;313C +rieulpieupsioskorean;316B +rieulsioskorean;313D +rieulthieuthkorean;313E +rieultikeutkorean;316A +rieulyeorinhieuhkorean;316D +rightangle;221F +righttackbelowcmb;0319 +righttriangle;22BF +rihiragana;308A +rikatakana;30EA +rikatakanahalfwidth;FF98 +ring;02DA +ringbelowcmb;0325 +ringcmb;030A +ringhalfleft;02BF +ringhalfleftarmenian;0559 +ringhalfleftbelowcmb;031C +ringhalfleftcentered;02D3 +ringhalfright;02BE +ringhalfrightbelowcmb;0339 +ringhalfrightcentered;02D2 +rinvertedbreve;0213 +rittorusquare;3351 +rlinebelow;1E5F +rlongleg;027C +rlonglegturned;027A +rmonospace;FF52 +rohiragana;308D +rokatakana;30ED +rokatakanahalfwidth;FF9B +roruathai;0E23 +rparen;24AD +rrabengali;09DC +rradeva;0931 +rragurmukhi;0A5C +rreharabic;0691 +rrehfinalarabic;FB8D +rrvocalicbengali;09E0 +rrvocalicdeva;0960 +rrvocalicgujarati;0AE0 +rrvocalicvowelsignbengali;09C4 +rrvocalicvowelsigndeva;0944 +rrvocalicvowelsigngujarati;0AC4 +rsuperior;F6F1 +rtblock;2590 +rturned;0279 +rturnedsuperior;02B4 +ruhiragana;308B +rukatakana;30EB +rukatakanahalfwidth;FF99 +rupeemarkbengali;09F2 +rupeesignbengali;09F3 +rupiah;F6DD +ruthai;0E24 +rvocalicbengali;098B +rvocalicdeva;090B +rvocalicgujarati;0A8B +rvocalicvowelsignbengali;09C3 +rvocalicvowelsigndeva;0943 +rvocalicvowelsigngujarati;0AC3 +s;0073 +sabengali;09B8 +sacute;015B +sacutedotaccent;1E65 +sadarabic;0635 +sadeva;0938 +sadfinalarabic;FEBA +sadinitialarabic;FEBB +sadmedialarabic;FEBC +sagujarati;0AB8 +sagurmukhi;0A38 +sahiragana;3055 +sakatakana;30B5 +sakatakanahalfwidth;FF7B +sallallahoualayhewasallamarabic;FDFA +samekh;05E1 +samekhdagesh;FB41 +samekhdageshhebrew;FB41 +samekhhebrew;05E1 +saraaathai;0E32 +saraaethai;0E41 +saraaimaimalaithai;0E44 +saraaimaimuanthai;0E43 +saraamthai;0E33 +saraathai;0E30 +saraethai;0E40 +saraiileftthai;F886 +saraiithai;0E35 +saraileftthai;F885 +saraithai;0E34 +saraothai;0E42 +saraueeleftthai;F888 +saraueethai;0E37 +saraueleftthai;F887 +sarauethai;0E36 +sarauthai;0E38 +sarauuthai;0E39 +sbopomofo;3119 +scaron;0161 +scarondotaccent;1E67 +scedilla;015F +schwa;0259 +schwacyrillic;04D9 +schwadieresiscyrillic;04DB +schwahook;025A +scircle;24E2 +scircumflex;015D +scommaaccent;0219 +sdotaccent;1E61 +sdotbelow;1E63 +sdotbelowdotaccent;1E69 +seagullbelowcmb;033C +second;2033 +secondtonechinese;02CA +section;00A7 +seenarabic;0633 +seenfinalarabic;FEB2 +seeninitialarabic;FEB3 +seenmedialarabic;FEB4 +segol;05B6 +segol13;05B6 +segol1f;05B6 +segol2c;05B6 +segolhebrew;05B6 +segolnarrowhebrew;05B6 +segolquarterhebrew;05B6 +segoltahebrew;0592 +segolwidehebrew;05B6 +seharmenian;057D +sehiragana;305B +sekatakana;30BB +sekatakanahalfwidth;FF7E +semicolon;003B +semicolonarabic;061B +semicolonmonospace;FF1B +semicolonsmall;FE54 +semivoicedmarkkana;309C +semivoicedmarkkanahalfwidth;FF9F +sentisquare;3322 +sentosquare;3323 +seven;0037 +sevenarabic;0667 +sevenbengali;09ED +sevencircle;2466 +sevencircleinversesansserif;2790 +sevendeva;096D +seveneighths;215E +sevengujarati;0AED +sevengurmukhi;0A6D +sevenhackarabic;0667 +sevenhangzhou;3027 +sevenideographicparen;3226 +seveninferior;2087 +sevenmonospace;FF17 +sevenoldstyle;F737 +sevenparen;247A +sevenperiod;248E +sevenpersian;06F7 +sevenroman;2176 +sevensuperior;2077 +seventeencircle;2470 +seventeenparen;2484 +seventeenperiod;2498 +seventhai;0E57 +sfthyphen;00AD +shaarmenian;0577 +shabengali;09B6 +shacyrillic;0448 +shaddaarabic;0651 +shaddadammaarabic;FC61 +shaddadammatanarabic;FC5E +shaddafathaarabic;FC60 +shaddafathatanarabic;0651 064B +shaddakasraarabic;FC62 +shaddakasratanarabic;FC5F +shade;2592 +shadedark;2593 +shadelight;2591 +shademedium;2592 +shadeva;0936 +shagujarati;0AB6 +shagurmukhi;0A36 +shalshelethebrew;0593 +shbopomofo;3115 +shchacyrillic;0449 +sheenarabic;0634 +sheenfinalarabic;FEB6 +sheeninitialarabic;FEB7 +sheenmedialarabic;FEB8 +sheicoptic;03E3 +sheqel;20AA +sheqelhebrew;20AA +sheva;05B0 +sheva115;05B0 +sheva15;05B0 +sheva22;05B0 +sheva2e;05B0 +shevahebrew;05B0 +shevanarrowhebrew;05B0 +shevaquarterhebrew;05B0 +shevawidehebrew;05B0 +shhacyrillic;04BB +shimacoptic;03ED +shin;05E9 +shindagesh;FB49 +shindageshhebrew;FB49 +shindageshshindot;FB2C +shindageshshindothebrew;FB2C +shindageshsindot;FB2D +shindageshsindothebrew;FB2D +shindothebrew;05C1 +shinhebrew;05E9 +shinshindot;FB2A +shinshindothebrew;FB2A +shinsindot;FB2B +shinsindothebrew;FB2B +shook;0282 +sigma;03C3 +sigma1;03C2 +sigmafinal;03C2 +sigmalunatesymbolgreek;03F2 +sihiragana;3057 +sikatakana;30B7 +sikatakanahalfwidth;FF7C +siluqhebrew;05BD +siluqlefthebrew;05BD +similar;223C +sindothebrew;05C2 +siosacirclekorean;3274 +siosaparenkorean;3214 +sioscieuckorean;317E +sioscirclekorean;3266 +sioskiyeokkorean;317A +sioskorean;3145 +siosnieunkorean;317B +siosparenkorean;3206 +siospieupkorean;317D +siostikeutkorean;317C +six;0036 +sixarabic;0666 +sixbengali;09EC +sixcircle;2465 +sixcircleinversesansserif;278F +sixdeva;096C +sixgujarati;0AEC +sixgurmukhi;0A6C +sixhackarabic;0666 +sixhangzhou;3026 +sixideographicparen;3225 +sixinferior;2086 +sixmonospace;FF16 +sixoldstyle;F736 +sixparen;2479 +sixperiod;248D +sixpersian;06F6 +sixroman;2175 +sixsuperior;2076 +sixteencircle;246F +sixteencurrencydenominatorbengali;09F9 +sixteenparen;2483 +sixteenperiod;2497 +sixthai;0E56 +slash;002F +slashmonospace;FF0F +slong;017F +slongdotaccent;1E9B +smileface;263A +smonospace;FF53 +sofpasuqhebrew;05C3 +softhyphen;00AD +softsigncyrillic;044C +sohiragana;305D +sokatakana;30BD +sokatakanahalfwidth;FF7F +soliduslongoverlaycmb;0338 +solidusshortoverlaycmb;0337 +sorusithai;0E29 +sosalathai;0E28 +sosothai;0E0B +sosuathai;0E2A +space;0020 +spacehackarabic;0020 +spade;2660 +spadesuitblack;2660 +spadesuitwhite;2664 +sparen;24AE +squarebelowcmb;033B +squarecc;33C4 +squarecm;339D +squarediagonalcrosshatchfill;25A9 +squarehorizontalfill;25A4 +squarekg;338F +squarekm;339E +squarekmcapital;33CE +squareln;33D1 +squarelog;33D2 +squaremg;338E +squaremil;33D5 +squaremm;339C +squaremsquared;33A1 +squareorthogonalcrosshatchfill;25A6 +squareupperlefttolowerrightfill;25A7 +squareupperrighttolowerleftfill;25A8 +squareverticalfill;25A5 +squarewhitewithsmallblack;25A3 +srsquare;33DB +ssabengali;09B7 +ssadeva;0937 +ssagujarati;0AB7 +ssangcieuckorean;3149 +ssanghieuhkorean;3185 +ssangieungkorean;3180 +ssangkiyeokkorean;3132 +ssangnieunkorean;3165 +ssangpieupkorean;3143 +ssangsioskorean;3146 +ssangtikeutkorean;3138 +ssuperior;F6F2 +sterling;00A3 +sterlingmonospace;FFE1 +strokelongoverlaycmb;0336 +strokeshortoverlaycmb;0335 +subset;2282 +subsetnotequal;228A +subsetorequal;2286 +succeeds;227B +suchthat;220B +suhiragana;3059 +sukatakana;30B9 +sukatakanahalfwidth;FF7D +sukunarabic;0652 +summation;2211 +sun;263C +superset;2283 +supersetnotequal;228B +supersetorequal;2287 +svsquare;33DC +syouwaerasquare;337C +t;0074 +tabengali;09A4 +tackdown;22A4 +tackleft;22A3 +tadeva;0924 +tagujarati;0AA4 +tagurmukhi;0A24 +taharabic;0637 +tahfinalarabic;FEC2 +tahinitialarabic;FEC3 +tahiragana;305F +tahmedialarabic;FEC4 +taisyouerasquare;337D +takatakana;30BF +takatakanahalfwidth;FF80 +tatweelarabic;0640 +tau;03C4 +tav;05EA +tavdages;FB4A +tavdagesh;FB4A +tavdageshhebrew;FB4A +tavhebrew;05EA +tbar;0167 +tbopomofo;310A +tcaron;0165 +tccurl;02A8 +tcedilla;0163 +tcheharabic;0686 +tchehfinalarabic;FB7B +tchehinitialarabic;FB7C +tchehmedialarabic;FB7D +tchehmeeminitialarabic;FB7C FEE4 +tcircle;24E3 +tcircumflexbelow;1E71 +tcommaaccent;0163 +tdieresis;1E97 +tdotaccent;1E6B +tdotbelow;1E6D +tecyrillic;0442 +tedescendercyrillic;04AD +teharabic;062A +tehfinalarabic;FE96 +tehhahinitialarabic;FCA2 +tehhahisolatedarabic;FC0C +tehinitialarabic;FE97 +tehiragana;3066 +tehjeeminitialarabic;FCA1 +tehjeemisolatedarabic;FC0B +tehmarbutaarabic;0629 +tehmarbutafinalarabic;FE94 +tehmedialarabic;FE98 +tehmeeminitialarabic;FCA4 +tehmeemisolatedarabic;FC0E +tehnoonfinalarabic;FC73 +tekatakana;30C6 +tekatakanahalfwidth;FF83 +telephone;2121 +telephoneblack;260E +telishagedolahebrew;05A0 +telishaqetanahebrew;05A9 +tencircle;2469 +tenideographicparen;3229 +tenparen;247D +tenperiod;2491 +tenroman;2179 +tesh;02A7 +tet;05D8 +tetdagesh;FB38 +tetdageshhebrew;FB38 +tethebrew;05D8 +tetsecyrillic;04B5 +tevirhebrew;059B +tevirlefthebrew;059B +thabengali;09A5 +thadeva;0925 +thagujarati;0AA5 +thagurmukhi;0A25 +thalarabic;0630 +thalfinalarabic;FEAC +thanthakhatlowleftthai;F898 +thanthakhatlowrightthai;F897 +thanthakhatthai;0E4C +thanthakhatupperleftthai;F896 +theharabic;062B +thehfinalarabic;FE9A +thehinitialarabic;FE9B +thehmedialarabic;FE9C +thereexists;2203 +therefore;2234 +theta;03B8 +theta1;03D1 +thetasymbolgreek;03D1 +thieuthacirclekorean;3279 +thieuthaparenkorean;3219 +thieuthcirclekorean;326B +thieuthkorean;314C +thieuthparenkorean;320B +thirteencircle;246C +thirteenparen;2480 +thirteenperiod;2494 +thonangmonthothai;0E11 +thook;01AD +thophuthaothai;0E12 +thorn;00FE +thothahanthai;0E17 +thothanthai;0E10 +thothongthai;0E18 +thothungthai;0E16 +thousandcyrillic;0482 +thousandsseparatorarabic;066C +thousandsseparatorpersian;066C +three;0033 +threearabic;0663 +threebengali;09E9 +threecircle;2462 +threecircleinversesansserif;278C +threedeva;0969 +threeeighths;215C +threegujarati;0AE9 +threegurmukhi;0A69 +threehackarabic;0663 +threehangzhou;3023 +threeideographicparen;3222 +threeinferior;2083 +threemonospace;FF13 +threenumeratorbengali;09F6 +threeoldstyle;F733 +threeparen;2476 +threeperiod;248A +threepersian;06F3 +threequarters;00BE +threequartersemdash;F6DE +threeroman;2172 +threesuperior;00B3 +threethai;0E53 +thzsquare;3394 +tihiragana;3061 +tikatakana;30C1 +tikatakanahalfwidth;FF81 +tikeutacirclekorean;3270 +tikeutaparenkorean;3210 +tikeutcirclekorean;3262 +tikeutkorean;3137 +tikeutparenkorean;3202 +tilde;02DC +tildebelowcmb;0330 +tildecmb;0303 +tildecomb;0303 +tildedoublecmb;0360 +tildeoperator;223C +tildeoverlaycmb;0334 +tildeverticalcmb;033E +timescircle;2297 +tipehahebrew;0596 +tipehalefthebrew;0596 +tippigurmukhi;0A70 +titlocyrilliccmb;0483 +tiwnarmenian;057F +tlinebelow;1E6F +tmonospace;FF54 +toarmenian;0569 +tohiragana;3068 +tokatakana;30C8 +tokatakanahalfwidth;FF84 +tonebarextrahighmod;02E5 +tonebarextralowmod;02E9 +tonebarhighmod;02E6 +tonebarlowmod;02E8 +tonebarmidmod;02E7 +tonefive;01BD +tonesix;0185 +tonetwo;01A8 +tonos;0384 +tonsquare;3327 +topatakthai;0E0F +tortoiseshellbracketleft;3014 +tortoiseshellbracketleftsmall;FE5D +tortoiseshellbracketleftvertical;FE39 +tortoiseshellbracketright;3015 +tortoiseshellbracketrightsmall;FE5E +tortoiseshellbracketrightvertical;FE3A +totaothai;0E15 +tpalatalhook;01AB +tparen;24AF +trademark;2122 +trademarksans;F8EA +trademarkserif;F6DB +tretroflexhook;0288 +triagdn;25BC +triaglf;25C4 +triagrt;25BA +triagup;25B2 +ts;02A6 +tsadi;05E6 +tsadidagesh;FB46 +tsadidageshhebrew;FB46 +tsadihebrew;05E6 +tsecyrillic;0446 +tsere;05B5 +tsere12;05B5 +tsere1e;05B5 +tsere2b;05B5 +tserehebrew;05B5 +tserenarrowhebrew;05B5 +tserequarterhebrew;05B5 +tserewidehebrew;05B5 +tshecyrillic;045B +tsuperior;F6F3 +ttabengali;099F +ttadeva;091F +ttagujarati;0A9F +ttagurmukhi;0A1F +tteharabic;0679 +ttehfinalarabic;FB67 +ttehinitialarabic;FB68 +ttehmedialarabic;FB69 +tthabengali;09A0 +tthadeva;0920 +tthagujarati;0AA0 +tthagurmukhi;0A20 +tturned;0287 +tuhiragana;3064 +tukatakana;30C4 +tukatakanahalfwidth;FF82 +tusmallhiragana;3063 +tusmallkatakana;30C3 +tusmallkatakanahalfwidth;FF6F +twelvecircle;246B +twelveparen;247F +twelveperiod;2493 +twelveroman;217B +twentycircle;2473 +twentyhangzhou;5344 +twentyparen;2487 +twentyperiod;249B +two;0032 +twoarabic;0662 +twobengali;09E8 +twocircle;2461 +twocircleinversesansserif;278B +twodeva;0968 +twodotenleader;2025 +twodotleader;2025 +twodotleadervertical;FE30 +twogujarati;0AE8 +twogurmukhi;0A68 +twohackarabic;0662 +twohangzhou;3022 +twoideographicparen;3221 +twoinferior;2082 +twomonospace;FF12 +twonumeratorbengali;09F5 +twooldstyle;F732 +twoparen;2475 +twoperiod;2489 +twopersian;06F2 +tworoman;2171 +twostroke;01BB +twosuperior;00B2 +twothai;0E52 +twothirds;2154 +u;0075 +uacute;00FA +ubar;0289 +ubengali;0989 +ubopomofo;3128 +ubreve;016D +ucaron;01D4 +ucircle;24E4 +ucircumflex;00FB +ucircumflexbelow;1E77 +ucyrillic;0443 +udattadeva;0951 +udblacute;0171 +udblgrave;0215 +udeva;0909 +udieresis;00FC +udieresisacute;01D8 +udieresisbelow;1E73 +udieresiscaron;01DA +udieresiscyrillic;04F1 +udieresisgrave;01DC +udieresismacron;01D6 +udotbelow;1EE5 +ugrave;00F9 +ugujarati;0A89 +ugurmukhi;0A09 +uhiragana;3046 +uhookabove;1EE7 +uhorn;01B0 +uhornacute;1EE9 +uhorndotbelow;1EF1 +uhorngrave;1EEB +uhornhookabove;1EED +uhorntilde;1EEF +uhungarumlaut;0171 +uhungarumlautcyrillic;04F3 +uinvertedbreve;0217 +ukatakana;30A6 +ukatakanahalfwidth;FF73 +ukcyrillic;0479 +ukorean;315C +umacron;016B +umacroncyrillic;04EF +umacrondieresis;1E7B +umatragurmukhi;0A41 +umonospace;FF55 +underscore;005F +underscoredbl;2017 +underscoremonospace;FF3F +underscorevertical;FE33 +underscorewavy;FE4F +union;222A +universal;2200 +uogonek;0173 +uparen;24B0 +upblock;2580 +upperdothebrew;05C4 +upsilon;03C5 +upsilondieresis;03CB +upsilondieresistonos;03B0 +upsilonlatin;028A +upsilontonos;03CD +uptackbelowcmb;031D +uptackmod;02D4 +uragurmukhi;0A73 +uring;016F +ushortcyrillic;045E +usmallhiragana;3045 +usmallkatakana;30A5 +usmallkatakanahalfwidth;FF69 +ustraightcyrillic;04AF +ustraightstrokecyrillic;04B1 +utilde;0169 +utildeacute;1E79 +utildebelow;1E75 +uubengali;098A +uudeva;090A +uugujarati;0A8A +uugurmukhi;0A0A +uumatragurmukhi;0A42 +uuvowelsignbengali;09C2 +uuvowelsigndeva;0942 +uuvowelsigngujarati;0AC2 +uvowelsignbengali;09C1 +uvowelsigndeva;0941 +uvowelsigngujarati;0AC1 +v;0076 +vadeva;0935 +vagujarati;0AB5 +vagurmukhi;0A35 +vakatakana;30F7 +vav;05D5 +vavdagesh;FB35 +vavdagesh65;FB35 +vavdageshhebrew;FB35 +vavhebrew;05D5 +vavholam;FB4B +vavholamhebrew;FB4B +vavvavhebrew;05F0 +vavyodhebrew;05F1 +vcircle;24E5 +vdotbelow;1E7F +vecyrillic;0432 +veharabic;06A4 +vehfinalarabic;FB6B +vehinitialarabic;FB6C +vehmedialarabic;FB6D +vekatakana;30F9 +venus;2640 +verticalbar;007C +verticallineabovecmb;030D +verticallinebelowcmb;0329 +verticallinelowmod;02CC +verticallinemod;02C8 +vewarmenian;057E +vhook;028B +vikatakana;30F8 +viramabengali;09CD +viramadeva;094D +viramagujarati;0ACD +visargabengali;0983 +visargadeva;0903 +visargagujarati;0A83 +vmonospace;FF56 +voarmenian;0578 +voicediterationhiragana;309E +voicediterationkatakana;30FE +voicedmarkkana;309B +voicedmarkkanahalfwidth;FF9E +vokatakana;30FA +vparen;24B1 +vtilde;1E7D +vturned;028C +vuhiragana;3094 +vukatakana;30F4 +w;0077 +wacute;1E83 +waekorean;3159 +wahiragana;308F +wakatakana;30EF +wakatakanahalfwidth;FF9C +wakorean;3158 +wasmallhiragana;308E +wasmallkatakana;30EE +wattosquare;3357 +wavedash;301C +wavyunderscorevertical;FE34 +wawarabic;0648 +wawfinalarabic;FEEE +wawhamzaabovearabic;0624 +wawhamzaabovefinalarabic;FE86 +wbsquare;33DD +wcircle;24E6 +wcircumflex;0175 +wdieresis;1E85 +wdotaccent;1E87 +wdotbelow;1E89 +wehiragana;3091 +weierstrass;2118 +wekatakana;30F1 +wekorean;315E +weokorean;315D +wgrave;1E81 +whitebullet;25E6 +whitecircle;25CB +whitecircleinverse;25D9 +whitecornerbracketleft;300E +whitecornerbracketleftvertical;FE43 +whitecornerbracketright;300F +whitecornerbracketrightvertical;FE44 +whitediamond;25C7 +whitediamondcontainingblacksmalldiamond;25C8 +whitedownpointingsmalltriangle;25BF +whitedownpointingtriangle;25BD +whiteleftpointingsmalltriangle;25C3 +whiteleftpointingtriangle;25C1 +whitelenticularbracketleft;3016 +whitelenticularbracketright;3017 +whiterightpointingsmalltriangle;25B9 +whiterightpointingtriangle;25B7 +whitesmallsquare;25AB +whitesmilingface;263A +whitesquare;25A1 +whitestar;2606 +whitetelephone;260F +whitetortoiseshellbracketleft;3018 +whitetortoiseshellbracketright;3019 +whiteuppointingsmalltriangle;25B5 +whiteuppointingtriangle;25B3 +wihiragana;3090 +wikatakana;30F0 +wikorean;315F +wmonospace;FF57 +wohiragana;3092 +wokatakana;30F2 +wokatakanahalfwidth;FF66 +won;20A9 +wonmonospace;FFE6 +wowaenthai;0E27 +wparen;24B2 +wring;1E98 +wsuperior;02B7 +wturned;028D +wynn;01BF +x;0078 +xabovecmb;033D +xbopomofo;3112 +xcircle;24E7 +xdieresis;1E8D +xdotaccent;1E8B +xeharmenian;056D +xi;03BE +xmonospace;FF58 +xparen;24B3 +xsuperior;02E3 +y;0079 +yaadosquare;334E +yabengali;09AF +yacute;00FD +yadeva;092F +yaekorean;3152 +yagujarati;0AAF +yagurmukhi;0A2F +yahiragana;3084 +yakatakana;30E4 +yakatakanahalfwidth;FF94 +yakorean;3151 +yamakkanthai;0E4E +yasmallhiragana;3083 +yasmallkatakana;30E3 +yasmallkatakanahalfwidth;FF6C +yatcyrillic;0463 +ycircle;24E8 +ycircumflex;0177 +ydieresis;00FF +ydotaccent;1E8F +ydotbelow;1EF5 +yeharabic;064A +yehbarreearabic;06D2 +yehbarreefinalarabic;FBAF +yehfinalarabic;FEF2 +yehhamzaabovearabic;0626 +yehhamzaabovefinalarabic;FE8A +yehhamzaaboveinitialarabic;FE8B +yehhamzaabovemedialarabic;FE8C +yehinitialarabic;FEF3 +yehmedialarabic;FEF4 +yehmeeminitialarabic;FCDD +yehmeemisolatedarabic;FC58 +yehnoonfinalarabic;FC94 +yehthreedotsbelowarabic;06D1 +yekorean;3156 +yen;00A5 +yenmonospace;FFE5 +yeokorean;3155 +yeorinhieuhkorean;3186 +yerahbenyomohebrew;05AA +yerahbenyomolefthebrew;05AA +yericyrillic;044B +yerudieresiscyrillic;04F9 +yesieungkorean;3181 +yesieungpansioskorean;3183 +yesieungsioskorean;3182 +yetivhebrew;059A +ygrave;1EF3 +yhook;01B4 +yhookabove;1EF7 +yiarmenian;0575 +yicyrillic;0457 +yikorean;3162 +yinyang;262F +yiwnarmenian;0582 +ymonospace;FF59 +yod;05D9 +yoddagesh;FB39 +yoddageshhebrew;FB39 +yodhebrew;05D9 +yodyodhebrew;05F2 +yodyodpatahhebrew;FB1F +yohiragana;3088 +yoikorean;3189 +yokatakana;30E8 +yokatakanahalfwidth;FF96 +yokorean;315B +yosmallhiragana;3087 +yosmallkatakana;30E7 +yosmallkatakanahalfwidth;FF6E +yotgreek;03F3 +yoyaekorean;3188 +yoyakorean;3187 +yoyakthai;0E22 +yoyingthai;0E0D +yparen;24B4 +ypogegrammeni;037A +ypogegrammenigreekcmb;0345 +yr;01A6 +yring;1E99 +ysuperior;02B8 +ytilde;1EF9 +yturned;028E +yuhiragana;3086 +yuikorean;318C +yukatakana;30E6 +yukatakanahalfwidth;FF95 +yukorean;3160 +yusbigcyrillic;046B +yusbigiotifiedcyrillic;046D +yuslittlecyrillic;0467 +yuslittleiotifiedcyrillic;0469 +yusmallhiragana;3085 +yusmallkatakana;30E5 +yusmallkatakanahalfwidth;FF6D +yuyekorean;318B +yuyeokorean;318A +yyabengali;09DF +yyadeva;095F +z;007A +zaarmenian;0566 +zacute;017A +zadeva;095B +zagurmukhi;0A5B +zaharabic;0638 +zahfinalarabic;FEC6 +zahinitialarabic;FEC7 +zahiragana;3056 +zahmedialarabic;FEC8 +zainarabic;0632 +zainfinalarabic;FEB0 +zakatakana;30B6 +zaqefgadolhebrew;0595 +zaqefqatanhebrew;0594 +zarqahebrew;0598 +zayin;05D6 +zayindagesh;FB36 +zayindageshhebrew;FB36 +zayinhebrew;05D6 +zbopomofo;3117 +zcaron;017E +zcircle;24E9 +zcircumflex;1E91 +zcurl;0291 +zdot;017C +zdotaccent;017C +zdotbelow;1E93 +zecyrillic;0437 +zedescendercyrillic;0499 +zedieresiscyrillic;04DF +zehiragana;305C +zekatakana;30BC +zero;0030 +zeroarabic;0660 +zerobengali;09E6 +zerodeva;0966 +zerogujarati;0AE6 +zerogurmukhi;0A66 +zerohackarabic;0660 +zeroinferior;2080 +zeromonospace;FF10 +zerooldstyle;F730 +zeropersian;06F0 +zerosuperior;2070 +zerothai;0E50 +zerowidthjoiner;FEFF +zerowidthnonjoiner;200C +zerowidthspace;200B +zeta;03B6 +zhbopomofo;3113 +zhearmenian;056A +zhebrevecyrillic;04C2 +zhecyrillic;0436 +zhedescendercyrillic;0497 +zhedieresiscyrillic;04DD +zihiragana;3058 +zikatakana;30B8 +zinorhebrew;05AE +zlinebelow;1E95 +zmonospace;FF5A +zohiragana;305E +zokatakana;30BE +zparen;24B5 +zretroflexhook;0290 +zstroke;01B6 +zuhiragana;305A +zukatakana;30BA +#--end diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/fonts/zapfdingbats.txt b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/fonts/zapfdingbats.txt new file mode 100644 index 000000000..2b8cd5aab --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/fonts/zapfdingbats.txt @@ -0,0 +1,243 @@ +# ################################################################################### +# Copyright (c) 1997,1998,2002,2007 Adobe Systems Incorporated +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this documentation file to use, copy, publish, distribute, +# sublicense, and/or sell copies of the documentation, and to permit +# others to do the same, provided that: +# - No modification, editing or other alteration of this document is +# allowed; and +# - The above copyright notice and this permission notice shall be +# included in all copies of the documentation. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this documentation file, to create their own derivative works +# from the content of this document to use, copy, publish, distribute, +# sublicense, and/or sell the derivative works, and to permit others to do +# the same, provided that the derived work is not represented as being a +# copy or version of this document. +# +# Adobe shall not be liable to any party for any loss of revenue or profit +# or for indirect, incidental, special, consequential, or other similar +# damages, whether based on tort (including without limitation negligence +# or strict liability), contract or other legal or equitable grounds even +# if Adobe has been advised or had reason to know of the possibility of +# such damages.Ê The Adobe materials are provided on an "AS IS" basis.Ê +# Adobe specifically disclaims all express, statutory, or implied +# warranties relating to the Adobe materials, including but not limited to +# those concerning merchantability or fitness for a particular purpose or +# non-infringement of any third party rights regarding the Adobe +# materials. +# ################################################################################### +# Name: ITC Zapf Dingbats Glyph List +# Table version: 2.0 +# Date: September 20, 2002 +# +# See http://partners.adobe.com/asn/developer/typeforum/unicodegn.html +# +# Format: Semicolon-delimited fields: +# (1) glyph name +# (2) Unicode scalar value +# +a100;275E +a101;2761 +a102;2762 +a103;2763 +a104;2764 +a105;2710 +a106;2765 +a107;2766 +a108;2767 +a109;2660 +a10;2721 +a110;2665 +a111;2666 +a112;2663 +a117;2709 +a118;2708 +a119;2707 +a11;261B +a120;2460 +a121;2461 +a122;2462 +a123;2463 +a124;2464 +a125;2465 +a126;2466 +a127;2467 +a128;2468 +a129;2469 +a12;261E +a130;2776 +a131;2777 +a132;2778 +a133;2779 +a134;277A +a135;277B +a136;277C +a137;277D +a138;277E +a139;277F +a13;270C +a140;2780 +a141;2781 +a142;2782 +a143;2783 +a144;2784 +a145;2785 +a146;2786 +a147;2787 +a148;2788 +a149;2789 +a14;270D +a150;278A +a151;278B +a152;278C +a153;278D +a154;278E +a155;278F +a156;2790 +a157;2791 +a158;2792 +a159;2793 +a15;270E +a160;2794 +a161;2192 +a162;27A3 +a163;2194 +a164;2195 +a165;2799 +a166;279B +a167;279C +a168;279D +a169;279E +a16;270F +a170;279F +a171;27A0 +a172;27A1 +a173;27A2 +a174;27A4 +a175;27A5 +a176;27A6 +a177;27A7 +a178;27A8 +a179;27A9 +a17;2711 +a180;27AB +a181;27AD +a182;27AF +a183;27B2 +a184;27B3 +a185;27B5 +a186;27B8 +a187;27BA +a188;27BB +a189;27BC +a18;2712 +a190;27BD +a191;27BE +a192;279A +a193;27AA +a194;27B6 +a195;27B9 +a196;2798 +a197;27B4 +a198;27B7 +a199;27AC +a19;2713 +a1;2701 +a200;27AE +a201;27B1 +a202;2703 +a203;2750 +a204;2752 +a205;276E +a206;2770 +a20;2714 +a21;2715 +a22;2716 +a23;2717 +a24;2718 +a25;2719 +a26;271A +a27;271B +a28;271C +a29;2722 +a2;2702 +a30;2723 +a31;2724 +a32;2725 +a33;2726 +a34;2727 +a35;2605 +a36;2729 +a37;272A +a38;272B +a39;272C +a3;2704 +a40;272D +a41;272E +a42;272F +a43;2730 +a44;2731 +a45;2732 +a46;2733 +a47;2734 +a48;2735 +a49;2736 +a4;260E +a50;2737 +a51;2738 +a52;2739 +a53;273A +a54;273B +a55;273C +a56;273D +a57;273E +a58;273F +a59;2740 +a5;2706 +a60;2741 +a61;2742 +a62;2743 +a63;2744 +a64;2745 +a65;2746 +a66;2747 +a67;2748 +a68;2749 +a69;274A +a6;271D +a70;274B +a71;25CF +a72;274D +a73;25A0 +a74;274F +a75;2751 +a76;25B2 +a77;25BC +a78;25C6 +a79;2756 +a7;271E +a81;25D7 +a82;2758 +a83;2759 +a84;275A +a85;276F +a86;2771 +a87;2772 +a88;2773 +a89;2768 +a8;271F +a90;2769 +a91;276C +a92;276D +a93;276A +a94;276B +a95;2774 +a96;2775 +a97;275B +a98;275C +a99;275D +a9;2720 +#-- end diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/image/codec/Messages.properties b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/image/codec/Messages.properties new file mode 100644 index 000000000..ee208a294 --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/image/codec/Messages.properties @@ -0,0 +1,158 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +FileCacheSeekableStream0=pos < 0. +FileSeekableStream0=pos < 0. +FloatDoubleColorModel0=transferType must be DataBuffer.TYPE_FLOAT or DataBuffer.TYPE_DOUBLE. +FloatDoubleColorModel10=elements required in the components array. +FloatDoubleColorModel1=getRed(int) not supported by this ColorModel. +FloatDoubleColorModel2=getGreen(int) not supported by this ColorModel. +FloatDoubleColorModel3=getBlue(int) not supported by this ColorModel. +FloatDoubleColorModel4=getAlpha(int) not supported by this ColorModel. +FloatDoubleColorModel5=getRGB(int) not supported by this ColorModel. +FloatDoubleColorModel6=raster transfer type must match that of this ColorModel. +FloatDoubleColorModel7=Type of pixel does not match transfer type. +FloatDoubleColorModel8=pixel array is not large enough to hold all color/alpha components. +FloatDoubleColorModel9=Pixel values for FloatDoubleColorModel cannot be represented as a single integer. +MemoryCacheSeekableStream0=pos < 0. +PNGCodec0=PNG encoding not supported yet. +PNGDecodeParam0=User exponent must not be negative. +PNGDecodeParam1=Display exponent must not be negative. +PNGEncodeParam0=Bad palette length. +PNGEncodeParam10=Transparent RGB value has not been set. +PNGEncodeParam11=Grayscale bit depth has not been set. +PNGEncodeParam12=Chromaticity has not been set. +PNGEncodeParam13=Gamma has not been set. +PNGEncodeParam14=Palette histogram has not been set. +PNGEncodeParam15=ICC profile has not been set. +PNGEncodeParam16=Physical dimension information has not been set. +PNGEncodeParam17=Suggested palette information has not been set. +PNGEncodeParam18=Significant bits values have not been set. +PNGEncodeParam19=sRGB rendering intent has not been set. +PNGEncodeParam1=Not divisible by 3. +PNGEncodeParam20=Uncompressed text strings have not been set. +PNGEncodeParam21=Modification time has not been set. +PNGEncodeParam22=Compressed text strings have not been set. +PNGEncodeParam23='unsetBackground' not implemented by the superclass 'PNGEncodeParam'. +PNGEncodeParam24='isBackgroundSet' not implemented by the superclass 'PNGEncodeParam'. +PNGEncodeParam25=Bit shift must be greater than 0. +PNGEncodeParam26=Bit depth must be 8 or 16. +PNGEncodeParam27=RGB value must have three components. +PNGEncodeParam28=Chromaticity array must be non-empty. +PNGEncodeParam2=Bit depth not equal to 1, 2, 4, or 8. +PNGEncodeParam3=RGB palette has not been set. +PNGEncodeParam4=background palette index has not been set. +PNGEncodeParam5=Palette transparency has not been set. +PNGEncodeParam6=Background gray level has not been set. +PNGEncodeParam7=Transparent gray value has not been set. +PNGEncodeParam8=Bit shift has not been set. +PNGEncodeParam9=RGB background color has not been set. +PNGImageDecoder0=PNG magic number not found. +PNGImageDecoder10=Unsupported PNG filter method (not 0). +PNGImageDecoder11=Unsupported PNG interlace method (not 0 or 1). +PNGImageDecoder12=Unknown PNG pHYs unit specifier (not 0 or 1). +PNGImageDecoder13=Illegal PNG sBit value (< 0 or > bit depth). +PNGImageDecoder14=Too many PNG alpha palette entries. +PNGImageDecoder15=PNG image already has alpha, can't have tRNS chunk. +PNGImageDecoder16=Unknown PNG filter type (not 0-4). +PNGImageDecoder17=Illegal tile requested from a PNG image. +PNGImageDecoder18=PNG can't have hIST chunk without a PLTE chunk. +PNGImageDecoder19=Illegal page requested from a PNG file. +PNGImageDecoder1=Error reading PNG header. +PNGImageDecoder2=I/O error reading PNG file. +PNGImageDecoder3=Illegal bit depth for a PNG image. +PNGImageDecoder4=Bad color type for a PNG image. +PNGImageDecoder5=An RGB PNG image can't have a bit depth less than 8. +PNGImageDecoder6=A palette-color PNG image can't have a bit depth of 16. +PNGImageDecoder7=A PNG Gray+Alpha image can't have a bit depth less than 8. +PNGImageDecoder8=A PNG RGB+Alpha image can't have a bit depth less than 8. +PNGImageDecoder9=Unsupported PNG compression method (not 0). +PNGImageEncoder0=Sample size not equal to bit depth. +PNGImageEncoder1=Bit depth greater than 16. +PNGImageEncoder2=Bit depth less than 1 or greater than 8. +PNGImageEncoder3=Number of bands not equal to 1. +PNGImageEncoder4=PNG encode parameter must be Palette or Gray. +PropertySet0=Not implemented. +RasterFactory0=Number of bands must be greater than 0. +RasterFactory10=parentY lies outside raster. +RasterFactory11=(parentX + width) is outside raster. +RasterFactory12=(parentY + height) is outside raster. +RasterFactory13=Illegal value for transparency. +RasterFactory14=Transparency cannot be opaque when useAlpha is true. +RasterFactory15=bitsPerBands must be greater than 0. +RasterFactory16=Size of array must be smaller than Integer.MAX_VALUE. +RasterFactory1=Bank indices array is null. +RasterFactory2=bankIndices.length != bandOffsets.length +RasterFactory3=Unsupported data type. +RasterFactory4=Band offsets array is null. +RasterFactory5=Offsets between bands must be less than the scanline stride. +RasterFactory6=Pixel stride times width must be less than the scanline stride. +RasterFactory7=Pixel stride must be greater than or equal to the offset between bands. +RasterFactory8=This method does not support the input data type. +RasterFactory9=parentX lies outside raster. +SegmentedSeekableStream0=Source stream does not support seeking backwards. +SingleTileRenderedImage0=Illegal tile requested from a SingleTileRenderedImage. +TIFFImage0=Planar (band-sequential) format TIFF is not supported. +TIFFImage1=All samples must have the same bit depth. +TIFFImage2=All samples must have the same data format. +TIFFImage3=Unsupported combination of bit depth and sample format. +TIFFImage4=Unsupported image type. +TIFFImage5=Strip offsets, a required field, is not present in the TIFF file. +TIFFImage5=Strip byte counts, a required field, is not present in the TIFF file. +TIFFImage7=Unsupported compression type for non-bilevel data. +TIFFImage8=Illegal value for predictor in TIFF file. +TIFFImage9=Sample size must be 8 for horizontal differencing predictor. +TIFFImage10=Unsupported compression type +TIFFImage11=Colormap must be present for a Palette Color image. +TIFFImage12=Illegal tile requested from a TIFFImage. +TIFFImage13=IOException occured while reading TIFF image data +TIFFImage14=Unable to decode packbits compressed data - not enough data +TIFFImage15=Decoding of old style JPEG-in-TIFF data is not supported. +TIFFImage17=Error inflating data +TIFFImage18=Unsupported field type +TIFFImage19=Unsupported number of bands +TIFFImage20=Unsupported data type +TIFFImageDecoder0=Illegal page requested from a TIFF file. +TIFFImageEncoder0=All samples must have the same bit depth. +TIFFImageEncoder1=1- and 4-bit data supported for single band images only. +TIFFImageEncoder2=Byte buffers require 1-, 4-, or b-bit data. +TIFFImageEncoder3=Short or unsigned short buffers require 16-bit data. +TIFFImageEncoder4=Int or float buffers require 32-bit data. +TIFFImageEncoder5=Unsupported output data type. +TIFFImageEncoder6=TIFF encoder does not support (unsigned) short palette images. +TIFFImageEncoder7=Invalid image - An image with sampleSize of 1 bit must have IndexColorModel with mapsize of 2. +TIFFImageEncoder8=Image type not supported for output. +TIFFImageEncoder9=JPEG-in-TIFF encoding supported only for 8-bit samples and either 1 (grayscale) or 3 (RGB or YCbCr) samples per pixel. +TIFFImageEncoder10=Unsupported TIFFField type. +TIFFImageEncoder11=Extra images may not be used when encoding multiple page file. +TIFFImageEncoder12=JPEG compression not supported. +TIFFImageEncoder13=No output specified. +TIFFLZWDecoder0=TIFF 5.0 LZW codes are not supported. +TIFFFaxDecoder0=ERROR code word (0) encountered. +TIFFFaxDecoder1=EOL code word (15) encountered in White run. +TIFFFaxDecoder2=EOL code word (15) encountered in Black run. +TIFFFaxDecoder3=First scanline must be 1D encoded. +TIFFFaxDecoder4=Invalid code encountered while decoding 2D group 3 compressed data. +TIFFFaxDecoder5=Invalid code encountered while decoding 2D group 4 compressed data. +TIFFFaxDecoder6=Scanline must begin with EOL code word. +TIFFFaxDecoder7=TIFF_FILL_ORDER tag must be either 1 or 2. +TIFFFaxDecoder8=All fill bits preceding EOL code must be 0. +TIFFDirectory0=Unsupported TIFFField tag. +TIFFDirectory1=Bad endianness tag (not 0x4949 or 0x4d4d). +TIFFDirectory2=Bad magic number, should be 42. +TIFFDirectory3=Directory number too large. +TIFFEncodeParam0=Unsupported compression scheme specified. +TIFFEncodeParam1=Illegal DEFLATE compression level specified. \ No newline at end of file diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/image/writer/default-preferred-order.properties b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/image/writer/default-preferred-order.properties new file mode 100644 index 000000000..1bcbf16fa --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/image/writer/default-preferred-order.properties @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.apache.xmlgraphics.image.writer.internal=-2000 +org.apache.xmlgraphics.image.writer.imageio=-1000 \ No newline at end of file diff --git a/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/ps/Identity-H b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/ps/Identity-H new file mode 100644 index 000000000..6675416b2 --- /dev/null +++ b/fine-xmlgraphics/xmlgraphics-commons/src/main/resources/org/apache/xmlgraphics/ps/Identity-H @@ -0,0 +1,339 @@ +%!PS-Adobe-3.0 Resource-CMap +%%DocumentNeededResources: ProcSet (CIDInit) +%%IncludeResource: ProcSet (CIDInit) +%%BeginResource: CMap (Identity-H) +%%Title: (Identity-H Adobe Identity 0) +%%Version: 10.003 +%%Copyright: ----------------------------------------------------------- +%%Copyright: Copyright 1990-2009 Adobe Systems Incorporated. +%%Copyright: All rights reserved. +%%Copyright: +%%Copyright: Redistribution and use in source and binary forms, with or +%%Copyright: without modification, are permitted provided that the +%%Copyright: following conditions are met: +%%Copyright: +%%Copyright: Redistributions of source code must retain the above +%%Copyright: copyright notice, this list of conditions and the following +%%Copyright: disclaimer. +%%Copyright: +%%Copyright: Redistributions in binary form must reproduce the above +%%Copyright: copyright notice, this list of conditions and the following +%%Copyright: disclaimer in the documentation and/or other materials +%%Copyright: provided with the distribution. +%%Copyright: +%%Copyright: Neither the name of Adobe Systems Incorporated nor the names +%%Copyright: of its contributors may be used to endorse or promote +%%Copyright: products derived from this software without specific prior +%%Copyright: written permission. +%%Copyright: +%%Copyright: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +%%Copyright: CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +%%Copyright: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +%%Copyright: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +%%Copyright: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +%%Copyright: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +%%Copyright: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +%%Copyright: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +%%Copyright: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +%%Copyright: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%%Copyright: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +%%Copyright: OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +%%Copyright: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +%%Copyright: ----------------------------------------------------------- +%%EndComments + +/CIDInit /ProcSet findresource begin + +12 dict begin + +begincmap + +/CIDSystemInfo 3 dict dup begin + /Registry (Adobe) def + /Ordering (Identity) def + /Supplement 0 def +end def + +/CMapName /Identity-H def +/CMapVersion 10.003 def +/CMapType 1 def + +/XUID [1 10 25404 9999] def + +/WMode 0 def + +1 begincodespacerange + <0000> +endcodespacerange + +100 begincidrange +<0000> <00ff> 0 +<0100> <01ff> 256 +<0200> <02ff> 512 +<0300> <03ff> 768 +<0400> <04ff> 1024 +<0500> <05ff> 1280 +<0600> <06ff> 1536 +<0700> <07ff> 1792 +<0800> <08ff> 2048 +<0900> <09ff> 2304 +<0a00> <0aff> 2560 +<0b00> <0bff> 2816 +<0c00> <0cff> 3072 +<0d00> <0dff> 3328 +<0e00> <0eff> 3584 +<0f00> <0fff> 3840 +<1000> <10ff> 4096 +<1100> <11ff> 4352 +<1200> <12ff> 4608 +<1300> <13ff> 4864 +<1400> <14ff> 5120 +<1500> <15ff> 5376 +<1600> <16ff> 5632 +<1700> <17ff> 5888 +<1800> <18ff> 6144 +<1900> <19ff> 6400 +<1a00> <1aff> 6656 +<1b00> <1bff> 6912 +<1c00> <1cff> 7168 +<1d00> <1dff> 7424 +<1e00> <1eff> 7680 +<1f00> <1fff> 7936 +<2000> <20ff> 8192 +<2100> <21ff> 8448 +<2200> <22ff> 8704 +<2300> <23ff> 8960 +<2400> <24ff> 9216 +<2500> <25ff> 9472 +<2600> <26ff> 9728 +<2700> <27ff> 9984 +<2800> <28ff> 10240 +<2900> <29ff> 10496 +<2a00> <2aff> 10752 +<2b00> <2bff> 11008 +<2c00> <2cff> 11264 +<2d00> <2dff> 11520 +<2e00> <2eff> 11776 +<2f00> <2fff> 12032 +<3000> <30ff> 12288 +<3100> <31ff> 12544 +<3200> <32ff> 12800 +<3300> <33ff> 13056 +<3400> <34ff> 13312 +<3500> <35ff> 13568 +<3600> <36ff> 13824 +<3700> <37ff> 14080 +<3800> <38ff> 14336 +<3900> <39ff> 14592 +<3a00> <3aff> 14848 +<3b00> <3bff> 15104 +<3c00> <3cff> 15360 +<3d00> <3dff> 15616 +<3e00> <3eff> 15872 +<3f00> <3fff> 16128 +<4000> <40ff> 16384 +<4100> <41ff> 16640 +<4200> <42ff> 16896 +<4300> <43ff> 17152 +<4400> <44ff> 17408 +<4500> <45ff> 17664 +<4600> <46ff> 17920 +<4700> <47ff> 18176 +<4800> <48ff> 18432 +<4900> <49ff> 18688 +<4a00> <4aff> 18944 +<4b00> <4bff> 19200 +<4c00> <4cff> 19456 +<4d00> <4dff> 19712 +<4e00> <4eff> 19968 +<4f00> <4fff> 20224 +<5000> <50ff> 20480 +<5100> <51ff> 20736 +<5200> <52ff> 20992 +<5300> <53ff> 21248 +<5400> <54ff> 21504 +<5500> <55ff> 21760 +<5600> <56ff> 22016 +<5700> <57ff> 22272 +<5800> <58ff> 22528 +<5900> <59ff> 22784 +<5a00> <5aff> 23040 +<5b00> <5bff> 23296 +<5c00> <5cff> 23552 +<5d00> <5dff> 23808 +<5e00> <5eff> 24064 +<5f00> <5fff> 24320 +<6000> <60ff> 24576 +<6100> <61ff> 24832 +<6200> <62ff> 25088 +<6300> <63ff> 25344 +endcidrange + +100 begincidrange +<6400> <64ff> 25600 +<6500> <65ff> 25856 +<6600> <66ff> 26112 +<6700> <67ff> 26368 +<6800> <68ff> 26624 +<6900> <69ff> 26880 +<6a00> <6aff> 27136 +<6b00> <6bff> 27392 +<6c00> <6cff> 27648 +<6d00> <6dff> 27904 +<6e00> <6eff> 28160 +<6f00> <6fff> 28416 +<7000> <70ff> 28672 +<7100> <71ff> 28928 +<7200> <72ff> 29184 +<7300> <73ff> 29440 +<7400> <74ff> 29696 +<7500> <75ff> 29952 +<7600> <76ff> 30208 +<7700> <77ff> 30464 +<7800> <78ff> 30720 +<7900> <79ff> 30976 +<7a00> <7aff> 31232 +<7b00> <7bff> 31488 +<7c00> <7cff> 31744 +<7d00> <7dff> 32000 +<7e00> <7eff> 32256 +<7f00> <7fff> 32512 +<8000> <80ff> 32768 +<8100> <81ff> 33024 +<8200> <82ff> 33280 +<8300> <83ff> 33536 +<8400> <84ff> 33792 +<8500> <85ff> 34048 +<8600> <86ff> 34304 +<8700> <87ff> 34560 +<8800> <88ff> 34816 +<8900> <89ff> 35072 +<8a00> <8aff> 35328 +<8b00> <8bff> 35584 +<8c00> <8cff> 35840 +<8d00> <8dff> 36096 +<8e00> <8eff> 36352 +<8f00> <8fff> 36608 +<9000> <90ff> 36864 +<9100> <91ff> 37120 +<9200> <92ff> 37376 +<9300> <93ff> 37632 +<9400> <94ff> 37888 +<9500> <95ff> 38144 +<9600> <96ff> 38400 +<9700> <97ff> 38656 +<9800> <98ff> 38912 +<9900> <99ff> 39168 +<9a00> <9aff> 39424 +<9b00> <9bff> 39680 +<9c00> <9cff> 39936 +<9d00> <9dff> 40192 +<9e00> <9eff> 40448 +<9f00> <9fff> 40704 + 40960 + 41216 + 41472 + 41728 + 41984 + 42240 + 42496 + 42752 + 43008 + 43264 + 43520 + 43776 + 44032 + 44288 + 44544 + 44800 + 45056 + 45312 + 45568 + 45824 + 46080 + 46336 + 46592 + 46848 + 47104 + 47360 + 47616 + 47872 + 48128 + 48384 + 48640 + 48896 + 49152 + 49408 + 49664 + 49920 + 50176 + 50432 + 50688 + 50944 +endcidrange + +56 begincidrange + 51200 + 51456 + 51712 + 51968 + 52224 + 52480 + 52736 + 52992 + 53248 + 53504 + 53760 + 54016 + 54272 + 54528 + 54784 + 55040 + 55296 + 55552 + 55808 + 56064 + 56320 + 56576 + 56832 + 57088 + 57344 + 57600 + 57856 + 58112 + 58368 + 58624 + 58880 + 59136 + 59392 + 59648 + 59904 + 60160 + 60416 + 60672 + 60928 + 61184 + 61440 + 61696 + 61952 + 62208 + 62464 + 62720 + 62976 + 63232 + 63488 + 63744 + 64000 + 64256 + 64512 + 64768 + 65024 + 65280 +endcidrange +endcmap +CMapName currentdict /CMap defineresource pop +end +end + +%%EndResource +%%EOF

    Key:KEY_SCALE_TO_PAGE