当前位置: 首页>>代码示例>>Java>>正文


Java HashSet.iterator方法代码示例

本文整理汇总了Java中java.util.HashSet.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java HashSet.iterator方法的具体用法?Java HashSet.iterator怎么用?Java HashSet.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.HashSet的用法示例。


在下文中一共展示了HashSet.iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unique

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * Find unique elements of vector.
 * @param x an array of strings.
 * @return the same values as in x but with no repetitions.
 */
public static String[] unique(String[] x) {
    HashSet<String> hash = new HashSet<>(Arrays.asList(x));

    String[] y = new String[hash.size()];

    Iterator<String> keys = hash.iterator();
    for (int i = 0; i < y.length; i++) {
        y[i] = keys.next();
    }

    return y;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:18,代码来源:Math.java

示例2: saveEnabledServices

import java.util.HashSet; //导入方法依赖的package包/类
private void saveEnabledServices(HashSet<ComponentName> hashSet) {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_SECURE_SETTINGS)
            != PackageManager.PERMISSION_GRANTED)
        return;
    StringBuilder stringBuilder = null;
    Iterator it = hashSet.iterator();
    while (it.hasNext()) {
        ComponentName componentName = (ComponentName) it.next();
        if (stringBuilder == null) {
            stringBuilder = new StringBuilder();
        } else {
            stringBuilder.append(':');
        }
        stringBuilder.append(componentName.flattenToString());
    }
    Settings.Secure.putString(getContentResolver(), "enabled_notification_listeners", stringBuilder != null ? stringBuilder.toString() : "");
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:19,代码来源:XmsfApp.java

示例3: checkFileInPattern

import java.util.HashSet; //导入方法依赖的package包/类
public static boolean checkFileInPattern(HashSet<Pattern> patterns, String key) {
    if (!patterns.isEmpty()) {
        for (Iterator<Pattern> it = patterns.iterator(); it.hasNext();) {
            Pattern p = it.next();
            if (p.matcher(key).matches()) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ShareResPatchInfo.java

示例4: serverMultiKeyExecutionNoResult

import java.util.HashSet; //导入方法依赖的package包/类
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();
    LogWriterUtils.getLogWriter().info("Exception : " + expected.getMessage());
    assertTrue(expected.getMessage()
        .startsWith((LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE
            .toLocalizedString("return any"))));
  } catch (Exception notexpected) {
    Assert.fail("Test failed during execute or sleeping", notexpected);
  } finally {
    cache.getLogger()
        .info("<ExpectedException action=remove>" + "FunctionException" + "</ExpectedException>");
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:39,代码来源:PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.java

示例5: addToCart

import java.util.HashSet; //导入方法依赖的package包/类
public int addToCart(HashSet<Item> itemToCart){
	 /*for (Item temp : itemToCart) {
			  System.out.println("all items sent "+ temp.getItem_ID());
	   }*/
	//if user cart is not empty, search item set received: 
	//		if there is any item in set (with unique itemID) which already in user cart, add item with another itemID from set (if exist)
	//		if all the items in set is in user cart no items will be added and total item count will be same, which this method will return   
	if(!itemsInCart.isEmpty()){
			for (Item temp : itemToCart) {
					//System.out.println("itemToCart "+temp.getItem_ID());
				if(!itemsInCart.containsKey(temp.getItem_ID())){
					itemsInCart.put(temp.getItem_ID(),temp);
					totalPrice = totalPrice + temp.getItem_Price();
					totalItem = totalItem + 1;
					break;
				}
			}
	} //if user cart is empty take the first item from list and add to cart
	else{
	Iterator<Item> it = itemToCart.iterator();	
	Item i = it.next();
	itemsInCart.put(i.getItem_ID(),i);
	totalPrice = totalPrice + i.getItem_Price();
	totalItem = totalItem + 1;
	}

	return totalItem;
}
 
开发者ID:anirban99,项目名称:Shopping-Cart-using-Web-Services,代码行数:29,代码来源:shoppingCart.java

示例6: initializeCoefficients

import java.util.HashSet; //导入方法依赖的package包/类
private void initializeCoefficients(){
HashSet<Variable> varSet = new HashSet<Variable>();
constraints.collectVariables(varSet);
startCoefficients = new Coefficients(varSet.size(), constraints.getConstraintCount());
Iterator<Variable> vars = varSet.iterator();
int varIDX = 0;
while (vars.hasNext())
    startCoefficients.variables[varIDX++] = (NumericVariable)vars.next();
for (int constraintIDX = 0; constraintIDX < constraints.getConstraintCount(); constraintIDX++){
    NumericConstraint constraint = (NumericConstraint)constraints.getConstraint(constraintIDX);
    Polynomial poly = constraint.getPolynomial();
    Arrays.fill(startCoefficients.array[constraintIDX], numberFactory.getZero());
    NumberWrapper constant = poly.getConstant();
    if (constant != null)
	constant = constant.negate();
    else
	constant = numberFactory.getZero();
    startCoefficients.rhs[constraintIDX] = constant;
    for (varIDX = 0; varIDX < startCoefficients.width; varIDX++){
	constant = poly.getCoefficient(new Monomial(startCoefficients.variables[varIDX], 1));
	if (constant == null)
	    constant = numberFactory.getZero();
	startCoefficients.array[constraintIDX][varIDX] = constant;
	if (constraint.isEquation())
	    startCoefficients.rowType[constraintIDX] = EQUAL;
	else
	    if (constraint.isStrictInequation())
		startCoefficients.rowType[constraintIDX] = LESSTHAN;
	    else
		startCoefficients.rowType[constraintIDX] = LESSOREQUAL;
    }
}
   }
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:34,代码来源:EliminationSolver.java

示例7: main

import java.util.HashSet; //导入方法依赖的package包/类
public static void main(String[] args) {
	HashSet<String> ex = new HashSet<>();
	ex.add("������");
	ex.add("�Ķ���");
	ex.add("�����");
	System.out.println("�ݷ��� ũ��: " + ex.size());
	
	System.out.println("== ���׷����ͷ� ��� ==");
	Iterator<String> myInterator = ex.iterator();
	while(myInterator.hasNext())
		System.out.println(myInterator.next());
}
 
开发者ID:BedrockDev,项目名称:Sunrin2017,代码行数:13,代码来源:HashSetEx.java

示例8: tryPlacement

import java.util.HashSet; //导入方法依赖的package包/类
private void tryPlacement(ExamPlacement placement, int depth) {
    if (placement.equals(iAssignment.getValue(placement.variable()))) return;
    if (placement.variable().equals(iExam) && !match(placement.getPeriod().toString()+" "+placement.getRoomName(", "))) return;
    Set conflicts = iModel.conflictValues(iAssignment, placement);
    tryPlacement(placement, depth, conflicts);
    if (iConflictsToResolve.size()+conflicts.size()<depth) {
        Exam exam = (Exam)placement.variable();
        HashSet adepts = new HashSet();
        for (ExamStudent s: exam.getStudents()) {
            Set exams = s.getExams(iAssignment, placement.getPeriod());
            for (Iterator i=exams.iterator();i.hasNext();) {
                ExamPlacement conf = iAssignment.getValue((Exam)i.next());
                if (conf==null || conflicts.contains(conf)) continue;
                if (iResolvedExams.contains((Exam)conf.variable())) continue;
                adepts.add(conf);
            }
        }
        for (Iterator i=adepts.iterator();i.hasNext();) {
            ExamPlacement adept = (ExamPlacement)i.next();
            conflicts.add(adept);
            tryPlacement(placement, depth, conflicts);
            conflicts.remove(adept);
        }
        if (iConflictsToResolve.size()+conflicts.size()+1<depth) {
            for (Iterator i1=adepts.iterator();i1.hasNext();) {
                ExamPlacement a1 = (ExamPlacement)i1.next();
                conflicts.add(a1);
                for (Iterator i2=adepts.iterator();i2.hasNext();) {
                    ExamPlacement a2 = (ExamPlacement)i2.next();
                    if (a2.variable().getId()>=a1.variable().getId()) continue;
                    conflicts.add(a2);
                    tryPlacement(placement, depth, conflicts);
                    conflicts.remove(a2);
                }
                conflicts.remove(a1);
            }
        }
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:40,代码来源:ExamSuggestions.java

示例9: remove

import java.util.HashSet; //导入方法依赖的package包/类
public void remove(HashSet<FavouriteBean> set) {
    Iterator<FavouriteBean> i = set.iterator();
    while (i.hasNext()) {
        FavouriteBean favouriteBean = (FavouriteBean) i.next();
        remove(favouriteBean.pid, favouriteBean.vid);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:8,代码来源:FavoriteTraceHandler.java

示例10: prune

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * Removes all x-values for which all the y-values are <code>null</code>.
 */
public void prune() {
    final HashSet hs = (HashSet) this.xPoints.clone();
    final Iterator iterator = hs.iterator();
    while (iterator.hasNext()) {
        final Number x = (Number) iterator.next();
        if (canPrune(x)) {
            removeAllValuesForX(x);
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:14,代码来源:DefaultTableXYDataset.java

示例11: calculateFirstActivity

import java.util.HashSet; //导入方法依赖的package包/类
public Activity calculateFirstActivity() {
Activity newFirstActivity = null;
HashSet parentActivities = this.getParentActivities();
Iterator parentIterator = parentActivities.iterator();
while (parentIterator.hasNext()) {
    Activity activity = (Activity) parentIterator.next();
    if ((activity.getTransitionTo() == null) && !activity.isFloatingActivity()) {
	newFirstActivity = activity;
	break;
    }
}
return newFirstActivity;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:LearningDesign.java

示例12: serverMultiKeyExecutionSocketTimeOut

import java.util.HashSet; //导入方法依赖的package包/类
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());
    LogWriterUtils.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) {
    Assert.fail("Test failed after the function execution", e);

  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:34,代码来源:PRClientServerRegionFunctionExecutionSingleHopDUnitTest.java

示例13: serverMultiKeyExecution

import java.util.HashSet; //导入方法依赖的package包/类
public static void serverMultiKeyExecution(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, TEST_FUNCTION2);
  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());
    LogWriterUtils.getLogWriter().info("Result size : " + l.size());
    assertEquals(3, l.size());
    for (Iterator i = l.iterator(); i.hasNext();) {
      assertEquals(Boolean.TRUE, i.next());
    }

    List l2 = null;
    ResultCollector rc2 = execute(dataSet, testKeysSet, testKeysSet, function, isByName);
    l2 = ((List) rc2.getResult());
    assertEquals(3, l2.size());
    HashSet foundVals = new HashSet();
    for (Iterator i = l2.iterator(); i.hasNext();) {
      ArrayList subL = (ArrayList) i.next();
      assertTrue(subL.size() > 0);
      for (Iterator subI = subL.iterator(); subI.hasNext();) {
        assertTrue(foundVals.add(subI.next()));
      }
    }
    assertEquals(origVals, foundVals);

  } catch (Exception e) {
    Assert.fail("Test failed after the put operation", e);

  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:48,代码来源:PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest.java

示例14: serverAllKeyExecution

import java.util.HashSet; //导入方法依赖的package包/类
public static void serverAllKeyExecution(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, TEST_FUNCTION2);
  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);
    }
    ResultCollector rc1 = executeOnAll(dataSet, Boolean.TRUE, function, isByName);
    List resultList = ((List) rc1.getResult());
    LogWriterUtils.getLogWriter().info("Result size : " + resultList.size());
    LogWriterUtils.getLogWriter().info("Result are SSSS : " + resultList);
    assertEquals(3, resultList.size());

    // while (resultIterator.hasNext()) {
    // resultListForMember.add(resultIterator.next());
    //
    // for (Object result : resultListForMember) {
    // assertIndexDetailsEquals(Boolean.TRUE, result);
    // }
    // }
    for (Object result : resultList) {
      assertEquals(Boolean.TRUE, result);
    }
    List l2 = null;
    ResultCollector rc2 = executeOnAll(dataSet, testKeysSet, function, isByName);
    l2 = ((List) rc2.getResult());
    assertEquals(3, l2.size());
    HashSet foundVals = new HashSet();
    for (Iterator i = l2.iterator(); i.hasNext();) {
      ArrayList subL = (ArrayList) (i.next());
      assertTrue(subL.size() > 0);
      for (Iterator subI = subL.iterator(); subI.hasNext();) {
        assertTrue(foundVals.add(subI.next()));
      }
    }
    assertEquals(origVals, foundVals);

  } catch (Exception e) {
    Assert.fail("Test failed after the put operation", e);

  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:55,代码来源:PRClientServerRegionFunctionExecutionSingleHopDUnitTest.java

示例15: serverMultiKeyExecution_FunctionInvocationTargetException

import java.util.HashSet; //导入方法依赖的package包/类
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() {
      @Override
      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");
        }
      }

      @Override
      public String getId() {
        return getClass().getName();
      }

      @Override
      public boolean hasResult() {
        return true;
      }
    });

    List list = (ArrayList) rc1.getResult();
    assertEquals(list.get(0), 0);
  } catch (Throwable e) {
    e.printStackTrace();
    Assert.fail("This is not expected Exception", e);
  }

}
 
开发者ID:ampool,项目名称:monarch,代码行数:50,代码来源:PRClientServerRegionFunctionExecutionSingleHopDUnitTest.java


注:本文中的java.util.HashSet.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。