Java Code Examples for java.util.List#contains()

The following examples show how to use java.util.List#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryResponsesMeasures.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
/**
 * Computes Precision@`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;
}
 
Example 2
Source File: AccessControlContext.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 3
Source File: TypefaceLoader.java    From react-native-navigation with MIT License 6 votes vote down vote up
@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;
}
 
Example 4
Source File: IdlScopeBase.java    From cxf with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: EntityMetaFactory.java    From doma with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: FormPropertyEditorManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 7
Source File: MappingGenerationTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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");
        }
    }
}
 
Example 8
Source File: CmsPermissionService.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 根据条件获取用户有权限访问的所有文档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;
}
 
Example 9
Source File: PhpElementsUtil.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
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());
    }
 
Example 10
Source File: SecondaryAuthcSnsHandler.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
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));
		}
	}
}
 
Example 11
Source File: Accountant.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/** @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));
}
 
Example 12
Source File: ModeViewAdapter.java    From mapwize-ui-android with MIT License 5 votes vote down vote up
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();
    }
}
 
Example 13
Source File: SeriesEntity.java    From TestingApp with Apache License 2.0 5 votes vote down vote up
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;
        }
    }
 
Example 14
Source File: MethodCallOperator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 15
Source File: bug4726194.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 16
Source File: ScriptFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 17
Source File: MapReduceVertex.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 18
Source File: DigitalObjectResource.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: LatticeChildNode.java    From Bats with Apache License 2.0 4 votes vote down vote up
void use(List<LatticeNode> usedNodes) {
  if (!usedNodes.contains(this)) {
    parent.use(usedNodes);
    usedNodes.add(this);
  }
}
 
Example 20
Source File: Macros.java    From document-management-system with GNU General Public License v2.0 2 votes vote down vote up
/**
 * isRegistered
 *
 * @param uuidList
 * @return
 */
public static boolean isRegistered(List<String> uuidList) {
	return uuidList.contains(UUID);
}