Skip to content

Instantly share code, notes, and snippets.

@andy-polhill
Created August 7, 2013 08:31
Show Gist options
  • Save andy-polhill/6172271 to your computer and use it in GitHub Desktop.
Save andy-polhill/6172271 to your computer and use it in GitHub Desktop.
public abstract class StringUtils {
public String cropAndConcat(String toCrop, int index, String toConcat) {
return toCrop.substring(index) + toConcat;
}
public String removeFromAndConcatToEnd(String containing, String concat) {
if (containing.contains(concat)) {
return containing;
}
return concat + containing;
}
public int getDriverAge(int months) {
return months / 12;
}
}
public class Car extends StringUtils {
private String model;
private String make;
private String driverName;
private int driverAge;
Car() {
super();
}
public String getModel() {
return removeFromAndConcatToEnd(model, "mark 2");
}
public String getMake() {
return make;
}
public String getDriverName() {
return driverName;
}
public int getDriverAge() {
return getDriverAge();
}
@Override
public boolean equals(Object that) {
if (that == null) {
throw new NullPointerException("that cannot be null");
}
if (!(that instanceof String)) {
return false;
}
String other = (String) that;
if (other.equals(model)) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment