2015의 게시물 표시

java Byte.parseByte throw exception java.lang.NumberFormatException

 Java 에서 개발중에 16진수 값으로 구성된 String type의 Mac 주소를 String을 Byte Array로 변경하기 위해 다음의 코드를 작성하였다. 1 2 3 4 5 String temp [] = strMacAddr . split ( "(?<=\\G..)" ); byte [] mac Addr = new byte [ temp . length ]; for ( int i = 0 ; i < mac Addr . length ; i ++) { mac Addr [ i ] = Byte . parseByte ( temp [ i ], 16 ); } 여기서 잘 실행될줄 알았지만... java.lang.NumberFormatException이 발생했다. 이유는 java의 모든 정수형 primitive type은 signed value 이기 때문이다. unsigned를 지원하지 않는 이유는 찾아보면 많다 ㅋ 다음은 java를 만든 james gosling 횽님의 인터뷰이다. (발췌 :  http://www.gotw.ca/publications/c_family_interview.htm ) Gosling: For me as a language designer, which I don't really count myself as these days, what "simple" really ended up meaning was could I expect J. Random Developer to hold the spec in his head. That definition says that, for instance, Java isn't -- and in fact a lot of these languages end up with a lot of corner cases, things that nobody really understands. Quiz an

git reset 으로 원하는 이전 commit으로 되돌리기

git에서 commit을 이전의 commit 상태나 branch로 되돌리리려면 아래와 같이 reset을 사용하면 된다. $ > git reset [commit-id][ ~|^] [숫자] 여기서 [commit-id]  다음에 ~ 와 ^ 가 올수 있는데 각각의 의미는 다음과 같다. [commit-id][~][숫자] : [commit-id]를 기준으로 [숫자]만큼의 commit-id [commit-id][^][숫자] : [commit-id]를 기준으로 [숫자] 번째의 branch의 commit-id 1은 master branch  만약에 latest commit-id의 3번째 이전 commit으로 되돌아간다면 $ > git reset HEAD~3 3번째 이전 commit에 2번째 branch로 되돌아 간다면 $ > git reset HEAD~3^2 위와 같이 사용할 수 있다. 참고로 정확하게 돌아갈 commit id를 가리키는지 확인하려면 $ > git log HEAD~3^2 를 먼저 해서 가장 위의 log가 되돌리려는 commit-id인지를 확인하는걸 추천한다...

Google Mock

Why Mock? Mock Object는 real object를 모방하여 대신하기 위해 만들어진 객체로서 real object와 같은 interface를 가지고 각각의 interface 호출시 유저가 정의한 값을 반환하도록 만들어진다. 이러한 Mock Object는 다음의 이유로 사용된다. Object가 비결정적 결과를 return할 때 (현재 시간, 온도 등) Object가 재현 또는 구현하기 힘든 상태를 가질 때 (network error) Object의 동작이 느릴 때 (Test 전에 초기화 되어야 하는 DB) Object를 아직 구현하지 않았거나 동작이 바뀌었을 때 Test를 위한 method나 information을 포함해야 할 때 여기서 Unit Test 시에는 마지막 두가지 이유로 Mock을 사용한다. 아직 구현되지 않은 Object를 대신하여 Test를 진행할 수 없을 때 fake object의 목적으로 구현 Test하고자 하는 과정에서 대상 객체의 Interface가 다음과 같이 정상적으로 호출되었는지를 검사 호출시 parameter 검사 호출 횟수 검사 Google Mock 자체는 Test Framework가 아니라 앞서 말한 Mock Object를 쉽게 만들어주기 위한 도구이다. 결국 Test를 위해서는 Test Framework와 같이 사용되야 한다. Google Test bundel과 함께 제공되므로 Google Test를 사용해도 좋고 CppUnit등과 같은 다른 Test Framework 와 같이 사용할 수 도 있다. System Requirement gcc 4.0+ or Microsoft Visual C++ 8.0 SP1 Users reported that it also works with gcc 3.4, Microsoft Visual C++ 7.1, and Cygwin, although we haven't tested it there ourselves. E