size ( )源码实例Demo

java.util.Collection#size ( )源码实例Demo

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

源代码1 项目: phoenix   文件: ReadMetricQueue.java
/**
 * @return map of table name -> list of pair of (metric name, metric value)
 */
public Map<String, Map<MetricType, Long>> aggregate() {
    Map<String, Map<MetricType, Long>> publishedMetrics = new HashMap<>();
    for (Entry<MetricKey, Queue<CombinableMetric>> entry : metricsMap.entrySet()) {
        String tableNameToPublish = entry.getKey().tableName;
        Collection<CombinableMetric> metrics = entry.getValue();
        if (metrics.size() > 0) {
            CombinableMetric m = combine(metrics);
            Map<MetricType, Long> map = publishedMetrics.get(tableNameToPublish);
            if (map == null) {
                map = new HashMap<>();
                publishedMetrics.put(tableNameToPublish, map);
            }
            map.put(m.getMetricType(), m.getValue());
        }
    }
    return publishedMetrics;
}
 
源代码2 项目: tablesaw   文件: IntDictionaryMap.java
@Override
public Selection selectIsIn(Collection<String> strings) {
  IntOpenHashSet keys = new IntOpenHashSet(strings.size());
  for (String string : strings) {
    int key = getKeyForValue(string);
    if (key != DEFAULT_RETURN_VALUE) {
      keys.add(key);
    }
  }

  Selection results = new BitmapBackedSelection();
  for (int i = 0; i < values.size(); i++) {
    if (keys.contains(values.getInt(i))) {
      results.add(i);
    }
  }
  return results;
}
 
源代码3 项目: seldon-server   文件: SqlItemPeer.java
@Override
public long getMinItemId(Date after, Integer dimension,ConsumerBean cb) {
	String typeFilter = "";
	if(dimension != null && dimension != Constants.DEFAULT_DIMENSION) {
		DimensionBean d = ItemService.getDimension(cb, dimension);
		Integer type = d.getItemType();
		if(type!=null) { typeFilter = " and type ="+ type; }
	}
	Query query = pm.newQuery( Item.class, "lastOp >= d" + typeFilter );
	query.declareParameters("java.util.Date d");
	query.setRange(0, 1);
	query.setOrdering("lastOp ASC,itemId ASC");
	Collection<Item> c = (Collection<Item>) query.execute(after);
	if (c.size() >= 1)
		return c.iterator().next().getItemId();
	else
		return 0L;
}
 
源代码4 项目: DDMQ   文件: VerifyUtils.java
public static boolean verifyOrderMsg(Collection<Object> msgs) {
    int min = Integer.MIN_VALUE;
    int curr;
    if (msgs.size() == 0 || msgs.size() == 1) {
        return true;
    } else {
        for (Object msg : msgs) {
            curr = Integer.parseInt((String) msg);
            if (curr < min) {
                return false;
            } else {
                min = curr;
            }
        }
    }
    return true;
}
 
@Override
public void describeCUI(LocalSession session, Actor player) {
    checkNotNull(player);
    checkNotNull(session);

    Collection<Vector> vertices = region.getVertices();
    Collection<Triangle> triangles = region.getTriangles();

    Map<Vector, Integer> vertexIds = new HashMap<Vector, Integer>(vertices.size());
    int lastVertexId = -1;
    for (Vector vertex : vertices) {
        vertexIds.put(vertex, ++lastVertexId);
        session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea()));
    }

    for (Triangle triangle : triangles) {
        final int[] v = new int[3];
        for (int i = 0; i < 3; ++i) {
            v[i] = vertexIds.get(triangle.getVertex(i));
        }
        session.dispatchCUIEvent(player, new SelectionPolygonEvent(v));
    }
}
 
源代码6 项目: ditto   文件: ImmutableAcknowledgements.java
private static HttpStatusCode getCombinedStatusCode(final Collection<? extends Acknowledgement> acknowledgements) {
    final HttpStatusCode result;
    if (1 == acknowledgements.size()) {
        result = acknowledgements.stream()
                .findFirst()
                .map(Acknowledgement::getStatusCode)
                .orElse(HttpStatusCode.INTERNAL_SERVER_ERROR);
    } else {
        final Stream<? extends Acknowledgement> acknowledgementStream = acknowledgements.stream();
        final boolean allAcknowledgementsSuccessful = acknowledgementStream.allMatch(Acknowledgement::isSuccess);
        if (allAcknowledgementsSuccessful) {
            result = HttpStatusCode.OK;
        } else {
            result = HttpStatusCode.FAILED_DEPENDENCY;
        }
    }
    return result;
}
 
源代码7 项目: OPC_Client   文件: ServerList.java
/**
 * List all servers that match the requirements
 * @param implemented All implemented categories
 * @param required All required categories
 * @return A collection of <q>class ids</q>
 * @throws IllegalArgumentException
 * @throws UnknownHostException
 * @throws JIException
 */
public Collection<String> listServers ( final Category[] implemented, final Category[] required ) throws IllegalArgumentException, UnknownHostException, JIException
{
    // convert the type safe categories to plain UUIDs
    UUID[] u1 = new UUID[implemented.length];
    UUID[] u2 = new UUID[required.length];

    for ( int i = 0; i < implemented.length; i++ )
    {
        u1[i] = new UUID ( implemented[i].toString () );
    }

    for ( int i = 0; i < required.length; i++ )
    {
        u2[i] = new UUID ( required[i].toString () );
    }

    // get them as UUIDs
    Collection<UUID> resultU = this._serverList.enumClassesOfCategories ( u1, u2 ).asCollection ();

    // and convert to easier usable strings
    Collection<String> result = new ArrayList<String> ( resultU.size () );
    for ( UUID uuid : resultU )
    {
        result.add ( uuid.toString () );
    }
    return result;
}
 
源代码8 项目: onos   文件: PcepClientControllerImplTest.java
@Override
public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
    Collection<Tunnel> result = new HashSet<Tunnel>();
    Tunnel tunnel = null;
    for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
        tunnel = tunnelIdAsKeyStore.get(tunnelId);

        if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
            result.add(tunnel);
        }
    }

    return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
}
 
源代码9 项目: activiti6-boot2   文件: DbSqlSession.java
protected void flushInsertEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToInsert) {
 if (entitiesToInsert.size() == 1) {
 	flushRegularInsert(entitiesToInsert.iterator().next(), entityClass);
 } else if (Boolean.FALSE.equals(dbSqlSessionFactory.isBulkInsertable(entityClass))) {
 	for (Entity entity : entitiesToInsert) {
 		flushRegularInsert(entity, entityClass);
 	}
 }	else {
 	flushBulkInsert(entitiesToInsert, entityClass);
 }
}
 
public void refresh(Collection<LoadBalancerListener> listeners, boolean clearCheckBox) {
    if (clearCheckBox) {
        checkBoxes.clear();
    }
    setContainerDataSource(new LoadBalancerListenerContainer(listeners));
    setVisibleColumns(VISIBLE_COLNAME);
    if (listeners.size() > 0) {
        setColumnHeaders(COLNAME);
    }
}
 
源代码11 项目: consulo   文件: StdArrangementEntryMatcher.java
@SuppressWarnings("ConstantConditions")
@Nonnull
public ArrangementEntryMatcher getMatcher() {
  Collection<ArrangementEntryMatcher> matchers = myMatcherBuilder.buildMatchers();

  if (matchers.size() == 1) {
    return matchers.iterator().next();
  } else {
    CompositeArrangementEntryMatcher result = new CompositeArrangementEntryMatcher();
    for (ArrangementEntryMatcher matcher: matchers) {
      result.addMatcher(matcher);
    }
    return result;
  }
}
 
源代码12 项目: gameserver   文件: AbstractApnsService.java
public Collection<EnhancedApnsNotification> push(Collection<byte[]> deviceTokens, byte[] payload, int expiry) throws NetworkIOException {
    List<EnhancedApnsNotification> notifications = new ArrayList<EnhancedApnsNotification>(deviceTokens.size());
    for (byte[] deviceToken : deviceTokens) {
        EnhancedApnsNotification notification =
            new EnhancedApnsNotification(c.incrementAndGet(), expiry, deviceToken, payload);
        notifications.add(notification);
        push(notification);
    }
    return notifications;
}
 
源代码13 项目: belling-admin   文件: BaseServiceImpl.java
/**
 * 通过主键集合查询实体
 * 
 * @param List
 *            <PK> pks
 * @return List<T>
 */
public List<T> get(Collection<ID> pks) {
	List<T> list = new ArrayList<T>(pks.size());
	for (ID pk : pks) {
		list.add(get(pk));
	}
	return list;
}
 
源代码14 项目: datawave   文件: MetricsCorrelatorReducer.java
/**
 * Utility method for getting the average of longs. Hopes to avoid overflow of adding longs together by doing the window method.
 * 
 * @param data
 * @return
 */
public long getAverage(Collection<LongWritable> data) {
    int size = data.size();
    long average = 0l;
    for (LongWritable l : data) {
        average += l.get() / size;
    }
    return average;
}
 
private List<String> getAuxAppArns(Collection<Upload> auxUploads) {
    List<String> auxAppArns = Lists.newArrayList();

    if (auxUploads == null || auxUploads.size() == 0) {
        return auxAppArns;
    }

    for (Upload auxApp : auxUploads) {
        auxAppArns.add(auxApp.getArn());
    }

    return auxAppArns;
}
 
源代码16 项目: netbeans   文件: Children.java
@Override
public boolean remove(final Node[] arr) {
    synchronized (COLLECTION_LOCK) {
        final Collection<Node> collection = getCollection();
        // fast check
        boolean same = false;
        if (collection.size() == arr.length) {
            same = true;
            int i = 0;
            for (Node n : collection) {
                if (n != arr[i++]) {
                    same = false;
                    break;
                }
            }
        }
        if (same) {
            collection.clear();
        } else {
            if (!collection.removeAll(Arrays.asList(arr))) {
                // the collection was not changed
                return false;
            }
        }
    }

    refresh();

    return true;
}
 
源代码17 项目: alfresco-repository   文件: FormServiceImplTest.java
@Test
public void testGetSelectedFieldsCreateForm() throws Exception
{
    // define a list of fields to retrieve from the node
    List<String> fields = new ArrayList<String>(8);
    fields.add("cm:name");
    fields.add("cm:title");
    
    // get a form for the cm:content type
    Form form = this.formService.getForm(new Item(TYPE_FORM_ITEM_KIND, "cm:content"), fields);
    
    // check a form got returned
    assertNotNull("Expecting form to be present", form);
    
    // check item identifier matches
    assertEquals(TYPE_FORM_ITEM_KIND, form.getItem().getKind());
    assertEquals("cm:content", form.getItem().getId());
    
    // check the type is correct
    assertEquals(ContentModel.TYPE_CONTENT.toPrefixString(this.namespaceService), 
                form.getItem().getType());
    
    // check there is no group info
    assertNull("Expecting the form groups to be null!", form.getFieldGroups());
    
    // check the field definitions
    Collection<FieldDefinition> fieldDefs = form.getFieldDefinitions();
    assertNotNull("Expecting to find fields", fieldDefs);
    assertEquals("Expecting to find 1 field", 1, fieldDefs.size());
    
    // create a Map of the field definitions
    // NOTE: we can safely do this as we know there are no duplicate field names and we're not
    //       concerned with ordering!
    Map<String, FieldDefinition> fieldDefMap = new HashMap<String, FieldDefinition>(fieldDefs.size());
    for (FieldDefinition fieldDef : fieldDefs)
    {
        fieldDefMap.put(fieldDef.getName(), fieldDef);
    }
    
    // find the fields
    PropertyFieldDefinition nameField = (PropertyFieldDefinition)fieldDefMap.get("cm:name");
    assertNotNull("Expecting to find the cm:name field", nameField);
    
    // now force the title field to be present and check
    List<String> forcedFields = new ArrayList<String>(2);
    forcedFields.add("cm:title");
    // get a form for the cm:content type
    form = this.formService.getForm(new Item(TYPE_FORM_ITEM_KIND, "cm:content"), fields, forcedFields);
    fieldDefs = form.getFieldDefinitions();
    assertNotNull("Expecting to find fields", fieldDefs);
    assertEquals("Expecting to find 2 fields", 2, fieldDefs.size());
    
}
 
源代码18 项目: registry   文件: SchemaVersionLifecycleManager.java
private SchemaVersionInfo findSchemaVersion(String schemaBranchName,
                                            String type,
                                            String schemaText,
                                            String schemaMetadataName,
                                            boolean disableCanonicalCheck) throws InvalidSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {

    Preconditions.checkNotNull(schemaBranchName, "Schema branch name can't be null");

    String fingerPrint = getFingerprint(type, schemaText);
    LOG.debug("Fingerprint of the given schema [{}] is [{}]", schemaText, fingerPrint);
    List<QueryParam> queryParams = Lists.newArrayList(
            new QueryParam(SchemaVersionStorable.NAME, schemaMetadataName),
            new QueryParam(SchemaVersionStorable.FINGERPRINT, fingerPrint));

    Collection<SchemaVersionStorable> versionedSchemas = storageManager.find(SchemaVersionStorable.NAME_SPACE, queryParams);

    Map<Long, SchemaVersionStorable> matchedSchemaVersionMap = null;
    if (versionedSchemas != null && !versionedSchemas.isEmpty()) {
        if (versionedSchemas.size() > 1) {
            LOG.warn("Exists more than one schema with schemaMetadataName: [{}] and schemaText [{}]", schemaMetadataName, schemaText);
        }

        matchedSchemaVersionMap = versionedSchemas.stream().collect(Collectors.toMap(SchemaVersionStorable::getId, v -> v));
    }

    if (matchedSchemaVersionMap == null) {
        return null;
    } else {
        SchemaBranch schemaBranch = schemaBranchCache.get(SchemaBranchCache.Key.of(new SchemaBranchKey(schemaBranchName, schemaMetadataName)));
        SchemaVersionInfo matchedSchemaVersionInfo = null;

        // If the disableCanonicalCheck is set to false, then return the lastest schema version that matches the fingerprint
        for (SchemaVersionInfo schemaVersionInfo : getSortedSchemaVersions(schemaBranch)) {
            if (matchedSchemaVersionMap.containsKey(schemaVersionInfo.getId())) {
                if (!disableCanonicalCheck || schemaVersionInfo.getSchemaText().equals(schemaText)) {
                    matchedSchemaVersionInfo = schemaVersionInfo;
                }
            }
        }

        return matchedSchemaVersionInfo;
    }
}
 
源代码19 项目: netbeans   文件: SOAPComponentVisitor.java
private void ensureUniqueParts(Map<MessagePart, SOAPMessageBase> partsMap,
                               SOAPBody elem,
                               WSDLComponent parent) {
    
    // Obtain the Message definition whose part this SOAPBody element extends
    OperationParameter param;
    if (parent instanceof BindingInput) {
        param = ((BindingInput) parent).getInput().get();
    } else if (parent instanceof BindingOutput) {
        param = ((BindingOutput) parent).getOutput().get();
    } else {
        throw new IllegalArgumentException("(Internal error) Unexpected WSDLComponent sub-type "
                + parent.getClass().getName());
    }
    
    // Let wsdl validator catch undefined message for operation input or output
    if (param == null || param.getMessage() == null || param.getMessage().get() == null) {
        return;
    }
    
    Message msg = param.getMessage().get();
    
    List<String> partNames = elem.getParts();
    // If the SOAPBOdy does not explicitly specify a part, assume
    // it refers to the all the parts.
    if (partNames == null || partNames.isEmpty()) {
        Collection<Part> parts = msg.getParts();
        partNames = new ArrayList<String>(parts.size());
        for (Part part: parts) {
            partNames.add(part.getName());
        }
    }
    for (String name: partNames) {
        if (name != null && !"".equals(name)) {
            MessagePart msgpart = new MessagePart(msg, name);
            if (!partsMap.containsKey(msgpart)) {
                partsMap.put(msgpart, elem);
            } else {
                SOAPMessageBase conflictElem = partsMap.get(msgpart);
                results.add(new Validator.ResultItem(
                    mValidator,
                    Validator.ResultType.ERROR,
                    elem,
                    NbBundle.getMessage(SOAPComponentVisitor.class,
                        "SOAPBodyValidator.Part_already_in_use_by_elem",
                        name,
                        msg.getName(),
                        conflictElem.getQName().toString())));
            }
        }
    }
}
 
源代码20 项目: open-Autoscaler   文件: DashboardREST.java
@GET
@Path("/{serviceId}")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings({ "rawtypes", "unchecked" })
public Response getAppMetricsLastestData(@PathParam("serviceId") String serviceId, @QueryParam("appId") String appId) {
    try {
    	
        List<AppInstanceMetrics> stats = new ArrayList<AppInstanceMetrics>();
        MonitorController controller = MonitorController.getInstance();
        Collection<BoundApp> apps = controller.getSerivceBoundApps(serviceId);
        if (apps != null && apps.size() > 0) {
        	controller.updateBoundAppName(apps);
            for (BoundApp app : apps) {
                String boundAppId = app.getAppId();
                //query all bounded app for this service when appId == null
                //query for a specific app when appId is defined
                if ((appId == null) || (appId.equals(boundAppId))) {
                    AppInstanceMetrics appInstanceMetrics = new AppInstanceMetrics();
                    ApplicationMetrics appMetrics = controller.getAppMetrics(boundAppId);
                    if (appMetrics != null) {
                    	//not store to db 
                    	//stale data is allowed for overview page
                    	appInstanceMetrics = appMetrics.mergeToAppInstanceMetrics(false, true);
                    } else {
                    	appInstanceMetrics.setAppId(boundAppId);
                    	appInstanceMetrics.setAppName(app.getAppName());
                    	appInstanceMetrics.setServiceId(app.getServiceId());
                    	appInstanceMetrics.setAppType(app.getAppType());
                    }
                    stats.add(appInstanceMetrics);
                    //get out of the loop if the appId is defined.
                    if ((appId != null) && (appId.equals(boundAppId)))
                    	break; 
                    
                }
            }
        }
        
        return RestApiResponseHandler.getResponseOk(mapper.writeValueAsString(stats));
    } catch (Exception e) {
        logger.error("Internal_Server_Error", e);
        return RestApiResponseHandler.getResponse(Status.INTERNAL_SERVER_ERROR);
    }

}