From 635a5aa5ea55b8b540031d04e2502b39b1da6b4a Mon Sep 17 00:00:00 2001 From: egimaben Date: Mon, 6 Jun 2016 17:05:54 +0300 Subject: [PATCH 01/19] Added guava set+function=map tutorial and tests --- .../org/baeldung/guava/GuavaMapFromSet.java | 101 ++++++++++++++++++ .../baeldung/guava/GuavaMapFromSetTests.java | 66 ++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 guava/src/test/java/org/baeldung/guava/GuavaMapFromSet.java create mode 100644 guava/src/test/java/org/baeldung/guava/GuavaMapFromSetTests.java diff --git a/guava/src/test/java/org/baeldung/guava/GuavaMapFromSet.java b/guava/src/test/java/org/baeldung/guava/GuavaMapFromSet.java new file mode 100644 index 0000000000..602205ff9f --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/GuavaMapFromSet.java @@ -0,0 +1,101 @@ +package org.baeldung.guava; + +import java.util.AbstractMap; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; + +import com.google.common.base.Function; + +public class GuavaMapFromSet extends AbstractMap { + + private class SingleEntry implements Entry { + private K key; + + public SingleEntry( K key) { + this.key = key; + } + + @Override + public K getKey() { + return this.key; + } + + @Override + public V getValue() { + V value = GuavaMapFromSet.this.cache.get(this.key); + if (value == null) { + value = GuavaMapFromSet.this.function.apply(this.key); + GuavaMapFromSet.this.cache.put(this.key, value); + } + return value; + } + + @Override + public V setValue( V value) { + throw new UnsupportedOperationException(); + } + } + + private class MyEntrySet extends AbstractSet> { + + public class EntryIterator implements Iterator> { + private Iterator inner; + + public EntryIterator() { + this.inner = MyEntrySet.this.keys.iterator(); + } + + @Override + public boolean hasNext() { + return this.inner.hasNext(); + } + + @Override + public Map.Entry next() { + K key = this.inner.next(); + return new SingleEntry(key); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + } + + private Set keys; + + public MyEntrySet( Set keys) { + this.keys = keys; + } + + @Override + public Iterator> iterator() { + return new EntryIterator(); + } + + @Override + public int size() { + return this.keys.size(); + } + + } + + private WeakHashMap cache; + private Set> entries; + private Function function; + + public GuavaMapFromSet( Set keys, Function function) { + this.function = function; + this.cache = new WeakHashMap(); + this.entries = new MyEntrySet(keys); + } + + @Override + public Set> entrySet() { + return this.entries; + } + +} diff --git a/guava/src/test/java/org/baeldung/guava/GuavaMapFromSetTests.java b/guava/src/test/java/org/baeldung/guava/GuavaMapFromSetTests.java new file mode 100644 index 0000000000..9abb5d14a9 --- /dev/null +++ b/guava/src/test/java/org/baeldung/guava/GuavaMapFromSetTests.java @@ -0,0 +1,66 @@ +package org.baeldung.guava; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.junit.Test; + +import com.google.common.base.Function; + +public class GuavaMapFromSetTests { + + @Test + public void givenStringSet_whenMapsToElementLength_thenCorrect() { + Function function = new Function() { + + @Override + public String apply(Integer from) { + return Integer.toBinaryString(from.intValue()); + } + }; + Set set = (Set) new TreeSet(Arrays.asList( + 32, 64, 128)); + Map map = new GuavaMapFromSet(set, + function); + assertTrue(map.get(32).equals("100000") + && map.get(64).equals("1000000") + && map.get(128).equals("10000000")); + } + + @Test + public void givenIntSet_whenMapsToElementBinaryValue_thenCorrect() { + Function function = new Function() { + + @Override + public Integer apply(String from) { + return from.length(); + } + }; + Set set = (Set) new TreeSet(Arrays.asList( + "four", "three", "twelve")); + Map map = new GuavaMapFromSet(set, + function); + assertTrue(map.get("four") == 4 && map.get("three") == 5 + && map.get("twelve") == 6); + } + @Test + public void givenSet_whenNewSetElementAddedAndMappedLive_thenCorrect() { + Function function = new Function() { + + @Override + public Integer apply(String from) { + return from.length(); + } + }; + Set set = (Set) new TreeSet(Arrays.asList( + "four", "three", "twelve")); + Map map = new GuavaMapFromSet(set, + function); + set.add("one"); + assertTrue(map.get("one") == 3 && map.size()==4); + } +} From 604e79d4264b2170716205145693bbfe94be1ed6 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 18 Jun 2016 00:52:28 +0200 Subject: [PATCH 02/19] modify httpclient digest test --- .../org/baeldung/httpclient/SandboxTest.java | 65 +++++++++++++++---- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java b/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java index eb3084f941..514611d1f9 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java @@ -1,5 +1,7 @@ package org.baeldung.httpclient; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import org.apache.http.Header; @@ -24,29 +26,25 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.util.EntityUtils; +import org.junit.Ignore; import org.junit.Test; public class SandboxTest { + // original example + @Ignore @Test - public final void whenInterestingDigestAuthScenario_then200OK() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { + public final void whenInterestingDigestAuthScenario_then401UnAuthorized() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { final HttpHost targetHost = new HttpHost("httpbin.org", 80, "http"); // set up the credentials to run agains the server final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("user", "passwd")); - // This endpoint need fake cookie to work properly - final CookieStore cookieStore = new BasicCookieStore(); - final BasicClientCookie cookie = new BasicClientCookie("fake", "fake_value"); - cookie.setDomain("httpbin.org"); - cookie.setPath("/"); - cookieStore.addCookie(cookie); - // We need a first run to get a 401 to seed the digest auth // Make a client using those creds - final CloseableHttpClient client = HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credsProvider).build(); + final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); // And make a call to the URL we are after final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); @@ -91,6 +89,49 @@ public class SandboxTest { responseGood.close(); } } + } + + @Test + public final void whenInterestingDigestAuthScenario_then200OK() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { + final HttpHost targetHost = new HttpHost("httpbin.org", 80, "http"); + + // set up the credentials to run agains the server + final CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("user", "passwd")); + + // This endpoint need fake cookie to work properly + final CookieStore cookieStore = new BasicCookieStore(); + final BasicClientCookie cookie = new BasicClientCookie("fake", "fake_value"); + cookie.setDomain("httpbin.org"); + cookie.setPath("/"); + cookieStore.addCookie(cookie); + + // Make a client using those creds + final CloseableHttpClient client = HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credsProvider).build(); + + // And make a call to the URL we are after + final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); + + // Create a context to use + final HttpClientContext context = HttpClientContext.create(); + + // Get a response from the sever (401 implicitly) + final HttpResponse authResponse = client.execute(targetHost, httpget, context); + assertEquals(200, authResponse.getStatusLine().getStatusCode()); + + // HttpClient will use cached digest parameters for future requests + System.out.println("Executing request " + httpget.getRequestLine() + " to target " + targetHost); + + for (int i = 0; i < 3; i++) { + final CloseableHttpResponse responseGood = client.execute(targetHost, httpget, context); + + try { + System.out.println("----------------------------------------"); + assertEquals(200, responseGood.getStatusLine().getStatusCode()); + } finally { + responseGood.close(); + } + } client.close(); } @@ -117,7 +158,7 @@ public class SandboxTest { // == end System.out.println("Executing The Request knowing the digest parameters ==== "); final HttpResponse authResponse = client.execute(targetHost, httpget, context); - System.out.println(authResponse.toString()); + assertEquals(200, authResponse.getStatusLine().getStatusCode()); client.close(); } @@ -133,12 +174,12 @@ public class SandboxTest { final HttpGet httpget = new HttpGet("http://localhost:8080/spring-security-rest-digest-auth/api/foos/1"); System.out.println("Executing The Request NOT knowing the digest parameters ==== "); final HttpResponse tempResponse = client.execute(targetHost, httpget, context); - System.out.println(tempResponse.toString()); + assertEquals(200, tempResponse.getStatusLine().getStatusCode()); for (int i = 0; i < 3; i++) { System.out.println("No more Challenges or 401"); final CloseableHttpResponse authResponse = client.execute(targetHost, httpget, context); - System.out.println(authResponse.toString()); + assertEquals(200, authResponse.getStatusLine().getStatusCode()); authResponse.close(); } client.close(); From 9a915901af244200f119a1f4b36bb4b743c4be06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Gonz=C3=A1lez?= Date: Sat, 18 Jun 2016 19:22:30 +0200 Subject: [PATCH 03/19] Add mock-comparisons module (#453) * Add new module for mocks comparison. * Add sources for testing. * Changes on testCase. * Enter some tests for mockito. * More tests for Mockito. * Even more tests. * Add the rest of the mocking libraries. * Javadoc on test. * Test bare bones for EasyMock. * Fist kind of test and setup. * Add tests using EasyMock with a change on LoginService. * Create LoginControllerTest.java * Test setup * [JMockit] No method called test. * [JMockit] Two methods called test. * [JMockit] One method called test. * [JMockit] Exception mock test * [JMockit] Mocked object to pass around test. * [JMockit] Custom matcher test. * [JMockit] Partial mocking test. * [JMockit] Fix with IDE. * Not stubs. Mocks. MOCKS!!! * Remove unnecesary import. --- mock-comparisons/README.md | 7 + mock-comparisons/pom.xml | 105 +++++++++++++ .../mocks/testCase/LoginController.java | 29 ++++ .../org/baeldung/mocks/testCase/LoginDao.java | 9 ++ .../baeldung/mocks/testCase/LoginService.java | 33 ++++ .../org/baeldung/mocks/testCase/UserForm.java | 15 ++ .../mocks/easymock/LoginControllerTest.java | 147 +++++++++++++++++ .../mocks/jmockit/LoginControllerTest.java | 148 ++++++++++++++++++ .../mocks/mockito/LoginControllerTest.java | 129 +++++++++++++++ pom.xml | 1 + 10 files changed, 623 insertions(+) create mode 100644 mock-comparisons/README.md create mode 100644 mock-comparisons/pom.xml create mode 100644 mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java create mode 100644 mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java create mode 100644 mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java create mode 100644 mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java create mode 100644 mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java create mode 100644 mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java create mode 100644 mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java diff --git a/mock-comparisons/README.md b/mock-comparisons/README.md new file mode 100644 index 0000000000..7795487b77 --- /dev/null +++ b/mock-comparisons/README.md @@ -0,0 +1,7 @@ +========= + +## Mock comparison realated tutorials + + +### Relevant Articles: +- [Mockito vs EasyMock vs JMockit](http://www.baeldung.com/mockito-vs-easymock-vs-jmockit) diff --git a/mock-comparisons/pom.xml b/mock-comparisons/pom.xml new file mode 100644 index 0000000000..c7a6dcb09d --- /dev/null +++ b/mock-comparisons/pom.xml @@ -0,0 +1,105 @@ + + 4.0.0 + org.baeldung + mock-comparisons + 0.1-SNAPSHOT + + mockito + + + + + + + + + + + junit + junit + ${junit.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + org.easymock + easymock + ${easymock.version} + test + + + + org.jmockit + jmockit + ${jmockit.version} + test + + + + + + mock-comparisons + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + + + + + + + + + + + + + 4.12 + 1.10.19 + 3.4 + 1.24 + + + 3.3 + 2.6 + 2.18.1 + 2.7 + 1.4.14 + + + + \ No newline at end of file diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java new file mode 100644 index 0000000000..2e25332db8 --- /dev/null +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java @@ -0,0 +1,29 @@ +package org.baeldung.mocks.testCase; + +public class LoginController { + + public LoginService loginService; + + public String login(UserForm userForm){ + if(null == userForm){ + return "ERROR"; + }else{ + boolean logged; + + try { + logged = loginService.login(userForm); + } catch (Exception e) { + return "ERROR"; + } + + if(logged){ + loginService.setCurrentUser(userForm.getUsername()); + return "OK"; + }else{ + return "KO"; + } + } + } + + // standard setters and getters +} diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java new file mode 100644 index 0000000000..4641fc1889 --- /dev/null +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java @@ -0,0 +1,9 @@ +package org.baeldung.mocks.testCase; + +public class LoginDao { + + public int login(UserForm userForm){ + //actual call to a third party library + return 0; + } +} diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java new file mode 100644 index 0000000000..2a20159393 --- /dev/null +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java @@ -0,0 +1,33 @@ +package org.baeldung.mocks.testCase; + +public class LoginService { + + private LoginDao loginDao; + + private String currentUser; + + public boolean login(UserForm userForm) { + assert null != userForm; + + int loginResults = loginDao.login(userForm); + + switch (loginResults){ + case 1: + return true; + default: + return false; + } + } + + public void setCurrentUser(String username) { + if(null != username){ + this.currentUser = username; + } + } + + public void setLoginDao(LoginDao loginDao) { + this.loginDao = loginDao; + } + + // standard setters and getters +} diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java new file mode 100644 index 0000000000..d6ee444909 --- /dev/null +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java @@ -0,0 +1,15 @@ +package org.baeldung.mocks.testCase; + +public class UserForm { + + // public access modifiers as only for testing + + public String password; + + public String username; + + public String getUsername(){ + return username; + } + +} diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java b/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java new file mode 100644 index 0000000000..b80c28804a --- /dev/null +++ b/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java @@ -0,0 +1,147 @@ +package org.baeldung.mocks.easymock; + +import org.baeldung.mocks.testCase.LoginController; +import org.baeldung.mocks.testCase.LoginDao; +import org.baeldung.mocks.testCase.LoginService; +import org.baeldung.mocks.testCase.UserForm; +import org.easymock.*; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + *

Test for LoginController using EasyMock.

+ * Created by Alvaro on 12/06/2016. + */ +@RunWith(EasyMockRunner.class) +public class LoginControllerTest { + + @Mock + private LoginDao loginDao; + + @Mock + private LoginService loginService; + + @TestSubject + private LoginController loginController = new LoginController(); + + @Test + public void assertThatNoMethodHasBeenCalled() { + EasyMock.replay(loginService); + loginController.login(null); + + // no method called + EasyMock.verify(loginService); + } + + @Test + public void assertTwoMethodsHaveBeenCalled() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + EasyMock.expect(loginService.login(userForm)).andReturn(true); + loginService.setCurrentUser("foo"); + EasyMock.replay(loginService); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + EasyMock.verify(loginService); + } + + @Test + public void assertOnlyOneMethodHasBeenCalled() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + EasyMock.expect(loginService.login(userForm)).andReturn(false); + EasyMock.replay(loginService); + + String login = loginController.login(userForm); + + Assert.assertEquals("KO", login); + EasyMock.verify(loginService); + } + + @Test + public void mockExceptionThrowing() { + UserForm userForm = new UserForm(); + EasyMock.expect(loginService.login(userForm)).andThrow(new IllegalArgumentException()); + EasyMock.replay(loginService); + + String login = loginController.login(userForm); + + Assert.assertEquals("ERROR", login); + EasyMock.verify(loginService); + } + + @Test + public void mockAnObjectToPassAround() { + UserForm userForm = EasyMock.mock(UserForm.class); + EasyMock.expect(userForm.getUsername()).andReturn("foo"); + EasyMock.expect(loginService.login(userForm)).andReturn(true); + loginService.setCurrentUser("foo"); + EasyMock.replay(userForm); + EasyMock.replay(loginService); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + EasyMock.verify(userForm); + EasyMock.verify(loginService); + } + + @Test + public void argumentMatching() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + // default matcher + EasyMock.expect(loginService.login(EasyMock.isA(UserForm.class))).andReturn(true); + // complex matcher + loginService.setCurrentUser(specificArgumentMatching("foo")); + EasyMock.replay(loginService); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + EasyMock.verify(loginService); + } + + private static String specificArgumentMatching(final String expected) { + EasyMock.reportMatcher(new IArgumentMatcher() { + @Override + public boolean matches(Object argument) { + return argument instanceof String && ((String) argument).startsWith(expected); + } + + @Override + public void appendTo(StringBuffer buffer) { + //NOOP + } + }); + return null; + } + + @Test + public void partialMocking() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + // use partial mock + LoginService loginServicePartial = EasyMock.partialMockBuilder(LoginService.class). + addMockedMethod("setCurrentUser").createMock(); + loginServicePartial.setCurrentUser("foo"); + // let service's login use implementation so let's mock DAO call + EasyMock.expect(loginDao.login(userForm)).andReturn(1); + + loginServicePartial.setLoginDao(loginDao); + loginController.loginService = loginServicePartial; + + EasyMock.replay(loginDao); + EasyMock.replay(loginServicePartial); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + // verify mocked call + EasyMock.verify(loginServicePartial); + EasyMock.verify(loginDao); + } +} diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java b/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java new file mode 100644 index 0000000000..d1c502ce55 --- /dev/null +++ b/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java @@ -0,0 +1,148 @@ +package org.baeldung.mocks.jmockit; + +import mockit.*; +import mockit.integration.junit4.JMockit; +import org.baeldung.mocks.testCase.LoginController; +import org.baeldung.mocks.testCase.LoginDao; +import org.baeldung.mocks.testCase.LoginService; +import org.baeldung.mocks.testCase.UserForm; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + *

Test for LoginController using JMockit.

+ * Created by Alvaro on 12/06/2016. + */ +@RunWith(JMockit.class) +public class LoginControllerTest { + + @Injectable + private LoginDao loginDao; + + @Injectable + private LoginService loginService; + + @Tested + private LoginController loginController; + + @Test + public void assertThatNoMethodHasBeenCalled() { + loginController.login(null); + // no method called + new FullVerifications(loginService) {}; + } + + @Test + public void assertTwoMethodsHaveBeenCalled() { + final UserForm userForm = new UserForm(); + userForm.username = "foo"; + new Expectations() {{ + loginService.login(userForm); result = true; + loginService.setCurrentUser("foo"); + }}; + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + new FullVerifications(loginService) {}; + } + + @Test + public void assertOnlyOneMethodHasBeenCalled() { + final UserForm userForm = new UserForm(); + userForm.username = "foo"; + new Expectations() {{ + loginService.login(userForm); result = false; + // no expectation for setCurrentUser + }}; + + String login = loginController.login(userForm); + + Assert.assertEquals("KO", login); + new FullVerifications(loginService) {}; + } + + @Test + public void mockExceptionThrowing() { + final UserForm userForm = new UserForm(); + new Expectations() {{ + loginService.login(userForm); result = new IllegalArgumentException(); + // no expectation for setCurrentUser + }}; + + String login = loginController.login(userForm); + + Assert.assertEquals("ERROR", login); + new FullVerifications(loginService) {}; + } + + @Test + public void mockAnObjectToPassAround(@Mocked final UserForm userForm) { + new Expectations() {{ + userForm.getUsername(); result = "foo"; + loginService.login(userForm); result = true; + loginService.setCurrentUser("foo"); + }}; + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + new FullVerifications(loginService) {}; + new FullVerifications(userForm) {}; + } + + @Test + public void argumentMatching() { + final UserForm userForm = new UserForm(); + userForm.username = "foo"; + // default matcher + new Expectations() {{ + loginService.login((UserForm) any); + result = true; + // complex matcher + loginService.setCurrentUser(withArgThat(new BaseMatcher() { + @Override + public boolean matches(Object item) { + return item instanceof String && ((String) item).startsWith("foo"); + } + + @Override + public void describeTo(Description description) { + //NOOP + } + })); + }}; + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + new FullVerifications(loginService) {}; + } + + @Test + public void partialMocking() { + // use partial mock + final LoginService partialLoginService = new LoginService(); + partialLoginService.setLoginDao(loginDao); + loginController.loginService = partialLoginService; + + final UserForm userForm = new UserForm(); + userForm.username = "foo"; + // let service's login use implementation so let's mock DAO call + new Expectations() {{ + loginDao.login(userForm); result = 1; + // no expectation for loginService.login + partialLoginService.setCurrentUser("foo"); + }}; + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + // verify mocked call + new FullVerifications(partialLoginService) {}; + new FullVerifications(loginDao) {}; + } +} diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java b/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java new file mode 100644 index 0000000000..841dd493e6 --- /dev/null +++ b/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java @@ -0,0 +1,129 @@ +package org.baeldung.mocks.mockito; + +import org.baeldung.mocks.testCase.LoginController; +import org.baeldung.mocks.testCase.LoginDao; +import org.baeldung.mocks.testCase.LoginService; +import org.baeldung.mocks.testCase.UserForm; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.*; + +/** + *

Test for LoginController using Mockito.

+ * Created by Alvaro on 12/06/2016. + */ +public class LoginControllerTest { + + @Mock + private LoginDao loginDao; + + @Spy + @InjectMocks + private LoginService spiedLoginService; + + @Mock + private LoginService loginService; + + @InjectMocks + private LoginController loginController; + + @Before + public void setUp() { + loginController = new LoginController(); + MockitoAnnotations.initMocks(this); + } + + @Test + public void assertThatNoMethodHasBeenCalled() { + loginController.login(null); + // no method called + Mockito.verifyZeroInteractions(loginService); + } + + @Test + public void assertTwoMethodsHaveBeenCalled() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + Mockito.when(loginService.login(userForm)).thenReturn(true); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + Mockito.verify(loginService).login(userForm); + Mockito.verify(loginService).setCurrentUser("foo"); + } + + @Test + public void assertOnlyOneMethodHasBeenCalled() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + Mockito.when(loginService.login(userForm)).thenReturn(false); + + String login = loginController.login(userForm); + + Assert.assertEquals("KO", login); + Mockito.verify(loginService).login(userForm); + Mockito.verifyNoMoreInteractions(loginService); + } + + @Test + public void mockExceptionThrowing() { + UserForm userForm = new UserForm(); + Mockito.when(loginService.login(userForm)).thenThrow(IllegalArgumentException.class); + + String login = loginController.login(userForm); + + Assert.assertEquals("ERROR", login); + Mockito.verify(loginService).login(userForm); + Mockito.verifyZeroInteractions(loginService); + } + + @Test + public void mockAnObjectToPassAround() { + UserForm userForm = Mockito.when(Mockito.mock(UserForm.class).getUsername()).thenReturn("foo").getMock(); + Mockito.when(loginService.login(userForm)).thenReturn(true); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + Mockito.verify(loginService).login(userForm); + Mockito.verify(loginService).setCurrentUser("foo"); + } + + @Test + public void argumentMatching() { + UserForm userForm = new UserForm(); + userForm.username = "foo"; + // default matcher + Mockito.when(loginService.login(Mockito.any(UserForm.class))).thenReturn(true); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + Mockito.verify(loginService).login(userForm); + // complex matcher + Mockito.verify(loginService).setCurrentUser(Mockito.argThat(new ArgumentMatcher() { + @Override + public boolean matches(Object argument) { + return argument instanceof String && ((String) argument).startsWith("foo"); + } + })); + } + + @Test + public void partialMocking() { + // use partial mock + loginController.loginService = spiedLoginService; + UserForm userForm = new UserForm(); + userForm.username = "foo"; + // let service's login use implementation so let's mock DAO call + Mockito.when(loginDao.login(userForm)).thenReturn(1); + + String login = loginController.login(userForm); + + Assert.assertEquals("OK", login); + // verify mocked call + Mockito.verify(spiedLoginService).setCurrentUser("foo"); + } +} diff --git a/pom.xml b/pom.xml index 85861685ba..f16861cc68 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,7 @@ jooq-spring json-path mockito + mock-comparisons jee7schedule querydsl From d9223b24fbb1709a9eb20545e2a67cf43ccd5563 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 18 Jun 2016 20:21:17 +0200 Subject: [PATCH 04/19] Refactor mock-comparisons --- mock-comparisons/pom.xml | 47 +++++------------ .../mocks/testCase/LoginController.java | 10 ++-- .../org/baeldung/mocks/testCase/LoginDao.java | 2 +- .../baeldung/mocks/testCase/LoginService.java | 4 +- .../org/baeldung/mocks/testCase/UserForm.java | 2 +- .../mocks/easymock/LoginControllerTest.java | 6 +-- .../mocks/jmockit/LoginControllerTest.java | 51 +++++++++++-------- .../mocks/mockito/LoginControllerTest.java | 4 -- 8 files changed, 54 insertions(+), 72 deletions(-) diff --git a/mock-comparisons/pom.xml b/mock-comparisons/pom.xml index c7a6dcb09d..97e24c61cd 100644 --- a/mock-comparisons/pom.xml +++ b/mock-comparisons/pom.xml @@ -7,14 +7,18 @@ mockito + + 4.12 + 1.10.19 + 3.4 + 1.24 + + + 3.3 + 2.18.1 + + - - - - - - - junit junit @@ -61,8 +65,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 1.7 - 1.7 + 1.8 + 1.8 @@ -76,30 +80,5 @@ - - - - - - - - - - - - - 4.12 - 1.10.19 - 3.4 - 1.24 - - - 3.3 - 2.6 - 2.18.1 - 2.7 - 1.4.14 - - \ No newline at end of file diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java index 2e25332db8..914b0034d2 100644 --- a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginController.java @@ -4,10 +4,10 @@ public class LoginController { public LoginService loginService; - public String login(UserForm userForm){ - if(null == userForm){ + public String login(UserForm userForm) { + if (null == userForm) { return "ERROR"; - }else{ + } else { boolean logged; try { @@ -16,10 +16,10 @@ public class LoginController { return "ERROR"; } - if(logged){ + if (logged) { loginService.setCurrentUser(userForm.getUsername()); return "OK"; - }else{ + } else { return "KO"; } } diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java index 4641fc1889..2cbff6c9d4 100644 --- a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginDao.java @@ -2,7 +2,7 @@ package org.baeldung.mocks.testCase; public class LoginDao { - public int login(UserForm userForm){ + public int login(UserForm userForm) { //actual call to a third party library return 0; } diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java index 2a20159393..d6a31a8047 100644 --- a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/LoginService.java @@ -11,7 +11,7 @@ public class LoginService { int loginResults = loginDao.login(userForm); - switch (loginResults){ + switch (loginResults) { case 1: return true; default: @@ -20,7 +20,7 @@ public class LoginService { } public void setCurrentUser(String username) { - if(null != username){ + if (null != username) { this.currentUser = username; } } diff --git a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java index d6ee444909..14136d0f31 100644 --- a/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java +++ b/mock-comparisons/src/main/java/org/baeldung/mocks/testCase/UserForm.java @@ -8,7 +8,7 @@ public class UserForm { public String username; - public String getUsername(){ + public String getUsername() { return username; } diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java b/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java index b80c28804a..25d2b91ede 100644 --- a/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java +++ b/mock-comparisons/src/test/java/org/baeldung/mocks/easymock/LoginControllerTest.java @@ -9,10 +9,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -/** - *

Test for LoginController using EasyMock.

- * Created by Alvaro on 12/06/2016. - */ @RunWith(EasyMockRunner.class) public class LoginControllerTest { @@ -133,7 +129,7 @@ public class LoginControllerTest { loginServicePartial.setLoginDao(loginDao); loginController.loginService = loginServicePartial; - + EasyMock.replay(loginDao); EasyMock.replay(loginServicePartial); diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java b/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java index d1c502ce55..621342fed2 100644 --- a/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java +++ b/mock-comparisons/src/test/java/org/baeldung/mocks/jmockit/LoginControllerTest.java @@ -12,10 +12,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -/** - *

Test for LoginController using JMockit.

- * Created by Alvaro on 12/06/2016. - */ @RunWith(JMockit.class) public class LoginControllerTest { @@ -32,7 +28,8 @@ public class LoginControllerTest { public void assertThatNoMethodHasBeenCalled() { loginController.login(null); // no method called - new FullVerifications(loginService) {}; + new FullVerifications(loginService) { + }; } @Test @@ -40,14 +37,16 @@ public class LoginControllerTest { final UserForm userForm = new UserForm(); userForm.username = "foo"; new Expectations() {{ - loginService.login(userForm); result = true; + loginService.login(userForm); + result = true; loginService.setCurrentUser("foo"); }}; String login = loginController.login(userForm); Assert.assertEquals("OK", login); - new FullVerifications(loginService) {}; + new FullVerifications(loginService) { + }; } @Test @@ -55,43 +54,51 @@ public class LoginControllerTest { final UserForm userForm = new UserForm(); userForm.username = "foo"; new Expectations() {{ - loginService.login(userForm); result = false; + loginService.login(userForm); + result = false; // no expectation for setCurrentUser }}; String login = loginController.login(userForm); Assert.assertEquals("KO", login); - new FullVerifications(loginService) {}; + new FullVerifications(loginService) { + }; } @Test public void mockExceptionThrowing() { final UserForm userForm = new UserForm(); new Expectations() {{ - loginService.login(userForm); result = new IllegalArgumentException(); + loginService.login(userForm); + result = new IllegalArgumentException(); // no expectation for setCurrentUser }}; String login = loginController.login(userForm); Assert.assertEquals("ERROR", login); - new FullVerifications(loginService) {}; + new FullVerifications(loginService) { + }; } @Test public void mockAnObjectToPassAround(@Mocked final UserForm userForm) { new Expectations() {{ - userForm.getUsername(); result = "foo"; - loginService.login(userForm); result = true; + userForm.getUsername(); + result = "foo"; + loginService.login(userForm); + result = true; loginService.setCurrentUser("foo"); }}; - + String login = loginController.login(userForm); Assert.assertEquals("OK", login); - new FullVerifications(loginService) {}; - new FullVerifications(userForm) {}; + new FullVerifications(loginService) { + }; + new FullVerifications(userForm) { + }; } @Test @@ -119,7 +126,8 @@ public class LoginControllerTest { String login = loginController.login(userForm); Assert.assertEquals("OK", login); - new FullVerifications(loginService) {}; + new FullVerifications(loginService) { + }; } @Test @@ -133,7 +141,8 @@ public class LoginControllerTest { userForm.username = "foo"; // let service's login use implementation so let's mock DAO call new Expectations() {{ - loginDao.login(userForm); result = 1; + loginDao.login(userForm); + result = 1; // no expectation for loginService.login partialLoginService.setCurrentUser("foo"); }}; @@ -142,7 +151,9 @@ public class LoginControllerTest { Assert.assertEquals("OK", login); // verify mocked call - new FullVerifications(partialLoginService) {}; - new FullVerifications(loginDao) {}; + new FullVerifications(partialLoginService) { + }; + new FullVerifications(loginDao) { + }; } } diff --git a/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java b/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java index 841dd493e6..59b28a2cb4 100644 --- a/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java +++ b/mock-comparisons/src/test/java/org/baeldung/mocks/mockito/LoginControllerTest.java @@ -9,10 +9,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.*; -/** - *

Test for LoginController using Mockito.

- * Created by Alvaro on 12/06/2016. - */ public class LoginControllerTest { @Mock From 85ad446ccfb81b6289be24f4795aedd22e813554 Mon Sep 17 00:00:00 2001 From: nguyennamthai Date: Sun, 19 Jun 2016 02:57:35 +0700 Subject: [PATCH 05/19] First commit of protocol buffers. (#452) --- spring-protobuf/pom.xml | 43 + .../com/baeldung/protobuf/Application.java | 68 + .../baeldung/protobuf/BaeldungTraining.java | 2719 +++++++++++++++++ .../baeldung/protobuf/CourseController.java | 19 + .../baeldung/protobuf/CourseRepository.java | 17 + .../src/main/resources/baeldung.proto | 30 + .../baeldung/protobuf/ApplicationTest.java | 76 + 7 files changed, 2972 insertions(+) create mode 100644 spring-protobuf/pom.xml create mode 100644 spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java create mode 100644 spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java create mode 100644 spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java create mode 100644 spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java create mode 100644 spring-protobuf/src/main/resources/baeldung.proto create mode 100644 spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java diff --git a/spring-protobuf/pom.xml b/spring-protobuf/pom.xml new file mode 100644 index 0000000000..28338f26c3 --- /dev/null +++ b/spring-protobuf/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + com.baeldung + spring-protobuf + 0.1-SNAPSHOT + spring-protobuf + + + org.springframework.boot + spring-boot-starter-parent + 1.2.4.RELEASE + + + + + com.google.protobuf + protobuf-java + 3.0.0-beta-3 + + + com.googlecode.protobuf-java-format + protobuf-java-format + 1.4 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java new file mode 100644 index 0000000000..38a49367a3 --- /dev/null +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java @@ -0,0 +1,68 @@ +package com.baeldung.protobuf; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +import com.baeldung.protobuf.BaeldungTraining.Course; +import com.baeldung.protobuf.BaeldungTraining.Student; +import com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber; +import com.baeldung.protobuf.BaeldungTraining.Student.PhoneType; + +@SpringBootApplication +public class Application { + @Bean + RestTemplate restTemplate(ProtobufHttpMessageConverter hmc) { + return new RestTemplate(Arrays.asList(hmc)); + } + + @Bean + ProtobufHttpMessageConverter protobufHttpMessageConverter() { + return new ProtobufHttpMessageConverter(); + } + + @Bean + public CourseRepository createDummyCourses() { + Map dummy = new HashMap<>(); + + Course course1 = Course.newBuilder().setId(1).setCourseName("REST with Spring").addAllStudent(createDummyStudents()).build(); + Course course2 = Course.newBuilder().setId(2).setCourseName("Learn Spring Security").addAllStudent(new ArrayList()).build(); + + dummy.put(course1.getId(), course1); + dummy.put(course2.getId(), course2); + + return new CourseRepository(dummy); + } + + private List createDummyStudents() { + List studentList = new ArrayList<>(); + + PhoneNumber phone1 = createPhone("123456", PhoneType.MOBILE); + Student student1 = createStudent(1, "John", "Doe", "john.doe@baeldung.com", Arrays.asList(phone1)); + + PhoneNumber phone2 = createPhone("234567", PhoneType.LANDLINE); + Student student2 = createStudent(2, "Richard", "Roe", "richard.roe@baeldung.com", Arrays.asList(phone2)); + + PhoneNumber phone3_1 = createPhone("345678", PhoneType.MOBILE); + PhoneNumber phone3_2 = createPhone("456789", PhoneType.LANDLINE); + Student student3 = createStudent(3, "Jane", "Doe", "jane.doe@baeldung.com", Arrays.asList(phone3_1, phone3_2)); + + studentList.addAll(Arrays.asList(student1, student2, student3)); + return studentList; + } + + private Student createStudent(int id, String firstName, String lastName, String email, List phones) { + return Student.newBuilder().setId(id).setFirstName(firstName).setLastName(lastName).setEmail(email).addAllPhone(phones).build(); + } + + private PhoneNumber createPhone(String number, PhoneType type) { + return PhoneNumber.newBuilder().setNumber(number).setType(type).build(); + } +} \ No newline at end of file diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java new file mode 100644 index 0000000000..3869ebfaeb --- /dev/null +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java @@ -0,0 +1,2719 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: resources/baeldung.proto + +package com.baeldung.protobuf; + +public final class BaeldungTraining { + private BaeldungTraining() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface CourseOrBuilder extends + // @@protoc_insertion_point(interface_extends:baeldung.Course) + com.google.protobuf.MessageOrBuilder { + + /** + * optional int32 id = 1; + */ + int getId(); + + /** + * optional string course_name = 2; + */ + java.lang.String getCourseName(); + /** + * optional string course_name = 2; + */ + com.google.protobuf.ByteString + getCourseNameBytes(); + + /** + * repeated .baeldung.Student student = 3; + */ + java.util.List + getStudentList(); + /** + * repeated .baeldung.Student student = 3; + */ + com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index); + /** + * repeated .baeldung.Student student = 3; + */ + int getStudentCount(); + /** + * repeated .baeldung.Student student = 3; + */ + java.util.List + getStudentOrBuilderList(); + /** + * repeated .baeldung.Student student = 3; + */ + com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder( + int index); + } + /** + * Protobuf type {@code baeldung.Course} + */ + public static final class Course extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:baeldung.Course) + CourseOrBuilder { + // Use Course.newBuilder() to construct. + private Course(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private Course() { + id_ = 0; + courseName_ = ""; + student_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private Course( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 8: { + + id_ = input.readInt32(); + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + courseName_ = s; + break; + } + case 26: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + student_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + student_.add(input.readMessage(com.baeldung.protobuf.BaeldungTraining.Student.parser(), extensionRegistry)); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + student_ = java.util.Collections.unmodifiableList(student_); + } + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.baeldung.protobuf.BaeldungTraining.Course.class, com.baeldung.protobuf.BaeldungTraining.Course.Builder.class); + } + + private int bitField0_; + public static final int ID_FIELD_NUMBER = 1; + private int id_; + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + + public static final int COURSE_NAME_FIELD_NUMBER = 2; + private volatile java.lang.Object courseName_; + /** + * optional string course_name = 2; + */ + public java.lang.String getCourseName() { + java.lang.Object ref = courseName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + courseName_ = s; + return s; + } + } + /** + * optional string course_name = 2; + */ + public com.google.protobuf.ByteString + getCourseNameBytes() { + java.lang.Object ref = courseName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + courseName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int STUDENT_FIELD_NUMBER = 3; + private java.util.List student_; + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentList() { + return student_; + } + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List + getStudentOrBuilderList() { + return student_; + } + /** + * repeated .baeldung.Student student = 3; + */ + public int getStudentCount() { + return student_.size(); + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index) { + return student_.get(index); + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder( + int index) { + return student_.get(index); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (id_ != 0) { + output.writeInt32(1, id_); + } + if (!getCourseNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, courseName_); + } + for (int i = 0; i < student_.size(); i++) { + output.writeMessage(3, student_.get(i)); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (id_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, id_); + } + if (!getCourseNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, courseName_); + } + for (int i = 0; i < student_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(3, student_.get(i)); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Course prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code baeldung.Course} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:baeldung.Course) + com.baeldung.protobuf.BaeldungTraining.CourseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.baeldung.protobuf.BaeldungTraining.Course.class, com.baeldung.protobuf.BaeldungTraining.Course.Builder.class); + } + + // Construct using com.baeldung.protobuf.BaeldungTraining.Course.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getStudentFieldBuilder(); + } + } + public Builder clear() { + super.clear(); + id_ = 0; + + courseName_ = ""; + + if (studentBuilder_ == null) { + student_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + } else { + studentBuilder_.clear(); + } + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; + } + + public com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstanceForType() { + return com.baeldung.protobuf.BaeldungTraining.Course.getDefaultInstance(); + } + + public com.baeldung.protobuf.BaeldungTraining.Course build() { + com.baeldung.protobuf.BaeldungTraining.Course result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.baeldung.protobuf.BaeldungTraining.Course buildPartial() { + com.baeldung.protobuf.BaeldungTraining.Course result = new com.baeldung.protobuf.BaeldungTraining.Course(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + result.id_ = id_; + result.courseName_ = courseName_; + if (studentBuilder_ == null) { + if (((bitField0_ & 0x00000004) == 0x00000004)) { + student_ = java.util.Collections.unmodifiableList(student_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.student_ = student_; + } else { + result.student_ = studentBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.baeldung.protobuf.BaeldungTraining.Course) { + return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Course)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Course other) { + if (other == com.baeldung.protobuf.BaeldungTraining.Course.getDefaultInstance()) return this; + if (other.getId() != 0) { + setId(other.getId()); + } + if (!other.getCourseName().isEmpty()) { + courseName_ = other.courseName_; + onChanged(); + } + if (studentBuilder_ == null) { + if (!other.student_.isEmpty()) { + if (student_.isEmpty()) { + student_ = other.student_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureStudentIsMutable(); + student_.addAll(other.student_); + } + onChanged(); + } + } else { + if (!other.student_.isEmpty()) { + if (studentBuilder_.isEmpty()) { + studentBuilder_.dispose(); + studentBuilder_ = null; + student_ = other.student_; + bitField0_ = (bitField0_ & ~0x00000004); + studentBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getStudentFieldBuilder() : null; + } else { + studentBuilder_.addAllMessages(other.student_); + } + } + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.baeldung.protobuf.BaeldungTraining.Course parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Course) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private int id_ ; + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + /** + * optional int32 id = 1; + */ + public Builder setId(int value) { + + id_ = value; + onChanged(); + return this; + } + /** + * optional int32 id = 1; + */ + public Builder clearId() { + + id_ = 0; + onChanged(); + return this; + } + + private java.lang.Object courseName_ = ""; + /** + * optional string course_name = 2; + */ + public java.lang.String getCourseName() { + java.lang.Object ref = courseName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + courseName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string course_name = 2; + */ + public com.google.protobuf.ByteString + getCourseNameBytes() { + java.lang.Object ref = courseName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + courseName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string course_name = 2; + */ + public Builder setCourseName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + courseName_ = value; + onChanged(); + return this; + } + /** + * optional string course_name = 2; + */ + public Builder clearCourseName() { + + courseName_ = getDefaultInstance().getCourseName(); + onChanged(); + return this; + } + /** + * optional string course_name = 2; + */ + public Builder setCourseNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + courseName_ = value; + onChanged(); + return this; + } + + private java.util.List student_ = + java.util.Collections.emptyList(); + private void ensureStudentIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + student_ = new java.util.ArrayList(student_); + bitField0_ |= 0x00000004; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + com.baeldung.protobuf.BaeldungTraining.Student, com.baeldung.protobuf.BaeldungTraining.Student.Builder, com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder> studentBuilder_; + + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentList() { + if (studentBuilder_ == null) { + return java.util.Collections.unmodifiableList(student_); + } else { + return studentBuilder_.getMessageList(); + } + } + /** + * repeated .baeldung.Student student = 3; + */ + public int getStudentCount() { + if (studentBuilder_ == null) { + return student_.size(); + } else { + return studentBuilder_.getCount(); + } + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index) { + if (studentBuilder_ == null) { + return student_.get(index); + } else { + return studentBuilder_.getMessage(index); + } + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder setStudent( + int index, com.baeldung.protobuf.BaeldungTraining.Student value) { + if (studentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStudentIsMutable(); + student_.set(index, value); + onChanged(); + } else { + studentBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder setStudent( + int index, com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.set(index, builderForValue.build()); + onChanged(); + } else { + studentBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent(com.baeldung.protobuf.BaeldungTraining.Student value) { + if (studentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStudentIsMutable(); + student_.add(value); + onChanged(); + } else { + studentBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent( + int index, com.baeldung.protobuf.BaeldungTraining.Student value) { + if (studentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStudentIsMutable(); + student_.add(index, value); + onChanged(); + } else { + studentBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent( + com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.add(builderForValue.build()); + onChanged(); + } else { + studentBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent( + int index, com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.add(index, builderForValue.build()); + onChanged(); + } else { + studentBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addAllStudent( + java.lang.Iterable values) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, student_); + onChanged(); + } else { + studentBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder clearStudent() { + if (studentBuilder_ == null) { + student_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + } else { + studentBuilder_.clear(); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public Builder removeStudent(int index) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.remove(index); + onChanged(); + } else { + studentBuilder_.remove(index); + } + return this; + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.Builder getStudentBuilder( + int index) { + return getStudentFieldBuilder().getBuilder(index); + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder( + int index) { + if (studentBuilder_ == null) { + return student_.get(index); } else { + return studentBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List + getStudentOrBuilderList() { + if (studentBuilder_ != null) { + return studentBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(student_); + } + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.Builder addStudentBuilder() { + return getStudentFieldBuilder().addBuilder( + com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()); + } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.Builder addStudentBuilder( + int index) { + return getStudentFieldBuilder().addBuilder( + index, com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()); + } + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List + getStudentBuilderList() { + return getStudentFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + com.baeldung.protobuf.BaeldungTraining.Student, com.baeldung.protobuf.BaeldungTraining.Student.Builder, com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder> + getStudentFieldBuilder() { + if (studentBuilder_ == null) { + studentBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + com.baeldung.protobuf.BaeldungTraining.Student, com.baeldung.protobuf.BaeldungTraining.Student.Builder, com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder>( + student_, + ((bitField0_ & 0x00000004) == 0x00000004), + getParentForChildren(), + isClean()); + student_ = null; + } + return studentBuilder_; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:baeldung.Course) + } + + // @@protoc_insertion_point(class_scope:baeldung.Course) + private static final com.baeldung.protobuf.BaeldungTraining.Course DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Course(); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public Course parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new Course(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + public interface StudentOrBuilder extends + // @@protoc_insertion_point(interface_extends:baeldung.Student) + com.google.protobuf.MessageOrBuilder { + + /** + * optional int32 id = 1; + */ + int getId(); + + /** + * optional string first_name = 2; + */ + java.lang.String getFirstName(); + /** + * optional string first_name = 2; + */ + com.google.protobuf.ByteString + getFirstNameBytes(); + + /** + * optional string last_name = 3; + */ + java.lang.String getLastName(); + /** + * optional string last_name = 3; + */ + com.google.protobuf.ByteString + getLastNameBytes(); + + /** + * optional string email = 4; + */ + java.lang.String getEmail(); + /** + * optional string email = 4; + */ + com.google.protobuf.ByteString + getEmailBytes(); + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + java.util.List + getPhoneList(); + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index); + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + int getPhoneCount(); + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + java.util.List + getPhoneOrBuilderList(); + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder( + int index); + } + /** + * Protobuf type {@code baeldung.Student} + */ + public static final class Student extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:baeldung.Student) + StudentOrBuilder { + // Use Student.newBuilder() to construct. + private Student(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private Student() { + id_ = 0; + firstName_ = ""; + lastName_ = ""; + email_ = ""; + phone_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private Student( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 8: { + + id_ = input.readInt32(); + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + firstName_ = s; + break; + } + case 26: { + java.lang.String s = input.readStringRequireUtf8(); + + lastName_ = s; + break; + } + case 34: { + java.lang.String s = input.readStringRequireUtf8(); + + email_ = s; + break; + } + case 42: { + if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000010; + } + phone_.add(input.readMessage(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.parser(), extensionRegistry)); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = java.util.Collections.unmodifiableList(phone_); + } + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.baeldung.protobuf.BaeldungTraining.Student.class, com.baeldung.protobuf.BaeldungTraining.Student.Builder.class); + } + + /** + * Protobuf enum {@code baeldung.Student.PhoneType} + */ + public enum PhoneType + implements com.google.protobuf.ProtocolMessageEnum { + /** + * MOBILE = 0; + */ + MOBILE(0), + /** + * LANDLINE = 1; + */ + LANDLINE(1), + UNRECOGNIZED(-1), + ; + + /** + * MOBILE = 0; + */ + public static final int MOBILE_VALUE = 0; + /** + * LANDLINE = 1; + */ + public static final int LANDLINE_VALUE = 1; + + + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static PhoneType valueOf(int value) { + return forNumber(value); + } + + public static PhoneType forNumber(int value) { + switch (value) { + case 0: return MOBILE; + case 1: return LANDLINE; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + PhoneType> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public PhoneType findValueByNumber(int number) { + return PhoneType.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(ordinal()); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.Student.getDescriptor().getEnumTypes().get(0); + } + + private static final PhoneType[] VALUES = values(); + + public static PhoneType valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private PhoneType(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:baeldung.Student.PhoneType) + } + + public interface PhoneNumberOrBuilder extends + // @@protoc_insertion_point(interface_extends:baeldung.Student.PhoneNumber) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string number = 1; + */ + java.lang.String getNumber(); + /** + * optional string number = 1; + */ + com.google.protobuf.ByteString + getNumberBytes(); + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + int getTypeValue(); + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType(); + } + /** + * Protobuf type {@code baeldung.Student.PhoneNumber} + */ + public static final class PhoneNumber extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:baeldung.Student.PhoneNumber) + PhoneNumberOrBuilder { + // Use PhoneNumber.newBuilder() to construct. + private PhoneNumber(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } + private PhoneNumber() { + number_ = ""; + type_ = 0; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } + private PhoneNumber( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + number_ = s; + break; + } + case 16: { + int rawValue = input.readEnum(); + + type_ = rawValue; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.class, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder.class); + } + + public static final int NUMBER_FIELD_NUMBER = 1; + private volatile java.lang.Object number_; + /** + * optional string number = 1; + */ + public java.lang.String getNumber() { + java.lang.Object ref = number_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + number_ = s; + return s; + } + } + /** + * optional string number = 1; + */ + public com.google.protobuf.ByteString + getNumberBytes() { + java.lang.Object ref = number_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + number_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TYPE_FIELD_NUMBER = 2; + private int type_; + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public int getTypeValue() { + return type_; + } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneType result = com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.forNumber(type_); + return result == null ? com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.UNRECOGNIZED : result; + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getNumberBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, number_); + } + if (type_ != com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.MOBILE.getNumber()) { + output.writeEnum(2, type_); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getNumberBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(1, number_); + } + if (type_ != com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.MOBILE.getNumber()) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(2, type_); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code baeldung.Student.PhoneNumber} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:baeldung.Student.PhoneNumber) + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.class, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder.class); + } + + // Construct using com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + number_ = ""; + + type_ = 0; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstanceForType() { + return com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance(); + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber build() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber buildPartial() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber result = new com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber(this); + result.number_ = number_; + result.type_ = type_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) { + return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber other) { + if (other == com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()) return this; + if (!other.getNumber().isEmpty()) { + number_ = other.number_; + onChanged(); + } + if (other.type_ != 0) { + setTypeValue(other.getTypeValue()); + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object number_ = ""; + /** + * optional string number = 1; + */ + public java.lang.String getNumber() { + java.lang.Object ref = number_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + number_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string number = 1; + */ + public com.google.protobuf.ByteString + getNumberBytes() { + java.lang.Object ref = number_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + number_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string number = 1; + */ + public Builder setNumber( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + number_ = value; + onChanged(); + return this; + } + /** + * optional string number = 1; + */ + public Builder clearNumber() { + + number_ = getDefaultInstance().getNumber(); + onChanged(); + return this; + } + /** + * optional string number = 1; + */ + public Builder setNumberBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + number_ = value; + onChanged(); + return this; + } + + private int type_ = 0; + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public int getTypeValue() { + return type_; + } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public Builder setTypeValue(int value) { + type_ = value; + onChanged(); + return this; + } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneType result = com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.forNumber(type_); + return result == null ? com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.UNRECOGNIZED : result; + } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public Builder setType(com.baeldung.protobuf.BaeldungTraining.Student.PhoneType value) { + if (value == null) { + throw new NullPointerException(); + } + + type_ = value.getNumber(); + onChanged(); + return this; + } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public Builder clearType() { + + type_ = 0; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:baeldung.Student.PhoneNumber) + } + + // @@protoc_insertion_point(class_scope:baeldung.Student.PhoneNumber) + private static final com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber(); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public PhoneNumber parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new PhoneNumber(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private int bitField0_; + public static final int ID_FIELD_NUMBER = 1; + private int id_; + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + + public static final int FIRST_NAME_FIELD_NUMBER = 2; + private volatile java.lang.Object firstName_; + /** + * optional string first_name = 2; + */ + public java.lang.String getFirstName() { + java.lang.Object ref = firstName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + firstName_ = s; + return s; + } + } + /** + * optional string first_name = 2; + */ + public com.google.protobuf.ByteString + getFirstNameBytes() { + java.lang.Object ref = firstName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + firstName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int LAST_NAME_FIELD_NUMBER = 3; + private volatile java.lang.Object lastName_; + /** + * optional string last_name = 3; + */ + public java.lang.String getLastName() { + java.lang.Object ref = lastName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lastName_ = s; + return s; + } + } + /** + * optional string last_name = 3; + */ + public com.google.protobuf.ByteString + getLastNameBytes() { + java.lang.Object ref = lastName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + lastName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int EMAIL_FIELD_NUMBER = 4; + private volatile java.lang.Object email_; + /** + * optional string email = 4; + */ + public java.lang.String getEmail() { + java.lang.Object ref = email_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + email_ = s; + return s; + } + } + /** + * optional string email = 4; + */ + public com.google.protobuf.ByteString + getEmailBytes() { + java.lang.Object ref = email_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + email_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PHONE_FIELD_NUMBER = 5; + private java.util.List phone_; + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneList() { + return phone_; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List + getPhoneOrBuilderList() { + return phone_; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public int getPhoneCount() { + return phone_.size(); + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index) { + return phone_.get(index); + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder( + int index) { + return phone_.get(index); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (id_ != 0) { + output.writeInt32(1, id_); + } + if (!getFirstNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, firstName_); + } + if (!getLastNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 3, lastName_); + } + if (!getEmailBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 4, email_); + } + for (int i = 0; i < phone_.size(); i++) { + output.writeMessage(5, phone_.get(i)); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (id_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, id_); + } + if (!getFirstNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, firstName_); + } + if (!getLastNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(3, lastName_); + } + if (!getEmailBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(4, email_); + } + for (int i = 0; i < phone_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(5, phone_.get(i)); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input); + } + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessage + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Student prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code baeldung.Student} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:baeldung.Student) + com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.baeldung.protobuf.BaeldungTraining.Student.class, com.baeldung.protobuf.BaeldungTraining.Student.Builder.class); + } + + // Construct using com.baeldung.protobuf.BaeldungTraining.Student.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getPhoneFieldBuilder(); + } + } + public Builder clear() { + super.clear(); + id_ = 0; + + firstName_ = ""; + + lastName_ = ""; + + email_ = ""; + + if (phoneBuilder_ == null) { + phone_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000010); + } else { + phoneBuilder_.clear(); + } + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; + } + + public com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstanceForType() { + return com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance(); + } + + public com.baeldung.protobuf.BaeldungTraining.Student build() { + com.baeldung.protobuf.BaeldungTraining.Student result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.baeldung.protobuf.BaeldungTraining.Student buildPartial() { + com.baeldung.protobuf.BaeldungTraining.Student result = new com.baeldung.protobuf.BaeldungTraining.Student(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + result.id_ = id_; + result.firstName_ = firstName_; + result.lastName_ = lastName_; + result.email_ = email_; + if (phoneBuilder_ == null) { + if (((bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = java.util.Collections.unmodifiableList(phone_); + bitField0_ = (bitField0_ & ~0x00000010); + } + result.phone_ = phone_; + } else { + result.phone_ = phoneBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.baeldung.protobuf.BaeldungTraining.Student) { + return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Student)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Student other) { + if (other == com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()) return this; + if (other.getId() != 0) { + setId(other.getId()); + } + if (!other.getFirstName().isEmpty()) { + firstName_ = other.firstName_; + onChanged(); + } + if (!other.getLastName().isEmpty()) { + lastName_ = other.lastName_; + onChanged(); + } + if (!other.getEmail().isEmpty()) { + email_ = other.email_; + onChanged(); + } + if (phoneBuilder_ == null) { + if (!other.phone_.isEmpty()) { + if (phone_.isEmpty()) { + phone_ = other.phone_; + bitField0_ = (bitField0_ & ~0x00000010); + } else { + ensurePhoneIsMutable(); + phone_.addAll(other.phone_); + } + onChanged(); + } + } else { + if (!other.phone_.isEmpty()) { + if (phoneBuilder_.isEmpty()) { + phoneBuilder_.dispose(); + phoneBuilder_ = null; + phone_ = other.phone_; + bitField0_ = (bitField0_ & ~0x00000010); + phoneBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getPhoneFieldBuilder() : null; + } else { + phoneBuilder_.addAllMessages(other.phone_); + } + } + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.baeldung.protobuf.BaeldungTraining.Student parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Student) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private int id_ ; + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + /** + * optional int32 id = 1; + */ + public Builder setId(int value) { + + id_ = value; + onChanged(); + return this; + } + /** + * optional int32 id = 1; + */ + public Builder clearId() { + + id_ = 0; + onChanged(); + return this; + } + + private java.lang.Object firstName_ = ""; + /** + * optional string first_name = 2; + */ + public java.lang.String getFirstName() { + java.lang.Object ref = firstName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + firstName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string first_name = 2; + */ + public com.google.protobuf.ByteString + getFirstNameBytes() { + java.lang.Object ref = firstName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + firstName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string first_name = 2; + */ + public Builder setFirstName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + firstName_ = value; + onChanged(); + return this; + } + /** + * optional string first_name = 2; + */ + public Builder clearFirstName() { + + firstName_ = getDefaultInstance().getFirstName(); + onChanged(); + return this; + } + /** + * optional string first_name = 2; + */ + public Builder setFirstNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + firstName_ = value; + onChanged(); + return this; + } + + private java.lang.Object lastName_ = ""; + /** + * optional string last_name = 3; + */ + public java.lang.String getLastName() { + java.lang.Object ref = lastName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lastName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string last_name = 3; + */ + public com.google.protobuf.ByteString + getLastNameBytes() { + java.lang.Object ref = lastName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + lastName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string last_name = 3; + */ + public Builder setLastName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + lastName_ = value; + onChanged(); + return this; + } + /** + * optional string last_name = 3; + */ + public Builder clearLastName() { + + lastName_ = getDefaultInstance().getLastName(); + onChanged(); + return this; + } + /** + * optional string last_name = 3; + */ + public Builder setLastNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + lastName_ = value; + onChanged(); + return this; + } + + private java.lang.Object email_ = ""; + /** + * optional string email = 4; + */ + public java.lang.String getEmail() { + java.lang.Object ref = email_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + email_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string email = 4; + */ + public com.google.protobuf.ByteString + getEmailBytes() { + java.lang.Object ref = email_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + email_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string email = 4; + */ + public Builder setEmail( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + email_ = value; + onChanged(); + return this; + } + /** + * optional string email = 4; + */ + public Builder clearEmail() { + + email_ = getDefaultInstance().getEmail(); + onChanged(); + return this; + } + /** + * optional string email = 4; + */ + public Builder setEmailBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + email_ = value; + onChanged(); + return this; + } + + private java.util.List phone_ = + java.util.Collections.emptyList(); + private void ensurePhoneIsMutable() { + if (!((bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = new java.util.ArrayList(phone_); + bitField0_ |= 0x00000010; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder> phoneBuilder_; + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneList() { + if (phoneBuilder_ == null) { + return java.util.Collections.unmodifiableList(phone_); + } else { + return phoneBuilder_.getMessageList(); + } + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public int getPhoneCount() { + if (phoneBuilder_ == null) { + return phone_.size(); + } else { + return phoneBuilder_.getCount(); + } + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index) { + if (phoneBuilder_ == null) { + return phone_.get(index); + } else { + return phoneBuilder_.getMessage(index); + } + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder setPhone( + int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.set(index, value); + onChanged(); + } else { + phoneBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder setPhone( + int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.set(index, builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.add(value); + onChanged(); + } else { + phoneBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone( + int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.add(index, value); + onChanged(); + } else { + phoneBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone( + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.add(builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone( + int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.add(index, builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addAllPhone( + java.lang.Iterable values) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, phone_); + onChanged(); + } else { + phoneBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder clearPhone() { + if (phoneBuilder_ == null) { + phone_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000010); + onChanged(); + } else { + phoneBuilder_.clear(); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder removePhone(int index) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.remove(index); + onChanged(); + } else { + phoneBuilder_.remove(index); + } + return this; + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder getPhoneBuilder( + int index) { + return getPhoneFieldBuilder().getBuilder(index); + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder( + int index) { + if (phoneBuilder_ == null) { + return phone_.get(index); } else { + return phoneBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List + getPhoneOrBuilderList() { + if (phoneBuilder_ != null) { + return phoneBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(phone_); + } + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder addPhoneBuilder() { + return getPhoneFieldBuilder().addBuilder( + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()); + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder addPhoneBuilder( + int index) { + return getPhoneFieldBuilder().addBuilder( + index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()); + } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List + getPhoneBuilderList() { + return getPhoneFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder> + getPhoneFieldBuilder() { + if (phoneBuilder_ == null) { + phoneBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder>( + phone_, + ((bitField0_ & 0x00000010) == 0x00000010), + getParentForChildren(), + isClean()); + phone_ = null; + } + return phoneBuilder_; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + + // @@protoc_insertion_point(builder_scope:baeldung.Student) + } + + // @@protoc_insertion_point(class_scope:baeldung.Student) + private static final com.baeldung.protobuf.BaeldungTraining.Student DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Student(); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public Student parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new Student(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_baeldung_Course_descriptor; + private static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_baeldung_Course_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_baeldung_Student_descriptor; + private static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_baeldung_Student_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_baeldung_Student_PhoneNumber_descriptor; + private static final + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\030resources/baeldung.proto\022\010baeldung\"M\n\006" + + "Course\022\n\n\002id\030\001 \001(\005\022\023\n\013course_name\030\002 \001(\t\022" + + "\"\n\007student\030\003 \003(\0132\021.baeldung.Student\"\352\001\n\007" + + "Student\022\n\n\002id\030\001 \001(\005\022\022\n\nfirst_name\030\002 \001(\t\022" + + "\021\n\tlast_name\030\003 \001(\t\022\r\n\005email\030\004 \001(\t\022,\n\005pho" + + "ne\030\005 \003(\0132\035.baeldung.Student.PhoneNumber\032" + + "H\n\013PhoneNumber\022\016\n\006number\030\001 \001(\t\022)\n\004type\030\002" + + " \001(\0162\033.baeldung.Student.PhoneType\"%\n\tPho" + + "neType\022\n\n\006MOBILE\020\000\022\014\n\010LANDLINE\020\001B)\n\025com." + + "baeldung.protobufB\020BaeldungTrainingb\006pro", + "to3" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_baeldung_Course_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_baeldung_Course_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_baeldung_Course_descriptor, + new java.lang.String[] { "Id", "CourseName", "Student", }); + internal_static_baeldung_Student_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_baeldung_Student_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_baeldung_Student_descriptor, + new java.lang.String[] { "Id", "FirstName", "LastName", "Email", "Phone", }); + internal_static_baeldung_Student_PhoneNumber_descriptor = + internal_static_baeldung_Student_descriptor.getNestedTypes().get(0); + internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_baeldung_Student_PhoneNumber_descriptor, + new java.lang.String[] { "Number", "Type", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java new file mode 100644 index 0000000000..027f296fa2 --- /dev/null +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java @@ -0,0 +1,19 @@ +package com.baeldung.protobuf; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.protobuf.BaeldungTraining.Course; + +@RestController +public class CourseController { + @Autowired + CourseRepository courseRepo; + + @RequestMapping("/courses/{id}") + Course customer(@PathVariable Integer id) { + return courseRepo.getCourse(id); + } +} diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java new file mode 100644 index 0000000000..aa00b2a850 --- /dev/null +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java @@ -0,0 +1,17 @@ +package com.baeldung.protobuf; + +import java.util.Map; + +import com.baeldung.protobuf.BaeldungTraining.Course; + +public class CourseRepository { + Map courses; + + public CourseRepository (Map courses) { + this.courses = courses; + } + + public Course getCourse(int id) { + return courses.get(id); + } +} diff --git a/spring-protobuf/src/main/resources/baeldung.proto b/spring-protobuf/src/main/resources/baeldung.proto new file mode 100644 index 0000000000..20124c34c4 --- /dev/null +++ b/spring-protobuf/src/main/resources/baeldung.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; + +package baeldung; + +option java_package = "com.baeldung.protobuf"; +option java_outer_classname = "BaeldungTraining"; + +message Course { + int32 id = 1; + string course_name = 2; + repeated Student student = 3; +} + +message Student { + int32 id = 1; + string first_name = 2; + string last_name = 3; + string email = 4; + repeated PhoneNumber phone = 5; + + message PhoneNumber { + string number = 1; + PhoneType type = 2; + } + + enum PhoneType { + MOBILE = 0; + LANDLINE = 1; + } +} \ No newline at end of file diff --git a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java new file mode 100644 index 0000000000..026fa04fa2 --- /dev/null +++ b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java @@ -0,0 +1,76 @@ +package com.baeldung.protobuf; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.client.RestTemplate; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.baeldung.protobuf.BaeldungTraining.Course; +import com.googlecode.protobuf.format.JsonFormat; + +import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.containsString; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +@WebIntegrationTest +public class ApplicationTest { + private static final String COURSE1_URL = "http://localhost:8080/courses/1"; + @Autowired + private RestTemplate restTemplate; + + @Test + public void whenUsingRestTemplate_thenSucceed() { + ResponseEntity course = restTemplate.getForEntity(COURSE1_URL, Course.class); + assertResponse(course.toString()); + } + + @Test + public void whenUsingHttpClient_thenSucceed() throws IOException { + InputStream responseStream = executeHttpRequest(COURSE1_URL); + String jsonOutput = convertProtobufMessageStreamToJsonString(responseStream); + assertResponse(jsonOutput); + } + + private InputStream executeHttpRequest(String url) throws IOException { + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpGet request = new HttpGet(url); + HttpResponse httpResponse = httpClient.execute(request); + return httpResponse.getEntity().getContent(); + } + + private String convertProtobufMessageStreamToJsonString(InputStream protobufStream) throws IOException { + JsonFormat jsonFormat = new JsonFormat(); + Course course = Course.parseFrom(protobufStream); + return jsonFormat.printToString(course); + } + + private void assertResponse(String response) { + assertThat(response, containsString("id")); + assertThat(response, containsString("course_name")); + assertThat(response, containsString("REST with Spring")); + assertThat(response, containsString("student")); + assertThat(response, containsString("first_name")); + assertThat(response, containsString("last_name")); + assertThat(response, containsString("email")); + assertThat(response, containsString("john.doe@baeldung.com")); + assertThat(response, containsString("richard.roe@baeldung.com")); + assertThat(response, containsString("jane.doe@baeldung.com")); + assertThat(response, containsString("phone")); + assertThat(response, containsString("number")); + assertThat(response, containsString("type")); + } +} \ No newline at end of file From c77a992a523e6f62892ca235c013a5297c73fc4b Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 18 Jun 2016 22:08:24 +0200 Subject: [PATCH 06/19] Refactor spring-protobuf --- pom.xml | 1 + spring-protobuf/pom.xml | 15 +++++ .../com/baeldung/protobuf/Application.java | 56 ++++++++++--------- .../baeldung/protobuf/CourseController.java | 1 + .../baeldung/protobuf/CourseRepository.java | 7 ++- .../baeldung/protobuf/ApplicationTest.java | 19 +++---- 6 files changed, 61 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index f16861cc68..19c602091d 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,7 @@ spring-mvc-no-xml spring-mvc-xml spring-openid + spring-protobuf spring-quartz spring-rest diff --git a/spring-protobuf/pom.xml b/spring-protobuf/pom.xml index 28338f26c3..1275d72edf 100644 --- a/spring-protobuf/pom.xml +++ b/spring-protobuf/pom.xml @@ -40,4 +40,19 @@ 4.5.2
+ + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java index 38a49367a3..ce5453af61 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java @@ -1,23 +1,23 @@ package com.baeldung.protobuf; +import com.baeldung.protobuf.BaeldungTraining.Course; +import com.baeldung.protobuf.BaeldungTraining.Student; +import com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber; +import com.baeldung.protobuf.BaeldungTraining.Student.PhoneType; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; -import org.springframework.web.client.RestTemplate; - -import com.baeldung.protobuf.BaeldungTraining.Course; -import com.baeldung.protobuf.BaeldungTraining.Student; -import com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber; -import com.baeldung.protobuf.BaeldungTraining.Student.PhoneType; - @SpringBootApplication public class Application { + @Bean RestTemplate restTemplate(ProtobufHttpMessageConverter hmc) { return new RestTemplate(Arrays.asList(hmc)); @@ -29,21 +29,28 @@ public class Application { } @Bean - public CourseRepository createDummyCourses() { - Map dummy = new HashMap<>(); - - Course course1 = Course.newBuilder().setId(1).setCourseName("REST with Spring").addAllStudent(createDummyStudents()).build(); - Course course2 = Course.newBuilder().setId(2).setCourseName("Learn Spring Security").addAllStudent(new ArrayList()).build(); - - dummy.put(course1.getId(), course1); - dummy.put(course2.getId(), course2); - - return new CourseRepository(dummy); + public CourseRepository createStubCourses() { + Map courses = new HashMap<>(); + + Course course1 = Course.newBuilder() + .setId(1) + .setCourseName("REST with Spring") + .addAllStudent(createStubStudents()) + .build(); + + Course course2 = Course.newBuilder() + .setId(2) + .setCourseName("Learn Spring Security") + .addAllStudent(new ArrayList<>()) + .build(); + + courses.put(course1.getId(), course1); + courses.put(course2.getId(), course2); + + return new CourseRepository(courses); } - private List createDummyStudents() { - List studentList = new ArrayList<>(); - + private List createStubStudents() { PhoneNumber phone1 = createPhone("123456", PhoneType.MOBILE); Student student1 = createStudent(1, "John", "Doe", "john.doe@baeldung.com", Arrays.asList(phone1)); @@ -54,8 +61,7 @@ public class Application { PhoneNumber phone3_2 = createPhone("456789", PhoneType.LANDLINE); Student student3 = createStudent(3, "Jane", "Doe", "jane.doe@baeldung.com", Arrays.asList(phone3_1, phone3_2)); - studentList.addAll(Arrays.asList(student1, student2, student3)); - return studentList; + return Arrays.asList(student1, student2, student3); } private Student createStudent(int id, String firstName, String lastName, String email, List phones) { diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java index 027f296fa2..807b9a9ea4 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseController.java @@ -9,6 +9,7 @@ import com.baeldung.protobuf.BaeldungTraining.Course; @RestController public class CourseController { + @Autowired CourseRepository courseRepo; diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java index aa00b2a850..60f24abf93 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java @@ -1,11 +1,12 @@ package com.baeldung.protobuf; -import java.util.Map; - import com.baeldung.protobuf.BaeldungTraining.Course; +import java.util.Map; + public class CourseRepository { - Map courses; + + private final Map courses; public CourseRepository (Map courses) { this.courses = courses; diff --git a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java index 026fa04fa2..a17082cea7 100644 --- a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java +++ b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java @@ -1,13 +1,13 @@ package com.baeldung.protobuf; -import java.io.IOException; -import java.io.InputStream; - +import com.baeldung.protobuf.BaeldungTraining.Course; +import com.googlecode.protobuf.format.JsonFormat; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; - +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.WebIntegrationTest; @@ -15,20 +15,19 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.client.RestTemplate; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.io.IOException; +import java.io.InputStream; -import com.baeldung.protobuf.BaeldungTraining.Course; -import com.googlecode.protobuf.format.JsonFormat; - -import static org.junit.Assert.assertThat; import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebIntegrationTest public class ApplicationTest { + private static final String COURSE1_URL = "http://localhost:8080/courses/1"; + @Autowired private RestTemplate restTemplate; From b1bdeb92d68848c26aab5cbaedce50327886854e Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 18 Jun 2016 23:52:26 +0300 Subject: [PATCH 07/19] minor formatting work --- .../org/baeldung/httpclient/SandboxTest.java | 3 +- .../com/baeldung/protobuf/Application.java | 12 +- .../baeldung/protobuf/BaeldungTraining.java | 5074 ++++++++--------- .../baeldung/protobuf/CourseRepository.java | 6 +- 4 files changed, 2479 insertions(+), 2616 deletions(-) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java b/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java index 514611d1f9..dc1a206f0d 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java @@ -108,7 +108,7 @@ public class SandboxTest { // Make a client using those creds final CloseableHttpClient client = HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credsProvider).build(); - + // And make a call to the URL we are after final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); @@ -127,6 +127,7 @@ public class SandboxTest { try { System.out.println("----------------------------------------"); + System.out.println(responseGood.getStatusLine()); assertEquals(200, responseGood.getStatusLine().getStatusCode()); } finally { responseGood.close(); diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java index ce5453af61..234c3e3382 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java @@ -32,17 +32,9 @@ public class Application { public CourseRepository createStubCourses() { Map courses = new HashMap<>(); - Course course1 = Course.newBuilder() - .setId(1) - .setCourseName("REST with Spring") - .addAllStudent(createStubStudents()) - .build(); + Course course1 = Course.newBuilder().setId(1).setCourseName("REST with Spring").addAllStudent(createStubStudents()).build(); - Course course2 = Course.newBuilder() - .setId(2) - .setCourseName("Learn Spring Security") - .addAllStudent(new ArrayList<>()) - .build(); + Course course2 = Course.newBuilder().setId(2).setCourseName("Learn Spring Security").addAllStudent(new ArrayList<>()).build(); courses.put(course1.getId(), course1); courses.put(course2.getId(), course2); diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java index 3869ebfaeb..5cab2ae908 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/BaeldungTraining.java @@ -4,2716 +4,2586 @@ package com.baeldung.protobuf; public final class BaeldungTraining { - private BaeldungTraining() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface CourseOrBuilder extends - // @@protoc_insertion_point(interface_extends:baeldung.Course) - com.google.protobuf.MessageOrBuilder { - - /** - * optional int32 id = 1; - */ - int getId(); - - /** - * optional string course_name = 2; - */ - java.lang.String getCourseName(); - /** - * optional string course_name = 2; - */ - com.google.protobuf.ByteString - getCourseNameBytes(); - - /** - * repeated .baeldung.Student student = 3; - */ - java.util.List - getStudentList(); - /** - * repeated .baeldung.Student student = 3; - */ - com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index); - /** - * repeated .baeldung.Student student = 3; - */ - int getStudentCount(); - /** - * repeated .baeldung.Student student = 3; - */ - java.util.List - getStudentOrBuilderList(); - /** - * repeated .baeldung.Student student = 3; - */ - com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder( - int index); - } - /** - * Protobuf type {@code baeldung.Course} - */ - public static final class Course extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:baeldung.Course) - CourseOrBuilder { - // Use Course.newBuilder() to construct. - private Course(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private Course() { - id_ = 0; - courseName_ = ""; - student_ = java.util.Collections.emptyList(); + private BaeldungTraining() { } - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private Course( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 8: { - - id_ = input.readInt32(); - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - courseName_ = s; - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - student_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000004; - } - student_.add(input.readMessage(com.baeldung.protobuf.BaeldungTraining.Student.parser(), extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { - student_ = java.util.Collections.unmodifiableList(student_); - } - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.baeldung.protobuf.BaeldungTraining.Course.class, com.baeldung.protobuf.BaeldungTraining.Course.Builder.class); + public interface CourseOrBuilder extends + // @@protoc_insertion_point(interface_extends:baeldung.Course) + com.google.protobuf.MessageOrBuilder { + + /** + * optional int32 id = 1; + */ + int getId(); + + /** + * optional string course_name = 2; + */ + java.lang.String getCourseName(); + + /** + * optional string course_name = 2; + */ + com.google.protobuf.ByteString getCourseNameBytes(); + + /** + * repeated .baeldung.Student student = 3; + */ + java.util.List getStudentList(); + + /** + * repeated .baeldung.Student student = 3; + */ + com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index); + + /** + * repeated .baeldung.Student student = 3; + */ + int getStudentCount(); + + /** + * repeated .baeldung.Student student = 3; + */ + java.util.List getStudentOrBuilderList(); + + /** + * repeated .baeldung.Student student = 3; + */ + com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder(int index); } - private int bitField0_; - public static final int ID_FIELD_NUMBER = 1; - private int id_; - /** - * optional int32 id = 1; - */ - public int getId() { - return id_; - } - - public static final int COURSE_NAME_FIELD_NUMBER = 2; - private volatile java.lang.Object courseName_; - /** - * optional string course_name = 2; - */ - public java.lang.String getCourseName() { - java.lang.Object ref = courseName_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - courseName_ = s; - return s; - } - } - /** - * optional string course_name = 2; - */ - public com.google.protobuf.ByteString - getCourseNameBytes() { - java.lang.Object ref = courseName_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - courseName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int STUDENT_FIELD_NUMBER = 3; - private java.util.List student_; - /** - * repeated .baeldung.Student student = 3; - */ - public java.util.List getStudentList() { - return student_; - } - /** - * repeated .baeldung.Student student = 3; - */ - public java.util.List - getStudentOrBuilderList() { - return student_; - } - /** - * repeated .baeldung.Student student = 3; - */ - public int getStudentCount() { - return student_.size(); - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index) { - return student_.get(index); - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder( - int index) { - return student_.get(index); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (id_ != 0) { - output.writeInt32(1, id_); - } - if (!getCourseNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 2, courseName_); - } - for (int i = 0; i < student_.size(); i++) { - output.writeMessage(3, student_.get(i)); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (id_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, id_); - } - if (!getCourseNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(2, courseName_); - } - for (int i = 0; i < student_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, student_.get(i)); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Course prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } /** * Protobuf type {@code baeldung.Course} */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:baeldung.Course) - com.baeldung.protobuf.BaeldungTraining.CourseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.baeldung.protobuf.BaeldungTraining.Course.class, com.baeldung.protobuf.BaeldungTraining.Course.Builder.class); - } - - // Construct using com.baeldung.protobuf.BaeldungTraining.Course.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getStudentFieldBuilder(); + public static final class Course extends com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:baeldung.Course) + CourseOrBuilder { + // Use Course.newBuilder() to construct. + private Course(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); } - } - public Builder clear() { - super.clear(); - id_ = 0; - courseName_ = ""; - - if (studentBuilder_ == null) { - student_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000004); - } else { - studentBuilder_.clear(); + private Course() { + id_ = 0; + courseName_ = ""; + student_ = java.util.Collections.emptyList(); } - return this; - } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; - } - - public com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstanceForType() { - return com.baeldung.protobuf.BaeldungTraining.Course.getDefaultInstance(); - } - - public com.baeldung.protobuf.BaeldungTraining.Course build() { - com.baeldung.protobuf.BaeldungTraining.Course result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - return result; - } - public com.baeldung.protobuf.BaeldungTraining.Course buildPartial() { - com.baeldung.protobuf.BaeldungTraining.Course result = new com.baeldung.protobuf.BaeldungTraining.Course(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - result.id_ = id_; - result.courseName_ = courseName_; - if (studentBuilder_ == null) { - if (((bitField0_ & 0x00000004) == 0x00000004)) { - student_ = java.util.Collections.unmodifiableList(student_); - bitField0_ = (bitField0_ & ~0x00000004); - } - result.student_ = student_; - } else { - result.student_ = studentBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } + private Course(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 8: { - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.baeldung.protobuf.BaeldungTraining.Course) { - return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Course)other); - } else { - super.mergeFrom(other); - return this; - } - } + id_ = input.readInt32(); + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); - public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Course other) { - if (other == com.baeldung.protobuf.BaeldungTraining.Course.getDefaultInstance()) return this; - if (other.getId() != 0) { - setId(other.getId()); - } - if (!other.getCourseName().isEmpty()) { - courseName_ = other.courseName_; - onChanged(); - } - if (studentBuilder_ == null) { - if (!other.student_.isEmpty()) { - if (student_.isEmpty()) { - student_ = other.student_; - bitField0_ = (bitField0_ & ~0x00000004); - } else { - ensureStudentIsMutable(); - student_.addAll(other.student_); - } - onChanged(); - } - } else { - if (!other.student_.isEmpty()) { - if (studentBuilder_.isEmpty()) { - studentBuilder_.dispose(); - studentBuilder_ = null; - student_ = other.student_; - bitField0_ = (bitField0_ & ~0x00000004); - studentBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getStudentFieldBuilder() : null; - } else { - studentBuilder_.addAllMessages(other.student_); - } - } - } - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.baeldung.protobuf.BaeldungTraining.Course parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Course) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private int id_ ; - /** - * optional int32 id = 1; - */ - public int getId() { - return id_; - } - /** - * optional int32 id = 1; - */ - public Builder setId(int value) { - - id_ = value; - onChanged(); - return this; - } - /** - * optional int32 id = 1; - */ - public Builder clearId() { - - id_ = 0; - onChanged(); - return this; - } - - private java.lang.Object courseName_ = ""; - /** - * optional string course_name = 2; - */ - public java.lang.String getCourseName() { - java.lang.Object ref = courseName_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - courseName_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string course_name = 2; - */ - public com.google.protobuf.ByteString - getCourseNameBytes() { - java.lang.Object ref = courseName_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - courseName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string course_name = 2; - */ - public Builder setCourseName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - courseName_ = value; - onChanged(); - return this; - } - /** - * optional string course_name = 2; - */ - public Builder clearCourseName() { - - courseName_ = getDefaultInstance().getCourseName(); - onChanged(); - return this; - } - /** - * optional string course_name = 2; - */ - public Builder setCourseNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - courseName_ = value; - onChanged(); - return this; - } - - private java.util.List student_ = - java.util.Collections.emptyList(); - private void ensureStudentIsMutable() { - if (!((bitField0_ & 0x00000004) == 0x00000004)) { - student_ = new java.util.ArrayList(student_); - bitField0_ |= 0x00000004; - } - } - - private com.google.protobuf.RepeatedFieldBuilder< - com.baeldung.protobuf.BaeldungTraining.Student, com.baeldung.protobuf.BaeldungTraining.Student.Builder, com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder> studentBuilder_; - - /** - * repeated .baeldung.Student student = 3; - */ - public java.util.List getStudentList() { - if (studentBuilder_ == null) { - return java.util.Collections.unmodifiableList(student_); - } else { - return studentBuilder_.getMessageList(); - } - } - /** - * repeated .baeldung.Student student = 3; - */ - public int getStudentCount() { - if (studentBuilder_ == null) { - return student_.size(); - } else { - return studentBuilder_.getCount(); - } - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index) { - if (studentBuilder_ == null) { - return student_.get(index); - } else { - return studentBuilder_.getMessage(index); - } - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder setStudent( - int index, com.baeldung.protobuf.BaeldungTraining.Student value) { - if (studentBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureStudentIsMutable(); - student_.set(index, value); - onChanged(); - } else { - studentBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder setStudent( - int index, com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { - if (studentBuilder_ == null) { - ensureStudentIsMutable(); - student_.set(index, builderForValue.build()); - onChanged(); - } else { - studentBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder addStudent(com.baeldung.protobuf.BaeldungTraining.Student value) { - if (studentBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureStudentIsMutable(); - student_.add(value); - onChanged(); - } else { - studentBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder addStudent( - int index, com.baeldung.protobuf.BaeldungTraining.Student value) { - if (studentBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureStudentIsMutable(); - student_.add(index, value); - onChanged(); - } else { - studentBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder addStudent( - com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { - if (studentBuilder_ == null) { - ensureStudentIsMutable(); - student_.add(builderForValue.build()); - onChanged(); - } else { - studentBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder addStudent( - int index, com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { - if (studentBuilder_ == null) { - ensureStudentIsMutable(); - student_.add(index, builderForValue.build()); - onChanged(); - } else { - studentBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder addAllStudent( - java.lang.Iterable values) { - if (studentBuilder_ == null) { - ensureStudentIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, student_); - onChanged(); - } else { - studentBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder clearStudent() { - if (studentBuilder_ == null) { - student_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000004); - onChanged(); - } else { - studentBuilder_.clear(); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public Builder removeStudent(int index) { - if (studentBuilder_ == null) { - ensureStudentIsMutable(); - student_.remove(index); - onChanged(); - } else { - studentBuilder_.remove(index); - } - return this; - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.Builder getStudentBuilder( - int index) { - return getStudentFieldBuilder().getBuilder(index); - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder( - int index) { - if (studentBuilder_ == null) { - return student_.get(index); } else { - return studentBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .baeldung.Student student = 3; - */ - public java.util.List - getStudentOrBuilderList() { - if (studentBuilder_ != null) { - return studentBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(student_); - } - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.Builder addStudentBuilder() { - return getStudentFieldBuilder().addBuilder( - com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()); - } - /** - * repeated .baeldung.Student student = 3; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.Builder addStudentBuilder( - int index) { - return getStudentFieldBuilder().addBuilder( - index, com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()); - } - /** - * repeated .baeldung.Student student = 3; - */ - public java.util.List - getStudentBuilderList() { - return getStudentFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilder< - com.baeldung.protobuf.BaeldungTraining.Student, com.baeldung.protobuf.BaeldungTraining.Student.Builder, com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder> - getStudentFieldBuilder() { - if (studentBuilder_ == null) { - studentBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< - com.baeldung.protobuf.BaeldungTraining.Student, com.baeldung.protobuf.BaeldungTraining.Student.Builder, com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder>( - student_, - ((bitField0_ & 0x00000004) == 0x00000004), - getParentForChildren(), - isClean()); - student_ = null; - } - return studentBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - - // @@protoc_insertion_point(builder_scope:baeldung.Course) - } - - // @@protoc_insertion_point(class_scope:baeldung.Course) - private static final com.baeldung.protobuf.BaeldungTraining.Course DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Course(); - } - - public static com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Course parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Course(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StudentOrBuilder extends - // @@protoc_insertion_point(interface_extends:baeldung.Student) - com.google.protobuf.MessageOrBuilder { - - /** - * optional int32 id = 1; - */ - int getId(); - - /** - * optional string first_name = 2; - */ - java.lang.String getFirstName(); - /** - * optional string first_name = 2; - */ - com.google.protobuf.ByteString - getFirstNameBytes(); - - /** - * optional string last_name = 3; - */ - java.lang.String getLastName(); - /** - * optional string last_name = 3; - */ - com.google.protobuf.ByteString - getLastNameBytes(); - - /** - * optional string email = 4; - */ - java.lang.String getEmail(); - /** - * optional string email = 4; - */ - com.google.protobuf.ByteString - getEmailBytes(); - - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - java.util.List - getPhoneList(); - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index); - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - int getPhoneCount(); - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - java.util.List - getPhoneOrBuilderList(); - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder( - int index); - } - /** - * Protobuf type {@code baeldung.Student} - */ - public static final class Student extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:baeldung.Student) - StudentOrBuilder { - // Use Student.newBuilder() to construct. - private Student(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private Student() { - id_ = 0; - firstName_ = ""; - lastName_ = ""; - email_ = ""; - phone_ = java.util.Collections.emptyList(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private Student( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 8: { - - id_ = input.readInt32(); - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - firstName_ = s; - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - lastName_ = s; - break; - } - case 34: { - java.lang.String s = input.readStringRequireUtf8(); - - email_ = s; - break; - } - case 42: { - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { - phone_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; - } - phone_.add(input.readMessage(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.parser(), extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { - phone_ = java.util.Collections.unmodifiableList(phone_); - } - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.baeldung.protobuf.BaeldungTraining.Student.class, com.baeldung.protobuf.BaeldungTraining.Student.Builder.class); - } - - /** - * Protobuf enum {@code baeldung.Student.PhoneType} - */ - public enum PhoneType - implements com.google.protobuf.ProtocolMessageEnum { - /** - * MOBILE = 0; - */ - MOBILE(0), - /** - * LANDLINE = 1; - */ - LANDLINE(1), - UNRECOGNIZED(-1), - ; - - /** - * MOBILE = 0; - */ - public static final int MOBILE_VALUE = 0; - /** - * LANDLINE = 1; - */ - public static final int LANDLINE_VALUE = 1; - - - public final int getNumber() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static PhoneType valueOf(int value) { - return forNumber(value); - } - - public static PhoneType forNumber(int value) { - switch (value) { - case 0: return MOBILE; - case 1: return LANDLINE; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - PhoneType> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public PhoneType findValueByNumber(int number) { - return PhoneType.forNumber(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.Student.getDescriptor().getEnumTypes().get(0); - } - - private static final PhoneType[] VALUES = values(); - - public static PhoneType valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int value; - - private PhoneType(int value) { - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:baeldung.Student.PhoneType) - } - - public interface PhoneNumberOrBuilder extends - // @@protoc_insertion_point(interface_extends:baeldung.Student.PhoneNumber) - com.google.protobuf.MessageOrBuilder { - - /** - * optional string number = 1; - */ - java.lang.String getNumber(); - /** - * optional string number = 1; - */ - com.google.protobuf.ByteString - getNumberBytes(); - - /** - * optional .baeldung.Student.PhoneType type = 2; - */ - int getTypeValue(); - /** - * optional .baeldung.Student.PhoneType type = 2; - */ - com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType(); - } - /** - * Protobuf type {@code baeldung.Student.PhoneNumber} - */ - public static final class PhoneNumber extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:baeldung.Student.PhoneNumber) - PhoneNumberOrBuilder { - // Use PhoneNumber.newBuilder() to construct. - private PhoneNumber(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private PhoneNumber() { - number_ = ""; - type_ = 0; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private PhoneNumber( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; + courseName_ = s; + break; + } + case 26: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + student_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + student_.add(input.readMessage(com.baeldung.protobuf.BaeldungTraining.Student.parser(), extensionRegistry)); + break; + } + } } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - number_ = s; - break; - } - case 16: { - int rawValue = input.readEnum(); - - type_ = rawValue; - break; - } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + student_ = java.util.Collections.unmodifiableList(student_); + } + makeExtensionsImmutable(); } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.class, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder.class); - } - - public static final int NUMBER_FIELD_NUMBER = 1; - private volatile java.lang.Object number_; - /** - * optional string number = 1; - */ - public java.lang.String getNumber() { - java.lang.Object ref = number_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - number_ = s; - return s; - } - } - /** - * optional string number = 1; - */ - public com.google.protobuf.ByteString - getNumberBytes() { - java.lang.Object ref = number_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - number_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int TYPE_FIELD_NUMBER = 2; - private int type_; - /** - * optional .baeldung.Student.PhoneType type = 2; - */ - public int getTypeValue() { - return type_; - } - /** - * optional .baeldung.Student.PhoneType type = 2; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType() { - com.baeldung.protobuf.BaeldungTraining.Student.PhoneType result = com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.forNumber(type_); - return result == null ? com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.UNRECOGNIZED : result; - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getNumberBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 1, number_); - } - if (type_ != com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.MOBILE.getNumber()) { - output.writeEnum(2, type_); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getNumberBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(1, number_); - } - if (type_ != com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.MOBILE.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(2, type_); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code baeldung.Student.PhoneNumber} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:baeldung.Student.PhoneNumber) - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; } - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.class, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder.class); + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; } - // Construct using com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_fieldAccessorTable.ensureFieldAccessorsInitialized(com.baeldung.protobuf.BaeldungTraining.Course.class, com.baeldung.protobuf.BaeldungTraining.Course.Builder.class); } - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - number_ = ""; + private int bitField0_; + public static final int ID_FIELD_NUMBER = 1; + private int id_; - type_ = 0; - - return this; + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + public static final int COURSE_NAME_FIELD_NUMBER = 2; + private volatile java.lang.Object courseName_; + + /** + * optional string course_name = 2; + */ + public java.lang.String getCourseName() { + java.lang.Object ref = courseName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + courseName_ = s; + return s; + } } - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstanceForType() { - return com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance(); + /** + * optional string course_name = 2; + */ + public com.google.protobuf.ByteString getCourseNameBytes() { + java.lang.Object ref = courseName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + courseName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } } - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber build() { - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; + public static final int STUDENT_FIELD_NUMBER = 3; + private java.util.List student_; + + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentList() { + return student_; } - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber buildPartial() { - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber result = new com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber(this); - result.number_ = number_; - result.type_ = type_; - onBuilt(); - return result; + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentOrBuilderList() { + return student_; } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) { - return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber)other); - } else { - super.mergeFrom(other); - return this; - } + /** + * repeated .baeldung.Student student = 3; + */ + public int getStudentCount() { + return student_.size(); } - public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber other) { - if (other == com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()) return this; - if (!other.getNumber().isEmpty()) { - number_ = other.number_; - onChanged(); - } - if (other.type_ != 0) { - setTypeValue(other.getTypeValue()); - } - onChanged(); - return this; + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index) { + return student_.get(index); } + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder(int index) { + return student_.get(index); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { - return true; + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) + return true; + if (isInitialized == 0) + return false; + + memoizedIsInitialized = 1; + return true; } - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (id_ != 0) { + output.writeInt32(1, id_); + } + if (!getCourseNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, courseName_); + } + for (int i = 0; i < student_.size(); i++) { + output.writeMessage(3, student_.get(i)); } - } - return this; } - private java.lang.Object number_ = ""; + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) + return size; + + size = 0; + if (id_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(1, id_); + } + if (!getCourseNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, courseName_); + } + for (int i = 0; i < student_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, student_.get(i)); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseDelimitedFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course parseFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Course prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** - * optional string number = 1; + * Protobuf type {@code baeldung.Course} */ - public java.lang.String getNumber() { - java.lang.Object ref = number_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - number_ = s; - return s; - } else { - return (java.lang.String) ref; - } + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:baeldung.Course) + com.baeldung.protobuf.BaeldungTraining.CourseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_fieldAccessorTable.ensureFieldAccessorsInitialized(com.baeldung.protobuf.BaeldungTraining.Course.class, com.baeldung.protobuf.BaeldungTraining.Course.Builder.class); + } + + // Construct using com.baeldung.protobuf.BaeldungTraining.Course.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getStudentFieldBuilder(); + } + } + + public Builder clear() { + super.clear(); + id_ = 0; + + courseName_ = ""; + + if (studentBuilder_ == null) { + student_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + } else { + studentBuilder_.clear(); + } + return this; + } + + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Course_descriptor; + } + + public com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstanceForType() { + return com.baeldung.protobuf.BaeldungTraining.Course.getDefaultInstance(); + } + + public com.baeldung.protobuf.BaeldungTraining.Course build() { + com.baeldung.protobuf.BaeldungTraining.Course result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.baeldung.protobuf.BaeldungTraining.Course buildPartial() { + com.baeldung.protobuf.BaeldungTraining.Course result = new com.baeldung.protobuf.BaeldungTraining.Course(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + result.id_ = id_; + result.courseName_ = courseName_; + if (studentBuilder_ == null) { + if (((bitField0_ & 0x00000004) == 0x00000004)) { + student_ = java.util.Collections.unmodifiableList(student_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.student_ = student_; + } else { + result.student_ = studentBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.baeldung.protobuf.BaeldungTraining.Course) { + return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Course) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Course other) { + if (other == com.baeldung.protobuf.BaeldungTraining.Course.getDefaultInstance()) + return this; + if (other.getId() != 0) { + setId(other.getId()); + } + if (!other.getCourseName().isEmpty()) { + courseName_ = other.courseName_; + onChanged(); + } + if (studentBuilder_ == null) { + if (!other.student_.isEmpty()) { + if (student_.isEmpty()) { + student_ = other.student_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureStudentIsMutable(); + student_.addAll(other.student_); + } + onChanged(); + } + } else { + if (!other.student_.isEmpty()) { + if (studentBuilder_.isEmpty()) { + studentBuilder_.dispose(); + studentBuilder_ = null; + student_ = other.student_; + bitField0_ = (bitField0_ & ~0x00000004); + studentBuilder_ = com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? getStudentFieldBuilder() : null; + } else { + studentBuilder_.addAllMessages(other.student_); + } + } + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + com.baeldung.protobuf.BaeldungTraining.Course parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Course) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private int bitField0_; + + private int id_; + + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + + /** + * optional int32 id = 1; + */ + public Builder setId(int value) { + + id_ = value; + onChanged(); + return this; + } + + /** + * optional int32 id = 1; + */ + public Builder clearId() { + + id_ = 0; + onChanged(); + return this; + } + + private java.lang.Object courseName_ = ""; + + /** + * optional string course_name = 2; + */ + public java.lang.String getCourseName() { + java.lang.Object ref = courseName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + courseName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string course_name = 2; + */ + public com.google.protobuf.ByteString getCourseNameBytes() { + java.lang.Object ref = courseName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + courseName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string course_name = 2; + */ + public Builder setCourseName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + courseName_ = value; + onChanged(); + return this; + } + + /** + * optional string course_name = 2; + */ + public Builder clearCourseName() { + + courseName_ = getDefaultInstance().getCourseName(); + onChanged(); + return this; + } + + /** + * optional string course_name = 2; + */ + public Builder setCourseNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + courseName_ = value; + onChanged(); + return this; + } + + private java.util.List student_ = java.util.Collections.emptyList(); + + private void ensureStudentIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + student_ = new java.util.ArrayList(student_); + bitField0_ |= 0x00000004; + } + } + + private com.google.protobuf.RepeatedFieldBuilder studentBuilder_; + + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentList() { + if (studentBuilder_ == null) { + return java.util.Collections.unmodifiableList(student_); + } else { + return studentBuilder_.getMessageList(); + } + } + + /** + * repeated .baeldung.Student student = 3; + */ + public int getStudentCount() { + if (studentBuilder_ == null) { + return student_.size(); + } else { + return studentBuilder_.getCount(); + } + } + + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student getStudent(int index) { + if (studentBuilder_ == null) { + return student_.get(index); + } else { + return studentBuilder_.getMessage(index); + } + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder setStudent(int index, com.baeldung.protobuf.BaeldungTraining.Student value) { + if (studentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStudentIsMutable(); + student_.set(index, value); + onChanged(); + } else { + studentBuilder_.setMessage(index, value); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder setStudent(int index, com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.set(index, builderForValue.build()); + onChanged(); + } else { + studentBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent(com.baeldung.protobuf.BaeldungTraining.Student value) { + if (studentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStudentIsMutable(); + student_.add(value); + onChanged(); + } else { + studentBuilder_.addMessage(value); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent(int index, com.baeldung.protobuf.BaeldungTraining.Student value) { + if (studentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureStudentIsMutable(); + student_.add(index, value); + onChanged(); + } else { + studentBuilder_.addMessage(index, value); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent(com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.add(builderForValue.build()); + onChanged(); + } else { + studentBuilder_.addMessage(builderForValue.build()); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addStudent(int index, com.baeldung.protobuf.BaeldungTraining.Student.Builder builderForValue) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.add(index, builderForValue.build()); + onChanged(); + } else { + studentBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder addAllStudent(java.lang.Iterable values) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, student_); + onChanged(); + } else { + studentBuilder_.addAllMessages(values); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder clearStudent() { + if (studentBuilder_ == null) { + student_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + } else { + studentBuilder_.clear(); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public Builder removeStudent(int index) { + if (studentBuilder_ == null) { + ensureStudentIsMutable(); + student_.remove(index); + onChanged(); + } else { + studentBuilder_.remove(index); + } + return this; + } + + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.Builder getStudentBuilder(int index) { + return getStudentFieldBuilder().getBuilder(index); + } + + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder getStudentOrBuilder(int index) { + if (studentBuilder_ == null) { + return student_.get(index); + } else { + return studentBuilder_.getMessageOrBuilder(index); + } + } + + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentOrBuilderList() { + if (studentBuilder_ != null) { + return studentBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(student_); + } + } + + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.Builder addStudentBuilder() { + return getStudentFieldBuilder().addBuilder(com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()); + } + + /** + * repeated .baeldung.Student student = 3; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.Builder addStudentBuilder(int index) { + return getStudentFieldBuilder().addBuilder(index, com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()); + } + + /** + * repeated .baeldung.Student student = 3; + */ + public java.util.List getStudentBuilderList() { + return getStudentFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilder getStudentFieldBuilder() { + if (studentBuilder_ == null) { + studentBuilder_ = new com.google.protobuf.RepeatedFieldBuilder(student_, + ((bitField0_ & 0x00000004) == 0x00000004), getParentForChildren(), isClean()); + student_ = null; + } + return studentBuilder_; + } + + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + // @@protoc_insertion_point(builder_scope:baeldung.Course) } + + // @@protoc_insertion_point(class_scope:baeldung.Course) + private static final com.baeldung.protobuf.BaeldungTraining.Course DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Course(); + } + + public static com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { + public Course parsePartialFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return new Course(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.baeldung.protobuf.BaeldungTraining.Course getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + public interface StudentOrBuilder extends + // @@protoc_insertion_point(interface_extends:baeldung.Student) + com.google.protobuf.MessageOrBuilder { + /** - * optional string number = 1; + * optional int32 id = 1; */ - public com.google.protobuf.ByteString - getNumberBytes() { - java.lang.Object ref = number_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - number_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } + int getId(); + /** - * optional string number = 1; + * optional string first_name = 2; */ - public Builder setNumber( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - number_ = value; - onChanged(); - return this; - } + java.lang.String getFirstName(); + /** - * optional string number = 1; + * optional string first_name = 2; */ - public Builder clearNumber() { - - number_ = getDefaultInstance().getNumber(); - onChanged(); - return this; - } + com.google.protobuf.ByteString getFirstNameBytes(); + /** - * optional string number = 1; + * optional string last_name = 3; */ - public Builder setNumberBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - number_ = value; - onChanged(); - return this; - } + java.lang.String getLastName(); - private int type_ = 0; /** - * optional .baeldung.Student.PhoneType type = 2; + * optional string last_name = 3; */ - public int getTypeValue() { - return type_; - } + com.google.protobuf.ByteString getLastNameBytes(); + /** - * optional .baeldung.Student.PhoneType type = 2; + * optional string email = 4; */ - public Builder setTypeValue(int value) { - type_ = value; - onChanged(); - return this; - } + java.lang.String getEmail(); + /** - * optional .baeldung.Student.PhoneType type = 2; + * optional string email = 4; */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType() { - com.baeldung.protobuf.BaeldungTraining.Student.PhoneType result = com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.forNumber(type_); - return result == null ? com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.UNRECOGNIZED : result; - } + com.google.protobuf.ByteString getEmailBytes(); + /** - * optional .baeldung.Student.PhoneType type = 2; + * repeated .baeldung.Student.PhoneNumber phone = 5; */ - public Builder setType(com.baeldung.protobuf.BaeldungTraining.Student.PhoneType value) { - if (value == null) { - throw new NullPointerException(); - } - - type_ = value.getNumber(); - onChanged(); - return this; - } + java.util.List getPhoneList(); + /** - * optional .baeldung.Student.PhoneType type = 2; + * repeated .baeldung.Student.PhoneNumber phone = 5; */ - public Builder clearType() { - - type_ = 0; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index); - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + int getPhoneCount(); + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + java.util.List getPhoneOrBuilderList(); - // @@protoc_insertion_point(builder_scope:baeldung.Student.PhoneNumber) - } - - // @@protoc_insertion_point(class_scope:baeldung.Student.PhoneNumber) - private static final com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber(); - } - - public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public PhoneNumber parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new PhoneNumber(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder(int index); } - private int bitField0_; - public static final int ID_FIELD_NUMBER = 1; - private int id_; - /** - * optional int32 id = 1; - */ - public int getId() { - return id_; - } - - public static final int FIRST_NAME_FIELD_NUMBER = 2; - private volatile java.lang.Object firstName_; - /** - * optional string first_name = 2; - */ - public java.lang.String getFirstName() { - java.lang.Object ref = firstName_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - firstName_ = s; - return s; - } - } - /** - * optional string first_name = 2; - */ - public com.google.protobuf.ByteString - getFirstNameBytes() { - java.lang.Object ref = firstName_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - firstName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int LAST_NAME_FIELD_NUMBER = 3; - private volatile java.lang.Object lastName_; - /** - * optional string last_name = 3; - */ - public java.lang.String getLastName() { - java.lang.Object ref = lastName_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - lastName_ = s; - return s; - } - } - /** - * optional string last_name = 3; - */ - public com.google.protobuf.ByteString - getLastNameBytes() { - java.lang.Object ref = lastName_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - lastName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int EMAIL_FIELD_NUMBER = 4; - private volatile java.lang.Object email_; - /** - * optional string email = 4; - */ - public java.lang.String getEmail() { - java.lang.Object ref = email_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - email_ = s; - return s; - } - } - /** - * optional string email = 4; - */ - public com.google.protobuf.ByteString - getEmailBytes() { - java.lang.Object ref = email_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - email_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int PHONE_FIELD_NUMBER = 5; - private java.util.List phone_; - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public java.util.List getPhoneList() { - return phone_; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public java.util.List - getPhoneOrBuilderList() { - return phone_; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public int getPhoneCount() { - return phone_.size(); - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index) { - return phone_.get(index); - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder( - int index) { - return phone_.get(index); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (id_ != 0) { - output.writeInt32(1, id_); - } - if (!getFirstNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 2, firstName_); - } - if (!getLastNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 3, lastName_); - } - if (!getEmailBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 4, email_); - } - for (int i = 0; i < phone_.size(); i++) { - output.writeMessage(5, phone_.get(i)); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (id_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, id_); - } - if (!getFirstNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(2, firstName_); - } - if (!getLastNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(3, lastName_); - } - if (!getEmailBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(4, email_); - } - for (int i = 0; i < phone_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, phone_.get(i)); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Student prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } /** * Protobuf type {@code baeldung.Student} */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:baeldung.Student) - com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.baeldung.protobuf.BaeldungTraining.Student.class, com.baeldung.protobuf.BaeldungTraining.Student.Builder.class); - } - - // Construct using com.baeldung.protobuf.BaeldungTraining.Student.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getPhoneFieldBuilder(); + public static final class Student extends com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:baeldung.Student) + StudentOrBuilder { + // Use Student.newBuilder() to construct. + private Student(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); } - } - public Builder clear() { - super.clear(); - id_ = 0; - firstName_ = ""; - - lastName_ = ""; - - email_ = ""; - - if (phoneBuilder_ == null) { - phone_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000010); - } else { - phoneBuilder_.clear(); + private Student() { + id_ = 0; + firstName_ = ""; + lastName_ = ""; + email_ = ""; + phone_ = java.util.Collections.emptyList(); } - return this; - } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; - } + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } - public com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstanceForType() { - return com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance(); - } + private Student(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 8: { - public com.baeldung.protobuf.BaeldungTraining.Student build() { - com.baeldung.protobuf.BaeldungTraining.Student result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } + id_ = input.readInt32(); + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); - public com.baeldung.protobuf.BaeldungTraining.Student buildPartial() { - com.baeldung.protobuf.BaeldungTraining.Student result = new com.baeldung.protobuf.BaeldungTraining.Student(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - result.id_ = id_; - result.firstName_ = firstName_; - result.lastName_ = lastName_; - result.email_ = email_; - if (phoneBuilder_ == null) { - if (((bitField0_ & 0x00000010) == 0x00000010)) { - phone_ = java.util.Collections.unmodifiableList(phone_); - bitField0_ = (bitField0_ & ~0x00000010); - } - result.phone_ = phone_; - } else { - result.phone_ = phoneBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } + firstName_ = s; + break; + } + case 26: { + java.lang.String s = input.readStringRequireUtf8(); - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.baeldung.protobuf.BaeldungTraining.Student) { - return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Student)other); - } else { - super.mergeFrom(other); - return this; - } - } + lastName_ = s; + break; + } + case 34: { + java.lang.String s = input.readStringRequireUtf8(); - public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Student other) { - if (other == com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()) return this; - if (other.getId() != 0) { - setId(other.getId()); - } - if (!other.getFirstName().isEmpty()) { - firstName_ = other.firstName_; - onChanged(); - } - if (!other.getLastName().isEmpty()) { - lastName_ = other.lastName_; - onChanged(); - } - if (!other.getEmail().isEmpty()) { - email_ = other.email_; - onChanged(); - } - if (phoneBuilder_ == null) { - if (!other.phone_.isEmpty()) { - if (phone_.isEmpty()) { - phone_ = other.phone_; - bitField0_ = (bitField0_ & ~0x00000010); - } else { - ensurePhoneIsMutable(); - phone_.addAll(other.phone_); + email_ = s; + break; + } + case 42: { + if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000010; + } + phone_.add(input.readMessage(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.parser(), extensionRegistry)); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = java.util.Collections.unmodifiableList(phone_); + } + makeExtensionsImmutable(); } - onChanged(); - } - } else { - if (!other.phone_.isEmpty()) { - if (phoneBuilder_.isEmpty()) { - phoneBuilder_.dispose(); - phoneBuilder_ = null; - phone_ = other.phone_; - bitField0_ = (bitField0_ & ~0x00000010); - phoneBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getPhoneFieldBuilder() : null; - } else { - phoneBuilder_.addAllMessages(other.phone_); + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_fieldAccessorTable.ensureFieldAccessorsInitialized(com.baeldung.protobuf.BaeldungTraining.Student.class, com.baeldung.protobuf.BaeldungTraining.Student.Builder.class); + } + + /** + * Protobuf enum {@code baeldung.Student.PhoneType} + */ + public enum PhoneType implements com.google.protobuf.ProtocolMessageEnum { + /** + * MOBILE = 0; + */ + MOBILE(0), + /** + * LANDLINE = 1; + */ + LANDLINE(1), UNRECOGNIZED(-1),; + + /** + * MOBILE = 0; + */ + public static final int MOBILE_VALUE = 0; + /** + * LANDLINE = 1; + */ + public static final int LANDLINE_VALUE = 1; + + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException("Can't get the number of an unknown enum value."); + } + return value; } - } - } - onChanged(); - return this; - } - public final boolean isInitialized() { - return true; - } + /** + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static PhoneType valueOf(int value) { + return forNumber(value); + } - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.baeldung.protobuf.BaeldungTraining.Student parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Student) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; + public static PhoneType forNumber(int value) { + switch (value) { + case 0: + return MOBILE; + case 1: + return LANDLINE; + default: + return null; + } + } - private int id_ ; - /** - * optional int32 id = 1; - */ - public int getId() { - return id_; - } - /** - * optional int32 id = 1; - */ - public Builder setId(int value) { - - id_ = value; - onChanged(); - return this; - } - /** - * optional int32 id = 1; - */ - public Builder clearId() { - - id_ = 0; - onChanged(); - return this; - } + public static com.google.protobuf.Internal.EnumLiteMap internalGetValueMap() { + return internalValueMap; + } - private java.lang.Object firstName_ = ""; - /** - * optional string first_name = 2; - */ - public java.lang.String getFirstName() { - java.lang.Object ref = firstName_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - firstName_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string first_name = 2; - */ - public com.google.protobuf.ByteString - getFirstNameBytes() { - java.lang.Object ref = firstName_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - firstName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string first_name = 2; - */ - public Builder setFirstName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - firstName_ = value; - onChanged(); - return this; - } - /** - * optional string first_name = 2; - */ - public Builder clearFirstName() { - - firstName_ = getDefaultInstance().getFirstName(); - onChanged(); - return this; - } - /** - * optional string first_name = 2; - */ - public Builder setFirstNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - firstName_ = value; - onChanged(); - return this; - } + private static final com.google.protobuf.Internal.EnumLiteMap internalValueMap = new com.google.protobuf.Internal.EnumLiteMap() { + public PhoneType findValueByNumber(int number) { + return PhoneType.forNumber(number); + } + }; - private java.lang.Object lastName_ = ""; - /** - * optional string last_name = 3; - */ - public java.lang.String getLastName() { - java.lang.Object ref = lastName_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - lastName_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string last_name = 3; - */ - public com.google.protobuf.ByteString - getLastNameBytes() { - java.lang.Object ref = lastName_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - lastName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string last_name = 3; - */ - public Builder setLastName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - lastName_ = value; - onChanged(); - return this; - } - /** - * optional string last_name = 3; - */ - public Builder clearLastName() { - - lastName_ = getDefaultInstance().getLastName(); - onChanged(); - return this; - } - /** - * optional string last_name = 3; - */ - public Builder setLastNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - lastName_ = value; - onChanged(); - return this; - } + public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { + return getDescriptor().getValues().get(ordinal()); + } - private java.lang.Object email_ = ""; - /** - * optional string email = 4; - */ - public java.lang.String getEmail() { - java.lang.Object ref = email_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - email_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string email = 4; - */ - public com.google.protobuf.ByteString - getEmailBytes() { - java.lang.Object ref = email_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - email_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string email = 4; - */ - public Builder setEmail( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - email_ = value; - onChanged(); - return this; - } - /** - * optional string email = 4; - */ - public Builder clearEmail() { - - email_ = getDefaultInstance().getEmail(); - onChanged(); - return this; - } - /** - * optional string email = 4; - */ - public Builder setEmailBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - email_ = value; - onChanged(); - return this; - } + public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { + return getDescriptor(); + } - private java.util.List phone_ = - java.util.Collections.emptyList(); - private void ensurePhoneIsMutable() { - if (!((bitField0_ & 0x00000010) == 0x00000010)) { - phone_ = new java.util.ArrayList(phone_); - bitField0_ |= 0x00000010; - } - } + public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.Student.getDescriptor().getEnumTypes().get(0); + } - private com.google.protobuf.RepeatedFieldBuilder< - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder> phoneBuilder_; + private static final PhoneType[] VALUES = values(); - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public java.util.List getPhoneList() { - if (phoneBuilder_ == null) { - return java.util.Collections.unmodifiableList(phone_); - } else { - return phoneBuilder_.getMessageList(); - } - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public int getPhoneCount() { - if (phoneBuilder_ == null) { - return phone_.size(); - } else { - return phoneBuilder_.getCount(); - } - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index) { - if (phoneBuilder_ == null) { - return phone_.get(index); - } else { - return phoneBuilder_.getMessage(index); - } - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder setPhone( - int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { - if (phoneBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePhoneIsMutable(); - phone_.set(index, value); - onChanged(); - } else { - phoneBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder setPhone( - int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { - if (phoneBuilder_ == null) { - ensurePhoneIsMutable(); - phone_.set(index, builderForValue.build()); - onChanged(); - } else { - phoneBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder addPhone(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { - if (phoneBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePhoneIsMutable(); - phone_.add(value); - onChanged(); - } else { - phoneBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder addPhone( - int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { - if (phoneBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePhoneIsMutable(); - phone_.add(index, value); - onChanged(); - } else { - phoneBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder addPhone( - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { - if (phoneBuilder_ == null) { - ensurePhoneIsMutable(); - phone_.add(builderForValue.build()); - onChanged(); - } else { - phoneBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder addPhone( - int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { - if (phoneBuilder_ == null) { - ensurePhoneIsMutable(); - phone_.add(index, builderForValue.build()); - onChanged(); - } else { - phoneBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder addAllPhone( - java.lang.Iterable values) { - if (phoneBuilder_ == null) { - ensurePhoneIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, phone_); - onChanged(); - } else { - phoneBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder clearPhone() { - if (phoneBuilder_ == null) { - phone_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000010); - onChanged(); - } else { - phoneBuilder_.clear(); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public Builder removePhone(int index) { - if (phoneBuilder_ == null) { - ensurePhoneIsMutable(); - phone_.remove(index); - onChanged(); - } else { - phoneBuilder_.remove(index); - } - return this; - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder getPhoneBuilder( - int index) { - return getPhoneFieldBuilder().getBuilder(index); - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder( - int index) { - if (phoneBuilder_ == null) { - return phone_.get(index); } else { - return phoneBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public java.util.List - getPhoneOrBuilderList() { - if (phoneBuilder_ != null) { - return phoneBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(phone_); - } - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder addPhoneBuilder() { - return getPhoneFieldBuilder().addBuilder( - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()); - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder addPhoneBuilder( - int index) { - return getPhoneFieldBuilder().addBuilder( - index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()); - } - /** - * repeated .baeldung.Student.PhoneNumber phone = 5; - */ - public java.util.List - getPhoneBuilderList() { - return getPhoneFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilder< - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder> - getPhoneFieldBuilder() { - if (phoneBuilder_ == null) { - phoneBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< - com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder>( - phone_, - ((bitField0_ & 0x00000010) == 0x00000010), - getParentForChildren(), - isClean()); - phone_ = null; - } - return phoneBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } + public static PhoneType valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException("EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } + private final int value; + private PhoneType(int value) { + this.value = value; + } - // @@protoc_insertion_point(builder_scope:baeldung.Student) - } + // @@protoc_insertion_point(enum_scope:baeldung.Student.PhoneType) + } - // @@protoc_insertion_point(class_scope:baeldung.Student) - private static final com.baeldung.protobuf.BaeldungTraining.Student DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Student(); - } + public interface PhoneNumberOrBuilder extends + // @@protoc_insertion_point(interface_extends:baeldung.Student.PhoneNumber) + com.google.protobuf.MessageOrBuilder { - public static com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstance() { - return DEFAULT_INSTANCE; - } + /** + * optional string number = 1; + */ + java.lang.String getNumber(); - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Student parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Student(input, extensionRegistry); - } - }; + /** + * optional string number = 1; + */ + com.google.protobuf.ByteString getNumberBytes(); - public static com.google.protobuf.Parser parser() { - return PARSER; - } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + int getTypeValue(); - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType(); + } - public com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } + /** + * Protobuf type {@code baeldung.Student.PhoneNumber} + */ + public static final class PhoneNumber extends com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:baeldung.Student.PhoneNumber) + PhoneNumberOrBuilder { + // Use PhoneNumber.newBuilder() to construct. + private PhoneNumber(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + } - } + private PhoneNumber() { + number_ = ""; + type_ = 0; + } - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_baeldung_Course_descriptor; - private static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_baeldung_Course_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_baeldung_Student_descriptor; - private static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_baeldung_Student_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_baeldung_Student_PhoneNumber_descriptor; - private static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { + return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); + } - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\030resources/baeldung.proto\022\010baeldung\"M\n\006" + - "Course\022\n\n\002id\030\001 \001(\005\022\023\n\013course_name\030\002 \001(\t\022" + - "\"\n\007student\030\003 \003(\0132\021.baeldung.Student\"\352\001\n\007" + - "Student\022\n\n\002id\030\001 \001(\005\022\022\n\nfirst_name\030\002 \001(\t\022" + - "\021\n\tlast_name\030\003 \001(\t\022\r\n\005email\030\004 \001(\t\022,\n\005pho" + - "ne\030\005 \003(\0132\035.baeldung.Student.PhoneNumber\032" + - "H\n\013PhoneNumber\022\016\n\006number\030\001 \001(\t\022)\n\004type\030\002" + - " \001(\0162\033.baeldung.Student.PhoneType\"%\n\tPho" + - "neType\022\n\n\006MOBILE\020\000\022\014\n\010LANDLINE\020\001B)\n\025com." + - "baeldung.protobufB\020BaeldungTrainingb\006pro", - "to3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } + private PhoneNumber(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!input.skipField(tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + number_ = s; + break; + } + case 16: { + int rawValue = input.readEnum(); + + type_ = rawValue; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(this); + } finally { + makeExtensionsImmutable(); + } + } + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable.ensureFieldAccessorsInitialized(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.class, + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder.class); + } + + public static final int NUMBER_FIELD_NUMBER = 1; + private volatile java.lang.Object number_; + + /** + * optional string number = 1; + */ + public java.lang.String getNumber() { + java.lang.Object ref = number_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + number_ = s; + return s; + } + } + + /** + * optional string number = 1; + */ + public com.google.protobuf.ByteString getNumberBytes() { + java.lang.Object ref = number_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + number_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TYPE_FIELD_NUMBER = 2; + private int type_; + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public int getTypeValue() { + return type_; + } + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneType result = com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.forNumber(type_); + return result == null ? com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.UNRECOGNIZED : result; + } + + private byte memoizedIsInitialized = -1; + + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) + return true; + if (isInitialized == 0) + return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (!getNumberBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 1, number_); + } + if (type_ != com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.MOBILE.getNumber()) { + output.writeEnum(2, type_); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) + return size; + + size = 0; + if (!getNumberBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(1, number_); + } + if (type_ != com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.MOBILE.getNumber()) { + size += com.google.protobuf.CodedOutputStream.computeEnumSize(2, type_); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseDelimitedFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parseFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + /** + * Protobuf type {@code baeldung.Student.PhoneNumber} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:baeldung.Student.PhoneNumber) + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable.ensureFieldAccessorsInitialized(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.class, + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder.class); + } + + // Construct using com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + + public Builder clear() { + super.clear(); + number_ = ""; + + type_ = 0; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_PhoneNumber_descriptor; + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstanceForType() { + return com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance(); + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber build() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber buildPartial() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber result = new com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber(this); + result.number_ = number_; + result.type_ = type_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) { + return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber other) { + if (other == com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()) + return this; + if (!other.getNumber().isEmpty()) { + number_ = other.number_; + onChanged(); + } + if (other.type_ != 0) { + setTypeValue(other.getTypeValue()); + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object number_ = ""; + + /** + * optional string number = 1; + */ + public java.lang.String getNumber() { + java.lang.Object ref = number_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + number_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string number = 1; + */ + public com.google.protobuf.ByteString getNumberBytes() { + java.lang.Object ref = number_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + number_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string number = 1; + */ + public Builder setNumber(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + number_ = value; + onChanged(); + return this; + } + + /** + * optional string number = 1; + */ + public Builder clearNumber() { + + number_ = getDefaultInstance().getNumber(); + onChanged(); + return this; + } + + /** + * optional string number = 1; + */ + public Builder setNumberBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + number_ = value; + onChanged(); + return this; + } + + private int type_ = 0; + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public int getTypeValue() { + return type_; + } + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public Builder setTypeValue(int value) { + type_ = value; + onChanged(); + return this; + } + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneType getType() { + com.baeldung.protobuf.BaeldungTraining.Student.PhoneType result = com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.forNumber(type_); + return result == null ? com.baeldung.protobuf.BaeldungTraining.Student.PhoneType.UNRECOGNIZED : result; + } + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public Builder setType(com.baeldung.protobuf.BaeldungTraining.Student.PhoneType value) { + if (value == null) { + throw new NullPointerException(); + } + + type_ = value.getNumber(); + onChanged(); + return this; + } + + /** + * optional .baeldung.Student.PhoneType type = 2; + */ + public Builder clearType() { + + type_ = 0; + onChanged(); + return this; + } + + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + // @@protoc_insertion_point(builder_scope:baeldung.Student.PhoneNumber) + } + + // @@protoc_insertion_point(class_scope:baeldung.Student.PhoneNumber) + private static final com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber(); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { + public PhoneNumber parsePartialFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return new PhoneNumber(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private int bitField0_; + public static final int ID_FIELD_NUMBER = 1; + private int id_; + + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + + public static final int FIRST_NAME_FIELD_NUMBER = 2; + private volatile java.lang.Object firstName_; + + /** + * optional string first_name = 2; + */ + public java.lang.String getFirstName() { + java.lang.Object ref = firstName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + firstName_ = s; + return s; + } + } + + /** + * optional string first_name = 2; + */ + public com.google.protobuf.ByteString getFirstNameBytes() { + java.lang.Object ref = firstName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + firstName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int LAST_NAME_FIELD_NUMBER = 3; + private volatile java.lang.Object lastName_; + + /** + * optional string last_name = 3; + */ + public java.lang.String getLastName() { + java.lang.Object ref = lastName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lastName_ = s; + return s; + } + } + + /** + * optional string last_name = 3; + */ + public com.google.protobuf.ByteString getLastNameBytes() { + java.lang.Object ref = lastName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + lastName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int EMAIL_FIELD_NUMBER = 4; + private volatile java.lang.Object email_; + + /** + * optional string email = 4; + */ + public java.lang.String getEmail() { + java.lang.Object ref = email_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + email_ = s; + return s; + } + } + + /** + * optional string email = 4; + */ + public com.google.protobuf.ByteString getEmailBytes() { + java.lang.Object ref = email_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + email_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PHONE_FIELD_NUMBER = 5; + private java.util.List phone_; + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneList() { + return phone_; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneOrBuilderList() { + return phone_; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public int getPhoneCount() { + return phone_.size(); + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index) { + return phone_.get(index); + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder(int index) { + return phone_.get(index); + } + + private byte memoizedIsInitialized = -1; + + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) + return true; + if (isInitialized == 0) + return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { + if (id_ != 0) { + output.writeInt32(1, id_); + } + if (!getFirstNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, firstName_); + } + if (!getLastNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 3, lastName_); + } + if (!getEmailBytes().isEmpty()) { + com.google.protobuf.GeneratedMessage.writeString(output, 4, email_); + } + for (int i = 0; i < phone_.size(); i++) { + output.writeMessage(5, phone_.get(i)); + } + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) + return size; + + size = 0; + if (id_ != 0) { + size += com.google.protobuf.CodedOutputStream.computeInt32Size(1, id_); + } + if (!getFirstNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, firstName_); + } + if (!getLastNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(3, lastName_); + } + if (!getEmailBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(4, email_); + } + for (int i = 0; i < phone_.size(); i++) { + size += com.google.protobuf.CodedOutputStream.computeMessageSize(5, phone_.get(i)); + } + memoizedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseDelimitedFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student parseFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { + return newBuilder(); + } + + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + + public static Builder newBuilder(com.baeldung.protobuf.BaeldungTraining.Student prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + + public Builder toBuilder() { + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + + /** + * Protobuf type {@code baeldung.Student} + */ + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:baeldung.Student) + com.baeldung.protobuf.BaeldungTraining.StudentOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_fieldAccessorTable.ensureFieldAccessorsInitialized(com.baeldung.protobuf.BaeldungTraining.Student.class, + com.baeldung.protobuf.BaeldungTraining.Student.Builder.class); + } + + // Construct using com.baeldung.protobuf.BaeldungTraining.Student.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getPhoneFieldBuilder(); + } + } + + public Builder clear() { + super.clear(); + id_ = 0; + + firstName_ = ""; + + lastName_ = ""; + + email_ = ""; + + if (phoneBuilder_ == null) { + phone_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000010); + } else { + phoneBuilder_.clear(); + } + return this; + } + + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.baeldung.protobuf.BaeldungTraining.internal_static_baeldung_Student_descriptor; + } + + public com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstanceForType() { + return com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance(); + } + + public com.baeldung.protobuf.BaeldungTraining.Student build() { + com.baeldung.protobuf.BaeldungTraining.Student result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.baeldung.protobuf.BaeldungTraining.Student buildPartial() { + com.baeldung.protobuf.BaeldungTraining.Student result = new com.baeldung.protobuf.BaeldungTraining.Student(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + result.id_ = id_; + result.firstName_ = firstName_; + result.lastName_ = lastName_; + result.email_ = email_; + if (phoneBuilder_ == null) { + if (((bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = java.util.Collections.unmodifiableList(phone_); + bitField0_ = (bitField0_ & ~0x00000010); + } + result.phone_ = phone_; + } else { + result.phone_ = phoneBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.baeldung.protobuf.BaeldungTraining.Student) { + return mergeFrom((com.baeldung.protobuf.BaeldungTraining.Student) other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.baeldung.protobuf.BaeldungTraining.Student other) { + if (other == com.baeldung.protobuf.BaeldungTraining.Student.getDefaultInstance()) + return this; + if (other.getId() != 0) { + setId(other.getId()); + } + if (!other.getFirstName().isEmpty()) { + firstName_ = other.firstName_; + onChanged(); + } + if (!other.getLastName().isEmpty()) { + lastName_ = other.lastName_; + onChanged(); + } + if (!other.getEmail().isEmpty()) { + email_ = other.email_; + onChanged(); + } + if (phoneBuilder_ == null) { + if (!other.phone_.isEmpty()) { + if (phone_.isEmpty()) { + phone_ = other.phone_; + bitField0_ = (bitField0_ & ~0x00000010); + } else { + ensurePhoneIsMutable(); + phone_.addAll(other.phone_); + } + onChanged(); + } + } else { + if (!other.phone_.isEmpty()) { + if (phoneBuilder_.isEmpty()) { + phoneBuilder_.dispose(); + phoneBuilder_ = null; + phone_ = other.phone_; + bitField0_ = (bitField0_ & ~0x00000010); + phoneBuilder_ = com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? getPhoneFieldBuilder() : null; + } else { + phoneBuilder_.addAllMessages(other.phone_); + } + } + } + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { + com.baeldung.protobuf.BaeldungTraining.Student parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.baeldung.protobuf.BaeldungTraining.Student) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private int bitField0_; + + private int id_; + + /** + * optional int32 id = 1; + */ + public int getId() { + return id_; + } + + /** + * optional int32 id = 1; + */ + public Builder setId(int value) { + + id_ = value; + onChanged(); + return this; + } + + /** + * optional int32 id = 1; + */ + public Builder clearId() { + + id_ = 0; + onChanged(); + return this; + } + + private java.lang.Object firstName_ = ""; + + /** + * optional string first_name = 2; + */ + public java.lang.String getFirstName() { + java.lang.Object ref = firstName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + firstName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string first_name = 2; + */ + public com.google.protobuf.ByteString getFirstNameBytes() { + java.lang.Object ref = firstName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + firstName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string first_name = 2; + */ + public Builder setFirstName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + firstName_ = value; + onChanged(); + return this; + } + + /** + * optional string first_name = 2; + */ + public Builder clearFirstName() { + + firstName_ = getDefaultInstance().getFirstName(); + onChanged(); + return this; + } + + /** + * optional string first_name = 2; + */ + public Builder setFirstNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + firstName_ = value; + onChanged(); + return this; + } + + private java.lang.Object lastName_ = ""; + + /** + * optional string last_name = 3; + */ + public java.lang.String getLastName() { + java.lang.Object ref = lastName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lastName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string last_name = 3; + */ + public com.google.protobuf.ByteString getLastNameBytes() { + java.lang.Object ref = lastName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + lastName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string last_name = 3; + */ + public Builder setLastName(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + lastName_ = value; + onChanged(); + return this; + } + + /** + * optional string last_name = 3; + */ + public Builder clearLastName() { + + lastName_ = getDefaultInstance().getLastName(); + onChanged(); + return this; + } + + /** + * optional string last_name = 3; + */ + public Builder setLastNameBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + lastName_ = value; + onChanged(); + return this; + } + + private java.lang.Object email_ = ""; + + /** + * optional string email = 4; + */ + public java.lang.String getEmail() { + java.lang.Object ref = email_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + email_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + + /** + * optional string email = 4; + */ + public com.google.protobuf.ByteString getEmailBytes() { + java.lang.Object ref = email_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); + email_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + /** + * optional string email = 4; + */ + public Builder setEmail(java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + email_ = value; + onChanged(); + return this; + } + + /** + * optional string email = 4; + */ + public Builder clearEmail() { + + email_ = getDefaultInstance().getEmail(); + onChanged(); + return this; + } + + /** + * optional string email = 4; + */ + public Builder setEmailBytes(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + email_ = value; + onChanged(); + return this; + } + + private java.util.List phone_ = java.util.Collections.emptyList(); + + private void ensurePhoneIsMutable() { + if (!((bitField0_ & 0x00000010) == 0x00000010)) { + phone_ = new java.util.ArrayList(phone_); + bitField0_ |= 0x00000010; + } + } + + private com.google.protobuf.RepeatedFieldBuilder phoneBuilder_; + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneList() { + if (phoneBuilder_ == null) { + return java.util.Collections.unmodifiableList(phone_); + } else { + return phoneBuilder_.getMessageList(); + } + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public int getPhoneCount() { + if (phoneBuilder_ == null) { + return phone_.size(); + } else { + return phoneBuilder_.getCount(); + } + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber getPhone(int index) { + if (phoneBuilder_ == null) { + return phone_.get(index); + } else { + return phoneBuilder_.getMessage(index); + } + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder setPhone(int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.set(index, value); + onChanged(); + } else { + phoneBuilder_.setMessage(index, value); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder setPhone(int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.set(index, builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.add(value); + onChanged(); + } else { + phoneBuilder_.addMessage(value); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone(int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.add(index, value); + onChanged(); + } else { + phoneBuilder_.addMessage(index, value); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.add(builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.addMessage(builderForValue.build()); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addPhone(int index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.add(index, builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder addAllPhone(java.lang.Iterable values) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, phone_); + onChanged(); + } else { + phoneBuilder_.addAllMessages(values); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder clearPhone() { + if (phoneBuilder_ == null) { + phone_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000010); + onChanged(); + } else { + phoneBuilder_.clear(); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public Builder removePhone(int index) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.remove(index); + onChanged(); + } else { + phoneBuilder_.remove(index); + } + return this; + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder getPhoneBuilder(int index) { + return getPhoneFieldBuilder().getBuilder(index); + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumberOrBuilder getPhoneOrBuilder(int index) { + if (phoneBuilder_ == null) { + return phone_.get(index); + } else { + return phoneBuilder_.getMessageOrBuilder(index); + } + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneOrBuilderList() { + if (phoneBuilder_ != null) { + return phoneBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(phone_); + } + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder addPhoneBuilder() { + return getPhoneFieldBuilder().addBuilder(com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()); + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.Builder addPhoneBuilder(int index) { + return getPhoneFieldBuilder().addBuilder(index, com.baeldung.protobuf.BaeldungTraining.Student.PhoneNumber.getDefaultInstance()); + } + + /** + * repeated .baeldung.Student.PhoneNumber phone = 5; + */ + public java.util.List getPhoneBuilderList() { + return getPhoneFieldBuilder().getBuilderList(); + } + + private com.google.protobuf.RepeatedFieldBuilder getPhoneFieldBuilder() { + if (phoneBuilder_ == null) { + phoneBuilder_ = new com.google.protobuf.RepeatedFieldBuilder( + phone_, ((bitField0_ & 0x00000010) == 0x00000010), getParentForChildren(), isClean()); + phone_ = null; + } + return phoneBuilder_; + } + + public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { + return this; + } + + // @@protoc_insertion_point(builder_scope:baeldung.Student) + } + + // @@protoc_insertion_point(class_scope:baeldung.Student) + private static final com.baeldung.protobuf.BaeldungTraining.Student DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.baeldung.protobuf.BaeldungTraining.Student(); + } + + public static com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { + public Student parsePartialFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { + return new Student(input, extensionRegistry); + } }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_baeldung_Course_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_baeldung_Course_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_baeldung_Course_descriptor, - new java.lang.String[] { "Id", "CourseName", "Student", }); - internal_static_baeldung_Student_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_baeldung_Student_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_baeldung_Student_descriptor, - new java.lang.String[] { "Id", "FirstName", "LastName", "Email", "Phone", }); - internal_static_baeldung_Student_PhoneNumber_descriptor = - internal_static_baeldung_Student_descriptor.getNestedTypes().get(0); - internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_baeldung_Student_PhoneNumber_descriptor, - new java.lang.String[] { "Number", "Type", }); - } - // @@protoc_insertion_point(outer_class_scope) + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.baeldung.protobuf.BaeldungTraining.Student getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor internal_static_baeldung_Course_descriptor; + private static final com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_baeldung_Course_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor internal_static_baeldung_Student_descriptor; + private static final com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_baeldung_Student_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor internal_static_baeldung_Student_PhoneNumber_descriptor; + private static final com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + static { + java.lang.String[] descriptorData = { "\n\030resources/baeldung.proto\022\010baeldung\"M\n\006" + "Course\022\n\n\002id\030\001 \001(\005\022\023\n\013course_name\030\002 \001(\t\022" + + "\"\n\007student\030\003 \003(\0132\021.baeldung.Student\"\352\001\n\007" + "Student\022\n\n\002id\030\001 \001(\005\022\022\n\nfirst_name\030\002 \001(\t\022" + + "\021\n\tlast_name\030\003 \001(\t\022\r\n\005email\030\004 \001(\t\022,\n\005pho" + "ne\030\005 \003(\0132\035.baeldung.Student.PhoneNumber\032" + "H\n\013PhoneNumber\022\016\n\006number\030\001 \001(\t\022)\n\004type\030\002" + + " \001(\0162\033.baeldung.Student.PhoneType\"%\n\tPho" + "neType\022\n\n\006MOBILE\020\000\022\014\n\010LANDLINE\020\001B)\n\025com." + "baeldung.protobufB\020BaeldungTrainingb\006pro", "to3" }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors(com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}, assigner); + internal_static_baeldung_Course_descriptor = getDescriptor().getMessageTypes().get(0); + internal_static_baeldung_Course_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_baeldung_Course_descriptor, new java.lang.String[] { "Id", "CourseName", "Student", }); + internal_static_baeldung_Student_descriptor = getDescriptor().getMessageTypes().get(1); + internal_static_baeldung_Student_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_baeldung_Student_descriptor, new java.lang.String[] { "Id", "FirstName", "LastName", "Email", "Phone", }); + internal_static_baeldung_Student_PhoneNumber_descriptor = internal_static_baeldung_Student_descriptor.getNestedTypes().get(0); + internal_static_baeldung_Student_PhoneNumber_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_baeldung_Student_PhoneNumber_descriptor, new java.lang.String[] { "Number", "Type", }); + } + + // @@protoc_insertion_point(outer_class_scope) } diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java index 60f24abf93..cbafd7d224 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/CourseRepository.java @@ -7,11 +7,11 @@ import java.util.Map; public class CourseRepository { private final Map courses; - - public CourseRepository (Map courses) { + + public CourseRepository(Map courses) { this.courses = courses; } - + public Course getCourse(int id) { return courses.get(id); } From 2b2022c80abd3f7b7ed6bf8ec70bdc323d5a0a7a Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 18 Jun 2016 23:28:32 +0200 Subject: [PATCH 08/19] Refactor spring-protobuf --- .../src/main/java/com/baeldung/protobuf/Application.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java index 234c3e3382..76f0e45244 100644 --- a/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java +++ b/spring-protobuf/src/main/java/com/baeldung/protobuf/Application.java @@ -29,10 +29,10 @@ public class Application { } @Bean - public CourseRepository createStubCourses() { + public CourseRepository createTestCourses() { Map courses = new HashMap<>(); - Course course1 = Course.newBuilder().setId(1).setCourseName("REST with Spring").addAllStudent(createStubStudents()).build(); + Course course1 = Course.newBuilder().setId(1).setCourseName("REST with Spring").addAllStudent(createTestStudents()).build(); Course course2 = Course.newBuilder().setId(2).setCourseName("Learn Spring Security").addAllStudent(new ArrayList<>()).build(); @@ -42,7 +42,7 @@ public class Application { return new CourseRepository(courses); } - private List createStubStudents() { + private List createTestStudents() { PhoneNumber phone1 = createPhone("123456", PhoneType.MOBILE); Student student1 = createStudent(1, "John", "Doe", "john.doe@baeldung.com", Arrays.asList(phone1)); From 83df968617730c42f6871324916e21304cd74433 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 20 Jun 2016 07:49:39 +0200 Subject: [PATCH 09/19] Initial commit --- assertj-introduction/pom.xml | 38 +++++++++++++++++++ .../com/baeldung/assertj/AssertJDemoTest.java | 10 +++++ pom.xml | 2 + 3 files changed, 50 insertions(+) create mode 100644 assertj-introduction/pom.xml create mode 100644 assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java diff --git a/assertj-introduction/pom.xml b/assertj-introduction/pom.xml new file mode 100644 index 0000000000..21cd0c0121 --- /dev/null +++ b/assertj-introduction/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + com.baeldung + assertj-introduction + 1.0.0-SNAPSHOT + + + + junit + junit + 4.12 + + + org.assertj + assertj-core + 3.4.1 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java b/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java new file mode 100644 index 0000000000..3f4cb390bb --- /dev/null +++ b/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java @@ -0,0 +1,10 @@ +package com.baeldung.assertj; + +import org.junit.Test; + +public class AssertJDemoTest { + + @Test + public void shouldTest() throws Exception { + } +} diff --git a/pom.xml b/pom.xml index 19c602091d..505b72e1ab 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,8 @@ apache-fop + assertj-introduction + core-java core-java-8 gson From a871f2558fa32e7c40c08b9eeb90f2b3acdb6ecc Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 21 Jun 2016 19:53:15 +0200 Subject: [PATCH 10/19] Add first set of assertions --- .../java/com/baeldung/assertj/domain/Dog.java | 19 +++++++ .../com/baeldung/assertj/AssertJDemoTest.java | 57 ++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java diff --git a/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java b/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java new file mode 100644 index 0000000000..adfcf05225 --- /dev/null +++ b/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java @@ -0,0 +1,19 @@ +package com.baeldung.assertj.domain; + +public class Dog { + private String name; + private Float weight; + + public Dog(String name, Float weight) { + this.name = name; + this.weight = weight; + } + + public String getName() { + return name; + } + + public Float getWeight() { + return weight; + } +} diff --git a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java b/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java index 3f4cb390bb..249cb865d9 100644 --- a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java +++ b/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java @@ -1,10 +1,65 @@ package com.baeldung.assertj; +import com.baeldung.assertj.domain.Dog; import org.junit.Test; +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.withPrecision; + public class AssertJDemoTest { @Test - public void shouldTest() throws Exception { + public void whenComparingReferences_thenNotEqual() throws Exception { + Dog fido = new Dog("Fido", 5.15f); + Dog fidosClone = new Dog("Fido", 5.15f); + + assertThat(fido).isNotEqualTo(fidosClone); + } + + @Test + public void whenComparingFields_thenEqual() throws Exception { + Dog fido = new Dog("Fido", 5.15f); + Dog fidosClone = new Dog("Fido", 5.15f); + + assertThat(fido).isEqualToComparingFieldByFieldRecursively(fidosClone); + } + + @Test + public void whenCheckingForElement_thenContains() throws Exception { + List list = Arrays.asList("1", "2", "3"); + + assertThat(list) + .contains("1"); + } + + @Test + public void whenCheckingForElement_thenMultipleAssertions() throws Exception { + List list = Arrays.asList("1", "2", "3"); + + assertThat(list) + .isNotEmpty() + .contains("1") + .startsWith("1") + .doesNotContainNull() + .containsSequence("2", "3"); + } + + @Test + public void whenCheckingRunnable_thenIsInterface() throws Exception { + assertThat(Runnable.class).isInterface(); + } + + @Test + public void whenAssigningNSEExToException_thenIsAssignable() throws Exception { + assertThat(Exception.class).isAssignableFrom(NoSuchElementException.class); + } + + @Test + public void whenComparingWithOffset_thenEquals() throws Exception { + assertThat(5.1).isEqualTo(5, withPrecision(1d)); } } From 4aa5f7f30c98c49fecf7608a7f667a0622400ea9 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 21 Jun 2016 20:14:22 +0200 Subject: [PATCH 11/19] Add second set of assertions --- .../com/baeldung/assertj/domain/Person.java | 19 +++++++++++++++++++ .../com/baeldung/assertj/AssertJDemoTest.java | 12 ++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java diff --git a/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java b/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java new file mode 100644 index 0000000000..4f6bb7f55b --- /dev/null +++ b/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java @@ -0,0 +1,19 @@ +package com.baeldung.assertj.domain; + +public class Person { + private String name; + private Integer age; + + public Person(String name, Integer age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public Integer getAge() { + return age; + } +} diff --git a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java b/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java index 249cb865d9..71ce2c53b5 100644 --- a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java +++ b/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java @@ -1,6 +1,8 @@ package com.baeldung.assertj; import com.baeldung.assertj.domain.Dog; +import com.baeldung.assertj.domain.Person; +import org.junit.Ignore; import org.junit.Test; import java.util.Arrays; @@ -62,4 +64,14 @@ public class AssertJDemoTest { public void whenComparingWithOffset_thenEquals() throws Exception { assertThat(5.1).isEqualTo(5, withPrecision(1d)); } + + @Ignore // IN ORDER TO TEST, REMOVE THIS LINE + @Test + public void whenRunningAssertion_thenDescribed() throws Exception { + Person person = new Person("Alex", 34); + + assertThat(person.getAge()) + .as("%s's age should be equal to 100") + .isEqualTo(100); + } } From 28029711e43df1d6317aacb571487c540cb29288 Mon Sep 17 00:00:00 2001 From: eugenp Date: Wed, 22 Jun 2016 17:49:39 +0300 Subject: [PATCH 12/19] minor cleanup --- spring-rest/.project | 6 ------ spring-rest/.settings/.jsdtscope | 7 ------- .../org.eclipse.wst.common.project.facet.core.xml | 5 +---- spring-rest/pom.xml | 15 ++------------- 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/spring-rest/.project b/spring-rest/.project index 894841d690..525c5e7795 100644 --- a/spring-rest/.project +++ b/spring-rest/.project @@ -15,11 +15,6 @@ - - org.eclipse.wst.validation.validationbuilder - - - org.springframework.ide.eclipse.core.springbuilder @@ -38,6 +33,5 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.jsdt.core.jsNature diff --git a/spring-rest/.settings/.jsdtscope b/spring-rest/.settings/.jsdtscope index b46b9207a8..7b3f0c8b9f 100644 --- a/spring-rest/.settings/.jsdtscope +++ b/spring-rest/.settings/.jsdtscope @@ -1,12 +1,5 @@ - - - - - - - diff --git a/spring-rest/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-rest/.settings/org.eclipse.wst.common.project.facet.core.xml index b9386231e6..8a1c189419 100644 --- a/spring-rest/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/spring-rest/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,8 +1,5 @@ - - - - + diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 767f90a6a6..7941279936 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -9,7 +9,7 @@ org.springframework.boot spring-boot-starter-parent - 1.2.4.RELEASE + 1.3.5.RELEASE @@ -59,7 +59,6 @@ javax.servlet javax.servlet-api - 3.0.1 provided @@ -101,24 +100,20 @@ org.slf4j slf4j-api - ${org.slf4j.version} ch.qos.logback logback-classic - ${logback.version} org.slf4j jcl-over-slf4j - ${org.slf4j.version} org.slf4j log4j-over-slf4j - ${org.slf4j.version} @@ -126,34 +121,29 @@ junit junit - ${junit.version} test org.hamcrest hamcrest-core - ${org.hamcrest.version} test org.hamcrest hamcrest-library - ${org.hamcrest.version} test org.mockito mockito-core - ${mockito.version} test org.springframework spring-test - ${spring.version} @@ -226,11 +216,10 @@ - 4.0.4.RELEASE 4.3.11.Final - 5.1.38 + 5.1.39 From d429cb401e5bbaf2d22e338ce06a7e8df9c30665 Mon Sep 17 00:00:00 2001 From: Alex Theedom Date: Wed, 22 Jun 2016 22:42:49 +0100 Subject: [PATCH 13/19] Code and tests for AssertJ --- {assertj-introduction => assertj}/pom.xml | 0 .../java/com/baeldung/assertj/introduction}/domain/Dog.java | 2 +- .../com/baeldung/assertj/introduction}/domain/Person.java | 2 +- .../com/baeldung/assertj/introduction}/AssertJDemoTest.java | 6 +++--- 4 files changed, 5 insertions(+), 5 deletions(-) rename {assertj-introduction => assertj}/pom.xml (100%) rename {assertj-introduction/src/main/java/com/baeldung/assertj => assertj/src/main/java/com/baeldung/assertj/introduction}/domain/Dog.java (85%) rename {assertj-introduction/src/main/java/com/baeldung/assertj => assertj/src/main/java/com/baeldung/assertj/introduction}/domain/Person.java (85%) rename {assertj-introduction/src/test/java/com/baeldung/assertj => assertj/src/test/java/com/baeldung/assertj/introduction}/AssertJDemoTest.java (93%) diff --git a/assertj-introduction/pom.xml b/assertj/pom.xml similarity index 100% rename from assertj-introduction/pom.xml rename to assertj/pom.xml diff --git a/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java b/assertj/src/main/java/com/baeldung/assertj/introduction/domain/Dog.java similarity index 85% rename from assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java rename to assertj/src/main/java/com/baeldung/assertj/introduction/domain/Dog.java index adfcf05225..623f71214c 100644 --- a/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Dog.java +++ b/assertj/src/main/java/com/baeldung/assertj/introduction/domain/Dog.java @@ -1,4 +1,4 @@ -package com.baeldung.assertj.domain; +package com.baeldung.assertj.introduction.domain; public class Dog { private String name; diff --git a/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java b/assertj/src/main/java/com/baeldung/assertj/introduction/domain/Person.java similarity index 85% rename from assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java rename to assertj/src/main/java/com/baeldung/assertj/introduction/domain/Person.java index 4f6bb7f55b..90ef787ebe 100644 --- a/assertj-introduction/src/main/java/com/baeldung/assertj/domain/Person.java +++ b/assertj/src/main/java/com/baeldung/assertj/introduction/domain/Person.java @@ -1,4 +1,4 @@ -package com.baeldung.assertj.domain; +package com.baeldung.assertj.introduction.domain; public class Person { private String name; diff --git a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java b/assertj/src/test/java/com/baeldung/assertj/introduction/AssertJDemoTest.java similarity index 93% rename from assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java rename to assertj/src/test/java/com/baeldung/assertj/introduction/AssertJDemoTest.java index 71ce2c53b5..729c252c3c 100644 --- a/assertj-introduction/src/test/java/com/baeldung/assertj/AssertJDemoTest.java +++ b/assertj/src/test/java/com/baeldung/assertj/introduction/AssertJDemoTest.java @@ -1,7 +1,7 @@ -package com.baeldung.assertj; +package com.baeldung.assertj.introduction; -import com.baeldung.assertj.domain.Dog; -import com.baeldung.assertj.domain.Person; +import com.baeldung.assertj.introduction.domain.Dog; +import com.baeldung.assertj.introduction.domain.Person; import org.junit.Ignore; import org.junit.Test; From 3c17c9ef4a923e4e30ad9193acb99f8c0fe6a8a3 Mon Sep 17 00:00:00 2001 From: eugenp Date: Thu, 23 Jun 2016 01:04:21 +0300 Subject: [PATCH 14/19] minor cleanup --- core-java/.classpath | 2 +- core-java/.settings/org.eclipse.jdt.core.prefs | 11 ++++++++--- .../org.eclipse.wst.common.project.facet.core.xml | 2 +- .../collections/JavaCollectionConversionUnitTest.java | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core-java/.classpath b/core-java/.classpath index f9b079e8c9..ca829f1262 100644 --- a/core-java/.classpath +++ b/core-java/.classpath @@ -27,7 +27,7 @@ - + diff --git a/core-java/.settings/org.eclipse.jdt.core.prefs b/core-java/.settings/org.eclipse.jdt.core.prefs index 046168cf24..1882edb712 100644 --- a/core-java/.settings/org.eclipse.jdt.core.prefs +++ b/core-java/.settings/org.eclipse.jdt.core.prefs @@ -6,8 +6,13 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore @@ -92,4 +97,4 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/core-java/.settings/org.eclipse.wst.common.project.facet.core.xml b/core-java/.settings/org.eclipse.wst.common.project.facet.core.xml index bc0009a455..f4ef8aa0a5 100644 --- a/core-java/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/core-java/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,4 +1,4 @@ - + diff --git a/core-java/src/test/java/org/baeldung/java/collections/JavaCollectionConversionUnitTest.java b/core-java/src/test/java/org/baeldung/java/collections/JavaCollectionConversionUnitTest.java index 95b79810cd..a5f684a141 100644 --- a/core-java/src/test/java/org/baeldung/java/collections/JavaCollectionConversionUnitTest.java +++ b/core-java/src/test/java/org/baeldung/java/collections/JavaCollectionConversionUnitTest.java @@ -31,7 +31,7 @@ public class JavaCollectionConversionUnitTest { @Test public final void givenUsingCoreJava_whenListConvertedToArray_thenCorrect() { - final List sourceList = Lists. newArrayList(0, 1, 2, 3, 4, 5); + final List sourceList = Arrays.asList(0, 1, 2, 3, 4, 5); final Integer[] targetArray = sourceList.toArray(new Integer[sourceList.size()]); } From 0d1d3cbd8b9053548a7d480a4a80b8173c618c7d Mon Sep 17 00:00:00 2001 From: eugenp Date: Thu, 23 Jun 2016 10:11:56 +0300 Subject: [PATCH 15/19] minor cleanup --- jooq-spring/pom.xml | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/jooq-spring/pom.xml b/jooq-spring/pom.xml index 7a3ec0ac24..e77ff0cbfd 100644 --- a/jooq-spring/pom.xml +++ b/jooq-spring/pom.xml @@ -5,22 +5,13 @@ jooq-spring 0.0.1-SNAPSHOT - - 3.7.3 - 1.4.191 - 4.2.5.RELEASE - 1.7.18 - 1.1.3 - 4.12 - - org.springframework.boot spring-boot-dependencies - 1.3.3.RELEASE + 1.3.5.RELEASE pom import @@ -46,30 +37,25 @@ org.springframework spring-context - ${org.springframework.version} org.springframework spring-jdbc - ${org.springframework.version} org.springframework.boot spring-boot-starter-jooq - 1.3.3.RELEASE org.slf4j slf4j-api - ${org.slf4j.version} runtime ch.qos.logback logback-classic - ${ch.qos.logback.version} runtime @@ -77,15 +63,13 @@ junit junit - ${junit.version} test org.springframework spring-test - ${org.springframework.version} test - + @@ -166,6 +150,29 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + 3.7.3 + 1.4.191 + 4.2.5.RELEASE + 1.7.18 + 1.1.3 + 4.12 + + 3.5.1 + + \ No newline at end of file From 920991ece1c696baf941937bcb091ea0b2eb8e80 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Thu, 23 Jun 2016 11:33:25 +0200 Subject: [PATCH 16/19] Pom fix --- assertj/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assertj/pom.xml b/assertj/pom.xml index 21cd0c0121..ce97278a97 100644 --- a/assertj/pom.xml +++ b/assertj/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.baeldung - assertj-introduction + assertj 1.0.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 505b72e1ab..75281ce80d 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ apache-fop - assertj-introduction + assertj core-java core-java-8 From b3e9b08887fbf46d05acb301d710e7bd6877396c Mon Sep 17 00:00:00 2001 From: Eugen Date: Thu, 23 Jun 2016 17:15:46 +0300 Subject: [PATCH 17/19] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da46989455..f0d3d29da7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ The "REST with Spring" Classes ============================== -After 5 months of work, here's the Master Class:
+After 5 months of work, here's the Master Class of REST With Spring:
**[>> THE REST WITH SPRING MASTER CLASS](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)** @@ -19,3 +19,8 @@ Any IDE can be used to work with the projects, but if you're using Eclipse, cons - import the included **formatter** in Eclipse: `https://github.com/eugenp/tutorials/tree/master/eclipse` + + +CI - Jenkins +================================ +This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials/)** From 024b4f8f614debf5c20da774bd438534d03cdd4f Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Thu, 23 Jun 2016 17:33:59 +0200 Subject: [PATCH 18/19] Add additional AssertJ examples --- .gitignore | 1 + ...ertJDemoTest.java => AssertJCoreTest.java} | 68 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) rename assertj/src/test/java/com/baeldung/assertj/introduction/{AssertJDemoTest.java => AssertJCoreTest.java} (54%) diff --git a/.gitignore b/.gitignore index e841cc4bf5..319eb5ca2d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ target/ spring-openid/src/main/resources/application.properties .recommenders/ + diff --git a/assertj/src/test/java/com/baeldung/assertj/introduction/AssertJDemoTest.java b/assertj/src/test/java/com/baeldung/assertj/introduction/AssertJCoreTest.java similarity index 54% rename from assertj/src/test/java/com/baeldung/assertj/introduction/AssertJDemoTest.java rename to assertj/src/test/java/com/baeldung/assertj/introduction/AssertJCoreTest.java index 729c252c3c..21bc40ae9f 100644 --- a/assertj/src/test/java/com/baeldung/assertj/introduction/AssertJDemoTest.java +++ b/assertj/src/test/java/com/baeldung/assertj/introduction/AssertJCoreTest.java @@ -2,17 +2,23 @@ package com.baeldung.assertj.introduction; import com.baeldung.assertj.introduction.domain.Dog; import com.baeldung.assertj.introduction.domain.Person; +import org.assertj.core.util.Maps; import org.junit.Ignore; import org.junit.Test; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; import static org.assertj.core.api.Assertions.withPrecision; -public class AssertJDemoTest { +public class AssertJCoreTest { @Test public void whenComparingReferences_thenNotEqual() throws Exception { @@ -42,6 +48,10 @@ public class AssertJDemoTest { public void whenCheckingForElement_thenMultipleAssertions() throws Exception { List list = Arrays.asList("1", "2", "3"); + assertThat(list).isNotEmpty(); + assertThat(list).startsWith("1"); + assertThat(list).doesNotContainNull(); + assertThat(list) .isNotEmpty() .contains("1") @@ -55,6 +65,17 @@ public class AssertJDemoTest { assertThat(Runnable.class).isInterface(); } + @Test + public void whenCheckingCharacter_thenIsUnicode() throws Exception { + char someCharacter = 'c'; + + assertThat(someCharacter) + .isNotEqualTo('a') + .inUnicode() + .isGreaterThanOrEqualTo('b') + .isLowerCase(); + } + @Test public void whenAssigningNSEExToException_thenIsAssignable() throws Exception { assertThat(Exception.class).isAssignableFrom(NoSuchElementException.class); @@ -65,6 +86,51 @@ public class AssertJDemoTest { assertThat(5.1).isEqualTo(5, withPrecision(1d)); } + @Test + public void whenCheckingString_then() throws Exception { + assertThat("".isEmpty()).isTrue(); + } + + @Test + public void whenCheckingFile_then() throws Exception { + final File someFile = File.createTempFile("aaa", "bbb"); + someFile.deleteOnExit(); + + assertThat(someFile) + .exists() + .isFile() + .canRead() + .canWrite(); + } + + @Test + public void whenCheckingIS_then() throws Exception { + InputStream given = new ByteArrayInputStream("foo".getBytes()); + InputStream expected = new ByteArrayInputStream("foo".getBytes()); + + assertThat(given).hasSameContentAs(expected); + } + + @Test + public void whenGivenMap_then() throws Exception { + Map map = Maps.newHashMap(2, "a"); + + assertThat(map) + .isNotEmpty() + .containsKey(2) + .doesNotContainKeys(10) + .contains(entry(2, "a")); + } + + @Test + public void whenGivenException_then() throws Exception { + Exception ex = new Exception("abc"); + + assertThat(ex) + .hasNoCause() + .hasMessageEndingWith("c"); + } + @Ignore // IN ORDER TO TEST, REMOVE THIS LINE @Test public void whenRunningAssertion_thenDescribed() throws Exception { From 57ed00a134839fb50b2bce7f0224121e6a0c3351 Mon Sep 17 00:00:00 2001 From: Dmytro Kulaiev Date: Fri, 24 Jun 2016 16:41:41 +0300 Subject: [PATCH 19/19] Code examples for Java 8 date migration (#460) --- .../baeldung/date_migration/Conversion.java | 19 ++++++ .../com/baeldung/date_migration/NewApi.java | 54 +++++++++++++++ .../com/baeldung/date_migration/OldApi.java | 68 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java create mode 100644 core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java create mode 100644 core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java diff --git a/core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java b/core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java new file mode 100644 index 0000000000..c672b7ee44 --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/date_migration/Conversion.java @@ -0,0 +1,19 @@ +package com.baeldung.date_migration; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +public class Conversion { + public static void main(String[] args) { + Instant instantFromCalendar = GregorianCalendar.getInstance().toInstant(); + ZonedDateTime zonedDateTimeFromCalendar = new GregorianCalendar().toZonedDateTime(); + Date dateFromInstant = Date.from(Instant.now()); + GregorianCalendar calendarFromZonedDateTime = GregorianCalendar.from(ZonedDateTime.now()); + Instant instantFromDate = new Date().toInstant(); + ZoneId zoneIdFromTimeZone = TimeZone.getTimeZone("PST").toZoneId(); + } +} diff --git a/core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java b/core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java new file mode 100644 index 0000000000..0abf7f7864 --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/date_migration/NewApi.java @@ -0,0 +1,54 @@ +package com.baeldung.date_migration; + +import java.text.ParseException; +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + +public class NewApi { + public void currentTime() { + ZonedDateTime now = ZonedDateTime.now(); + } + + public void specificTime() { + LocalDate birthDay = LocalDate.of(1990, Month.DECEMBER, 15); + } + + public void extractMonth() { + Month month = LocalDateTime.now().getMonth(); + } + + public void subtractTime() { + LocalDateTime fiveHoursBefore = LocalDateTime.now().minusHours(5); + } + + public void alterField() { + LocalDateTime inJune = LocalDateTime.now().withMonth(Month.JUNE.getValue()); + } + + public void truncate() { + LocalTime truncated = LocalTime.now().truncatedTo(ChronoUnit.HOURS); + } + + public void convertTimeZone() { + ZonedDateTime centralEastern = LocalDateTime.now().atZone(ZoneId.of("CET")); + } + + public void getTimeSpan() { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime hourLater = LocalDateTime.now().plusHours(1); + Duration span = Duration.between(now, hourLater); + } + + public void formatAndParse() throws ParseException { + LocalDate now = LocalDate.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String formattedDate = now.format(formatter); + LocalDate parsedDate = LocalDate.parse(formattedDate, formatter); + } + + public void daysInMonth() { + int daysInMonth = YearMonth.of(1990, 2).lengthOfMonth(); + } + +} diff --git a/core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java b/core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java new file mode 100644 index 0000000000..de4edf99e9 --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/date_migration/OldApi.java @@ -0,0 +1,68 @@ +package com.baeldung.date_migration; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +public class OldApi { + public void currentTime() { + Date now = new Date(); + } + + public void specificTime () { + Date birthDay = new GregorianCalendar(1990, Calendar.DECEMBER, 15).getTime(); + } + + public void extractMonth() { + int month = new GregorianCalendar().get(Calendar.MONTH); + } + + public void subtractTime() { + GregorianCalendar calendar = new GregorianCalendar(); + calendar.add(Calendar.HOUR_OF_DAY, -5); + Date fiveHoursBefore = calendar.getTime(); + } + + public void alterField() { + GregorianCalendar calendar = new GregorianCalendar(); + calendar.set(Calendar.MONTH, Calendar.JUNE); + Date inJune = calendar.getTime(); + } + + public void truncate() { + Calendar now = Calendar.getInstance(); + now.set(Calendar.MINUTE, 0); + now.set(Calendar.SECOND, 0); + now.set(Calendar.MILLISECOND, 0); + Date truncated = now.getTime(); + } + + public void convertTimeZone() { + GregorianCalendar calendar = new GregorianCalendar(); + calendar.setTimeZone(TimeZone.getTimeZone("CET")); + Date centralEastern = calendar.getTime(); + } + + public void getTimeSpan() { + GregorianCalendar calendar = new GregorianCalendar(); + Date now = new Date(); + calendar.add(Calendar.HOUR, 1); + Date hourLater = calendar.getTime(); + long elapsed = hourLater.getTime() - now.getTime(); + } + + public void formatAndParse() throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date now = new Date(); + String formattedDate = dateFormat.format(now); + Date parsedDate = dateFormat.parse(formattedDate); + } + + public void daysInMonth() { + Calendar calendar = new GregorianCalendar(1990, Calendar.FEBRUARY, 20); + int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); + } +}