/*
 * Copyright 2013-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.facebook.buck.model;

import java.lang.ref.WeakReference;
import java.util.Objects;

/**
 * Simple type representing a pair of differently typed values.
 *
 * Used to represent pair-like structures in coerced values.
 */
public class Pair<FIRST, SECOND> {

  private FIRST first;
  private SECOND second;
  private WeakReference<Integer> hashCache = null;
  private WeakReference<String> stringCache = null;

  public Pair(FIRST first, SECOND second) {
    this.first = first;
    this.second = second;
  }

  public FIRST getFirst() {
    return first;
  }

  public SECOND getSecond() {
    return second;
  }

  @Override
  public boolean equals(Object other) {
    if (!(other instanceof Pair)) {
      return false;
    }

    Pair<?, ?> that = (Pair<?, ?>) other;
    return Objects.equals(this.first, that.first) &&
        Objects.equals(this.second, that.second);
  }

  @Override
  public int hashCode() {
    synchronized (this) {
      if (hashCache == null) {
        return calculateHashAndCache();
      }
      Integer hash = hashCache.get();
      if (hash == null) {
        return calculateHashAndCache();
      }
      return hash;
    }
  }

  private int calculateHashAndCache() {
    int hash = Objects.hash(first, second);
    hashCache = new WeakReference<>(hash);
    return hash;
  }

  @Override
  public String toString() {
    synchronized (this) {
      if (stringCache == null) {
        return createStringAndCache();
      }
      String string = stringCache.get();
      if (string == null) {
        return createStringAndCache();
      }
      return string;
    }
  }

  private String createStringAndCache() {
    String string = String.format("Pair(%s, %s)", first, second);
    stringCache = new WeakReference<>(string);
    return string;
  }

}

@@ -697,16 +697,51 @@
 jects;%0A%0A
+import javax.annotation.Nullable;%0A%0A
 /**%0A * S
@@ -951,16 +951,29 @@
  second;
+%0A%0A  @Nullable
 %0A  priva
@@ -1016,16 +1016,28 @@
 = null;%0A
+  @Nullable%0A
   privat

fix non-nullable fields