下面列出了怎么用java.util.Objects的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public final <U> Stream<U> mapToObj(IntFunction<? extends U> mapper) {
Objects.requireNonNull(mapper);
return new ReferencePipeline.StatelessOp<Integer, U>(this, StreamShape.INT_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Integer> opWrapSink(int flags, Sink<U> sink) {
return new Sink.ChainedInt<U>(sink) {
@Override
public void accept(int t) {
downstream.accept(mapper.apply(t));
}
};
}
};
}
/**
* Finds and returns all associated annotations matching the given class.
*
* The order of the elements in the array returned depends on the iteration
* order of the provided maps. Specifically, the directly present annotations
* come before the indirectly present annotations if and only if the
* directly present annotations come before the indirectly present
* annotations in the relevant map.
*
* @param declaredAnnotations the declared annotations indexed by their types
* @param decl the class declaration on which to search for annotations
* @param annoClass the type of annotation to search for
*
* @return an array of instances of {@code annoClass} or an empty array if none were found.
*/
public static <A extends Annotation> A[] getAssociatedAnnotations(
Map<Class<? extends Annotation>, Annotation> declaredAnnotations,
Class<?> decl,
Class<A> annoClass) {
Objects.requireNonNull(decl);
// Search declared
A[] result = getDirectlyAndIndirectlyPresent(declaredAnnotations, annoClass);
// Search inherited
if(AnnotationType.getInstance(annoClass).isInherited()) {
Class<?> superDecl = decl.getSuperclass();
while (result.length == 0 && superDecl != null) {
result = getDirectlyAndIndirectlyPresent(LANG_ACCESS.getDeclaredAnnotationMap(superDecl), annoClass);
superDecl = superDecl.getSuperclass();
}
}
return result;
}
public void wakeup(RpcResult result) {
long receiveTime = System.currentTimeMillis();
Objects.requireNonNull(result, "result cannot be null");
if (this.isWaked()) {
return;
}
if (!this.result.compareAndSet(null, result)) {
return;
}
Thread thread = awaitThread.getAndSet(null);
if (thread != null) {
LockSupport.unpark(thread);
}
if (this.callback != null) {
try {
callback.accept(result);
} catch (Throwable e) {
Log.printStack("sumk.rpc", e);
}
}
RpcLogs.clientLog(this.url, this.req, result, receiveTime);
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DiagnosticDataSummary diagnosticDataSummary = (DiagnosticDataSummary) o;
return Objects.equals(this.status, diagnosticDataSummary.status) &&
Objects.equals(this.collectionTime, diagnosticDataSummary.collectionTime) &&
Objects.equals(this.localFilePath, diagnosticDataSummary.localFilePath) &&
Objects.equals(this.details, diagnosticDataSummary.details) &&
Objects.equals(this.diagnosticDataCollected, diagnosticDataSummary.diagnosticDataCollected) &&
Objects.equals(this.diagnosticDataDownloaded, diagnosticDataSummary.diagnosticDataDownloaded) &&
Objects.equals(this.clouderaManagerLogsDownloaded, diagnosticDataSummary.clouderaManagerLogsDownloaded);
}
@Override
public boolean equals(Object obj) {
if (Objects.isNull(obj)) {
return false;
}
if (this == obj) {
return true;
}
if (!(obj instanceof Deposit)) {
return false;
}
Deposit other = (Deposit) obj;
return Objects.equals(this.getProof(), other.getProof())
&& Objects.equals(this.getData(), other.getData());
}
/**
* Creates a string for the charge of atom <code>a</code>. If the charge is
* 1 + is returned if it is -1 - is returned. The positive values all have +
* in front of them.
*
* @return string representing the charge on <code>a</code>
*/
private String generateChargeString(IAtom a) {
int charge = Objects.equals(a.getFormalCharge(), UNSET) ? 0 : a.getFormalCharge();
StringBuilder buffer = new StringBuilder(3);
if (charge > 0) {
//Positive
buffer.append('+');
if (charge > 1) {
buffer.append(charge);
}
} else if (charge < 0) {
//Negative
if (charge == -1) {
buffer.append('-');
} else {
buffer.append(charge);
}
}
return buffer.toString();
}
/**
* Sets the Subscription once but does not request anything.
* @param s the Subscription to set
* @return true if successful, false if the current subscription is not null
*/
protected final boolean setWithoutRequesting(Subscription s) {
Objects.requireNonNull(s, "s");
for (;;) {
Subscription a = this.s;
if (a == SubscriptionHelper.cancelled()) {
s.cancel();
return false;
}
if (a != null) {
s.cancel();
SubscriptionHelper.reportSubscriptionSet();
return false;
}
if (S.compareAndSet(this, null, s)) {
return true;
}
}
}
@Override
public int hashCode() {
int result = hashCode;
if (result == 0) {
result = Objects.hash(id, extension, value);
hashCode = result;
}
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FormatToExpression that = (FormatToExpression) o;
return Objects.equals(orString, that.orString)
&& Objects.equals(andString, that.andString)
&& Objects.equals(falseString, that.falseString)
&& Objects.equals(trueString, that.trueString)
&& Objects.equals(xorString, that.xorString)
&& Objects.equals(notString, that.notString)
&& Objects.equals(getEqual(), that.getEqual());
}
/**
* 写数据
*/
private void writeFlush() {
//添加数据长度响应头
int length = Objects.isNull(getBody()) ? 0 : getBody().getBytes().length;
response.headers().add(CONTENT_LENGTH, length);
ChannelFuture future = channel.writeAndFlush(response);
if (!isKeepAlive()) {
future.addListener(ChannelFutureListener.CLOSE);
}
//只能写一次。
setWritable(false);
}
/**
* Register a converter associated to the supplied {@code type}.
*
* @param type An instance of {link Class} of type {@link T}.
* @param converter An instance of {@link Codec}.
* @param <T> An instance of {@link T}.
*
* @return A {@link CodecContext} for the supplied {@code type}.
*/
public <T> CodecContext register(final Class<? extends T> type, final Codec<T> converter) {
Objects.requireNonNull(type);
Objects.requireNonNull(converter);
this.codecs.put(type, converter);
if (converter instanceof InterledgerPacketCodec<?>) {
InterledgerPacketCodec<?> commandTypeConverter = (InterledgerPacketCodec) converter;
this.packetCodecs.put(commandTypeConverter.getTypeId(), type);
}
return this;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ListASRAnnotationSetsResponse v1SkillAsrAnnotationSetsListASRAnnotationSetsResponse = (ListASRAnnotationSetsResponse) o;
return Objects.equals(this.annotationSets, v1SkillAsrAnnotationSetsListASRAnnotationSetsResponse.annotationSets) &&
Objects.equals(this.paginationContext, v1SkillAsrAnnotationSetsListASRAnnotationSetsResponse.paginationContext);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WallpostStat wallpostStat = (WallpostStat) o;
return Objects.equals(joinGroup, wallpostStat.joinGroup) &&
Objects.equals(reachSubscribers, wallpostStat.reachSubscribers) &&
Objects.equals(hide, wallpostStat.hide) &&
Objects.equals(toGroup, wallpostStat.toGroup) &&
Objects.equals(unsubscribe, wallpostStat.unsubscribe) &&
Objects.equals(reachTotal, wallpostStat.reachTotal) &&
Objects.equals(report, wallpostStat.report) &&
Objects.equals(links, wallpostStat.links);
}
/**
* Create a parser for the provided URL's content.
*
* @param url URL's content must be a well-formed bencoded document.
* @since 1.0
*/
public BEParser(URL url) {
Objects.requireNonNull(url, "Missing URL");
try {
this.scanner = new Scanner(url.openStream());
} catch (IOException e) {
throw new BtParseException("Failed to open stream for URL: " + url, new byte[0], e);
}
this.type = getTypeForPrefix((char) scanner.peek());
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BulkSendingCopyTab bulkSendingCopyTab = (BulkSendingCopyTab) o;
return Objects.equals(this.initialValue, bulkSendingCopyTab.initialValue) &&
Objects.equals(this.tabLabel, bulkSendingCopyTab.tabLabel);
}
public ReportDestination getReportDestinationByID(Integer id) {
//System.out.println("Looking for a timingLocation with id " + id);
// This is ugly. Setup a map for faster lookups
if (!reportDestinationListInitialized.get()) refreshReportDestinationList();
Optional<ReportDestination> result = reportDestinationList.stream()
.filter(t -> Objects.equals(t.getID(), id))
.findFirst();
if (result.isPresent()) {
//System.out.println("Found " + result.get().LocationNameProperty());
return result.get();
}
return null;
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
Objects.requireNonNull(name);
// this loader
List<URL> urls = findResourcesAsList(name);
// parent loader
Enumeration<URL> e;
if (parent != null) {
e = parent.getResources(name);
} else {
e = BootLoader.findResources(name);
}
// concat the URLs with the URLs returned by the parent
return new Enumeration<>() {
final Iterator<URL> iterator = urls.iterator();
@Override
public boolean hasMoreElements() {
return (iterator.hasNext() || e.hasMoreElements());
}
@Override
public URL nextElement() {
if (iterator.hasNext()) {
return iterator.next();
} else {
return e.nextElement();
}
}
};
}
public final boolean equals(Object o) {
if (o == this)
return true;
if (o instanceof Map.Entry) {
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
if (Objects.equals(key, e.getKey()) && Objects.equals(value, e.getValue()))
return true;
}
return false;
}
@Override
public void removePropertyValue(String propertyName, Object propertyValue) {
Iterator<? extends Property<Object>> it = getWrappedElement().properties(propertyName);
while (it.hasNext()) {
Property currentProperty = it.next();
Object currentPropertyValue = currentProperty.value();
if (Objects.equals(currentPropertyValue, propertyValue)) {
currentProperty.remove();
break;
}
}
}
protected boolean hasItemChanged(Item item1, Item item2) {
return !Objects.equals(item1.getClass(), item2.getClass()) || //
!Objects.equals(item1.getName(), item2.getName()) || //
!Objects.equals(item1.getCategory(), item2.getCategory()) || //
!Objects.equals(item1.getGroupNames(), item2.getGroupNames()) || //
!Objects.equals(item1.getLabel(), item2.getLabel()) || //
!Objects.equals(item1.getTags(), item2.getTags()) || //
!Objects.equals(item1.getType(), item2.getType()) || //
hasGroupItemChanged(item1, item2);
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AdditionalPropertiesBoolean additionalPropertiesBoolean = (AdditionalPropertiesBoolean) o;
return Objects.equals(this.name, additionalPropertiesBoolean.name) &&
super.equals(o);
}
@Test(timeout = 90_000L)
public void testStreamQueryExecutionTableMultipleTimes() throws Exception {
final URL url = getClass().getClassLoader().getResource("test-data.csv");
Objects.requireNonNull(url);
final Map<String, String> replaceVars = new HashMap<>();
replaceVars.put("$VAR_PLANNER", planner);
replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
replaceVars.put("$VAR_EXECUTION_TYPE", "streaming");
replaceVars.put("$VAR_RESULT_MODE", "table");
replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append");
replaceVars.put("$VAR_MAX_ROWS", "100");
final String query = "SELECT scalarUDF(IntegerField1), StringField1 FROM TableNumber1";
final List<String> expectedResults = new ArrayList<>();
expectedResults.add("47,Hello World");
expectedResults.add("27,Hello World");
expectedResults.add("37,Hello World");
expectedResults.add("37,Hello World");
expectedResults.add("47,Hello World");
expectedResults.add("57,Hello World!!!!");
final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
final SessionContext session = new SessionContext("test-session", new Environment());
String sessionId = executor.openSession(session);
assertEquals("test-session", sessionId);
try {
for (int i = 0; i < 3; i++) {
executeStreamQueryTable(replaceVars, query, expectedResults);
}
} finally {
executor.closeSession(sessionId);
}
}
/**
* Creates an instance defining the yearly rule to create transitions between two offsets.
*
* @param month the month of the month-day of the first day of the cutover week, from 1 to 12
* @param dayOfMonthIndicator the day of the month-day of the cutover week, positive if the week is that
* day or later, negative if the week is that day or earlier, counting from the last day of the month,
* from -28 to 31 excluding 0
* @param dayOfWeek the required day-of-week, -1 if the month-day should not be changed
* @param time the cutover time in the 'before' offset, not null
* @param timeEndOfDay whether the time is midnight at the end of day
* @param timeDefnition how to interpret the cutover
* @param standardOffset the standard offset in force at the cutover, not null
* @param offsetBefore the offset before the cutover, not null
* @param offsetAfter the offset after the cutover, not null
* @throws IllegalArgumentException if the day of month indicator is invalid
* @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
*/
ZoneOffsetTransitionRule(
int month,
int dayOfMonthIndicator,
int dayOfWeek,
LocalTime time,
boolean timeEndOfDay,
TimeDefinition timeDefnition,
ZoneOffset standardOffset,
ZoneOffset offsetBefore,
ZoneOffset offsetAfter) {
Objects.requireNonNull(time, "time");
Objects.requireNonNull(timeDefnition, "timeDefnition");
Objects.requireNonNull(standardOffset, "standardOffset");
Objects.requireNonNull(offsetBefore, "offsetBefore");
Objects.requireNonNull(offsetAfter, "offsetAfter");
if (month < 1 || month > 12) {
throw new IllegalArgumentException("month must be between 1 and 12");
}
if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
}
if (timeEndOfDay && time.equals(LocalTime.MIDNIGHT) == false) {
throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
}
this.month = month;
this.dom = (byte) dayOfMonthIndicator;
this.dow = dayOfWeek;
this.time = time;
this.timeEndOfDay = timeEndOfDay;
this.timeDefinition = timeDefnition;
this.standardOffset = standardOffset;
this.offsetBefore = offsetBefore;
this.offsetAfter = offsetAfter;
}
private <T> void checkRead(SchemaType type, List<T> datas, Function<T, String> toStr, Class<T> tClass) throws Exception {
StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
see.setParallelism(1);
StreamTableEnvironment tEnv = StreamTableEnvironment.create(see);
String table = newTopic();
sendTypedMessages(table, type, datas, Optional.empty(), tClass);
tEnv.connect(getPulsarSourceDescriptor(table))
.inAppendMode()
.registerTableSource(table);
Table t = tEnv.scan(table).select("value");
tEnv.toAppendStream(t, t.getSchema().toRowType())
.map(new FailingIdentityMapper<>(datas.size()))
.addSink(new SingletonStreamSink.StringSink<>()).setParallelism(1);
Thread reader = new Thread("read") {
@Override
public void run() {
try {
see.execute("read from earliest");
} catch (Throwable e) {
// do nothing
}
}
};
reader.start();
reader.join();
if (toStr == null) {
SingletonStreamSink.compareWithList(datas.subList(0, datas.size() - 1).stream().map(Objects::toString).collect(Collectors.toList()));
} else {
SingletonStreamSink.compareWithList(datas.subList(0, datas.size() - 1).stream().map(e -> toStr.apply(e)).collect(Collectors.toList()));
}
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RowFieldName other = (RowFieldName) o;
return Objects.equals(this.name, other.name);
}
@SuppressWarnings("rawtypes")
@Override
public void init(NamedList args) {
this.config = args;
// Configure the size of the buffer used for copying index files to/from HDFS, if specified.
if (args.get(HDFS_COPY_BUFFER_SIZE_PARAM) != null) {
this.copyBufferSize = (Integer)args.get(HDFS_COPY_BUFFER_SIZE_PARAM);
if (this.copyBufferSize <= 0) {
throw new IllegalArgumentException("Value of " + HDFS_COPY_BUFFER_SIZE_PARAM + " must be > 0");
}
}
String hdfsSolrHome = (String) Objects.requireNonNull(args.get(HdfsDirectoryFactory.HDFS_HOME),
"Please specify " + HdfsDirectoryFactory.HDFS_HOME + " property.");
Path path = new Path(hdfsSolrHome);
while (path != null) { // Compute the path of root file-system (without requiring an additional system property).
baseHdfsPath = path;
path = path.getParent();
}
// We don't really need this factory instance. But we want to initialize it here to
// make sure that all HDFS related initialization is at one place (and not duplicated here).
factory = new HdfsDirectoryFactory();
factory.init(args);
this.hdfsConfig = factory.getConf(new Path(hdfsSolrHome));
// Configure the umask mode if specified.
if (args.get(HDFS_UMASK_MODE_PARAM) != null) {
String umaskVal = (String)args.get(HDFS_UMASK_MODE_PARAM);
this.hdfsConfig.set(FsPermission.UMASK_LABEL, umaskVal);
}
try {
this.fileSystem = FileSystem.get(this.baseHdfsPath.toUri(), this.hdfsConfig);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CallbackServer callbackServer = (CallbackServer) o;
return Objects.equals(secretKey, callbackServer.secretKey) &&
Objects.equals(creatorId, callbackServer.creatorId) &&
Objects.equals(id, callbackServer.id) &&
Objects.equals(title, callbackServer.title) &&
Objects.equals(url, callbackServer.url) &&
Objects.equals(status, callbackServer.status);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ViewMetaData view = (ViewMetaData) o;
return Objects.equals(stmt, view.stmt) &&
Objects.equals(owner, view.owner);
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Model200Response _200response = (Model200Response) o;
return Objects.equals(this.name, _200response.name) &&
Objects.equals(this.propertyClass, _200response.propertyClass);
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FailActionHTTPLocalResponse failActionHTTPLocalResponse = (FailActionHTTPLocalResponse) o;
return Objects.equals(this.file, failActionHTTPLocalResponse.file) &&
Objects.equals(this.statusCode, failActionHTTPLocalResponse.statusCode);
}