코드란게 한달짜고 버릴때도 있고 일주일 짜고 폐기 될때도 있지만


그래도 짜놓은게 아까워서 폐기코드를 저장해놓음..


서버에 존재하지 않는 블럭(404)의 연속된 순서에 많은 부분의 절반부터 Sequence를 부여하는 부분


(멀티 업로드 시 협업을 위함)



    /**

     * Set Block Sequence

     * <p>

     * 

     * @author YM,Jung

     * @date 2013. 12. 10.

     * @param blockHashRefList

     * @param notFoundBlockSeqList

     * @return

     */

    private void setBlockRefSequence(List<BlockHashRef> blockHashRefList, List<Integer> notFoundBlockSeqList) {

        Iterator<Integer> blockSeqIter = getUploadBlockSequence(notFoundBlockSeqList, blockHashRefList.size());


        for (Integer notFoundBlockSeq : notFoundBlockSeqList) {

            if (blockSeqIter.hasNext()) {

                //sequence. or sort.

                blockHashRefList.get(notFoundBlockSeq).setSequence(blockSeqIter.next());

            }

        }

    }


    /**

     * 업로드 지점 정해줌. 처음 업로드의 경우 블럭의 처음 반환

     * <p>

     * (0) N번째의 경우 남은 블럭의 반 지점 반환

     * <p>

     * 일반 업로드의 경우 블럭이 업로드 안된 지점부터 끝까지.

     * <p>

     * 

     * @author YM,Jung

     * @date 2013. 12. 10.

     * @param notFoundBlockSeqList

     * @param blockTotalSize

     * @return

     */

    private Iterator<Integer> getUploadBlockSequence(List<Integer> notFoundBlockSeqList, int blockTotalSize) {

        boolean multiUpload = false;

        int returnValue = 0;

        int compare = 0;

        int chainCount = 0;

        int topCount = 0;

        if (notFoundBlockSeqList.size() == blockTotalSize) { // 전체 처음 업로드

            return getSequence(notFoundBlockSeqList, returnValue);

        }

        for (int i = 0; i < notFoundBlockSeqList.size(); i++) {

            // 연속된 수를 구함

            if (compare + 1 == notFoundBlockSeqList.get(i)) {

                chainCount++;

            } else {

                // 연속된 수가 크면 대체.

                if (chainCount > topCount) {

                    topCount = chainCount;

                    returnValue = calculateUploadBlockPointer(chainCount, i);

                    chainCount = 0;

                    multiUpload = true;

                }

            }

            compare = notFoundBlockSeqList.get(i);

        }

        if (multiUpload) {

            if (chainCount > topCount) { // 마지막까지 not found 를 위한 추가.

                returnValue = calculateUploadBlockPointer(chainCount, blockTotalSize);

            }

            return getSequence(notFoundBlockSeqList, returnValue);

        } else {

            // 없는 블럭 차례대로 업로드

            return getSequence(notFoundBlockSeqList, 0);

        }


    }



    private Iterator<Integer> getSequence(List<Integer> notFoundBlockSeqList, int firstSequenceBlock) {

        List<Integer> blockSequenceList = new ArrayList<Integer>();

        int firstSeq = 0;

        // Set first sequence point.

        for (Integer notFoundBlockSeq : notFoundBlockSeqList) {

            if (notFoundBlockSeq == firstSequenceBlock) {

                break;

            } else {

                firstSeq++;

            }

        }


        //Set sequence.

        for (int i = 0; i < firstSeq; i++) {

            blockSequenceList.add(notFoundBlockSeqList.size() - firstSeq + i);

        }

        for (int i = firstSeq; i < notFoundBlockSeqList.size(); i++) {

            blockSequenceList.add(i - firstSeq);

        }

        return blockSequenceList.iterator();

    }



    private int calculateUploadBlockPointer(int chainCount, int blockPointer) {

        int half = chainCount / 2; // 버림.

        return blockPointer - half; //남은 블럭의 반지점.

    }

'java' 카테고리의 다른 글

자바 정규표현식 필터링 Pattern 사용법 예시  (0) 2014.02.04
TreeSet 을 사용한 List<> 중복 제거  (0) 2014.01.06
InputStream을 파일로 저장  (0) 2013.11.01
동일성 동등성 == equals  (0) 2013.05.22
어노테이션 사용  (0) 2013.05.16

+ Recent posts