![JAR search and dependency download from the Maven repository](/logo.png)
com.creativewidgetworks.goldparser.engine.CharacterSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of goldengine Show documentation
Show all versions of goldengine Show documentation
Java implementation of Devin Cook's GOLD Parser engine
package com.creativewidgetworks.goldparser.engine;
import java.util.ArrayList;
/**
* CharacterSet
*
* Manages a list of CharacterRange objects.
*
* Dependencies:
* @CharacterRange
*
* @author Devin Cook (http://www.DevinCook.com/GOLDParser)
* @author Ralph Iden (http://www.creativewidgetworks.com), port to Java
* @version 5.0.0
*/
public class CharacterSet extends ArrayList {
/**
* Default constructor
*/
public CharacterSet() {
// default constructor
}
/**
* Constructor that establishes the size of the list and creates placeholder
* objects so the list can be accessed in a "random" fashion when setting
* items.
* @param size
*/
public CharacterSet(int size) {
super(size);
for (int i = 0; i < size; i++) {
add(null);
}
}
/*----------------------------------------------------------------------------*/
/**
* This procedure searches the set to determine if the CharCode is in one
* of the ranges and therefore, the set.
*
* The number of ranges in any given set are relatively small - rarely
* exceeding 10 total. As a result, a simple linear search is sufficient
* rather than a binary search. In fact, a binary search overhead might
* slow down the search!
* @param charCode the search character
* @return true if the character is in the set.
*/
public boolean contains(int charCode) {
boolean found = false;
for (int i = 0; !found && i < size(); i++) {
CharacterRange range = get(i);
if (range.characterSet != null) {
// Version 1 CGT
found = range.characterSet.contains(String.valueOf((char)charCode));
} else {
// Version 5 EGT
found = charCode >= range.start && charCode <= range.end;
}
}
return found;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy