id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
11f5c2f8-b880-4e98-86c2-5832f96e0907 | public Factory setPath(final String path) {
final ConfigurationSection section = this.base.getConfigurationSection(path);
if (section == null) throw new IllegalArgumentException("ConfigurationSection not found: " + path);
this.setBase(section);
return this;
} |
d06b9174-a262-4fe4-9442-c9cdf59d9033 | public Factory setFormatCode(final String key) {
final String value = this.base.getString(key);
if (value == null) throw new IllegalArgumentException("Color code not found: " + this.base.getCurrentPath() + this.base.getRoot().options().pathSeparator() + key);
this.setFormatCode(value.charAt(0));
return this;
} |
9e8fe0ea-56fe-47e6-b1d6-c28dcf18edd0 | public Factory setFormatCode(final char formatCode) {
this.formatCode = formatCode;
return this;
} |
8630f2e1-885a-4eda-a314-e1f04bfe4978 | @Override
public Factory setTimestamp(final boolean timestamp) {
super.setTimestamp(timestamp);
return this;
} |
7031fe8e-7deb-4ab0-a136-90968984deb5 | @Override
public ConfigurationCourier build() {
return new ConfigurationCourier(this);
} |
eca1aabb-cb33-48db-bd83-7f49b21e98e7 | public WorldPlayers(final World world) {
this.world = world;
} |
3da82d88-a677-49cb-856f-151c7111bc23 | public World getWorld() {
return this.world;
} |
03e48438-7009-4714-ba60-15ae59adde53 | @Override
public Confirmation deliver(final Message message) {
final List<Player> players = this.world.getPlayers();
for (final Player player : players)
player.sendMessage(message.format(player).toString());
final int count = players.size();
return new Confirmation(Level.FINE, count, "[WORLD%{1}({2})] {0}", message, WorldPlayers.this.world.getName(), count);
} |
c44f6854-2033-4e01-a7d4-a2ffbc727734 | public static TimeZone getTimeZone(final CommandSender sender) {
if (!(sender instanceof Metadatable))
return Recipients.DEFAULT_TIME_ZONE;
final Metadatable meta = (Metadatable) sender;
final List<MetadataValue> values = meta.getMetadata("TimeZone");
if (values.size() == 0)
return Recipients.DEFAULT_TIME_ZONE;
return (TimeZone) values.get(0).value();
} |
06f260b0-79a7-47ab-9361-9dcef9657025 | public abstract Confirmation deliver(Message message); |
bd49a3bf-2822-4a01-a2ad-37af4d3a17be | protected Courier(final Courier.Factory parameters) {
this.plugin = parameters.plugin;
this.timestamp = parameters.timestamp;
} |
963d3c37-6e25-40fb-a62f-ded6a30a12ff | public Plugin getPlugin() {
return this.plugin;
} |
b5a391b2-f2aa-4967-a5db-d24381c5b053 | public boolean getTimestamp() {
return this.timestamp;
} |
8dc596f0-b0ab-4975-a708-7c0a36f129f3 | public String formatMessage(final String pattern, final Object... arguments) {
return MessageFormat.format(pattern, arguments);
} |
d5073e16-c0d2-4ca6-9a40-9c97c2109f3c | public Message draft(final String pattern, final Object... arguments) {
final Message.Factory factory = Message.create(pattern, arguments);
if (this.timestamp) factory.timestamp();
return factory.build();
} |
36c231e6-cb06-498a-bb38-4b859f6d3a6b | public void submit(final Recipients recipients, final Message message) {
try {
final Confirmation confirmation = recipients.deliver(message);
this.plugin.getLogger().log(confirmation.toLogRecord());
} catch (final RuntimeException e) {
this.plugin.getLogger().log(Level.WARNING, "Error submitting message for delivery; pattern: \"{0}\"{1}; {2}", new Object[] { message.original, ChatColor.RESET, e });
}
} |
8faa6b82-f26d-49a2-a27f-f2373492db69 | public void sendMessage(final CommandSender sender, final String pattern, final Object... arguments) {
final Recipients recipients = new Individual(sender);
final Message message = this.draft(pattern, arguments);
this.submit(recipients, message);
} |
6a9947de-66e9-4075-a963-039b7f69d924 | public void broadcastMessage(final String pattern, final Object... arguments) {
final Recipients recipients = new ServerPlayers();
final Message message = this.draft(pattern, arguments);
this.submit(recipients, message);
} |
b8fa2304-fd60-43cf-bbc9-5f77e717915c | public void worldMessage(final World world, final String pattern, final Object... arguments) {
final Recipients recipients = new WorldPlayers(world);
final Message message = this.draft(pattern, arguments);
this.submit(recipients, message);
} |
9adec076-cb1f-4203-b6ef-5657a2d60467 | public void publishMessage(final String permission, final String pattern, final Object... arguments) {
final Recipients recipients = new PermissionSubscribers(permission);
final Message message = this.draft(pattern, arguments);
this.submit(recipients, message);
} |
c3fc4e7c-c19e-443b-ab9a-dbe910da07c5 | public static Factory create(final Plugin plugin) {
return Factory.create(plugin);
} |
ebeb94e8-081c-42cf-81c3-4fe3bb15f0d5 | public static Factory create(final Plugin plugin) {
return new Factory(plugin);
} |
bf6a7bb3-2eb5-4a08-a403-42e8a58dbc94 | protected Factory(final Plugin plugin) {
this.plugin = plugin;
this.setTimestamp(true);
} |
a402264e-f0b1-46dd-8d2f-f460924f8711 | public Factory setTimestamp(final boolean timestamp) {
this.timestamp = true;
return this;
} |
60b4ded6-896a-4fc1-879a-64349b12dd35 | public Courier build() {
return new Courier(this);
} |
dec83928-9a6a-42b5-95b4-00378df4dac9 | public Individual(final CommandSender target) {
this.target = target;
} |
3bf193d2-c288-45ea-b83f-74b50d8b7488 | @Override
public Confirmation deliver(final Message message) {
final String formatted = message.format(this.target).toString();
this.target.sendMessage(formatted);
return new Confirmation(this.level(), 1, "[SEND>{1}] {0}", message, Individual.this.target.getName());
} |
96e3fa70-9411-469c-84c9-3e99024b6bc8 | private Level level() {
return (this.target instanceof Player ? Level.FINER : Level.FINEST);
} |
0bdc1250-6162-4b1a-81c5-e0a593f0cfe5 | protected Message(final String pattern, final Object... arguments) {
super(pattern);
this.original = pattern;
this.arguments = arguments;
this.suffix = null;
} |
8e83cfe7-28b6-42ac-887d-8b0c61dcb055 | public StringBuffer format(final CommandSender target) {
// format all dates with time zone for target
TimeZone timeZone = null;
final Format[] formats = this.getFormatsByArgumentIndex();
for(int i = 0; i < formats.length; i++) {
if (!(formats[i] instanceof DateFormat)) continue;
if (timeZone == null) timeZone = Recipients.getTimeZone(target);
final DateFormat sdf = (DateFormat) formats[i];
sdf.setTimeZone(timeZone);
this.setFormatByArgumentIndex(i, sdf);
}
final StringBuffer formatted = this.format(this.arguments, new StringBuffer(), null);
if (this.suffix != null) formatted.append(this.suffix.format(target));
return formatted;
} |
8e0a1b29-9922-498c-8ef0-1d81a4601da7 | public Message append(final Message suffix) {
if (this.suffix != null) {
this.suffix.append(suffix);
return this;
}
this.suffix = suffix;
return this;
} |
389f2dc8-5e43-4507-a36f-4649cf329e73 | public Message getSuffix() {
return this.suffix;
} |
348aa038-d8f8-4292-bed8-06329534b376 | @Override
public String toString() {
return this.format(Bukkit.getConsoleSender()).toString();
} |
0238db8f-96ca-4104-8e7a-302379311b42 | public static Factory create(final String pattern, final Object... arguments) {
return Factory.create(pattern, arguments);
} |
f2ec3b68-7f94-440a-a65b-26b21895fb80 | public static Factory create(final String pattern, final Object... arguments) {
return new Factory(pattern, arguments);
} |
a8ca7f34-b372-4a7b-bf36-162ef065fe11 | protected Factory(final String pattern, final Object... arguments) {
this.pattern = pattern;
this.arguments = arguments;
} |
11e7496d-e989-4a23-8b95-76ac01fbf5c5 | public Factory timestamp() {
final Object[] prepend = new Object[this.arguments.length + 1];
prepend[0] = new Date();
if (this.arguments.length >= 1) System.arraycopy(this.arguments, 0, prepend, 1, this.arguments.length);
this.arguments = prepend;
return this;
} |
2024dcde-4b07-4cd5-a808-8790838aebb5 | public Message build() {
return new Message(this.pattern, this.arguments);
} |
43219830-ea45-4fb5-a669-25c9933f5c78 | public PermissionSubscribers(final String permission) {
this.permission = permission;
} |
e9cff974-0837-4ea1-9c47-39aeb6c08912 | @Override
public Confirmation deliver(final Message message) {
int count = 0;
for (final Permissible permissible : Bukkit.getPluginManager().getPermissionSubscriptions(this.permission))
if (permissible instanceof CommandSender && permissible.hasPermission(this.permission)) {
final CommandSender target = (CommandSender) permissible;
target.sendMessage(message.format(target).toString());
count++;
}
return new Confirmation(Level.FINER, count, "[PUBLISH-{1}({2})] {0}", message, PermissionSubscribers.this.permission, count);
} |
d0f96d1b-5f81-4735-9ace-b251ca25e8da | public ComponentSelector(final CodeBuilder code) {
super("Component Selector");
for (final Class c : components) {
try {
final StatementComponent sc = (StatementComponent) c.newInstance();
JLabel label = new JLabel(c.getSimpleName(), sc.getIcon(), JLabel.CENTER);
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (JOptionPane.showConfirmDialog(ComponentSelector.this, sc) == JOptionPane.OK_OPTION) {
code.addItem(sc);
dispose();
}
}
});
add(label);
} catch (Exception ignored) {
}
}
setLayout(new GridLayout(2, 2));
setSize(320, 240);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setVisible(true);
} |
cf59472e-8b46-4a83-809f-237e797fa366 | @Override
public void mouseClicked(MouseEvent e) {
if (JOptionPane.showConfirmDialog(ComponentSelector.this, sc) == JOptionPane.OK_OPTION) {
code.addItem(sc);
dispose();
}
} |
73061209-31d3-4bef-b19d-55eb92816b38 | private CodeBuilder() {
super("CodeBuilder");
components = new HashMap<String, StatementComponent>();
tree = new JTree();
tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Project")));
tree.setBorder(new EmptyBorder(5, 5, 5, 5));
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (!e.getComponent().equals(tree) || tree.getSelectionPath() == null) return;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.getClickCount() == 2) {
if (components.get(tree.getSelectionPath().toString()) == null) System.out.println("Null");
JOptionPane.showMessageDialog(CodeBuilder.this, components.get(tree.getSelectionPath().toString()));
}
} else {
new ComponentSelector(CodeBuilder.this);
}
}
});
add(tree);
setSize(640, 480);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
} |
47e1653f-0887-4a63-b9fc-8888750390d8 | @Override
public void mousePressed(MouseEvent e) {
if (!e.getComponent().equals(tree) || tree.getSelectionPath() == null) return;
if (e.getButton() == MouseEvent.BUTTON1) {
if (e.getClickCount() == 2) {
if (components.get(tree.getSelectionPath().toString()) == null) System.out.println("Null");
JOptionPane.showMessageDialog(CodeBuilder.this, components.get(tree.getSelectionPath().toString()));
}
} else {
new ComponentSelector(CodeBuilder.this);
}
} |
2df9da8b-0d9d-4db0-a709-e71b3bf17c2e | public static void main(String[] args) {
new CodeBuilder();
} |
c77d0de1-c499-4f4e-b3b7-12417af7b423 | public void addItem(StatementComponent sc) {
components.put(tree.getSelectionPath().pathByAddingChild(sc.toSimple()).toString(), sc);
((DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent()).add(new DefaultMutableTreeNode(sc.toSimple()));
} |
c7f6dcfd-9fec-482b-8c80-e5db68736d7f | public Clazz() {
super("cl");
name = new JTextField();
visibility = Utils.createComboBox(Visibility.values());
add(visibility);
add(name);
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
} |
1f0de8b0-fd24-4427-8803-dbccca96c5b7 | @Override
public String toCode(Language lang) {
if (lang == Language.JAVA) return visibility.getSelectedItem() + " class " + name.getText() + " {";
return "Not supported.";
} |
9cb47bed-5ade-4b8f-9157-a3a62467c435 | @Override
public String toSimple() {
return "Class " + name.getText();
} |
933f415f-0f55-40da-b972-e92055d072f3 | public CustomLine() {
super("ln");
line = new JTextField();
add(line);
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
} |
8f5bc7ac-d46c-4c68-9552-9fc30b496515 | @Override
public String toCode(Language lang) {
return line.getText();
} |
f801a923-2629-45ab-848f-09bc4c510228 | @Override
public String toSimple() {
return "Line " + line.getText();
} |
0a3fc0bd-73c1-40d7-8838-ecbe05868472 | StatementComponent(String iconName) {
try {
icon = new ImageIcon(ImageIO.read(CodeBuilder.class.getResource("/res/" + iconName + ".png")));
} catch (Exception ignored) {
ignored.printStackTrace();
}
} |
33e4adb9-3550-4b60-8d4d-a4347e95064e | public ImageIcon getIcon() {
return icon;
} |
8459583c-22c8-4965-806d-9f43e994c545 | public abstract String toCode(Language lang); |
c97242ab-502a-4c57-9c28-8a1f461f22a6 | public abstract String toSimple(); |
3b68ec23-4665-4a4a-846c-377ab6933e6e | public If() {
super("if");
a = new JTextField();
b = new JTextField();
operator = Utils.createComboBox(Operation.values());
add(a);
add(operator);
add(b);
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
} |
0e462a9f-89f5-466d-8fa4-086a688e6c4c | @Override
public String toCode(Language lang) {
if (lang == Language.JAVA)
return "if (" + a.getText() + " " + operator.getSelectedItem() + " " + b.getText() + ") {";
return "Not supported.";
} |
aaeb7d0f-8d72-4cd7-ae35-c85ec580066e | @Override
public String toSimple() {
return "If " + a.getText() + " " + ((Operation) operator.getSelectedItem()).name().toLowerCase() + " " + b.getText();
} |
78b5b4b9-1fc8-4b2f-9ec0-8921d780f908 | @Override
public String toString() {
return this == NONE ? "" : name().toLowerCase();
} |
c37ee652-8aa3-42a1-ab9d-b74183f06914 | public static <T extends Enum<T>> JComboBox createComboBox(Enum<T>[] e) {
JComboBox box = new JComboBox();
for (Enum<T> v : e) box.addItem(v);
return box;
} |
2364bde1-fd3c-48e5-a69c-9153164ca7bd | Operation(String op) {
this.op = op;
} |
0c52bd5c-1ac4-4453-9882-2ab80b9992e6 | @Override
public String toString() {
return op;
} |
a52a8c1d-1aa4-42b7-acf3-b6b450e0138b | public String convert(String inFix){
inFix = inFix.replaceAll("\\s", "");
char charValue;
int i = 0;
while(i < inFix.length()){
charValue = inFix.charAt(i);
if (operator.contains(charValue)){
if (arrayStack.length() == 0){
arrayStack.push(charValue);
i++;
}
else{
while (operatorGreaterOrEqual(arrayStack.peek(), charValue)){
if (arrayStack.peek() == '('){
break;
}
postFix.append(arrayStack.pop())
.append(' ');
if (arrayStack.length() == 0){
break;
}
}
arrayStack.push(charValue);
i++;
}
}
else if (charValue == '('){
arrayStack.push(charValue);
i++;
}
else if (charValue == ')'){
while (arrayStack.peek() != '('){
postFix.append(arrayStack.pop())
.append(' ');
}
i++;
arrayStack.pop();
}
else if (charValue >= '0' && charValue <= '9'){
while (charValue >= '0' && charValue <= '9'){
postFix.append(charValue);
i++;
if (i == inFix.length()) break;
charValue = inFix.charAt(i);
}
postFix.append(' ');
}
else throw new IllegalArgumentException("Must be a number or one of the allowable operators");
}
while (arrayStack.length() > 0){
postFix.append(arrayStack.pop())
.append(' ');
}
return postFix.toString().trim();
} |
2ad91b29-1b64-4905-895d-a8d9289a92ef | private boolean operatorGreaterOrEqual (char left, char right){
int leftValue = 0, rightValue = 0;
switch (left){
case '+': leftValue = 1; break;
case '-': leftValue = 1; break;
case '*': leftValue = 2; break;
case '/': leftValue = 2; break;
case '(': leftValue = 3; break;
}
switch (right){
case '+': rightValue = 1; break;
case '-': rightValue = 1; break;
case '*': rightValue = 2; break;
case '/': rightValue = 2; break;
case '(': rightValue = 3; break;
}
return leftValue >= rightValue;
} |
741b38e7-099e-40eb-9783-b131d50888b4 | public static void main (String[] args){
String string = new String("(12+2)*3+4*+57/68/ (79+8(9+0))*(4+3*4)");
InfixToPostfixConverter converter = new InfixToPostfixConverter();
string = converter.convert(string);
System.out.println(string);
} |
a1329500-410e-46e2-9960-981cd93c30de | ArrayStack(){
arrayStack = (T[]) new Object[DEFAULT_ARRAY_SIZE];
index = 0;
} |
b08822a2-58ec-4810-8676-33d377e39367 | ArrayStack(int arraySize){
arrayStack = (T[]) new Object[arraySize];
index = 0;
} |
b7292425-02f4-4b3c-8d01-5094e60661c2 | public void push(T inf){
if (index == arrayStack.length) doubleArray();
arrayStack[index] = inf;
index++;
} |
4fb86fab-6715-42ee-8d78-3270f1f559cb | public T pop(){
if (index == 0) throw new IndexOutOfBoundsException("Can't pop. Out of bounds");
index--;
return arrayStack[index];
} |
6543bc40-06cf-4bfa-8f5c-b82007477526 | public T peek(){
if (index == 0) throw new IndexOutOfBoundsException("Can't peek. Out of bounds");
int tempIndex = index - 1;
return arrayStack[tempIndex];
} |
4bf1f1e6-378b-4391-898d-043e03508aca | public int length(){
return index;
} |
8aed8e8f-b246-47bb-9138-fe9a62a2f939 | private void doubleArray(){
T[] temp = (T[]) new Object[arrayStack.length*2];
for(int i = 0; i < arrayStack.length; i++){
temp[i] = arrayStack[i];
}
arrayStack = temp;
} |
7af66c45-7fa9-42fb-b231-17e5a4f4c914 | public static void main (String[] args)
{
String expression, again;
int result;
try
{
Scanner in = new Scanner(System.in);
do
{
PostfixEvaluator evaluator = new PostfixEvaluator();
System.out.println ("Enter a valid postfix expression: ");
expression = in.nextLine();
result = evaluator.evaluate (expression);
System.out.println();
System.out.println ("That expression equals " + result);
System.out.print ("Evaluate another expression [Y/N]? ");
again = in.nextLine();
System.out.println();
}
while (again.equalsIgnoreCase("y"));
}
catch (Exception IOException)
{
System.out.println("Input exception reported");
}
} |
17ac8817-2ee8-457d-a47a-528984433fd6 | public static void main (String[] args) throws Exception {
int results;
String string = new String();
Scanner scanner = new Scanner(System.in);
InfixToPostfixConverter converter = new InfixToPostfixConverter();
PostfixEvaluator evaluator = new PostfixEvaluator();
System.out.println("Enter an infix expression using '+', '-', '*', '/', '(', ')'");
string = scanner.nextLine();
string = converter.convert(string);
System.out.println("Postfix is: " + string);
results = evaluator.evaluate(string);
System.out.println("Result is: " + results);
} |
5e62e7c0-8653-458d-a98e-aff59c967b6c | public PostfixEvaluator()
{
stack = new ArrayStack<Integer>();
} |
e0a1461f-5e74-4d10-8351-04b2ca8b6848 | public int evaluate (String expr)
{
int op1, op2, result = 0;
String token;
StringTokenizer tokenizer = new StringTokenizer (expr);
while (tokenizer.hasMoreTokens())
{
token = tokenizer.nextToken();
if (isOperator(token))
{
op2 = (stack.pop()).intValue();
op1 = (stack.pop()).intValue();
result = evalSingleOp (token.charAt(0), op1, op2);
stack.push (new Integer(result));
}
else
stack.push (new Integer(Integer.parseInt(token)));
}
return result;
} |
2b286f85-62f3-4e64-a763-45291cf270f6 | private boolean isOperator (String token)
{
return ( token.equals("+") || token.equals("-") ||
token.equals("*") || token.equals("/") );
} |
0450c779-e6a3-42fd-ba96-6a02dafaf2e7 | private int evalSingleOp (char operation, int op1, int op2)
{
int result = 0;
switch (operation)
{
case ADD:
result = op1 + op2;
break;
case SUBTRACT:
result = op1 - op2;
break;
case MULTIPLY:
result = op1 * op2;
break;
case DIVIDE:
result = op1 / op2;
}
return result;
} |
a7a8c907-c2ce-4c3b-bc4a-967e6afd2ae9 | @Before
public void setUp() throws Exception {
inicio = new CargarFichero();
} |
5d8b22a7-d5f6-41b2-ba15-ac6949949c93 | @Test
public void testLoadData() {
String path = "test.tsp";
StringTokenizer contenidoFichero = inicio.cargarFichero(path);
assertNotNull("Error: El fichero no se ha cargado correctamente",
contenidoFichero);
String cadenarecostrudiacontenidofichero = reconstruirCadena(contenidoFichero);
assertNotNull("Error: El fichero no se ha cargado correctamente",
cadenarecostrudiacontenidofichero);
assertTrue(
"Error: El fichero no contiene ningún dato o se ha cargado incorrectamente",
cadenarecostrudiacontenidofichero.length() > 0);
} |
5f0a0c39-5ae0-441a-8398-ca0a8cbfe001 | private String reconstruirCadena(StringTokenizer contenidoFichero) {
StringBuilder cadena = new StringBuilder();
while (contenidoFichero.hasMoreTokens()) {
cadena.append(contenidoFichero.nextToken());
}
return cadena.toString();
} |
2b757b82-96cb-4199-8a1e-700fcf3f1087 | @Before
public void setUp() throws Exception {
} |
105a3c22-8830-4c82-8560-e13c5d603db0 | @Test
public void test() {
fail("Not yet implemented");
} |
84ea54d9-04d6-4dde-a45d-8bd5c442c149 | @Before
public void setUp() throws Exception {
} |
870a45bf-cc0f-48fb-bce8-370deb4c276f | @Test
public void testConstruirMatrizDijkstra() {
fail("Not yet implemented");
} |
1134b03a-ee67-41d1-adf3-bbf164b257e3 | @Before
public void setUp() throws Exception {
ACS = new SimpleACS();
// ACS.CITIES = NUM_CIUDADES;
} |
b7a6731d-a9e8-48c7-a12e-b6c63c3a7703 | @Test
public void test() {
ACS.iniciar("test1.tsp");
int expected[] = new int[NUM_CIUDADES + 1];
for (int i = 0; i < expected.length - 1; i++) {
expected[i] = i;
}
expected[expected.length - 1] = 0;
// assertArrayEqucals(expected, ACS.NNTour);
} |
015e64d0-49da-4af7-85f6-c9e0b091856b | public static void main(String args[]) {
String ficheroaabrir = "eil51.tsp";
SimpleACS main = new SimpleACS();
main.iniciar(ficheroaabrir);
main.ejecutar();
main.finalizar();
} |
236be7d0-d190-40b6-b5fe-e28128e23c04 | public int[][] generarMatriz(StringTokenizer contenidoFicheroCargado) {
int numerodeciudades = obtenerNumeroDeCiudades(contenidoFicheroCargado);
return construirMatrizDijkstra(contenidoFicheroCargado,
numerodeciudades);
} |
27dd6c95-28f2-43a8-9eca-c86cc6930f86 | public int[][] construirMatrizDijkstra(
StringTokenizer contenidodelficherocontokens, int numerodeciudades) {
String cadenaleida = "";
String edgeWeightType = "UNKNOWN";
int resultado[][] = {};
cadenaleida = contenidodelficherocontokens.nextToken();
if (cadenaleida.equals("EDGE WEIGHT TYPE")) {
contenidodelficherocontokens.nextToken();
edgeWeightType = contenidodelficherocontokens.nextToken();
if (edgeWeightType.equals("EXPLICIT")) {
resultado = construirMatrizExplicita(
contenidodelficherocontokens, numerodeciudades);
} else {
resultado = construirMatrizDijkstraCalculoDistanciaEuclides(
contenidodelficherocontokens, numerodeciudades);
}
} else if (cadenaleida.equals("EDGE WEIGHT TYPE:")) {
edgeWeightType = contenidodelficherocontokens.nextToken();
if (edgeWeightType.equals("EXPLICIT")) {
resultado = construirMatrizExplicita(
contenidodelficherocontokens, numerodeciudades);
} else {
resultado = construirMatrizDijkstraCalculoDistanciaEuclides(
contenidodelficherocontokens, numerodeciudades);
}
}
return resultado;
} |
2ac2df3a-3d11-4caf-89d6-bad178d224e7 | public int[][] calculoDistanciaPorEuclides(double[][] coordenadas,
int numerodeciudades) {
final int indiceprimeracoordenada = 0;
final int indicesegundacoordenada = 1;
int matrizDistancias[][] = new int[numerodeciudades][numerodeciudades];
int dist = 0;
for (int j = 0; j < coordenadas.length; j++) {
for (int i = j; i < coordenadas.length; i++) {
dist = (int) Math
.floor(.5 + Math.sqrt(Math
.pow(coordenadas[i][indiceprimeracoordenada]
- coordenadas[j][indiceprimeracoordenada],
2.0)
+ Math.pow(
coordenadas[i][indicesegundacoordenada]
- coordenadas[j][indicesegundacoordenada],
2.0)));
matrizDistancias[i][j] = dist;
matrizDistancias[j][i] = dist;
}
}
return matrizDistancias;
} |
8fc5955e-af87-4dab-abd4-0bd1cdd8b403 | private int[][] construirMatrizDijkstraCalculoDistanciaEuclides(
StringTokenizer strTok, int numerodeciudades) {
double coordenadas[][] = new double[numerodeciudades][2];
final int indiceprimeracoordenada = 0;
final int indicesegundacoordenada = 1;
int contador = 0;
String cadenaleida = "";
while (!cadenaleida.equals("EOF")) {
cadenaleida = strTok.nextToken();
if (cadenaleida.equals("NODE COORD SECTION")) {
cadenaleida = strTok.nextToken();
while (!cadenaleida.equals("EOF")) {
coordenadas[contador][indiceprimeracoordenada] = Double
.parseDouble(strTok.nextToken());
coordenadas[contador][indicesegundacoordenada] = Double
.parseDouble(strTok.nextToken());
contador++;
cadenaleida = strTok.nextToken();
}
}
}
int matrizAuxiliar[][] = new int[numerodeciudades][numerodeciudades];
matrizAuxiliar = calculoDistanciaPorEuclides(coordenadas,
numerodeciudades);
return matrizAuxiliar;
} |
a771082f-b1c1-4ed9-a00f-2a93c563b82b | private int[][] construirMatrizExplicita(StringTokenizer strTok,
int numerodeciudades) {
int matrizAuxiliar[][] = new int[numerodeciudades][numerodeciudades];
int countI = 0;
int countJ = 0;
String cadenaleida = "";
while (!cadenaleida.equals("EOF")) {
cadenaleida = strTok.nextToken();
if (cadenaleida.equals("EDGE WEIGHT SECTION")) {
boolean finfichero = false;
while (!finfichero) {
cadenaleida = strTok.nextToken();
if (cadenaleida.equals("EOF")) {
finfichero = true;
}
if (cadenaleida.equals("0")) {
matrizAuxiliar[countI][countJ] = Integer
.parseInt(cadenaleida);
matrizAuxiliar[countJ][countI] = Integer
.parseInt(cadenaleida);
countI++;
countJ = 0;
} else {
matrizAuxiliar[countI][countJ] = Integer
.parseInt(cadenaleida);
matrizAuxiliar[countJ][countI] = Integer
.parseInt(cadenaleida);
countJ++;
}
}
}
}
return matrizAuxiliar;
} |
073df52e-57dd-4511-8c9c-670c82723866 | private int obtenerNumeroDeCiudades(StringTokenizer strTok) {
String tempStr = "";
boolean encontradoNumeroCiudades = false;
while (encontradoNumeroCiudades == false) {
tempStr = strTok.nextToken();
if (tempStr.equals("DIMENSION")) {
strTok.nextToken();
tempStr = strTok.nextToken();
encontradoNumeroCiudades = true;
}
else if (tempStr.equals("DIMENSION:")) {
tempStr = strTok.nextToken();
encontradoNumeroCiudades = true;
}
}
return Integer.parseInt(tempStr);
} |
464fcba8-6735-4ad0-9b08-ffdfbc494343 | public StringTokenizer cargarFichero(String path) {
String contenidoficherocontokens = new String();
if (path != null) {
BufferedReader bufferdelectura;
try {
bufferdelectura = new BufferedReader(new FileReader(path));
while (bufferdelectura.ready())
contenidoficherocontokens += bufferdelectura.readLine()
+ "\n";
} catch (FileNotFoundException e) {
System.err.println(e + "\nArchivo no encontrado."
+ "Escriba el nuevo nombre de archivo y por área.");
} catch (IOException e) {
System.err.println(e
+ "\nError de hardware durante la lectura."
+ "Introduzca el nuevo nombre de archivo y por área.");
}
}
return new StringTokenizer(contenidoficherocontokens, "\n\t\r\f");
} |
6c919574-e902-4e40-9d52-5d19c8ed3273 | public void iniciar(String ficheroaabrir) {
CargarFichero cargarfichero = new CargarFichero();
CrearMatrices creadormatrices = new CrearMatrices();
StringTokenizer contenidofechero = cargarfichero
.cargarFichero(ficheroaabrir);
// Se genera una matriz con la clase creadormatrices que decidira
// dependiendo de la entrada la matriz a crear adecuada
distancias = creadormatrices.generarMatriz(contenidofechero);
// Obtención del número de ciudades a partir del tamaño de la matriz
numerodeciudades = distancias.length;
// Se contruyen las matrices necesarias a partir del número de ciudades
mejorrecorrido = new int[numerodeciudades];
visitadas = new boolean[numerodeciudades];
generarTour();
inicioFeromonasYvisibilidad();
} |
faf33b16-9031-4a70-9511-ab7b4bdb512b | public void ejecutar() {
construirNuevoTour();
} |
05836973-456b-4c1a-aa52-1dc0afb84a34 | public void finalizar() {
mostrarMejorRuta();
} |
56eb0eab-a520-41d1-b0be-63f58fcbdf86 | private void mostrarMejorRuta() {
SalidaDeDatos output = new SalidaDeDatos();
StringBuilder mensaje = new StringBuilder();
mensaje.append(mejorlongitudderecorrido);
output.mostrarPorPantalla(mensaje.toString(), "#defecto");
// Limpia el buffer completo para crear un nuevo mensaje
// reusando el objeto salida de datos.
mensaje.delete(0, mensaje.length());
for (int i = 0; i < numerodeciudades + 1; i++) {
mensaje.append(mejorrecorrido[i]).append(" ");
}
output.mostrarPorPantalla(mensaje.toString(), "#defecto");
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.