Пример #1
0
  public void testFromArgs() {
    Map m1 =
        MapUtil.map(
            "a", "1", "b", "2", "c", "3", "d", "4", "e", "5", "f", "6", "g", "7", "h", "8", "j",
            "9", "k", "10");
    Map exp = new HashMap();
    exp.put("a", "1");
    exp.put("b", "2");
    exp.put("c", "3");
    exp.put("d", "4");
    exp.put("e", "5");
    exp.put("f", "6");
    exp.put("g", "7");
    exp.put("h", "8");
    exp.put("j", "9");
    exp.put("k", "10");
    assertEquals(exp, m1);

    try {
      MapUtil.map(
          "a", "1", "b", "2", "c", "3", "d", "4", "e", "5", "f", "6", "g", "7", "h", "8", "j", "9",
          "k");
      fail("Odd length arg list should throw");
    } catch (IllegalArgumentException e) {
    }
  }
  @Test
  public void testSetOrIncrementMap() {
    Map<String, Number> map = new HashMap<>();
    MapUtil.setOrIncrementMap(map, "key", 1);
    assertEquals(new Long(1L), map.get("key"));

    MapUtil.setOrIncrementMap(map, "key", 1);
    assertEquals(new Long(2L), map.get("key"));

    MapUtil.setOrIncrementMap(map, "key2", 1);
    assertEquals(new Long(1L), map.get("key2"));
  }
Пример #3
0
 public static void main(String[] args) {
   //        String path = "data//DBIS//paper_conf.txt";
   String path = "data//DBIS//DBLP//title_conf.txt";
   DBLPParserSchema parser = new DBLPParserSchema();
   final List<Edge> paper_conf_edges = parser.readEdgeFile(path);
   Map<Integer, Integer> conf_pop = new HashMap<Integer, Integer>();
   for (Edge e : paper_conf_edges) {
     Integer val = conf_pop.get(e.node2);
     if (val == null) {
       conf_pop.put(e.node2, 1);
     } else {
       conf_pop.put(e.node2, val + 1);
     }
   }
   final Map<Integer, Integer> sorted_map = MapUtil.sortByValue(conf_pop);
   System.out.println(sorted_map);
   //        String node_path = "data//DBIS//conf.txt";
   String node_path = "data//DBIS//DBLP//conf.txt";
   final Map<Integer, String> conf_nodes = parser.readNodeFile(node_path);
   for (Integer conf : sorted_map.keySet()) {
     String name = conf_nodes.get(conf);
     if (name == null) {
       System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>");
     } else {
       System.out.println(conf + "\t" + name);
     }
   }
 }
Пример #4
0
  public static void handleDevLocationClick(LocationDTO location) {
    if (location1ID == -1) {
      location1ID = location.getId();
    } else {
      String roadPointsString = MapUtil.roadPointsToString(roadPoints);
      GameServices.devService.createRoad(
          GameInfo.getInstance().getPlayer(),
          "Road" + roadNum++,
          location1ID,
          location.getId(),
          roadPointsString,
          new AsyncCallback<Void>() {
            public void onFailure(Throwable caught) {
              // Window.alert("Failure because: " + caught.getMessage());
              InfoWindow alert =
                  new InfoWindow(200, 100, "Failure because: " + caught.getMessage());
              alert.center();
            }

            public void onSuccess(Void result) {
              //					Window.alert("Success");
              // TODO: Keep the auto-refresh when creating roads?
              // GameInformation.getInstance().refreshAll(true);
            }
          });
      location1ID = -1;
      roadPoints.clear();
      // Window.alert("Location 2 added - Road sent for creation");
    }
  }
Пример #5
0
 protected void initAuFeatureMap() {
   if (definitionMap.containsKey(DefinableArchivalUnit.KEY_AU_FEATURE_URL_MAP)) {
     Map<String, ?> featMap = definitionMap.getMap(DefinableArchivalUnit.KEY_AU_FEATURE_URL_MAP);
     for (Map.Entry ent : featMap.entrySet()) {
       Object val = ent.getValue();
       if (val instanceof Map) {
         ent.setValue(MapUtil.expandAlternativeKeyLists((Map) val));
       }
     }
   }
 }
Пример #6
0
  /**
   * 将key和value键值对形式的json转换成map,忽略为空的key,在解析异常时put空字符串
   *
   * @param sourceObj key和value键值对形式的json
   * @return JSONObject
   */
  @SuppressWarnings("rawtypes")
  public static Map<String, String> parseKeyAndValueToMap(JSONObject sourceObj) {
    if (sourceObj == null) {
      return null;
    }

    Map<String, String> keyAndValueMap = new HashMap<String, String>();
    for (Iterator iter = sourceObj.keys(); iter.hasNext(); ) {
      String key = (String) iter.next();
      MapUtil.putMapNotEmptyKey(keyAndValueMap, key, getString(sourceObj, key, ""));
    }
    return keyAndValueMap;
  }
  public void testFindLeastFullRepository() throws Exception {
    Map repoMap =
        MapUtil.map(
            "local:one",
            new MyDF("/one", 1000),
            "local:two",
            new MyDF("/two", 3000),
            "local:three",
            new MyDF("/three", 2000));
    mgr.setRepoMap(repoMap);

    assertEquals("local:two", mgr.findLeastFullRepository());
  }
Пример #8
0
  /** Map the foreground tile locations. */
  private void initForegroundTiles() {

    foregroundTiles = new byte[map.getWidth()][map.getHeight()];

    for (int y = 0; y < foregroundTiles[0].length; y++) {
      for (int x = 0; x < foregroundTiles.length; x++) {
        if (mapUtil.isForegroundAtTile(x, y)) {
          foregroundTiles[x][y] = 1;
        } else {
          foregroundTiles[x][y] = 0;
        }
      }
    }
  }
Пример #9
0
  public void testFromList1() {
    assertEquals(MapUtil.map(), MapUtil.fromList(ListUtil.list()));
    assertEquals(
        MapUtil.map("FOO", "bar", "One", "Two"),
        MapUtil.fromList(ListUtil.list("FOO", "bar", "One", "Two")));
    assertEquals(
        MapUtil.map("foo", "bar", "one", "two"),
        MapUtil.fromList(ListUtil.list(ListUtil.list("foo", "bar"), ListUtil.list("one", "two"))));

    try {
      MapUtil.fromList(ListUtil.list("FOO", "bar", "One"));
      fail("Odd length arg list should throw");
    } catch (IllegalArgumentException e) {
    }
    try {
      MapUtil.fromList(ListUtil.list(ListUtil.list("foo", "bar"), ListUtil.list("one")));
      fail("Short sublist should throw");
    } catch (IllegalArgumentException e) {
    }
  }
Пример #10
0
 public Map<String, List<String>> readInvertedMapListFromTsvReader(
     BufferedReader reader, int logFrequency) throws IOException {
   Map<String, List<String>> map = Maps.newHashMap();
   String line;
   int line_number = 0;
   while ((line = reader.readLine()) != null) {
     line_number++;
     if (logFrequency != -1) {
       logEvery(logFrequency, line_number);
     }
     String[] fields = line.split("\t");
     String key = fields[0];
     for (int i = 1; i < fields.length; i++) {
       String value = fields[i];
       // Remember, this is an _inverted_ map, so switching the value and key is correct.
       MapUtil.addValueToKeyList(map, value, key);
     }
   }
   return map;
 }
Пример #11
0
 public void testSubstanceState() {
   AuState aus = new AuState(mau, historyRepo);
   assertEquals(SubstanceChecker.State.Unknown, aus.getSubstanceState());
   assertFalse(aus.hasNoSubstance());
   aus.setSubstanceState(SubstanceChecker.State.Yes);
   assertEquals(1, historyRepo.getAuStateStoreCount());
   assertEquals(SubstanceChecker.State.Yes, aus.getSubstanceState());
   assertFalse(aus.hasNoSubstance());
   aus.setSubstanceState(SubstanceChecker.State.No);
   assertEquals(2, historyRepo.getAuStateStoreCount());
   assertEquals(SubstanceChecker.State.No, aus.getSubstanceState());
   assertTrue(aus.hasNoSubstance());
   assertNotEquals("2", aus.getFeatureVersion(Plugin.Feature.Substance));
   mplug.setFeatureVersionMap(MapUtil.map(Plugin.Feature.Substance, "2"));
   aus.setSubstanceState(SubstanceChecker.State.Yes);
   // changing both the substance state and feature version should store
   // only once
   assertEquals(3, historyRepo.getAuStateStoreCount());
   assertEquals(SubstanceChecker.State.Yes, aus.getSubstanceState());
   assertEquals("2", aus.getFeatureVersion(Plugin.Feature.Substance));
 }
Пример #12
0
  public Map<Long, Integer> getTopInfratores() {
    List<Infracao> listaInf = new ArrayList<Infracao>(getInfracoes());
    Iterator<Infracao> ite = listaInf.iterator();

    Map<Long, Integer> infConds = new HashMap<Long, Integer>();

    Condutor c;
    int cont = 0;

    while (ite.hasNext()) {
      c = banco.getCondutorComCpf(getVeiculoComPlaca(ite.next().getPlaca()).getCpfDono());
      cont = 1;

      if (infConds.get(c.getCPF()) != null) {
        cont = (infConds.get(c.getCPF()) + 1);
      }

      infConds.put(c.getCPF(), cont);
    }

    return MapUtil.ordenePorValor(infConds);
  }
Пример #13
0
 public int getG() {
   if (this.prev == null) {
     return 0;
   }
   return this.prev.getG() + MapUtil.dist(this, this.prev);
 }
Пример #14
0
 public void testExpandMultiKeys() {
   assertEquals(MapUtil.map(), MapUtil.expandAlternativeKeyLists(MapUtil.map()));
   assertEquals(MapUtil.map("1", "A"), MapUtil.expandAlternativeKeyLists(MapUtil.map("1", "A")));
   assertEquals(
       MapUtil.map("1", "A", "2", "A"),
       MapUtil.expandAlternativeKeyLists(MapUtil.map("1;2", "A")));
   assertEquals(
       MapUtil.map("1", "A", "2", "B", "*", "B"),
       MapUtil.expandAlternativeKeyLists(MapUtil.map("1", "A", "2;*", "B")));
 }
Пример #15
0
/** Describes the archive file types that should have their members exposed as pseudo-CachedUrls. */
public class ArchiveFileTypes {
  protected static Logger log = Logger.getLogger("ArchiveFileTypes");

  /** Default mime types and extensions for zip, tar, tgz. */
  private static final Map<String, String> DEFAULT_MAP =
      MapUtil.fromList(
          ListUtil.list(
              ".zip",
              ".zip",
              ".tar",
              ".tar",
              ".tgz",
              ".tgz",
              ".tar.gz",
              ".tar.gz",
              "application/zip",
              ".zip",
              "application/x-gtar",
              ".tar",
              "application/x-tar",
              ".tar"));

  public static final ArchiveFileTypes DEFAULT = new ArchiveFileTypes(DEFAULT_MAP);

  private Map<String, String> extMimeMap;

  public ArchiveFileTypes() {}

  public ArchiveFileTypes(Map<String, String> map) {
    extMimeMap = map;
  }

  public Map<String, String> getExtMimeMap() {
    return extMimeMap;
  }

  /**
   * Return the archive file type corresponding to the CU's MIME type or filename extension, or null
   * if none.
   */
  public String getFromCu(CachedUrl cu) throws MalformedURLException {
    String res = getFromMime(cu.getContentType());
    if (res == null) {
      res = getFromUrl(cu.getUrl());
    }
    return res;
  }

  /**
   * Return the archive file type corresponding to the filename extension in the URL, or null if
   * none.
   */
  public String getFromUrl(String url) throws MalformedURLException {
    if (StringUtil.endsWithIgnoreCase(url, ".tar.gz")) {
      return getExtMimeMap().get(".tar.gz");
    }
    String ext = UrlUtil.getFileExtension(url).toLowerCase();
    return getExtMimeMap().get("." + ext);
  }

  /** Return the archive file type corresponding to the MIME type, or null if none. */
  public String getFromMime(String contentType) {
    String mimeType = HeaderUtil.getMimeTypeFromContentType(contentType);
    if (mimeType == null) {
      return null;
    }
    return getExtMimeMap().get(mimeType.toLowerCase());
  }

  /**
   * Lookup the CU's archive file type in its AU's ArchiveFileTypes
   *
   * @return the file extension (including dot), or null if none found
   */
  public static String getArchiveExtension(CachedUrl cu) {
    ArchiveFileTypes aft = cu.getArchivalUnit().getArchiveFileTypes();
    if (aft == null) {
      return null;
    }
    try {
      return aft.getFromCu(cu);
    } catch (MalformedURLException e) {
      log.warning("isArchive(" + cu + ")", e);
      return null;
    }
  }
}