java.util.Objects Java Examples

The following examples show how to use java.util.Objects. 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: Deposit.java    From teku with Apache License 2.0 7 votes vote down vote up
@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());
}
 
Example #2
Source File: DeferredSubscription.java    From reactive-streams-commons with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example #3
Source File: IntPipeline.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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));
                }
            };
        }
    };
}
 
Example #4
Source File: DiagnosticDataSummary.java    From director-sdk with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: AnnotationSupport.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: RpcLocker.java    From sumk with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: RBlastSmilesGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #8
Source File: ManagedConcurrentWeakHashMap.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public V putIfAbsent(K key, V value) {
    Objects.requireNonNull(value);
    Key storeKey = createStoreKey(key);
    V oldValue = map.putIfAbsent(storeKey, value);
    if (oldValue != null) { // ack that key has not been stored
        storeKey.ackDeath();
    }
    return oldValue;
}
 
Example #9
Source File: MobileNotifierConfiguration.java    From docusign-java-client with MIT License 5 votes vote down vote up
@Override
public boolean equals(java.lang.Object o) {
  if (this == o) {
    return true;
  }
  if (o == null || getClass() != o.getClass()) {
    return false;
  }
  MobileNotifierConfiguration mobileNotifierConfiguration = (MobileNotifierConfiguration) o;
  return Objects.equals(this.deviceId, mobileNotifierConfiguration.deviceId) &&
      Objects.equals(this.errorDetails, mobileNotifierConfiguration.errorDetails) &&
      Objects.equals(this.platform, mobileNotifierConfiguration.platform);
}
 
Example #10
Source File: TriggerStateMachine.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (!(obj instanceof TriggerStateMachine)) {
    return false;
  }
  TriggerStateMachine that = (TriggerStateMachine) obj;
  return Objects.equals(getClass(), that.getClass())
      && Objects.equals(subTriggers, that.subTriggers);
}
 
Example #11
Source File: StreamPropertyDerivations.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (this == obj) {
        return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
        return false;
    }
    StreamProperties other = (StreamProperties) obj;
    return this.distribution == other.distribution &&
            Objects.equals(this.partitioningColumns, other.partitioningColumns);
}
 
Example #12
Source File: MedicinalProductPackaged.java    From FHIR with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
    int result = hashCode;
    if (result == 0) {
        result = Objects.hash(id, 
            extension, 
            modifierExtension, 
            outerPackaging, 
            immediatePackaging);
        hashCode = result;
    }
    return result;
}
 
Example #13
Source File: IsNotNullPredicate.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    IsNotNullPredicate that = (IsNotNullPredicate) o;
    return Objects.equals(value, that.value);
}
 
Example #14
Source File: CohortMembership.java    From egeria with Apache License 2.0 5 votes vote down vote up
/**
 * Hash code base on variable values.
 *
 * @return int
 */
@Override
public int hashCode()
{

    return Objects.hash(getLocalRegistration(), getRemoteRegistrations());
}
 
Example #15
Source File: AreaIDTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }

    if (obj instanceof AreaIDTlv) {
        AreaIDTlv other = (AreaIDTlv) obj;
        return Objects.equals(areaID, other.areaID);
    }
    return false;
}
 
Example #16
Source File: LogsQuery.java    From besu with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public LogsQuery(
    @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) @JsonProperty("address")
        final List<Address> addresses,
    @JsonDeserialize(using = TopicsDeserializer.class) @JsonProperty("topics")
        final List<List<LogTopic>> topics) {
  // Ordinarily this defensive copy wouldn't be surprising, style wise it should be an immutable
  // collection. However, the semantics of the Ethereum JSON-RPC APIs ascribe meaning to a null
  // value in lists for logs queries. We need to proactively put the values into a collection
  // that won't throw a null pointer exception when checking to see if the list contains null.
  // List.of(...) is one of the lists that reacts poorly to null member checks and is something
  // that we should expect to see passed in. So we must copy into a null-tolerant list.
  this.addresses = addresses != null ? new ArrayList<>(addresses) : emptyList();
  this.topics =
      topics != null
          ? topics.stream().map(ArrayList::new).collect(Collectors.toList())
          : emptyList();
  this.addressBlooms =
      this.addresses.stream()
          .map(address -> LogsBloomFilter.builder().insertBytes(address).build())
          .collect(toUnmodifiableList());
  this.topicsBlooms =
      this.topics.stream()
          .map(
              subTopics ->
                  subTopics.stream()
                      .filter(Objects::nonNull)
                      .map(logTopic -> LogsBloomFilter.builder().insertBytes(logTopic).build())
                      .collect(Collectors.toList()))
          .collect(toUnmodifiableList());
}
 
Example #17
Source File: LossFactor.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
LossFactor(Context context, HvdcLine.ConvertersMode mode, double pAC1, double pAC2, double poleLossP1,
    double poleLossP2) {
    Objects.requireNonNull(context);
    Objects.requireNonNull(mode);
    this.context = context;
    this.mode = mode;
    this.pAC1 = pAC1;
    this.pAC2 = pAC2;
    this.poleLossP1 = poleLossP1;
    this.poleLossP2 = poleLossP2;
    this.lossFactor1 = Double.NaN;
    this.lossFactor2 = Double.NaN;
}
 
Example #18
Source File: CacheService.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates bid cache request for the given bids.
 */
private static <T> BidCacheRequest toRequest(List<T> bids, Function<T, PutObject> requestItemCreator) {
    return BidCacheRequest.of(bids.stream()
            .filter(Objects::nonNull)
            .map(requestItemCreator)
            .filter(Objects::nonNull)
            .collect(Collectors.toList()));
}
 
Example #19
Source File: ZoneOffsetTransitionRule.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source File: AttestationTest.java    From teku with Apache License 2.0 5 votes vote down vote up
@Test
void equalsReturnsFalseWhenAttestationDataIsDifferent() {
  // AttestationData is rather involved to create. Just create a random one until it is not the
  // same as the original.
  AttestationData otherData = dataStructureUtil.randomAttestationData();
  while (Objects.equals(otherData, data)) {
    otherData = dataStructureUtil.randomAttestationData();
  }

  Attestation testAttestation =
      new Attestation(aggregationBitfield, otherData, aggregateSignature);

  assertNotEquals(attestation, testAttestation);
}
 
Example #21
Source File: XceiverServerRatis.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private XceiverServerRatis(DatanodeDetails dd, int port,
    ContainerDispatcher dispatcher, ContainerController containerController,
    StateContext context, GrpcTlsConfig tlsConfig, ConfigurationSource conf)
    throws IOException {
  this.conf = conf;
  Objects.requireNonNull(dd, "id == null");
  datanodeDetails = dd;
  this.port = port;
  RaftProperties serverProperties = newRaftProperties();
  this.context = context;
  this.dispatcher = dispatcher;
  this.containerController = containerController;
  this.raftPeerId = RatisHelper.toRaftPeerId(dd);
  chunkExecutors = createChunkExecutors(conf);

  RaftServer.Builder builder =
      RaftServer.newBuilder().setServerId(raftPeerId)
          .setProperties(serverProperties)
          .setStateMachineRegistry(this::getStateMachine);
  if (tlsConfig != null) {
    builder.setParameters(GrpcFactory.newRaftParameters(tlsConfig));
  }
  this.server = builder.build();
  this.requestTimeout = conf.getTimeDuration(
      HddsConfigKeys.HDDS_DATANODE_RATIS_SERVER_REQUEST_TIMEOUT,
      HddsConfigKeys.HDDS_DATANODE_RATIS_SERVER_REQUEST_TIMEOUT_DEFAULT,
      TimeUnit.MILLISECONDS);
}
 
Example #22
Source File: ASMMethodBuilder.java    From ForgeHax with MIT License 5 votes vote down vote up
public ASMMethod build() {
  // parent class not required
  Objects.requireNonNull(name, "Missing method name");
  Objects.requireNonNull(
    parameterTypes, "Missing method parameters (use emptyParameters() if none are present)");
  Objects.requireNonNull(returnType, "Missing method return type");
  if (auto) {
    attemptAutoAssign();
  }
  return new ASMMethod(
    parentClass, NameBuilder.create(name, srgName, obfuscatedName), parameterTypes, returnType);
}
 
Example #23
Source File: FailActionHTTPLocalResponse.java    From sdk with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: Model200Response.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: ViewMetaData.java    From crate with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: ResearchSubjectStatus.java    From FHIR with Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
    int result = hashCode;
    if (result == 0) {
        result = Objects.hash(id, extension, value);
        hashCode = result;
    }
    return result;
}
 
Example #27
Source File: HdfsBackupRepository.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #28
Source File: RowFieldName.java    From presto with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #29
Source File: SchemaITest.java    From pulsar-flink with Apache License 2.0 5 votes vote down vote up
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()));
    }
}
 
Example #30
Source File: CallbackServer.java    From vk-java-sdk with MIT License 5 votes vote down vote up
@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);
}