package net.miginfocom.layout;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;

public final class LinkHandler {
   public static final int X = 0;
   public static final int Y = 1;
   public static final int WIDTH = 2;
   public static final int HEIGHT = 3;
   public static final int X2 = 4;
   public static final int Y2 = 5;
   private static final ArrayList<WeakReference<Object>> LAYOUTS = new ArrayList(4);
   private static final ArrayList<HashMap<String, int[]>> VALUES = new ArrayList(4);
   private static final ArrayList<HashMap<String, int[]>> VALUES_TEMP = new ArrayList(4);

   private LinkHandler() {
   }

   public static synchronized Integer getValue(Object var0, String var1, int var2) {
      Integer var3 = null;
      boolean var4 = true;

      for(int var5 = LAYOUTS.size() - 1; var5 >= 0; --var5) {
         Object var6 = ((WeakReference)LAYOUTS.get(var5)).get();
         if (var3 == null && var6 == var0) {
            int[] var7 = (int[])((HashMap)VALUES_TEMP.get(var5)).get(var1);
            if (var4 && var7 != null && var7[var2] != -2147471302) {
               var3 = var7[var2];
            } else {
               var7 = (int[])((HashMap)VALUES.get(var5)).get(var1);
               var3 = var7 != null && var7[var2] != -2147471302 ? var7[var2] : null;
            }

            var4 = false;
         }

         if (var6 == null) {
            LAYOUTS.remove(var5);
            VALUES.remove(var5);
            VALUES_TEMP.remove(var5);
         }
      }

      return var3;
   }

   public static synchronized boolean setBounds(Object var0, String var1, int var2, int var3, int var4, int var5) {
      return setBounds(var0, var1, var2, var3, var4, var5, false, false);
   }

   static synchronized boolean setBounds(Object var0, String var1, int var2, int var3, int var4, int var5, boolean var6, boolean var7) {
      for(int var8 = LAYOUTS.size() - 1; var8 >= 0; --var8) {
         Object var9 = ((WeakReference)LAYOUTS.get(var8)).get();
         if (var9 == var0) {
            HashMap var10 = (HashMap)(var6 ? VALUES_TEMP : VALUES).get(var8);
            int[] var11 = (int[])var10.get(var1);
            if (var11 != null && var11[0] == var2 && var11[1] == var3 && var11[2] == var4 && var11[3] == var5) {
               return false;
            }

            if (var11 != null && var7) {
               boolean var12 = false;
               int var13;
               if (var2 != -2147471302) {
                  if (var11[0] == -2147471302 || var2 < var11[0]) {
                     var11[0] = var2;
                     var11[2] = var11[4] - var2;
                     var12 = true;
                  }

                  if (var4 != -2147471302) {
                     var13 = var2 + var4;
                     if (var11[4] == -2147471302 || var13 > var11[4]) {
                        var11[4] = var13;
                        var11[2] = var13 - var11[0];
                        var12 = true;
                     }
                  }
               }

               if (var3 != -2147471302) {
                  if (var11[1] == -2147471302 || var3 < var11[1]) {
                     var11[1] = var3;
                     var11[3] = var11[5] - var3;
                     var12 = true;
                  }

                  if (var5 != -2147471302) {
                     var13 = var3 + var5;
                     if (var11[5] == -2147471302 || var13 > var11[5]) {
                        var11[5] = var13;
                        var11[3] = var13 - var11[1];
                        var12 = true;
                     }
                  }
               }

               return var12;
            }

            var10.put(var1, new int[]{var2, var3, var4, var5, var2 + var4, var3 + var5});
            return true;
         }
      }

      LAYOUTS.add(new WeakReference(var0));
      int[] var14 = new int[]{var2, var3, var4, var5, var2 + var4, var3 + var5};
      HashMap var15 = new HashMap(4);
      if (var6) {
         var15.put(var1, var14);
      }

      VALUES_TEMP.add(var15);
      var15 = new HashMap(4);
      if (!var6) {
         var15.put(var1, var14);
      }

      VALUES.add(var15);
      return true;
   }

   public static synchronized void clearWeakReferencesNow() {
      LAYOUTS.clear();
   }

   public static synchronized boolean clearBounds(Object var0, String var1) {
      for(int var2 = LAYOUTS.size() - 1; var2 >= 0; --var2) {
         Object var3 = ((WeakReference)LAYOUTS.get(var2)).get();
         if (var3 == var0) {
            return ((HashMap)VALUES.get(var2)).remove(var1) != null;
         }
      }

      return false;
   }

   static synchronized void clearTemporaryBounds(Object var0) {
      for(int var1 = LAYOUTS.size() - 1; var1 >= 0; --var1) {
         Object var2 = ((WeakReference)LAYOUTS.get(var1)).get();
         if (var2 == var0) {
            ((HashMap)VALUES_TEMP.get(var1)).clear();
            return;
         }
      }

   }
}
