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


Java HashSet.add方法代码示例

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


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

示例1: entitiesSwitch

import java.util.HashSet; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
private <T extends PIMEntity> HashSet<T> entitiesSwitch(T t){
    HashSet<T> items = new HashSet<T>();
    for(PIMEntity item : this){
        if(item.getClass().equals(t.getClass())){
            items.add((T)item);
        }
    }
    return items;
    /*原先的基于C#的泛型写法
    HashSet<T> items = new HashSet<T>();
    for(PIMEntity item : this){
        if(item instaceof T){
            items.add((T)item);
        }
    }
    return items;

     */
}
 
开发者ID:starsriver,项目名称:JavaHomework,代码行数:21,代码来源:PIMCollection.java

示例2: getSnippetAnnotationRanks

import java.util.HashSet; //导入方法依赖的package包/类
private HashMap<Tag, List<Integer>> getSnippetAnnotationRanks(
		List<List<Pair<ScoredAnnotation, HashMap<String, Double>>>> snippetAnnotations) {
	HashMap<Tag, List<Integer>> res = new HashMap<>();
	for (int rank=0; rank<snippetAnnotations.size(); rank ++){
		HashSet<Tag> alreadyInserted = new HashSet<>();
		for (Pair<ScoredAnnotation, HashMap<String, Double>> annAndInfo : snippetAnnotations.get(rank)){
			ScoredAnnotation ann = annAndInfo.first;
			Tag t = new Tag(ann.getConcept());
			if (alreadyInserted.contains(t))
				continue;
			alreadyInserted.add(t);
			if (!res.containsKey(t))
				res.put(t, new Vector<Integer>());
			res.get(t).add(rank);
		}
	}
	return res;
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:19,代码来源:SmaphAnnotator.java

示例3: removeExistingImports

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * 
 */
private HashSet<TypeDescriptor> removeExistingImports(
        HashSet<TypeDescriptor> newImports,
        ArrayList<ImportInfo> curImports) {
    
    HashSet<TypeDescriptor> newSet = null;
    Iterator<TypeDescriptor> iterator = newImports.iterator();
    
    while (iterator.hasNext()) {
        TypeDescriptor curType = iterator.next();
        
        if (!containsType(curImports,curType)) {
            if (newSet == null) {
                newSet = new HashSet<>();
            }
            
            newSet.add(curType);
        }
    }
    
    return newSet;
}
 
开发者ID:annoflex,项目名称:annoflex,代码行数:25,代码来源:ImportInserter.java

示例4: getUpperBoundMentions

import java.util.HashSet; //导入方法依赖的package包/类
public HashSet<ScoredAnnotation> getUpperBoundMentions(String query,
		HashSet<Annotation> goldStandardAnn, BindingGenerator bg, SmaphDebugger debugger)
				throws Exception {
	QueryInformation qi = getQueryInformation(query, debugger);
	List<Triple<HashSet<Annotation>, BindingFeaturePack, Double>> bindingToFtrsAndF1 = getLBBindingToFtrsAndF1(
			query, qi, goldStandardAnn,
			new StrongMentionAnnotationMatch(), qi.allCandidates(), debugger);
	HashSet<Annotation> bestBinding = null;
	double bestF1 = Double.NEGATIVE_INFINITY;
	for (Triple<HashSet<Annotation>, BindingFeaturePack, Double> bindingAndFtrsAndF1 : bindingToFtrsAndF1) {
		double f1 = bindingAndFtrsAndF1.getRight();
		if (f1 > bestF1) {
			bestBinding = bindingAndFtrsAndF1.getLeft();
			bestF1 = f1;
		}
	}

	if (bestBinding == null) return null;

	HashSet<ScoredAnnotation> bestBindingScored= new HashSet<>();
	for (Annotation a : bestBinding)
		bestBindingScored.add(new ScoredAnnotation(a.getPosition(), a.getLength(), a.getConcept(), 1.0f));
	return bestBindingScored;
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:25,代码来源:SmaphAnnotator.java

示例5: getFormattedElement

import java.util.HashSet; //导入方法依赖的package包/类
@Test
public void getFormattedElement() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  HashSet<Cookie> cookieSet = new HashSet<>();
  String cookieValue = "cookieValue";
  CookieImpl cookie = new CookieImpl(COOKIE_NAME, cookieValue);

  cookieSet.add(cookie);
  Mockito.when(mockContext.cookieCount()).thenReturn(1);
  Mockito.when(mockContext.cookies()).thenReturn(cookieSet);
  param.setRoutingContext(mockContext);

  String result = ELEMENT.getFormattedElement(param);

  Assert.assertEquals(cookieValue, result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:CookieElementTest.java

示例6: findAllPitClassesWithContactHoursForDepartmentsAndSubjectAreas

import java.util.HashSet; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private HashSet<PitClass> findAllPitClassesWithContactHoursForDepartmentsAndSubjectAreas(
		PointInTimeData pointInTimeData, Session hibSession) {
	
	HashSet<PitClass> pitClasses = new HashSet<PitClass>();
			
	for(Long deptId : getDepartmentIds()) {
		List<PitClass> pitClassesQueryResult = findAllPitClassesWithContactHoursForDepartment(pointInTimeData, deptId, hibSession);
		for(PitClass pc : pitClassesQueryResult) {
			if(pc.getPitSchedulingSubpart().getPitInstrOfferingConfig().getPitInstructionalOffering().getControllingPitCourseOffering().isIsControl().booleanValue() 
					&& getSubjectAreaIds().contains(pc.getPitSchedulingSubpart().getPitInstrOfferingConfig().getPitInstructionalOffering().getControllingPitCourseOffering().getSubjectArea().getUniqueId())) {
				pitClasses.add(pc);
			};
		}
	}
	return(pitClasses);

}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:WSEByDayOfWeekAndPeriod.java

示例7: testInvokeAllCollection

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * invokeAll(collection) invokes all tasks in the collection
 */
public void testInvokeAllCollection() {
    RecursiveAction a = new CheckedRecursiveAction() {
        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            AsyncFib g = new AsyncFib(9);
            AsyncFib h = new AsyncFib(7);
            HashSet set = new HashSet();
            set.add(f);
            set.add(g);
            set.add(h);
            invokeAll(set);
            assertEquals(21, f.number);
            assertEquals(34, g.number);
            assertEquals(13, h.number);
            checkCompletedNormally(f);
            checkCompletedNormally(g);
            checkCompletedNormally(h);
        }};
    testInvokeOnPool(mainPool(), a);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ForkJoinTaskTest.java

示例8: find

import java.util.HashSet; //导入方法依赖的package包/类
@Override
public Collection<? extends Point> find(Point from, Point destination, DistanceComparator distanceComparator,
		CollisionDetector collisionDetector)
{
	Map<Point, Point> parents = new HashMap<>();
	TreeSet<Point> openList = new TreeSet<>(distanceComparator);
	HashSet<Point> closedList = new HashSet<>();
	openList.add(from);
	Point n = null; 
	Point closestNode = from;
	while (!openList.isEmpty())
	{
		n = openList.pollFirst();

		if(distanceComparator.compare(closestNode, n) > 0)
			closestNode = n;
		if (n.equals(destination))
			return createPath(from, destination, parents);
		
		closedList.add(n);
		List<Point> successors = createSuccessors(n, collisionDetector);
		for (Point successor: successors)
		{
			if (!closedList.contains(successor))
			{
				openList.add(successor);
				if (!parents.containsKey(successor)) 
					parents.put(successor, n);
			}
		}
	}

	return createPath(from, closestNode, parents);
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:35,代码来源:BestFirstPathFinder.java

示例9: toCourseSet

import java.util.HashSet; //导入方法依赖的package包/类
private HashSet<Course> toCourseSet(Collection<Long> courseIds) { // lazyload persistentset prevention
	HashSet<Course> result = new HashSet<Course>(courseIds.size());
	Iterator<Long> it = courseIds.iterator();
	while (it.hasNext()) {
		result.add(this.load(it.next()));
	}
	return result;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:9,代码来源:CourseDaoImpl.java

示例10: updateXPoints

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * Adds any unique x-values from 'series' to the dataset, and also adds any x-values that are
 * in the dataset but not in 'series' to the series.
 *
 * @param series  the series (<code>null</code> not permitted).
 */
private void updateXPoints(XYSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Null 'series' not permitted.");
    }
    HashSet seriesXPoints = new HashSet();
    boolean savedState = this.propagateEvents;
    this.propagateEvents = false;
    for (int itemNo = 0; itemNo < series.getItemCount(); itemNo++) {
        Number xValue = series.getX(itemNo);
        seriesXPoints.add(xValue);
        if (!this.xPoints.contains(xValue)) {
            this.xPoints.add(xValue);
            for (int seriesNo = 0; seriesNo < this.data.size(); seriesNo++) {
                XYSeries dataSeries = (XYSeries) this.data.get(seriesNo);
                if (!dataSeries.equals(series)) {
                    dataSeries.add(xValue, null);
                } 
            }
        }
    }
    Iterator iterator = this.xPoints.iterator();
    while (iterator.hasNext()) {
        final Number xPoint = (Number) iterator.next();
        if (!seriesXPoints.contains(xPoint)) {
            series.add(xPoint, null);
        }
    }
    this.propagateEvents = savedState;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:36,代码来源:DefaultTableXYDataset.java

示例11: generate

import java.util.HashSet; //导入方法依赖的package包/类
@Override
public void generate() {
    HashSet<MethodSpec> methodSpecs = new LinkedHashSet<>();

    MethodSpec methodDelete = MethodSpec.methodBuilder(REMOVE_ALL)
            .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
            .returns(TypeName.VOID)
            .addAnnotation(AnnotationSpec.builder(Apply.class).build())
            .addJavadoc(REMOVE_ALL_METHOD_JAVA_DOC)
            .build();

    methodSpecs.add(methodDelete);

    TypeSpec typeSpec = TypeSpec.interfaceBuilder(Constants.IHANDLE)
            .addModifiers(Modifier.PUBLIC)
            .addMethods(methodSpecs)
            .addJavadoc(CLASS_JAVA_DOC)
            .build();

    try {
        JavaFile.builder(Constants.PACKAGE_NAME, typeSpec)
                .build()
                .writeTo(EnvironmentManager.getManager().getFiler());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:xuehuayous,项目名称:Hannibai,代码行数:28,代码来源:IHandleGenerator.java

示例12: send

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * @return list of recipients who did not receive the message because they left the view (null if
 *         all received it or it was sent to {@link DistributionMessage#ALL_RECIPIENTS}).
 * @throws NotSerializableException If content cannot be serialized
 */
public Set send(InternalDistributedMember[] destinations, DistributionMessage content,
    DistributionManager dm, DistributionStats stats) throws NotSerializableException {
  if (membershipManager == null) {
    logger.warn(LocalizedMessage.create(
        LocalizedStrings.DistributionChannel_ATTEMPTING_A_SEND_TO_A_DISCONNECTED_DISTRIBUTIONMANAGER));
    if (destinations.length == 1 && destinations[0] == DistributionMessage.ALL_RECIPIENTS)
      return null;
    HashSet result = new HashSet();
    for (int i = 0; i < destinations.length; i++)
      result.add(destinations[i]);
    return result;
  }
  return membershipManager.send(destinations, content, stats);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:DistributionChannel.java

示例13: restore

import java.util.HashSet; //导入方法依赖的package包/类
private static HashSet<Badge> restore(Bundle bundle) {
	HashSet<Badge> badges = new HashSet<>();

	String[] names = bundle.getStringArray(BADGES);
	for (int i = 0; i < names.length; i++) {
		try {
			badges.add(Badge.valueOf(names[i]));
		} catch (Exception e) {
		}
	}

	return badges;
}
 
开发者ID:G2159687,项目名称:ESPD,代码行数:14,代码来源:Badges.java

示例14: testGapAckGen

import java.util.HashSet; //导入方法依赖的package包/类
@Test
public void testGapAckGen() {
    HashSet<Long> ls = new HashSet<>();
    ls.add(0L);
    ls.add(1L);
    ls.add(2L);
    ls.add(3L);
    ls.add(4L);

    ls.add(6L);
    ls.add(7L);

    ls.add(10L);

    List<SackUtil.GapAck> ackList = SackUtil.getGapAckList(ls);

    assertEquals(3,ackList.size());

    SackUtil.GapAck a = ackList.get(0);
    SackUtil.GapAck b = ackList.get(1);
    SackUtil.GapAck c = ackList.get(2);

    assertEquals(a.start,0L);
    assertEquals(a.end,4L);

    assertEquals(b.start,6L);
    assertEquals(b.end,7L);

    assertEquals(c.start,10L);
    assertEquals(c.end,10L);

}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:33,代码来源:SackUtilTest.java

示例15: getStorageDirectories

import java.util.HashSet; //导入方法依赖的package包/类
/**
 * Returns all available external SD-Card roots in the system.
 *
 * @return paths to all available external SD-Card roots in the system.
 */
private List<String> getStorageDirectories() {
    final HashSet<String> out = new HashSet<String>();
    String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
    String s = "";
    try {
        final Process process = new ProcessBuilder().command("mount")
                .redirectErrorStream(true).start();
        process.waitFor();
        final InputStream is = process.getInputStream();
        final byte[] buffer = new byte[1024];
        while (is.read(buffer) != -1) {
            s = s + new String(buffer);
        }
        is.close();
    } catch (final Exception e) {
        e.printStackTrace();
    }

    // parse output
    final String[] lines = s.split("\n");
    for (String line : lines) {
        if (!line.toLowerCase(Locale.US).contains("asec")) {
            if (line.matches(reg)) {
                String[] parts = line.split(" ");
                for (String part : parts) {
                    if (part.startsWith("/"))
                        if (!part.toLowerCase(Locale.US).contains("vold"))
                            out.add(part);
                }
            }
        }
    }
    return new ArrayList<>(out);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:40,代码来源:DStorageItemsLister.java


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