下面列出了java.util.HashSet#iterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Linear combination of this model with another model y. x = ax + by, where x and y are
* both LinearModel.
*
* @param a
* @param b
* @param y
* @return
*/
public void linearCombine(double a, double b, LinearModel y)
{
_intercept = a * _intercept + b * y.getIntercept();
HashSet<String> keys = new HashSet<String>(_coefficients.keySet());
keys.addAll(y.getCoefficients().keySet());
Iterator<String> iter = keys.iterator();
while (iter.hasNext())
{
String key = iter.next();
double value = 0;
if (_coefficients.containsKey(key))
{
value = value + a * _coefficients.get(key);
}
if (y.getCoefficients().containsKey(key))
{
value = value + b * y.getCoefficients().get(key);
}
_coefficients.put(key, value);
}
}
protected void deleteUnmatchedInstructionalOfferings(){
if (existingInstructionalOfferings.size() > 0){
HashSet<Long> deleteOfferings = new HashSet<Long>();
deleteOfferings.addAll(existingInstructionalOfferings);
addNote("Deleted Instructional Offerings that were not in the input file:");
for(Iterator<Long> ioIt = deleteOfferings.iterator(); ioIt.hasNext(); ){
Long uniqueId = (Long) ioIt.next();
InstructionalOffering unusedIo = findInstrOffrForUniqueId(uniqueId) ;
if (unusedIo != null){
addNote("\tdeleted: " + unusedIo.getCourseName());
deleteInstructionalOffering(unusedIo);
changeCount++;
}
}
flushIfNeeded(true);
updateChangeList(true);
}
}
private static char[] lookUpTable(String src, int index, Locale locale, boolean bLowerCasing) {
HashSet<Entry> set = entryTable.get(new Integer(src.codePointAt(index)));
char[] ret = null;
if (set != null) {
Iterator<Entry> iter = set.iterator();
String currentLang = locale.getLanguage();
while (iter.hasNext()) {
Entry entry = iter.next();
String conditionLang = entry.getLanguage();
if (((conditionLang == null) || (conditionLang.equals(currentLang))) &&
isConditionMet(src, index, locale, entry.getCondition())) {
ret = bLowerCasing ? entry.getLowerCase() : entry.getUpperCase();
if (conditionLang != null) {
break;
}
}
}
}
return ret;
}
private static char[] lookUpTable(String src, int index, Locale locale, boolean bLowerCasing) {
HashSet<Entry> set = entryTable.get(new Integer(src.codePointAt(index)));
char[] ret = null;
if (set != null) {
Iterator<Entry> iter = set.iterator();
String currentLang = locale.getLanguage();
while (iter.hasNext()) {
Entry entry = iter.next();
String conditionLang = entry.getLanguage();
if (((conditionLang == null) || (conditionLang.equals(currentLang))) &&
isConditionMet(src, index, locale, entry.getCondition())) {
ret = bLowerCasing ? entry.getLowerCase() : entry.getUpperCase();
if (conditionLang != null) {
break;
}
}
}
}
return ret;
}
private static StringBuilder CalcOps(StringBuilder Ops, String TermId, DriverGeneric LocalSess, int Level) throws PDException
{
PDThesaur T=new PDThesaur(LocalSess);
T.Load(TermId);
StringBuilder SLev=new StringBuilder(100);
for (int i = 0; i < Level-1; i++)
SLev.append(" ");
SLev.append("└ ");
//String SLev=ThesTree.substring(0, Level);
if (Level==0)
Ops.append("<option value=\"\" selected> </option>");
else
Ops.append("<option value=\"").append(T.getPDId()).append("\">").append(SLev).append(T.getName()).append("</option>");
HashSet listDirectDescendList = T.getListDirectDescendList(TermId);
for (Iterator iterator = listDirectDescendList.iterator(); iterator.hasNext();)
{
CalcOps(Ops,(String)iterator.next(), LocalSess, Level+1 );
}
return(Ops);
}
public static void serverMultiKeyExecutionSocketTimeOut(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true,TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
List l = null;
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE,
function, isByName);
l = ((List)rc1.getResult());
getLogWriter().info("Result size : " + l.size());
assertEquals(3, l.size());
for (Iterator i = l.iterator(); i.hasNext();) {
assertEquals(Boolean.TRUE, i.next());
}
}catch(Exception e){
fail("Test failed after the put operation", e);
}
}
public static HashSet<Integer> removeAllNumbersMoreThan10(HashSet<Integer> set) {
Iterator<Integer> iterator = set.iterator();
while (iterator.hasNext())
if (iterator.next() > 10)
iterator.remove();
return set;
}
private String GenTreeThes(HttpServletRequest Req)
{
StringBuilder ThesTree=new StringBuilder(3000);
DriverGeneric PDSession=getSessOPD(Req);
String ThesaurId=Req.getParameter("ThesId");
String ThesId=Req.getParameter("id");
try {
PDThesaur CurThes = new PDThesaur(PDSession);
if (ThesaurId!=null)
{
CurThes.Load(ThesaurId);
ThesTree.append("<tree id=\"0\" radio=\"1\"><item child=\"1\" id=\"").append(EscapeTree(CurThes.getPDId())).append("\" text=\"").append(EscapeTree(CurThes.getName())).append("\" open=\"1\">");
}
else
ThesTree.append("<tree id=\"").append(ThesId).append("\" open=\"1\">");
HashSet Child =CurThes.getListDirectDescendList(ThesId);
for (Iterator it = Child.iterator(); it.hasNext();)
{
String ChildId=(String)it.next();
if (ChildId.compareTo(PDThesaur.ROOTTERM)==0)
continue;
PDThesaur ChildTerm=new PDThesaur(PDSession);
ChildTerm.Load(ChildId);
ThesTree.append("<item child=\"1\" id=\"").append(EscapeTree(ChildTerm.getPDId())).append("\" text=\"").append(EscapeTree(ChildTerm.getName())).append("\"></item>");
}
} catch(Exception Ex)
{
}
if (ThesaurId!=null)
ThesTree.append("</item>");
ThesTree.append("</tree>");
return(ThesTree.toString());
}
public static void putOperation() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
}
/**
* Compares this foreign key to the given one while ignoring the case of identifiers.
*
* @param otherFk The other foreign key
* @return <code>true</code> if this foreign key is equal (ignoring case) to the given one
*/
public boolean equalsIgnoreCase(ForeignKey otherFk)
{
boolean checkName = (_name != null) && (_name.length() > 0) &&
(otherFk._name != null) && (otherFk._name.length() > 0);
if ((!checkName || _name.equalsIgnoreCase(otherFk._name)) &&
_foreignTableName.equalsIgnoreCase(otherFk._foreignTableName))
{
HashSet otherRefs = new HashSet();
otherRefs.addAll(otherFk._references);
for (Iterator it = _references.iterator(); it.hasNext();)
{
Reference curLocalRef = (Reference)it.next();
boolean found = false;
for (Iterator otherIt = otherRefs.iterator(); otherIt.hasNext();)
{
Reference curOtherRef = (Reference)otherIt.next();
if (curLocalRef.equalsIgnoreCase(curOtherRef))
{
otherIt.remove();
found = true;
break;
}
}
if (!found)
{
return false;
}
}
return otherRefs.isEmpty();
}
else
{
return false;
}
}
public static void putOperation() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
}
/**
* Compares this foreign key to the given one while ignoring the case of identifiers.
*
* @param otherFk The other foreign key
* @return <code>true</code> if this foreign key is equal (ignoring case) to the given one
*/
public boolean equalsIgnoreCase(ForeignKey otherFk)
{
boolean checkName = (_name != null) && (_name.length() > 0) &&
(otherFk._name != null) && (otherFk._name.length() > 0);
if ((!checkName || _name.equalsIgnoreCase(otherFk._name)) &&
_foreignTableName.equalsIgnoreCase(otherFk._foreignTableName))
{
HashSet otherRefs = new HashSet();
otherRefs.addAll(otherFk._references);
for (Iterator it = _references.iterator(); it.hasNext();)
{
Reference curLocalRef = (Reference)it.next();
boolean found = false;
for (Iterator otherIt = otherRefs.iterator(); otherIt.hasNext();)
{
Reference curOtherRef = (Reference)otherIt.next();
if (curLocalRef.equalsIgnoreCase(curOtherRef))
{
otherIt.remove();
found = true;
break;
}
}
if (!found)
{
return false;
}
}
return otherRefs.isEmpty();
}
else
{
return false;
}
}
public static void serverMultiKeyExecution_ThrowException(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true,TestFunction.TEST_FUNCTION_THROW_EXCEPTION);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
try {
List l = null;
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE,
function, isByName);
fail("Exception Expected");
}
catch(Exception ex){
ex.printStackTrace();
}
}
/**
* If node is an element of modules, it does nothing. If it is then it
* adds to <code>modules</code> all modules imported (directly or indirectly)
* by module <code>node</code> by an EXTENDS statement or by an unnamed
* INSTANCE occurring before Location <code>loc</code>. It adds to
* <code>symbols</code> all symbols sym that occur in a
*
* sym == INSTANCE ...
*
* statement that occurs in module <code>node</code> before location
* <code>loc</code> or anywhere in one of the modules added to <code>modules</code>.
*
* This procedure is called by declaredSymbolsInScope and by itself, the
* latter calls always with loc a Location beyond the end of any module.
*
* @param modules
* @param symbols
* @param loc
* @param node
*/
public static void addImportedModulesSet(HashSet<ModuleNode> modules, StringSet symbols,
Location loc, ModuleNode node) {
if (modules.contains(node)) {
return ;
}
modules.add(node) ;
HashSet<ModuleNode> extendees = node.getExtendedModuleSet();
Iterator<ModuleNode> iter = extendees.iterator() ;
while (iter.hasNext()) {
ModuleNode modNode = iter.next() ;
addImportedModulesSet(modules, symbols, infiniteLoc, modNode) ;
}
InstanceNode[] instances = node.getInstances() ;
for (int i = 0; i < instances.length; i++) {
// We add the instance only if its comes before loc.
// For a LOCAL instance, we add the module to `module' or its name to `symbols'
// only if this is the initial call, which is the case iff loc # infiniteLoc
if ( earlierLine(instances[i].stn.getLocation(), loc)
&& ( ! instances[i].getLocal()
|| earlierLine(loc, infiniteLoc))){
if (instances[i].getName() != null) {
symbols.add(instances[i].getName().toString()) ;
} else {
// Testing on 9 Oct 2014 revealed that the following is unnecessary because
// the defined operators imported into a module M without renaming by an INSTANCE
// are contained in M.getOpDefs(). Imported named theorems are similarly
// contained in M.getThmOrAssDefs().
addImportedModulesSet(modules, symbols, infiniteLoc, instances[i].getModule()) ;
}
}
}
}
public static void serverMultiKeyExecution_FunctionInvocationTargetException() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = null;
try {
rc1 = dataSet.withFilter(testKeysSet).withArgs(Boolean.TRUE)
.execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (((RegionFunctionContext)context).isPossibleDuplicate()) {
context.getResultSender().lastResult(new Integer(retryCount));
return;
}
if (context.getArguments() instanceof Boolean) {
throw new FunctionInvocationTargetException(
"I have been thrown from TestFunction");
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
});
List list = (ArrayList)rc1.getResult();
assertEquals(list.get(0), 0);
}
catch (Throwable e) {
e.printStackTrace();
fail("This is not expected Exception", e);
}
}
public StringSet(HashSet<String>hSet) {
Iterator iter = hSet.iterator() ;
while (iter.hasNext()) {
contents.add((String) iter.next()) ;
}
}
public static void serverMultiKeyExecution_Inline() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
List l = null;
ResultCollector rc1 = dataSet.withFilter(testKeysSet)
.withArgs(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
}
else if (context.getArguments() instanceof Boolean) {
context.getResultSender().lastResult(Boolean.TRUE);
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
});
l = ((List)rc1.getResult());
getLogWriter().info("Result size : " + l.size());
assertEquals(3, l.size());
for (Iterator i = l.iterator(); i.hasNext();) {
assertEquals(Boolean.TRUE, i.next());
}
}
catch (Exception e) {
getLogWriter().info("Exception : " + e.getMessage());
e.printStackTrace();
fail("Test failed after the put operation");
}
}
public static void serverMultiKeyExecutionNoResult(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(false, TEST_FUNCTION7);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
String msg = "<ExpectedException action=add>" + "FunctionException"
+ "</ExpectedException>";
cache.getLogger().info(msg);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE,
function, isByName);
rc1.getResult();
Thread.sleep(20000);
fail("Test failed after the put operation");
}
catch (FunctionException expected) {
expected.printStackTrace();
getLogWriter().info("Exception : " + expected.getMessage());
assertTrue(expected.getMessage().startsWith(
(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE
.toLocalizedString("return any"))));
}
catch (Exception notexpected) {
fail("Test failed during execute or sleeping", notexpected);
}
finally {
cache.getLogger().info(
"<ExpectedException action=remove>" + "FunctionException"
+ "</ExpectedException>");
}
}
public static void serverMultiKeyExecution_Inline() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
List l = null;
ResultCollector rc1 = dataSet.withFilter(testKeysSet)
.withArgs(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
}
else if (context.getArguments() instanceof Boolean) {
context.getResultSender().lastResult(Boolean.TRUE);
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
});
l = ((List)rc1.getResult());
getLogWriter().info("Result size : " + l.size());
assertEquals(3, l.size());
for (Iterator i = l.iterator(); i.hasNext();) {
assertEquals(Boolean.TRUE, i.next());
}
}
catch (Exception e) {
getLogWriter().info("Exception : " + e.getMessage());
e.printStackTrace();
fail("Test failed after the put operation");
}
}
public static void serverMultiKeyExecution_Inline() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext();) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
List l = null;
ResultCollector rc1 = dataSet.withFilter(testKeysSet)
.withArgs(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
}
else if (context.getArguments() instanceof Boolean) {
context.getResultSender().lastResult(Boolean.TRUE);
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
});
l = ((List)rc1.getResult());
getLogWriter().info("Result size : " + l.size());
assertEquals(3, l.size());
for (Iterator i = l.iterator(); i.hasNext();) {
assertEquals(Boolean.TRUE, i.next());
}
}
catch (Exception e) {
getLogWriter().info("Exception : " + e.getMessage());
e.printStackTrace();
fail("Test failed after the put operation");
}
}