Esempio n. 1
0
 public void visitBranch(Branch aBranch) {
   out.print("Branch(");
   ++indentLevel;
   out.println();
   printIndent();
   out.print("equations=");
   if (aBranch.getEquations() != null) {
     out.println("[");
     ++indentLevel;
     for (Equation e : aBranch.getEquations()) {
       printIndent();
       e.visit(this);
     }
     --indentLevel;
     printIndent();
     out.println("]");
   } else {
     out.println("null");
   }
   printIndent();
   out.print("pattern=");
   if (aBranch.getPattern() != null) {
     aBranch.getPattern().visit(this);
   } else {
     out.println("null");
   }
   --indentLevel;
   printIndent();
   out.println(")");
 }
Esempio n. 2
0
 public void visitConstructor(Constructor aConstructor) {
   out.print("Constructor(");
   ++indentLevel;
   out.println();
   printIndent();
   out.print("opnames=");
   if (aConstructor.getOpnames() != null) {
     out.println("[");
     ++indentLevel;
     for (OpName e : aConstructor.getOpnames()) {
       printIndent();
       e.visit(this);
     }
     --indentLevel;
     printIndent();
     out.println("]");
   } else {
     out.println("null");
   }
   printIndent();
   out.print("operands=");
   if (aConstructor.getOperands() != null) {
     out.println("[");
     ++indentLevel;
     for (Operand e : aConstructor.getOperands()) {
       printIndent();
       e.visit(this);
     }
     --indentLevel;
     printIndent();
     out.println("]");
   } else {
     out.println("null");
   }
   printIndent();
   out.print("type=");
   if (aConstructor.getType() != null) {
     aConstructor.getType().visit(this);
   } else {
     out.println("null");
   }
   printIndent();
   out.print("branches=");
   if (aConstructor.getBranches() != null) {
     out.println("[");
     ++indentLevel;
     for (Branch e : aConstructor.getBranches()) {
       printIndent();
       e.visit(this);
     }
     --indentLevel;
     printIndent();
     out.println("]");
   } else {
     out.println("null");
   }
   --indentLevel;
   printIndent();
   out.println(")");
 }
Esempio n. 3
0
  /** @see Proxy#startProxy() */
  public void startProxy() {
    _started = true;

    if (_tx.isCompleted()) throw new IllegalStateException("Transaction has completed");

    if (!_parallel && _actives > 0) return;

    // Patch TMP fix for CIPANGO 8
    CallSession callSession = _tx.getRequest().getCallSession();
    SessionManager cm = callSession.getServer().getSessionManager();

    SessionScope work = cm.openScope(callSession);
    try {
      // End patch
      while (LazyList.size(_targets) > 0) {
        Branch branch = (Branch) LazyList.get(_targets, 0);
        _targets = LazyList.remove(_targets, 0);

        if (LOG.isDebugEnabled()) LOG.debug("Proxying to {} ", branch.getUri(), null);

        branch.start();

        if (!_parallel) break;
      }
      // Patch TMP fix for CIPANGO 8
    } finally {
      work.close();
    }
    // End patch
  }
 public int compare(Branch b1, Branch b2) {
   double d1 = b1.getDistFromUser();
   double d2 = b2.getDistFromUser();
   if (d1 < d2) return -1;
   if (d1 > d2) return 1;
   return 0;
 }
Esempio n. 5
0
 /** @see Proxy#getProxyBranch(URI) */
 public ProxyBranch getProxyBranch(URI uri) {
   Iterator<Branch> it = new BranchIterator(_branches);
   while (it.hasNext()) {
     Branch branch = it.next();
     if (branch.getUri().equals(uri)) return branch;
   }
   return null;
 }
Esempio n. 6
0
 public static void main(String[] args) {
   Student st1 = new Student(12, "ramananda", "cserama");
   st1.getInfomation();
   Branch bn1 = new Branch("sarkar", "Dhaka");
   bn1.getInfomation();
   Employee emp1 = new Employee("Ahsu", "bkrcAhsu", "Mirpur");
   emp1.getInfomation();
 }
 /**
  * @param branch
  * @return distance between branch and user
  */
 private double getUserAndBranchCoordinatesCalculateDist(Branch branch) {
   double branchLat = branch.getLatitude();
   double branchLong = branch.getLongitude();
   double userLat = currentLocation.getLatitude();
   double userLong = currentLocation.getLongitude();
   double distFromUser = calculateDistance(branchLat, branchLong, userLat, userLong);
   return distFromUser;
 }
  public void drawBranch(Branch branch) {
    // only draw the branch if it is marked as active
    float leafSize =
        1.f
            + Main.sqrt(
                    Main.pow(branch.endX - branch.startX, 2)
                        + Main.pow(branch.endY - branch.startY, 2))
                / 160.0f;
    if (branch.activeP) {
      float alpha = 255.0f;
      // if the branch hasn't stopped growing, the alpha is less than 255.0
      if (!branch.stoppedGrowing) {
        alpha =
            255.0f
                * (float)
                    ((double) (System.nanoTime() - branch.startGrowTimestamp)
                        / (double) Tree.BRANCH_GROW_TIME);
        if (alpha >= 255.0f) branch.stoppedGrowing = true;
      }
      p.stroke(0, 100, 0, alpha);
      p.fill(0, 255, 0, alpha);

      // Get the shape of the box2d body, and get its coordinates
      p.beginShape();
      // get the body transform so that we can convert the shape's coordinates to world coordinates
      Transform transform = branch.body.getTransform();
      Vec2 pos;
      for (Fixture f = branch.body.getFixtureList(); f != null; f = f.getNext()) {
        PolygonShape shape = (PolygonShape) f.getShape();
        for (int i = 0; i < shape.getVertexCount(); i++) {
          // apply the transform to the shape coordinates, and
          // then convert box2d coordinates to processing coordinates
          pos = box2d.coordWorldToPixels(Transform.mul(transform, shape.getVertex(i)));
          p.vertex(pos.x, pos.y);
        }
      }
      p.endShape(Main.CLOSE);

      // draw leafs after the other branches
      p.pushMatrix();
      CPoint2 leafPos = branch.getLeafPosition();
      p.translate(leafPos.x, leafPos.y);
      // p.rotate(leafAngle);
      p.rotate(-branch.body.getAngle() + -0.25f * Main.PI); // + Main.PI);
      p.noStroke();
      p.fill(0, 255, 0, alpha * 0.25f);
      p.ellipseMode(Main.CORNER);
      float s = 0.0f;
      for (int i = 7; i > 2; i--) {
        s = leafSize * i;
        p.ellipse(0, 0, s, s);
      }
      p.ellipse(0, 0, s, s);
      p.popMatrix();
      p.strokeWeight(1.0f);
    }
  }
 @Override
 public void onCreate() {
   super.onCreate();
   if (BranchUtil.isTestModeEnabled(this) == false) {
     Branch.getInstance(this);
   } else {
     Branch.getTestInstance(this);
   }
 }
Esempio n. 10
0
 /*Borrower*/
 @RequestMapping(
     value = "/getBooksByBranch",
     method = {RequestMethod.GET, RequestMethod.POST},
     produces = "application/json",
     consumes = "application/json")
 public List<Book> getBooksByBranch(@RequestBody Branch branch) {
   Branch b = branchdao.getBranchById(branch.getBranchId());
   return b.getBooks();
 }
Esempio n. 11
0
  public List<Branch> filterMatchingBranches(Collection<Branch> branches) {
    List<Branch> items = new ArrayList<Branch>();

    for (Branch b : branches) {
      if (matches(b.getName())) items.add(b);
    }

    return items;
  }
Esempio n. 12
0
 public Branch trunk(Session session) {
   if (getBranches() != null) {
     for (Branch b : getBranches()) {
       if (Branch.TRUNK.equals(b.getName())) {
         return b;
       }
     }
   }
   return null;
 }
Esempio n. 13
0
    private static Branch newInstance(Node left, Node right, int nodeSize) {

      Branch branch = create(nodeSize);

      branch.setChild(0, left);
      branch.setChild(1, right.firstKey());
      branch.setChild(2, right);
      branch.size = 1;

      return branch;
    }
Esempio n. 14
0
  /**
   * Set up submodule URLs so that they correspond to the remote pertaining to the revision that has
   * been checked out.
   */
  public void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException {
    String remote = null;

    // try to locate the remote repository from where this commit came from
    // (by using the heuristics that the branch name, if available, contains the remote name)
    // if we can figure out the remote, the other setupSubmoduleUrls method
    // look at its URL, and if it's a non-bare repository, we attempt to retrieve modules
    // from this checked out copy.
    //
    // the idea is that you have something like tree-structured repositories: at the root you have
    // corporate central repositories that you
    // ultimately push to, which all .gitmodules point to, then you have intermediate team local
    // repository,
    // which is assumed to be a non-bare repository (say, a checked out copy on a shared server
    // accessed via SSH)
    //
    // the abovementioned behaviour of the Git plugin makes it pick up submodules from this team
    // local repository,
    // not the corporate central.
    //
    // (Kohsuke: I have a bit of hesitation/doubt about such a behaviour change triggered by
    // seemingly indirect
    // evidence of whether the upstream is bare or not (not to mention the fact that you can't
    // reliably
    // figure out if the repository is bare or not just from the URL), but that's what apparently
    // has been implemented
    // and we care about the backward compatibility.)
    //
    // note that "figuring out which remote repository the commit came from" isn't a well-defined
    // question, and this is really a heuristics. The user might be telling us to build a specific
    // SHA1.
    // or maybe someone pushed directly to the workspace and so it may not correspond to any remote
    // branch.
    // so if we fail to figure this out, we back out and avoid being too clever. See JENKINS-10060
    // as an example
    // of where our trying to be too clever here is breaking stuff for people.
    for (Branch br : rev.getBranches()) {
      String b = br.getName();
      if (b != null) {
        int slash = b.indexOf('/');

        if (slash != -1) remote = getDefaultRemote(b.substring(0, slash));
      }

      if (remote != null) break;
    }

    if (remote == null) remote = getDefaultRemote();

    if (remote != null) setupSubmoduleUrls(remote, listener);
  }
Esempio n. 15
0
  @Override
  public OntrackSVNRevisionInfo getOntrackRevisionInfo(SVNRepository repository, long revision) {

    // Gets information about the revision
    SVNRevisionInfo basicInfo = svnService.getRevisionInfo(repository, revision);
    SVNChangeLogRevision changeLogRevision =
        svnService.createChangeLogRevision(repository, basicInfo);

    // Gets the first copy event on this path after this revision
    SVNLocation firstCopy = svnService.getFirstCopyAfter(repository, basicInfo.toLocation());

    // Data to collect
    Collection<BuildView> buildViews = new ArrayList<>();
    Collection<BranchStatusView> branchStatusViews = new ArrayList<>();
    // Loops over all authorised branches
    for (Project project : structureService.getProjectList()) {
      // Filter on SVN configuration: must be present and equal to the one the revision info is
      // looked into
      Property<SVNProjectConfigurationProperty> projectSvnConfig =
          propertyService.getProperty(project, SVNProjectConfigurationPropertyType.class);
      if (!projectSvnConfig.isEmpty()
          && repository
              .getConfiguration()
              .getName()
              .equals(projectSvnConfig.getValue().getConfiguration().getName())) {
        for (Branch branch : structureService.getBranchesForProject(project.getId())) {
          // Filter on branch type
          // Filter on SVN configuration: must be present
          if (branch.getType() != BranchType.TEMPLATE_DEFINITION
              && propertyService.hasProperty(branch, SVNBranchConfigurationPropertyType.class)) {
            // Identifies a possible build given the path/revision and the first copy
            Optional<Build> build = lookupBuild(basicInfo.toLocation(), firstCopy, branch);
            // Build found
            if (build.isPresent()) {
              // Gets the build view
              BuildView buildView = structureService.getBuildView(build.get());
              // Adds it to the list
              buildViews.add(buildView);
              // Collects the promotions for the branch
              branchStatusViews.add(structureService.getEarliestPromotionsAfterBuild(build.get()));
            }
          }
        }
      }
    }

    // OK
    return new OntrackSVNRevisionInfo(
        repository.getConfiguration(), changeLogRevision, buildViews, branchStatusViews);
  }
Esempio n. 16
0
  protected Branch addBranch(URI uri) {
    if (_tx.isCompleted()) throw new IllegalStateException("transaction completed");

    Branch branch = addTarget(uri);
    if (branch != null) {
      branch.setRecurse(getRecurse());
      branch.setRecordRoute(getRecordRoute());
      branch.setAddToPath(getAddToPath());
      branch.setProxyBranchTimeout(getProxyTimeout());

      _branches = LazyList.add(_branches, branch);
    }
    return branch;
  }
Esempio n. 17
0
  public List<Branch> getRemoteBranches() throws GitException, IOException {
    Repository db = getRepository();
    Map<String, Ref> refs = db.getAllRefs();
    List<Branch> branches = new ArrayList<Branch>();

    for (Ref candidate : refs.values()) {
      if (candidate.getName().startsWith(Constants.R_REMOTES)) {
        Branch buildBranch = new Branch(candidate);
        listener.getLogger().println("Seen branch in repository " + buildBranch.getName());
        branches.add(buildBranch);
      }
    }

    return branches;
  }
Esempio n. 18
0
 public void delete(Session session) {
   if (getBranches() != null) {
     for (Branch b : getBranches()) {
       b.delete(session);
     }
     setBranches(null);
   }
   if (getNvPairs() != null) {
     for (NvPair p : getNvPairs()) {
       p.delete(session);
     }
     setNvPairs(null);
   }
   session.delete(this);
 }
 private void setupNearestBranchesAdapter() {
   Log.d(APP_TAG, "Branches after sort = " + branches);
   // initialize our list to pass to the adapter. The adapter
   // needs the names and the distances of the branches to show
   // the information
   ArrayList<Pair<String, Double>> branchesWithDistance = new ArrayList<Pair<String, Double>>();
   for (Branch branch : nearestBranchesList) {
     String name = branch.getName();
     Double distance = branch.getDistFromUser();
     Pair<String, Double> pair = new Pair<String, Double>(name, distance);
     branchesWithDistance.add(pair);
   }
   nearestBranchesAdapter = new BranchLocationAdapter(getActivity(), branchesWithDistance);
   this.setListAdapter(nearestBranchesAdapter);
 }
 @Before
 public void before() {
   SecurityService securityService = mock(SecurityService.class);
   ValidationRunStatusService validationRunStatusService = mock(ValidationRunStatusService.class);
   structureRepository = mock(StructureRepository.class);
   EventPostService eventService = mock(EventPostService.class);
   EventFactory eventFactory = mock(EventFactory.class);
   ExtensionManager extensionManager = mock(ExtensionManager.class);
   PropertyService propertyService = mock(PropertyService.class);
   PredefinedPromotionLevelService predefinedPromotionLevelService =
       mock(PredefinedPromotionLevelService.class);
   PredefinedValidationStampService predefinedValidationStampService =
       mock(PredefinedValidationStampService.class);
   DecorationService decorationService = mock(DecorationService.class);
   ProjectFavouriteService projectFavouriteService = mock(ProjectFavouriteService.class);
   service =
       new StructureServiceImpl(
           securityService,
           eventService,
           eventFactory,
           validationRunStatusService,
           structureRepository,
           extensionManager,
           propertyService,
           predefinedPromotionLevelService,
           predefinedValidationStampService,
           decorationService,
           projectFavouriteService);
   // Model
   Project project = Project.of(nd("P", "Project")).withId(ID.of(1));
   Branch branch = Branch.of(project, nd("B", "Branch")).withId(ID.of(1));
   copper = PromotionLevel.of(branch, nd("COPPER", "")).withId(ID.of(1));
   build = Build.of(branch, nd("1", "Build 1"), Signature.of("test")).withId(ID.of(1));
 }
Esempio n. 21
0
  /**
   * Specify the registers used by this instruction.
   *
   * @param rs is the register set in use
   * @param index is an index associated with the instruction
   * @param strength is the importance of the instruction
   * @see scale.backend.RegisterAllocator#useRegister(int,int,int)
   * @see scale.backend.RegisterAllocator#defRegister(int,int)
   */
  public void specifyRegisterUsage(RegisterAllocator rs, int index, int strength) {
    super.specifyRegisterUsage(rs, index, strength);

    if (annulled) return; // Annulled instructions are processed as part of an AnnulMarker.

    if (delaySlot != null) delaySlot.specifyRegisterUsage(rs, index, strength);
  }
Esempio n. 22
0
  /**
   * Performs any initialization for this tag that may be needed while parsing a branch definition.
   *
   * @param templateFile The template file in which this tag is used.
   * @param branch The branch in which this tag is used.
   * @param arguments The set of arguments provided for this tag.
   * @param lineNumber The line number on which this tag appears in the template file.
   * @param warnings A list into which any appropriate warning messages may be placed.
   * @throws InitializationException If a problem occurs while initializing this tag.
   */
  public void initializeForBranch(
      TemplateFile templateFile,
      Branch branch,
      String[] arguments,
      int lineNumber,
      List<Message> warnings)
      throws InitializationException {
    if ((arguments.length < 1) || (arguments.length > 2)) {
      Message message =
          ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(
              getName(), lineNumber, 1, 2, arguments.length);
      throw new InitializationException(message);
    }

    String lowerName = toLowerCase(arguments[0]);
    AttributeType t = DirectoryServer.getAttributeType(lowerName, true);
    if (!branch.hasAttribute(t)) {
      Message message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber);
      throw new InitializationException(message);
    }

    if (arguments.length == 2) {
      assertionValue = arguments[1];
    } else {
      assertionValue = null;
    }
  }
Esempio n. 23
0
  /**
   * Pass prices down and compute demand for the power system.
   *
   * @param theta_R real power demand multiplier
   * @param theta_I reactive power demand multiplier
   * @param pi_R price of real power demand
   * @param pi_I price of reactive power demand
   * @return the demand for the customers supported by this lateral
   */
  public Demand compute(double theta_R, double theta_I, double pi_R, double pi_I) {
    // generate the new prices and pass them down to the customers
    double new_pi_R = pi_R + alpha * (theta_R + (theta_I * X) / R);
    double new_pi_I = pi_I + beta * (theta_I + (theta_R * R) / X);

    Demand a1;
    if (next_lateral != null) a1 = next_lateral.compute(theta_R, theta_I, new_pi_R, new_pi_I);
    else a1 = null;

    Demand a2 = branch.compute(theta_R, theta_I, new_pi_R, new_pi_I);

    if (next_lateral != null) {
      D.add(a1, a2);
    } else {
      D.assign(a2);
    }

    // compute the new power demand values P,Q
    double a = R * R + X * X;
    double b = 2 * R * X * D.Q - 2 * X * X * D.P - R;
    double c = R * D.Q - X * D.P;
    c = c * c + R * D.P;
    double root = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a);
    D.Q = D.Q + ((root - D.P) * X) / R;
    D.P = root;

    // compute alpha, beta
    a = 2 * R * D.P;
    b = 2 * X * D.Q;
    alpha = a / (1 - a - b);
    beta = b / (1 - a - b);

    return D;
  }
Esempio n. 24
0
  private final Segment getSegment(CDOCommitInfo commitInfo) {
    CDOBranch cdoBranch = commitInfo.getBranch();
    long time = commitInfo.getTimeStamp();

    Branch branch = getBranch(cdoBranch);
    Segment segment = branch.getSegment(time);

    if (segment == null) {
      // This must be a new commit after the last or before the first
      boolean afterLast = isAfterLast(time); // false means beforeFirst
      segment = getOrCreateSegment(branch, time, afterLast);
    }

    branch.adjustCommitTimes(time);
    segment.adjustCommitTimes(time);
    return segment;
  }
Esempio n. 25
0
  private static byte[] makeExapndedCode(byte[] code, ArrayList jumps, int where, int gapLength)
      throws BadBytecode {
    int n = jumps.size();
    int size = code.length + gapLength;
    for (int i = 0; i < n; i++) {
      Branch b = (Branch) jumps.get(i);
      size += b.deltaSize();
    }

    byte[] newcode = new byte[size];
    int src = 0, dest = 0, bindex = 0;
    int len = code.length;
    Branch b;
    int bpos;
    if (0 < n) {
      b = (Branch) jumps.get(0);
      bpos = b.orgPos;
    } else {
      b = null;
      bpos = len; // src will be never equal to bpos
    }

    while (src < len) {
      if (src == where) {
        int pos2 = dest + gapLength;
        while (dest < pos2) newcode[dest++] = NOP;
      }

      if (src != bpos) newcode[dest++] = code[src++];
      else {
        int s = b.write(src, code, dest, newcode);
        src += s;
        dest += s + b.deltaSize();
        if (++bindex < n) {
          b = (Branch) jumps.get(bindex);
          bpos = b.orgPos;
        } else {
          b = null;
          bpos = len;
        }
      }
    }

    return newcode;
  }
 /** {@inheritDoc} */
 @Override
 protected Collection<P> orphanedItems(Collection<P> orphaned, TaskListener listener)
     throws IOException, InterruptedException {
   BranchProjectFactory<P, R> _factory = getProjectFactory();
   for (P project : orphaned) {
     if (!_factory.isProject(project)) {
       listener.getLogger().println("Detected unsupported subitem " + project + ", skipping");
       continue; // TODO perhaps better to remove from list passed to super, and return it from
                 // here
     }
     Branch b = _factory.getBranch(project);
     if (!(b instanceof Branch.Dead)) {
       _factory.decorate(
           _factory.setBranch(project, new Branch.Dead(b.getHead(), b.getProperties())));
     }
   }
   return super.orphanedItems(orphaned, listener);
 }
Esempio n. 27
0
    void shift(int where, int gapLength, boolean exclusive) {
      int p = pos;
      defaultByte = newOffset(p, defaultByte, where, gapLength, exclusive);
      int num = offsets.length;
      for (int i = 0; i < num; i++)
        offsets[i] = newOffset(p, offsets[i], where, gapLength, exclusive);

      super.shift(where, gapLength, exclusive);
    }
Esempio n. 28
0
  /**
   * 描画を行う。ここで全ての全体図を書いてしまう。スクロールに関してはViewで行う。
   *
   * @param aGraphics グラフィックス
   */
  public void paintComponent(Graphics aGraphics) {
    super.paintComponent(aGraphics);
    ForestModel aModel = (ForestModel) this.getModel();

    Font aFont = new Font(Font.Serif, Font.PLAIN, 12);
    FontMetrics aMetrics = new FontMetrics(aFont); // stringのwidthを知るために使用する
    aGraphics.setColor(Color.black);
    aGraphics.setFont(aFont);
    int fontHeight = aFont.getSize();

    /*
    drawRectで四角を描く
    Nodeの座標を得て、width,height分の大きさを描く
    drawlineでNode同士を結ぶ
    ここですべて描いちゃう。未完成
    */
    aGraphics.setColor(Color.black);

    for (Branch aBranch : aModel.getBranch()) {

      aGraphics.drawLine(
          aBranch.getStartPoint().getX(),
          aBranch.getStartPoint().getY() + fontHeight / 2,
          aBranch.getEndPoint().getX(),
          aBranch.getEndPoint().getY() + fontHeight / 2);

      Node aChildNode = aBranch.getChildNode();
      aGraphics.drawString(
          aChildNode.getLabel(), aChildNode.getPoint().getX(), aChildNode.getPoint().getY());
      int width = aMetrics.stringWidth(aChildNode.getLabel());
      aGraphics.drawRect(
          aChildNode.getPoint().getX(), aChildNode.getPoint().getY(), width, fontHeight);

      Node aParentNode = aBranch.getParentNode();
      aGraphics.drawString(
          aParentNode.getLabel(), aParentNode.getPoint().getX(), aParentNode.getPoint().getY());
      width = aMetrics.stringWidth(aParentNode.getLabel());
      aGraphics.drawRect(
          aParentNode.getPoint().getX(), aParentNode.getPoint().getY(), width, fontHeight);
    }
    return;
  }
Esempio n. 29
0
 @Test
 public void fromArray() {
   Branches branches = Branches.from(Branch.from("aaa"), Branch.from("bbb"), Branch.from("ccc"));
   assertEquals(3, branches.getSize());
   assertEquals(Branch.from("aaa"), branches.first());
   assertEquals(true, branches.contains(Branch.from("aaa")));
   assertEquals(true, branches.contains(Branch.from("bbb")));
   assertEquals(true, branches.contains(Branch.from("ccc")));
 }
Esempio n. 30
0
  /**
   * Creates and saves a new branch, including setting up initial commit etc
   *
   * @param name
   * @param user
   * @param session
   * @return
   */
  public Branch createBranch(String name, Profile user, Session session) {
    Commit head = new Commit();
    head.setCreatedDate(new Date());
    head.setEditor(user);
    head.setItemHash(null);
    session.save(head);

    Branch b = new Branch();
    b.setName(Branch.TRUNK);
    b.setRepository(this);
    b.setHead(head);
    session.save(b);

    if (getBranches() == null) {
      setBranches(new ArrayList<Branch>());
    }
    getBranches().add(b);

    return b;
  }