Change-Id: Idde4fc54950f2bb83e0bb8d36a84a5bf075eb8detags/7.6.0.alpha1
import com.vaadin.shared.ui.LayoutClickRpc; | import com.vaadin.shared.ui.LayoutClickRpc; | ||||
import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc; | import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc; | ||||
import com.vaadin.shared.ui.csslayout.CssLayoutState; | import com.vaadin.shared.ui.csslayout.CssLayoutState; | ||||
import com.vaadin.shared.util.SharedUtil; | |||||
import com.vaadin.ui.CssLayout; | import com.vaadin.ui.CssLayout; | ||||
/** | /** | ||||
* @return A string converted to camelcase | * @return A string converted to camelcase | ||||
*/ | */ | ||||
private static final String makeCamelCase(String cssProperty) { | private static final String makeCamelCase(String cssProperty) { | ||||
// TODO this might be cleaner to implement with regexp | |||||
while (cssProperty.contains("-")) { | |||||
int indexOf = cssProperty.indexOf("-"); | |||||
cssProperty = cssProperty.substring(0, indexOf) | |||||
+ String.valueOf(cssProperty.charAt(indexOf + 1)) | |||||
.toUpperCase() + cssProperty.substring(indexOf + 2); | |||||
} | |||||
cssProperty = SharedUtil.dashSeparatedToCamelCase(cssProperty); | |||||
if ("float".equals(cssProperty)) { | if ("float".equals(cssProperty)) { | ||||
if (BrowserInfo.get().isIE()) { | if (BrowserInfo.get().isIE()) { | ||||
return "styleFloat"; | return "styleFloat"; |
import java.util.logging.Logger; | import java.util.logging.Logger; | ||||
import com.vaadin.data.Property; | import com.vaadin.data.Property; | ||||
import com.vaadin.shared.util.SharedUtil; | |||||
import com.vaadin.util.SerializerHelper; | import com.vaadin.util.SerializerHelper; | ||||
/** | /** | ||||
// Assure that the first letter is upper cased (it is a common | // Assure that the first letter is upper cased (it is a common | ||||
// mistake to write firstName, not FirstName). | // mistake to write firstName, not FirstName). | ||||
if (Character.isLowerCase(beanPropertyName.charAt(0))) { | |||||
final char[] buf = beanPropertyName.toCharArray(); | |||||
buf[0] = Character.toUpperCase(buf[0]); | |||||
beanPropertyName = new String(buf); | |||||
} | |||||
beanPropertyName = SharedUtil.capitalize(beanPropertyName); | |||||
// Find the get method | // Find the get method | ||||
getMethod = null; | getMethod = null; | ||||
*/ | */ | ||||
static Method initGetterMethod(String propertyName, final Class<?> beanClass) | static Method initGetterMethod(String propertyName, final Class<?> beanClass) | ||||
throws NoSuchMethodException { | throws NoSuchMethodException { | ||||
propertyName = propertyName.substring(0, 1).toUpperCase() | |||||
+ propertyName.substring(1); | |||||
propertyName = SharedUtil.capitalize(propertyName); | |||||
Method getMethod = null; | Method getMethod = null; | ||||
try { | try { | ||||
private static final Logger getLogger() { | private static final Logger getLogger() { | ||||
return Logger.getLogger(MethodProperty.class.getName()); | return Logger.getLogger(MethodProperty.class.getName()); | ||||
} | } | ||||
} | } |
import com.vaadin.data.Property; | import com.vaadin.data.Property; | ||||
import com.vaadin.data.util.MethodProperty.MethodException; | import com.vaadin.data.util.MethodProperty.MethodException; | ||||
import com.vaadin.shared.util.SharedUtil; | |||||
/** | /** | ||||
* Nested accessor based property for a bean. | * Nested accessor based property for a bean. | ||||
try { | try { | ||||
// Assure that the first letter is upper cased (it is a common | // Assure that the first letter is upper cased (it is a common | ||||
// mistake to write firstName, not FirstName). | // mistake to write firstName, not FirstName). | ||||
if (Character.isLowerCase(lastSimplePropertyName.charAt(0))) { | |||||
final char[] buf = lastSimplePropertyName.toCharArray(); | |||||
buf[0] = Character.toUpperCase(buf[0]); | |||||
lastSimplePropertyName = new String(buf); | |||||
} | |||||
lastSimplePropertyName = SharedUtil | |||||
.capitalize(lastSimplePropertyName); | |||||
setMethod = lastClass.getMethod("set" + lastSimplePropertyName, | setMethod = lastClass.getMethod("set" + lastSimplePropertyName, | ||||
new Class[] { type }); | new Class[] { type }); |
sb.append(parts[i]); | sb.append(parts[i]); | ||||
sb.append(separator); | sb.append(separator); | ||||
} | } | ||||
return sb.substring(0, sb.length() - 1); | |||||
return sb.substring(0, sb.length() - separator.length()); | |||||
} | } | ||||
/** | /** | ||||
* Capitalizes the first character in the given string | |||||
* Capitalizes the first character in the given string in a way suitable for | |||||
* use in code (methods, properties etc) | |||||
* | * | ||||
* @since 7.4 | * @since 7.4 | ||||
* @param string | * @param string | ||||
return uri; | return uri; | ||||
} | } | ||||
/** | |||||
* Converts a dash ("-") separated string into camelCase. | |||||
* <p> | |||||
* Examples: | |||||
* <p> | |||||
* {@literal foo} becomes {@literal foo} {@literal foo-bar} becomes | |||||
* {@literal fooBar} {@literal foo--bar} becomes {@literal fooBar} | |||||
* | |||||
* @since | |||||
* @param dashSeparated | |||||
* The dash separated string to convert | |||||
* @return a camelCase version of the input string | |||||
*/ | |||||
public static String dashSeparatedToCamelCase(String dashSeparated) { | |||||
if (dashSeparated == null) { | |||||
return null; | |||||
} | |||||
String[] parts = dashSeparated.split("-"); | |||||
for (int i = 1; i < parts.length; i++) { | |||||
parts[i] = capitalize(parts[i]); | |||||
} | |||||
return join(parts, ""); | |||||
} | |||||
} | } |
import static org.hamcrest.CoreMatchers.is; | import static org.hamcrest.CoreMatchers.is; | ||||
import static org.junit.Assert.assertThat; | import static org.junit.Assert.assertThat; | ||||
import java.util.Locale; | |||||
import org.junit.Assert; | import org.junit.Assert; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
String[] splitParts = SharedUtil.splitCamelCase(camelCaseString); | String[] splitParts = SharedUtil.splitCamelCase(camelCaseString); | ||||
Assert.assertArrayEquals(parts, splitParts); | Assert.assertArrayEquals(parts, splitParts); | ||||
} | } | ||||
@Test | |||||
public void join() { | |||||
String s1 = "foo-bar-baz"; | |||||
String s2 = "foo--bar"; | |||||
Assert.assertEquals("foobarbaz", SharedUtil.join(s1.split("-"), "")); | |||||
Assert.assertEquals("foo!bar!baz", SharedUtil.join(s1.split("-"), "!")); | |||||
Assert.assertEquals("foo!!bar!!baz", | |||||
SharedUtil.join(s1.split("-"), "!!")); | |||||
Assert.assertEquals("foo##bar", SharedUtil.join(s2.split("-"), "#")); | |||||
} | |||||
@Test | |||||
public void dashSeparatedToCamelCase() { | |||||
Assert.assertEquals(null, SharedUtil.dashSeparatedToCamelCase(null)); | |||||
Assert.assertEquals("", SharedUtil.dashSeparatedToCamelCase("")); | |||||
Assert.assertEquals("foo", SharedUtil.dashSeparatedToCamelCase("foo")); | |||||
Assert.assertEquals("fooBar", | |||||
SharedUtil.dashSeparatedToCamelCase("foo-bar")); | |||||
Assert.assertEquals("fooBar", | |||||
SharedUtil.dashSeparatedToCamelCase("foo--bar")); | |||||
Assert.assertEquals("fooBarBaz", | |||||
SharedUtil.dashSeparatedToCamelCase("foo-bar-baz")); | |||||
Assert.assertEquals("fooBarBaz", | |||||
SharedUtil.dashSeparatedToCamelCase("foo-Bar-Baz")); | |||||
} | |||||
@Test | |||||
public void methodUppercaseWithTurkishLocale() { | |||||
Locale defaultLocale = Locale.getDefault(); | |||||
try { | |||||
Locale.setDefault(new Locale("tr", "TR")); | |||||
Assert.assertEquals("Integer", SharedUtil.capitalize("integer")); | |||||
} finally { | |||||
Locale.setDefault(defaultLocale); | |||||
} | |||||
} | |||||
} | } |
*/ | */ | ||||
package com.vaadin.tests.themes.valo; | package com.vaadin.tests.themes.valo; | ||||
import com.vaadin.shared.util.SharedUtil; | |||||
public class StringGenerator { | public class StringGenerator { | ||||
static String[] strings = new String[] { "lorem", "ipsum", "dolor", "sit", | static String[] strings = new String[] { "lorem", "ipsum", "dolor", "sit", | ||||
"amet", "consectetur", "quid", "securi", "etiam", "tamquam", "eu", | "amet", "consectetur", "quid", "securi", "etiam", "tamquam", "eu", | ||||
if (++stringCount >= strings.length) { | if (++stringCount >= strings.length) { | ||||
stringCount = 0; | stringCount = 0; | ||||
} | } | ||||
return capitalize ? strings[stringCount].substring(0, 1).toUpperCase() | |||||
+ strings[stringCount].substring(1) : strings[stringCount]; | |||||
return capitalize ? SharedUtil.capitalize(strings[stringCount]) | |||||
: strings[stringCount]; | |||||
} | } | ||||
} | } |