001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.commons.beanquery; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021/** 022 * The two neutral row counts a session can report: {@link #total()} (the rows in scope before the query's search) and 023 * {@link #matched()} (the rows that survive the search, before any page limit). 024 * 025 * <p> 026 * These names are transport-neutral on purpose; a request-facing adapter maps them to its own vocabulary (for example 027 * a DataTables adapter maps {@code total}→{@code recordsTotal} and {@code matched}→{@code recordsFiltered}). 028 * 029 * @since 10.0.0 030 */ 031public final class Counts { 032 033 private final long total; 034 private final long matched; 035 036 private Counts(long total, long matched) { 037 this.total = total; 038 this.matched = matched; 039 } 040 041 /** 042 * Creates a counts result. 043 * 044 * @param total The rows in scope before the search. 045 * @param matched The rows that survive the search, before any page limit. 046 * @return A new counts result. 047 */ 048 public static Counts of(long total, long matched) { 049 return new Counts(total, matched); 050 } 051 052 /** 053 * The number of rows in scope before the query's search (after any server-only guard). 054 * 055 * @return The total row count. 056 */ 057 public long total() { 058 return total; 059 } 060 061 /** 062 * The number of rows that survive the search, before any page limit. 063 * 064 * @return The matched row count. 065 */ 066 public long matched() { 067 return matched; 068 } 069 070 @Override /* Object */ 071 public boolean equals(Object o) { 072 return this == o || (o instanceof Counts c && total == c.total && matched == c.matched); 073 } 074 075 @Override /* Object */ 076 public int hashCode() { 077 return h(total, matched); 078 } 079 080 @Override /* Object */ 081 public String toString() { 082 return "Counts(total=" + total + ", matched=" + matched + ")"; 083 } 084}