001    package org.sonar.ide.api;
002    
003    import java.util.HashMap;
004    import java.util.Map;
005    
006    /**
007     * @author Evgeny Mandrikov
008     * @since 0.2
009     */
010    public final class SourceCodeDiff {
011    
012      public static final int NOT_FOUND = -1;
013    
014      private Map<Integer, Integer> diff = new HashMap<Integer, Integer>();
015    
016      public SourceCodeDiff() {
017      }
018    
019      /**
020       * @param oldLine line in Sonar server (starting from 1)
021       * @param newLine line in working copy (starting from 0), -1 if not found
022       */
023      public void map(int oldLine, int newLine) {
024        if (newLine != NOT_FOUND) {
025          diff.put(oldLine, newLine);
026        }
027      }
028    
029      /**
030       * @param oldLine line in Sonar server (starting from 1)
031       * @return line in working copy (starting from 0), -1 if not found
032       */
033      public Integer newLine(int oldLine) {
034        if (diff.containsKey(oldLine)) {
035          return diff.get(oldLine);
036        }
037        return NOT_FOUND;
038      }
039    
040      @Override
041      public String toString() {
042        return diff.toString();
043      }
044    }