Java Code Examples for java.util.Collection#size()
The following examples show how to use
java.util.Collection#size() .
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: IntDictionaryMap.java From tablesaw with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: SqlItemPeer.java From seldon-server with Apache License 2.0 | 6 votes |
@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; }
Example 3
Source File: VerifyUtils.java From DDMQ with Apache License 2.0 | 6 votes |
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; }
Example 4
Source File: PolyhedralRegionSelector.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@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)); } }
Example 5
Source File: ImmutableAcknowledgements.java From ditto with Eclipse Public License 2.0 | 6 votes |
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; }
Example 6
Source File: ReadMetricQueue.java From phoenix with Apache License 2.0 | 6 votes |
/** * @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; }
Example 7
Source File: MetricsCorrelatorReducer.java From datawave with Apache License 2.0 | 5 votes |
/** * 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; }
Example 8
Source File: BaseServiceImpl.java From belling-admin with Apache License 2.0 | 5 votes |
/** * 通过主键集合查询实体 * * @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; }
Example 9
Source File: AbstractApnsService.java From gameserver with Apache License 2.0 | 5 votes |
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; }
Example 10
Source File: StdArrangementEntryMatcher.java From consulo with Apache License 2.0 | 5 votes |
@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; } }
Example 11
Source File: DeviceFarmServer.java From aws-device-farm-gradle-plugin with Apache License 2.0 | 5 votes |
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; }
Example 12
Source File: LoadBalancerDescBasic.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
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); } }
Example 13
Source File: DbSqlSession.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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); } }
Example 14
Source File: PcepClientControllerImplTest.java From onos with Apache License 2.0 | 5 votes |
@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); }
Example 15
Source File: ServerList.java From OPC_Client with Apache License 2.0 | 5 votes |
/** * 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; }
Example 16
Source File: Children.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example 17
Source File: SchemaVersionLifecycleManager.java From registry with Apache License 2.0 | 4 votes |
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; } }
Example 18
Source File: DashboardREST.java From open-Autoscaler with Apache License 2.0 | 4 votes |
@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); } }
Example 19
Source File: SOAPComponentVisitor.java From netbeans with Apache License 2.0 | 4 votes |
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()))); } } } }
Example 20
Source File: FormServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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()); }