/** {@inheritDoc} */
 public void putAll(Map<? extends Integer, ? extends Integer> map) {
   ensureCapacity(map.size());
   // could optimize this for cases when map instanceof THashMap
   for (Map.Entry<? extends Integer, ? extends Integer> entry : map.entrySet()) {
     this.put(entry.getKey().intValue(), entry.getValue().intValue());
   }
 }
Esempio n. 2
1
 private Map<String, Object> query(HttpServletRequest req) {
   final Map<String, Object> map = new HashMap<>();
   for (Map.Entry<String, String[]> entry : req.getParameterMap().entrySet()) {
     map.put(entry.getKey(), entry.getValue());
   }
   return map;
 }
  /**
   * {@inheritDoc}
   *
   * @param ctx
   */
  @Override
  public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);

    if (ownedVals != null) {
      ownedValKeys = ownedVals.keySet();

      ownedValVals = ownedVals.values();

      for (Map.Entry<IgniteTxKey, CacheVersionedValue> entry : ownedVals.entrySet()) {
        GridCacheContext cacheCtx = ctx.cacheContext(entry.getKey().cacheId());

        entry.getKey().prepareMarshal(cacheCtx);

        entry.getValue().prepareMarshal(cacheCtx.cacheObjectContext());
      }
    }

    if (retVal != null && retVal.cacheId() != 0) {
      GridCacheContext cctx = ctx.cacheContext(retVal.cacheId());

      assert cctx != null : retVal.cacheId();

      retVal.prepareMarshal(cctx);
    }

    if (filterFailedKeys != null) {
      for (IgniteTxKey key : filterFailedKeys) {
        GridCacheContext cctx = ctx.cacheContext(key.cacheId());

        key.prepareMarshal(cctx);
      }
    }
  }
    public boolean equals(Object o) {
      if (!(o instanceof Map.Entry)) return false;
      Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;

      return (key == null ? e.getKey() == null : key.equals(e.getKey()))
          && (value == null ? e.getValue() == null : value.equals(e.getValue()));
    }
Esempio n. 5
0
 private void exportAttributes(Map<String, Object> attrMap) {
   for (Map.Entry<String, Object> e : attrMap.entrySet()) {
     if (e.getKey().equals(WikiPage.CHANGENOTE))
       exportProperty("wiki:changeNote", (String) e.getValue(), STRING);
     else exportProperty(e.getKey(), e.getValue().toString(), STRING);
   }
 }
Esempio n. 6
0
  static void itTest4(Map s, int size, int pos) {
    IdentityHashMap seen = new IdentityHashMap(size);
    reallyAssert(s.size() == size);
    int sum = 0;
    timer.start("Iter XEntry            ", size);
    Iterator it = s.entrySet().iterator();
    Object k = null;
    Object v = null;
    for (int i = 0; i < size - pos; ++i) {
      Map.Entry x = (Map.Entry) (it.next());
      k = x.getKey();
      v = x.getValue();
      seen.put(k, k);
      if (x != MISSING) ++sum;
    }
    reallyAssert(s.containsKey(k));
    it.remove();
    reallyAssert(!s.containsKey(k));
    while (it.hasNext()) {
      Map.Entry x = (Map.Entry) (it.next());
      Object k2 = x.getKey();
      seen.put(k2, k2);
      if (x != MISSING) ++sum;
    }

    reallyAssert(s.size() == size - 1);
    s.put(k, v);
    reallyAssert(seen.size() == size);
    timer.finish();
    reallyAssert(sum == size);
    reallyAssert(s.size() == size);
  }
  private void exportParameters() {
    synchronized (exported_parameters) {
      if (!exported_parameters_dirty) {

        return;
      }

      exported_parameters_dirty = false;

      try {
        TreeMap<String, String> tm = new TreeMap<String, String>();

        Set<String> exported_keys = new HashSet<String>();

        for (String[] entry : exported_parameters.values()) {

          String key = entry[0];
          String value = entry[1];

          exported_keys.add(key);

          if (value != null) {

            tm.put(key, value);
          }
        }

        for (Map.Entry<String, String> entry : imported_parameters.entrySet()) {

          String key = entry.getKey();

          if (!exported_keys.contains(key)) {

            tm.put(key, entry.getValue());
          }
        }

        File parent_dir = new File(SystemProperties.getUserPath());

        File props = new File(parent_dir, "exported_params.properties");

        PrintWriter pw =
            new PrintWriter(new OutputStreamWriter(new FileOutputStream(props), "UTF-8"));

        try {
          for (Map.Entry<String, String> entry : tm.entrySet()) {

            pw.println(entry.getKey() + "=" + entry.getValue());
          }

        } finally {

          pw.close();
        }
      } catch (Throwable e) {

        e.printStackTrace();
      }
    }
  }
  /**
   * The basic method for splitting off a clause of a tree. This modifies the tree in place. This
   * method addtionally follows ref edges.
   *
   * @param tree The tree to split a clause from.
   * @param toKeep The edge representing the clause to keep.
   */
  @SuppressWarnings("unchecked")
  private void simpleClause(SemanticGraph tree, SemanticGraphEdge toKeep) {
    splitToChildOfEdge(tree, toKeep);

    // Follow 'ref' edges
    Map<IndexedWord, IndexedWord> refReplaceMap = new HashMap<>();
    // (find replacements)
    for (IndexedWord vertex : tree.vertexSet()) {
      for (SemanticGraphEdge edge : extraEdgesByDependent.get(vertex)) {
        if ("ref".equals(edge.getRelation().toString())
            && // it's a ref edge...
            !tree.containsVertex(
                edge.getGovernor())) { // ...that doesn't already exist in the tree.
          refReplaceMap.put(vertex, edge.getGovernor());
        }
      }
    }
    // (do replacements)
    for (Map.Entry<IndexedWord, IndexedWord> entry : refReplaceMap.entrySet()) {
      Iterator<SemanticGraphEdge> iter = tree.incomingEdgeIterator(entry.getKey());
      if (!iter.hasNext()) {
        continue;
      }
      SemanticGraphEdge incomingEdge = iter.next();
      IndexedWord governor = incomingEdge.getGovernor();
      tree.removeVertex(entry.getKey());
      addSubtree(
          tree,
          governor,
          incomingEdge.getRelation().toString(),
          this.tree,
          entry.getValue(),
          this.tree.incomingEdgeList(tree.getFirstRoot()));
    }
  }
Esempio n. 9
0
 public static LauncherProfiles load() throws IOException {
   System.out.println("Loading Minecraft profiles from " + DevLauncher.workingDirectory);
   try (FileReader reader = new FileReader(getFile())) {
     LauncherProfiles profiles = new LauncherProfiles();
     JsonObject e = new JsonParser().parse(reader).getAsJsonObject();
     for (Map.Entry<String, JsonElement> entry : e.entrySet()) {
       if (entry.getKey().equals("clientToken")) {
         profiles.clientToken = entry.getValue().getAsString();
       } else if (entry.getKey().equals("authenticationDatabase")) {
         JsonObject o = entry.getValue().getAsJsonObject();
         for (Map.Entry<String, JsonElement> entry1 : o.entrySet()) {
           profiles.authenticationDatabase.profiles.put(
               UUIDTypeAdapter.fromString(entry1.getKey()),
               GSON.fromJson(entry1.getValue(), OnlineProfile.class));
         }
       } else {
         profiles.everythingElse.add(entry.getKey(), entry.getValue());
       }
     }
     INSTANCE = profiles;
     return INSTANCE;
   } finally {
     if (INSTANCE == null) {
       INSTANCE = new LauncherProfiles();
     }
     INSTANCE.markLoaded();
   }
 }
Esempio n. 10
0
 private List<String> getCurrentServerIds(boolean nag, boolean lagged) {
   try (Jedis jedis = pool.getResource()) {
     long time = getRedisTime(jedis.time());
     int nagTime = 0;
     if (nag) {
       nagTime = nagAboutServers.decrementAndGet();
       if (nagTime <= 0) {
         nagAboutServers.set(10);
       }
     }
     ImmutableList.Builder<String> servers = ImmutableList.builder();
     Map<String, String> heartbeats = jedis.hgetAll("heartbeats");
     for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
       try {
         long stamp = Long.parseLong(entry.getValue());
         if (lagged ? time >= stamp + 30 : time <= stamp + 30) servers.add(entry.getKey());
         else if (nag && nagTime <= 0) {
           getLogger()
               .severe(
                   entry.getKey()
                       + " is "
                       + (time - stamp)
                       + " seconds behind! (Time not synchronized or server down?)");
         }
       } catch (NumberFormatException ignored) {
       }
     }
     return servers.build();
   } catch (JedisConnectionException e) {
     getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
     return Collections.singletonList(configuration.getServerId());
   }
 }
Esempio n. 11
0
  public ReaderHandler(LowLevelDbAccess lowLevelDbAccess, String webDir) {

    loginInfoDb = new LoginInfo.DB(lowLevelDbAccess);
    userDb = new User.DB(lowLevelDbAccess);
    feedDb = new Feed.DB(lowLevelDbAccess);
    articleDb = new Article.DB(lowLevelDbAccess);
    readArticlesCollDb = new ReadArticlesColl.DB(lowLevelDbAccess);
    userHelpers = new UserHelpers(loginInfoDb, userDb);

    setContextPath("/");

    File warPath = new File(webDir);
    setWar(warPath.getAbsolutePath());

    if (isInJar) {
      for (Map.Entry<String, String> entry : PATH_MAPPING.entrySet()) {
        addPrebuiltJsp(entry.getKey(), "jsp." + entry.getValue().replaceAll("_", "_005f") + "_jsp");
      }
    } else {
      for (Map.Entry<String, String> entry : PATH_MAPPING.entrySet()) {
        addServlet(
            new ServletHolder(new RedirectServlet("/" + entry.getValue() + ".jsp")),
            entry.getKey());
      }
    }

    setErrorHandler(new ReaderErrorHandler());
  }
Esempio n. 12
0
 protected void initFeatureVersions() throws PluginException.InvalidDefinition {
   if (definitionMap.containsKey(KEY_PLUGIN_FEATURE_VERSION_MAP)) {
     Map<Plugin.Feature, String> map = new HashMap<Plugin.Feature, String>();
     Map<String, String> spec =
         (Map<String, String>) definitionMap.getMap(KEY_PLUGIN_FEATURE_VERSION_MAP);
     log.debug2("features: " + spec);
     for (Map.Entry<String, String> ent : spec.entrySet()) {
       try {
         // Prefix version string with feature name to create separate
         // namespace for each feature
         String key = ent.getKey();
         map.put(Plugin.Feature.valueOf(key), key + "_" + ent.getValue());
       } catch (RuntimeException e) {
         log.warning(
             getPluginName()
                 + " set unknown feature: "
                 + ent.getKey()
                 + " to version "
                 + ent.getValue(),
             e);
         throw new PluginException.InvalidDefinition("Unknown feature: " + ent.getKey(), e);
       }
     }
     featureVersion = map;
   } else {
     featureVersion = null;
   }
 }
  public static void main(String[] args) {
    String testDataLocation = "testData/HighResolutionTerrain/";
    HashMap<String, Sector> sectors = new HashMap<String, Sector>();
    sectors.put(
        testDataLocation + "HRTOutputTest01.txt", Sector.fromDegrees(37.8, 38.3, -120, -119.3));
    sectors.put(
        testDataLocation + "HRTOutputTest02.txt",
        Sector.fromDegrees(32.34767, 32.77991, 70.88239, 71.47658));
    sectors.put(
        testDataLocation + "HRTOutputTest03.txt",
        Sector.fromDegrees(32.37825, 71.21130, 32.50050, 71.37926));

    try {
      if (args.length > 0 && args[0].equals("-generateTestData")) {
        for (Map.Entry<String, Sector> sector : sectors.entrySet()) {
          String filePath = sector.getKey();

          generateReferenceValues(filePath, sector.getValue());
        }
      }

      for (Map.Entry<String, Sector> sector : sectors.entrySet()) {
        String filePath = sector.getKey();

        ArrayList<Position> referencePositions = readReferencePositions(filePath);
        ArrayList<Position> computedPositions = computeElevations(referencePositions);
        testPositions(filePath, referencePositions, computedPositions);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Esempio n. 14
0
  private boolean validateTables(TSelectSqlStatement stmt) {
    HashMap<String, Integer> present = new HashMap<String, Integer>();
    if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {

      int cols = stmt.getResultColumnList().size();
      for (int a = 0; a < cols; a++) {
        present.put(
            stmt.getResultColumnList()
                .getResultColumn(a)
                .toString()
                .toLowerCase()
                .replace("(", "")
                .replace(")", ""),
            0);
      }
    }

    TJoinList joins = stmt.joins;
    int j = joins.size();
    int invalid = 1;
    for (int i = 0; i < j; i++) {
      Iterator<Table> it = DBSystem.tableList.iterator();
      Table table = null;
      while (it.hasNext()) {
        table = it.next();
        if (table.getName().equalsIgnoreCase(joins.getJoin(i).toString())) {
          invalid = 0;
          if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {
            Iterator it1 = table.getColumnData().entrySet().iterator();

            while (it1.hasNext()) {
              Map.Entry pairs = (Map.Entry) it1.next();
              if (present.get(pairs.getKey().toString().toLowerCase()) != null
                  && present.get(pairs.getKey().toString().toLowerCase()) == 0) {
                present.put(pairs.getKey().toString(), 1);
              } else if (present.get(pairs.getKey().toString().toLowerCase()) != null
                  && present.get(pairs.getKey().toString().toLowerCase()) == 1) return false;
            }
          }
        }
      }
      if (invalid == 1) return false;
      else {
        invalid = 1;
      }
    }
    if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {
      Iterator it2 = present.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry pairs = (Map.Entry) it2.next();
        if ((Integer) pairs.getValue() == 0) {
          return false;
        }
      }
    }
    return true;
  }
Esempio n. 15
0
  public RestDocumentation filter(Iterable<Pattern> excludePatterns) {
    RestDocumentation filtered = new RestDocumentation();
    OUTER:
    for (Map.Entry<String, Resource> entry : _resources.entrySet()) {
      for (Pattern excludePattern : excludePatterns)
        if (excludePattern.matcher(entry.getKey()).matches()) continue OUTER;

      filtered._resources.put(entry.getKey(), entry.getValue());
    }
    return filtered;
  }
 /** 按照要求打印结果 */
 public void printStackInfo(Multimap<String, ThreadInfo> w_IdMap) {
   List<Map.Entry<String, Integer>> orderList = getOrderList(w_IdMap);
   for (Map.Entry<String, Integer> entry : orderList) {
     logger.info(entry.getKey() + "," + entry.getValue()); // 输出wait_id 对应个数
     Collection<ThreadInfo> threads = w_IdMap.get(entry.getKey()); // 输出wait_id对应的ThreadInfo集合
     for (ThreadInfo thread : threads) {
       logger.info("{}", thread);
     }
     logger.info("");
   }
 }
Esempio n. 17
0
  private Geobuf.Data.Feature makeFeature(GeobufFeature feature, List<String> keys) {
    Geobuf.Data.Feature.Builder feat =
        Geobuf.Data.Feature.newBuilder().setGeometry(geomToGeobuf(feature.geometry));

    for (Map.Entry<String, Object> e : feature.properties.entrySet()) {
      // TODO store keys separately from features
      Geobuf.Data.Value.Builder val = Geobuf.Data.Value.newBuilder();

      Object featVal = e.getValue();

      if (featVal instanceof String) val.setStringValue((String) featVal);
      else if (featVal instanceof Boolean) val.setBoolValue((Boolean) featVal);
      else if (featVal instanceof Integer) {
        int keyInt = (Integer) featVal;
        if (keyInt >= 0) val.setPosIntValue(keyInt);
        else val.setNegIntValue(keyInt);
      } else if (featVal instanceof Long) {
        long keyLong = (Long) featVal;
        if (keyLong >= 0) val.setPosIntValue(keyLong);
        else val.setNegIntValue(keyLong);
      } else if (featVal instanceof Double || featVal instanceof Float)
        val.setDoubleValue(((Number) featVal).doubleValue());
      else {
        // TODO serialize to JSON
        LOG.warn(
            "Unable to save object of type {} to geobuf, falling back on toString. Deserialization will not work as expected.",
            featVal.getClass());
        val.setStringValue(featVal.toString());
      }

      int keyIdx = keys.indexOf(e.getKey());
      if (keyIdx == -1) {
        synchronized (keys) {
          keyIdx = keys.size();
          keys.add(e.getKey());
        }
      }

      // properties is a jagged array of [key index, value index, . . .]
      feat.addProperties(keyIdx);
      feat.addProperties(feat.getValuesCount());
      feat.addValues(val);
    }

    if (feature.id != null) {
      feat.setId(feature.id);
      feat.clearIntId();
    } else {
      feat.setIntId(feature.numericId);
      feat.clearId();
    }

    return feat.build();
  }
  /** {@inheritDoc} */
  @Override
  public void onDiscoveryDataReceived(UUID nodeId, UUID rmtNodeId, Serializable data) {
    Map<String, Serializable> discData = (Map<String, Serializable>) data;

    if (discData != null) {
      for (Map.Entry<String, Serializable> e : discData.entrySet()) {
        PluginProvider provider = plugins.get(e.getKey());

        if (provider != null) provider.receiveDiscoveryData(nodeId, e.getValue());
        else U.warn(log, "Received discovery data for unknown plugin: " + e.getKey());
      }
    }
  }
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    Scanner input = new Scanner(System.in);
    int numberOfTestCases = input.nextInt();
    ArrayList<Integer> order = new ArrayList<Integer>(numberOfTestCases);
    int previousKey = -1;
    int previousValue = 0;
    int cycleNumber = 0;

    Map<Integer, Integer> testCases = new TreeMap<Integer, Integer>();

    for (int i = 0; i < numberOfTestCases; i++) {
      int numberOfCycles = input.nextInt();
      testCases.put(numberOfCycles, 1);
      order.add(numberOfCycles);
    }

    for (Map.Entry<Integer, Integer> entry : testCases.entrySet()) {
      int numberOfCycles;
      int initialHeight;

      if (previousKey == -1) {
        numberOfCycles = entry.getKey();
        initialHeight = entry.getValue();
      } else {
        numberOfCycles = entry.getKey() - previousKey;
        initialHeight = previousValue;
      }

      for (int i = 0; i < numberOfCycles; i++) {
        if (cycleNumber % 2 == 0) {
          initialHeight *= 2;
        } else {
          initialHeight += 1;
        }
        cycleNumber++;
      }

      entry.setValue(initialHeight);
      previousKey = entry.getKey();
      previousValue = initialHeight;
    }

    for (Integer element : order) {
      System.out.println(testCases.get(element));
    }

    long elapsed = System.currentTimeMillis() - start;
    System.out.println("time: " + elapsed);
  }
  /** ceilingEntry returns next entry. */
  public void testDescendingCeilingEntry() {
    ConcurrentNavigableMap map = dmap5();
    Map.Entry e1 = map.ceilingEntry(m3);
    assertEquals(m3, e1.getKey());

    Map.Entry e2 = map.ceilingEntry(zero);
    assertEquals(m1, e2.getKey());

    Map.Entry e3 = map.ceilingEntry(m5);
    assertEquals(m5, e3.getKey());

    Map.Entry e4 = map.ceilingEntry(m6);
    assertNull(e4);
  }
  /** lowerEntry returns preceding entry. */
  public void testDescendingLowerEntry() {
    ConcurrentNavigableMap map = dmap5();
    Map.Entry e1 = map.lowerEntry(m3);
    assertEquals(m2, e1.getKey());

    Map.Entry e2 = map.lowerEntry(m6);
    assertEquals(m5, e2.getKey());

    Map.Entry e3 = map.lowerEntry(m1);
    assertNull(e3);

    Map.Entry e4 = map.lowerEntry(zero);
    assertNull(e4);
  }
  /** ceilingEntry returns next entry. */
  public void testCeilingEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e1 = map.ceilingEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.ceilingEntry(zero);
    assertEquals(one, e2.getKey());

    Map.Entry e3 = map.ceilingEntry(five);
    assertEquals(five, e3.getKey());

    Map.Entry e4 = map.ceilingEntry(six);
    assertNull(e4);
  }
  /** higherEntry returns next entry. */
  public void testHigherEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e1 = map.higherEntry(three);
    assertEquals(four, e1.getKey());

    Map.Entry e2 = map.higherEntry(zero);
    assertEquals(one, e2.getKey());

    Map.Entry e3 = map.higherEntry(five);
    assertNull(e3);

    Map.Entry e4 = map.higherEntry(six);
    assertNull(e4);
  }
  /** lowerEntry returns preceding entry. */
  public void testLowerEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e1 = map.lowerEntry(three);
    assertEquals(two, e1.getKey());

    Map.Entry e2 = map.lowerEntry(six);
    assertEquals(five, e2.getKey());

    Map.Entry e3 = map.lowerEntry(one);
    assertNull(e3);

    Map.Entry e4 = map.lowerEntry(zero);
    assertNull(e4);
  }
 /** entrySet contains all pairs */
 public void testDescendingEntrySet() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.entrySet();
   assertEquals(5, s.size());
   Iterator it = s.iterator();
   while (it.hasNext()) {
     Map.Entry e = (Map.Entry) it.next();
     assertTrue(
         (e.getKey().equals(m1) && e.getValue().equals("A"))
             || (e.getKey().equals(m2) && e.getValue().equals("B"))
             || (e.getKey().equals(m3) && e.getValue().equals("C"))
             || (e.getKey().equals(m4) && e.getValue().equals("D"))
             || (e.getKey().equals(m5) && e.getValue().equals("E")));
   }
 }
 /** entrySet contains all pairs */
 public void testEntrySet() {
   ConcurrentNavigableMap map = map5();
   Set s = map.entrySet();
   assertEquals(5, s.size());
   Iterator it = s.iterator();
   while (it.hasNext()) {
     Map.Entry e = (Map.Entry) it.next();
     assertTrue(
         (e.getKey().equals(one) && e.getValue().equals("A"))
             || (e.getKey().equals(two) && e.getValue().equals("B"))
             || (e.getKey().equals(three) && e.getValue().equals("C"))
             || (e.getKey().equals(four) && e.getValue().equals("D"))
             || (e.getKey().equals(five) && e.getValue().equals("E")));
   }
 }
 public String printCategoryDistribution(SortedMap<Integer, Double> categoryDistribution) {
   StringBuilder scoreValues = new StringBuilder();
   LOG.debug("output category distribution:");
   scoreValues.append("scores<-c(");
   for (Map.Entry<Integer, Double> score : categoryDistribution.entrySet()) {
     String name = treeCache.getNameById(score.getKey(), String.valueOf(score.getKey()));
     LOG.debug(name + "\t\t" + score.getValue() + "\t" + treeCache.getDepth(score.getKey()));
     if (scoreValues.length() > 10) {
       scoreValues.append(", ");
     }
     scoreValues.append(score.getValue());
   }
   scoreValues.append(")");
   return scoreValues.toString();
 }
Esempio n. 28
0
 public static void main(String[] args) {
   try {
     if (args.length == 1) {
       URL url = new URL(args[0]);
       System.out.println("Content-Type: " + url.openConnection().getContentType());
       // 				Vector links = extractLinks(url);
       // 				for (int n = 0; n < links.size(); n++) {
       // 					System.out.println((String) links.elementAt(n));
       // 				}
       Set links = extractLinksWithText(url).entrySet();
       Iterator it = links.iterator();
       while (it.hasNext()) {
         Map.Entry en = (Map.Entry) it.next();
         String strLink = (String) en.getKey();
         String strText = (String) en.getValue();
         System.out.println(strLink + " \"" + strText + "\" ");
       }
       return;
     } else if (args.length == 2) {
       writeURLtoFile(new URL(args[0]), args[1]);
       return;
     }
   } catch (Exception e) {
     System.err.println("An error occured: ");
     e.printStackTrace();
     // 			System.err.println(e.toString());
   }
   System.err.println("Usage: java SaveURL <url> [<file>]");
   System.err.println("Saves a URL to a file.");
   System.err.println("If no file is given, extracts hyperlinks on url to console.");
 }
  /**
   * Compares the specified Object with this Map for equality, as per the definition in the Map
   * interface.
   *
   * @param o object to be compared for equality with this hashtable
   * @return true if the specified Object is equal to this Map
   * @see Map#equals(Object)
   * @since 1.2
   */
  public synchronized boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<?, ?> t = (Map<?, ?>) o;
    if (t.size() != size()) return false;

    try {
      for (Map.Entry<K, V> e : entrySet()) {
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!value.equals(t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
Esempio n. 30
0
  /**
   * Compares the specified Object with this Map for equality, as per the definition in the Map
   * interface.
   *
   * @param o object to be compared for equality with this hashtable
   * @return true if the specified Object is equal to this Map
   * @see Map#equals(Object)
   * @since 1.2
   */
  public synchronized boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<K, V> t = (Map<K, V>) o;
    if (t.size() != size()) return false;

    try {
      Iterator<Map.Entry<K, V>> i = entrySet().iterator();
      while (i.hasNext()) {
        Map.Entry<K, V> e = i.next();
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!value.equals(t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }