java.util.List#contains ( )源码实例Demo

下面列出了java.util.List#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Computes [email protected]`recommendSize`
 *
 * @param rankedList a list of ranked item IDs (first item is highest-ranked)
 * @param groundTruth a collection of positive/correct item IDs
 * @param recommendSize top-`recommendSize` items in `rankedList` are recommended
 * @return Precision
 */
public static double Precision(@Nonnull final List<?> rankedList,
        @Nonnull final List<?> groundTruth, @Nonnegative final int recommendSize) {
    Preconditions.checkArgument(recommendSize >= 0);

    if (rankedList.isEmpty()) {
        if (groundTruth.isEmpty()) {
            return 1.d;
        }
        return 0.d;
    }

    int nTruePositive = 0;
    final int k = Math.min(rankedList.size(), recommendSize);
    for (int i = 0; i < k; i++) {
        Object item_id = rankedList.get(i);
        if (groundTruth.contains(item_id)) {
            nTruePositive++;
        }
    }

    return ((double) nTruePositive) / k;
}
 
源代码2 项目: JDKSourceCode1.8   文件: AccessControlContext.java
/**
 * Create an AccessControlContext with the given array of ProtectionDomains.
 * Context must not be null. Duplicate domains will be removed from the
 * context.
 *
 * @param context the ProtectionDomains associated with this context.
 * The non-duplicate domains are copied from the array. Subsequent
 * changes to the array will not affect this AccessControlContext.
 * @throws NullPointerException if {@code context} is {@code null}
 */
public AccessControlContext(ProtectionDomain context[])
{
    if (context.length == 0) {
        this.context = null;
    } else if (context.length == 1) {
        if (context[0] != null) {
            this.context = context.clone();
        } else {
            this.context = null;
        }
    } else {
        List<ProtectionDomain> v = new ArrayList<>(context.length);
        for (int i =0; i< context.length; i++) {
            if ((context[i] != null) &&  (!v.contains(context[i])))
                v.add(context[i]);
        }
        if (!v.isEmpty()) {
            this.context = new ProtectionDomain[v.size()];
            this.context = v.toArray(this.context);
        }
    }
}
 
源代码3 项目: cxf   文件: IdlScopeBase.java
public IdlScopeBase getCircularScope(IdlScopeBase startScope, List<Object> doneDefn) {
    if (doneDefn.contains(this)) {
        return (this == startScope) ? this : null;
    }
    doneDefn.add(this);

    for (IdlDefn defn : definitions()) {
        IdlScopeBase circularScope = defn.getCircularScope(startScope, doneDefn);
        if (circularScope != null) {
            return circularScope;
        }
    }

    doneDefn.remove(this);
    return null;
}
 
源代码4 项目: netbeans   文件: FormPropertyEditorManager.java
public static synchronized void registerEditor(Class propertyType, Class editorClass) {
    List<Class> classList;
    if (expliciteEditors != null) {
        classList = expliciteEditors.get(propertyType);
    } else {
        classList = null;
        expliciteEditors = new HashMap<Class, List<Class>>();
    }
    if (classList == null) {
        classList = new LinkedList<Class>();
        classList.add(editorClass);
        expliciteEditors.put(propertyType, classList);
    } else if (!classList.contains(editorClass)) {
        classList.add(editorClass);
    }
}
 
源代码5 项目: hottub   文件: MappingGenerationTest.java
/**
 * Verifies that addUnencodedNativeForFlavor() really adds the specified
 * flavor-to-native mapping to the existing mappings.
 */
public static void test4() {
    DataFlavor df = new DataFlavor("text/plain-test4; charset=Unicode; class=java.io.Reader", null);
    String nat = "native4";
    List<String> natives = fm.getNativesForFlavor(df);
    if (!natives.contains(nat)) {
        fm.addUnencodedNativeForFlavor(df, nat);
        List<String> nativesNew = fm.getNativesForFlavor(df);
        natives.add(nat);
        if (!natives.equals(nativesNew)) {
            System.err.println("orig=" + natives);
            System.err.println("new=" + nativesNew);
            throw new RuntimeException("Test failed");
        }
    }
}
 
源代码6 项目: o2oa   文件: CmsPermissionService.java
/**
 * 根据条件获取用户有权限访问的所有文档ID列表
 * @param emc
 * @param queryFilter
 * @param maxResultCount
 * @return
 * @throws Exception
 */
public List<String> lisViewableDocIdsWithFilter(EntityManagerContainer emc, QueryFilter queryFilter,
		Integer maxResultCount) throws Exception {
	if (maxResultCount == null || maxResultCount == 0) {
		maxResultCount = 500;
	}
	List<String> ids = new ArrayList<>();
	List<Review> reviews = null;
	EntityManager em = emc.get(Review.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Review> cq = cb.createQuery(Review.class);
	Root<Review> root = cq.from(Review.class);
	// Predicate p=null;
	Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter(Review_.class, cb, null, root, queryFilter);
	cq.orderBy(cb.desc(root.get(Review.publishTime_FIELDNAME)));
	reviews = em.createQuery(cq.where(p)).setMaxResults(maxResultCount).getResultList();
	if ( ListTools.isNotEmpty( reviews )) {
		for (Review review : reviews) {
			if (!ids.contains(review.getDocId())) {
				ids.add(review.getDocId());
			}
		}
	}
	return ids;
}
 
源代码7 项目: doma   文件: EntityMetaFactory.java
private boolean resolveImmutable(TypeElement classElement, EntityAnnot entityAnnot) {
  if (ElementKindUtil.isRecord(classElement.getKind())) {
    return true;
  }
  boolean result = false;
  List<Boolean> resolvedList = new ArrayList<>();
  for (AnnotationValue value : getEntityElementValueList(classElement, "immutable")) {
    if (value != null) {
      Boolean immutable = AnnotationValueUtil.toBoolean(value);
      if (immutable == null) {
        throw new AptIllegalStateException("immutable");
      }
      result = immutable;
      resolvedList.add(immutable);
    }
  }
  if (resolvedList.contains(Boolean.TRUE) && resolvedList.contains(Boolean.FALSE)) {
    throw new AptException(
        Message.DOMA4226,
        classElement,
        entityAnnot.getAnnotationMirror(),
        entityAnnot.getImmutable(),
        new Object[] {});
  }
  return result;
}
 
源代码8 项目: react-native-navigation   文件: TypefaceLoader.java
@Nullable
   public Typeface getTypefaceFromAssets(String fontFamilyName) {
	try {
		if (context != null) {
			AssetManager assets = context.getAssets();
			List<String> fonts = Arrays.asList(assets.list("fonts"));
			if (fonts.contains(fontFamilyName + ".ttf")) {
				return Typeface.createFromAsset(assets, "fonts/" + fontFamilyName + ".ttf");
			}

			if (fonts.contains(fontFamilyName + ".otf")) {
				return Typeface.createFromAsset(assets, "fonts/" + fontFamilyName + ".otf");
			}
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	return null;
}
 
源代码9 项目: proarc   文件: DigitalObjectResource.java
/**
 * Deletes object members from digital object.
 * @param parentPid digital object ID
 * @param toRemovePids member IDs to remove
 * @param batchId optional batch import ID
 * @return list of removed IDs
 */
@DELETE
@Path(DigitalObjectResourceApi.MEMBERS_PATH)
@Produces({MediaType.APPLICATION_JSON})
public SmartGwtResponse<Item> deleteMembers(
        @QueryParam(DigitalObjectResourceApi.MEMBERS_ITEM_PARENT) String parentPid,
        @QueryParam(DigitalObjectResourceApi.MEMBERS_ITEM_PID) List<String> toRemovePids,
        @QueryParam(DigitalObjectResourceApi.MEMBERS_ITEM_BATCHID) Integer batchId
        ) throws IOException, DigitalObjectException {

    if (parentPid == null) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing parent parameter!");
    }
    if (toRemovePids == null || toRemovePids.isEmpty()) {
        throw RestException.plainText(Status.BAD_REQUEST, "Missing pid parameter!");
    }
    if (toRemovePids.contains(parentPid)) {
        throw RestException.plainText(Status.BAD_REQUEST, "parent and pid are same!");
    }

    HashSet<String> toRemovePidSet = new HashSet<String>(toRemovePids);
    if (toRemovePidSet.isEmpty()) {
        return new SmartGwtResponse<Item>(Collections.<Item>emptyList());
    }

    DigitalObjectHandler parent = findHandler(parentPid, batchId, false);
    deleteMembers(parent, toRemovePidSet);
    parent.commit();

    ArrayList<Item> removed = new ArrayList<Item>(toRemovePidSet.size());
    for (String removePid : toRemovePidSet) {
        Item item = new Item(removePid);
        item.setParentPid(parentPid);
        removed.add(item);
    }

    return new SmartGwtResponse<Item>(removed);
}
 
源代码10 项目: AccumuloGraph   文件: MapReduceVertex.java
private Iterable<Edge> getEdges(Collection<Edge> edges, String... labels) {
  if (labels.length > 0) {
    List<String> filters = Arrays.asList(labels);
    LinkedList<Edge> filteredEdges = new LinkedList<Edge>();
    for (Edge e : edges) {
      if (filters.contains(e.getLabel())) {
        filteredEdges.add(e);
      }
    }
    return filteredEdges;
  } else {
    return edges;
  }
}
 
源代码11 项目: o2oa   文件: ScriptFactory.java
@SuppressWarnings("unchecked")
public List<Script> listScriptNestedWithPortalWithFlag(Portal portal, String flag) throws Exception {
	List<Script> list = new ArrayList<>();
	String cacheKey = ApplicationCache.concreteCacheKey(flag, portal.getId(), "listScriptNestedWithPortalWithFlag");
	Element element = scriptCache.get(cacheKey);
	if ((null != element) && (null != element.getObjectValue())) {
		list = (List<Script>) element.getObjectValue();
	} else {
		List<String> names = new ArrayList<>();
		names.add(flag);
		while (!names.isEmpty()) {
			List<String> loops = new ArrayList<>();
			for (String name : names) {
				Script o = this.getScriptWithPortalWithFlag(portal, name);
				if ((null != o) && (!list.contains(o))) {
					list.add(o);
					loops.addAll(o.getDependScriptList());
				}
			}
			names = loops;
		}
		if (!list.isEmpty()) {
			Collections.reverse(list);
			scriptCache.put(new Element(cacheKey, list));
		}
	}
	return list;
}
 
源代码12 项目: openjdk-jdk9   文件: bug4726194.java
public static void test(int level, String[] constraints, List result, List soFar) {
    if (level == 0) {
        result.add(soFar);
        return;
    }
    for (int i = 0; i < constraints.length; i++) {
        if (soFar.contains(constraints[i]) && !TEST_DUPLICATES) {
            continue;
        }
        List child = new ArrayList(soFar);
        child.set(level - 1, constraints[i]);
        test(level - 1, constraints, result, child);
    }
}
 
源代码13 项目: micro-integrator   文件: MethodCallOperator.java
private VisitorOperand stringFunction(final StringFunction function, final EdmType returnValue)
        throws ODataApplicationException {
    List<String> stringParameters = getParametersAsString();
    if (stringParameters.contains(null)) {
        return new TypedOperand(null, EdmNull.getInstance());
    } else {
        return new TypedOperand(function.perform(stringParameters), returnValue);
    }
}
 
源代码14 项目: TestingApp   文件: SeriesEntity.java
public void includeOnlyFields(final IncludeFieldNames includeFieldNames) {

        List<String> fieldNames = includeFieldNames.getNames();

        if(!fieldNames.contains("id")){
            this.id=null;
        }

        if(!fieldNames.contains("name")){
            this.name=null;
        }
    }
 
源代码15 项目: mapwize-ui-android   文件: ModeViewAdapter.java
void swapData(List<DirectionMode> modes) {
    this.modes = modes;
    if (modes != null && modes.size() > 0 && (selectedMode == null || !modes.contains(selectedMode))) {
        setSelectedMode(modes.get(0), true);
    }
    else {
        notifyDataSetChanged();
    }
}
 
源代码16 项目: Noyze   文件: Accountant.java
/** @return True if the user has purchased the given SKU. */
public Boolean has(String sku) {
    if (FREE_FOR_ALL) return true;
    if (null == mService || null == sku) return null;
    LogUtils.LOGI("Accountant", "has(" + sku + ')');
    List<String> skus = getPurchases();
    return (null != skus && skus.contains(sku));
}
 
源代码17 项目: super-cloudops   文件: SecondaryAuthcSnsHandler.java
private void assertionSecondAuthentication(String provider, Oauth2OpenId openId, IamPrincipalInfo account, String authorizers,
		Map<String, String> connectParams) {
	// Check authorizer effectiveness
	if (isNull(account) || isBlank(account.getPrincipal())) {
		throw new SecondaryAuthenticationException(InvalidAuthorizer, format("Invalid authorizer, openId info[%s]", openId));
	}
	// Check authorizer matches
	else {
		List<String> authorizerList = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(authorizers);
		if (!authorizerList.contains(account.getPrincipal())) {
			throw new SecondaryAuthenticationException(IllegalAuthorizer, String.format(
					"Illegal authorizer, Please use [%s] account authorization bound by user [%s]", provider, authorizers));
		}
	}
}
 
源代码18 项目: idea-php-typo3-plugin   文件: PhpElementsUtil.java
public static boolean extendsClass(PhpClass subject, PhpClass extendedClass) {

        List<ClassReference> classReferences = allExtendedClasses(subject)
                .stream()
                .map(e -> (ClassReference) e.getReference())
                .collect(Collectors.toList());

        return classReferences.contains(extendedClass.getReference());
    }
 
源代码19 项目: Bats   文件: LatticeChildNode.java
void use(List<LatticeNode> usedNodes) {
  if (!usedNodes.contains(this)) {
    parent.use(usedNodes);
    usedNodes.add(this);
  }
}
 
源代码20 项目: document-management-system   文件: Macros.java
/**
 * isRegistered
 *
 * @param uuidList
 * @return
 */
public static boolean isRegistered(List<String> uuidList) {
	return uuidList.contains(UUID);
}